Changeset 04803bf in mainline for uspace/srv/hid/console/gcons.c


Ignore:
Timestamp:
2011-03-21T22:00:17Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
143932e3
Parents:
b50b5af2 (diff), 7308e84 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes (needs fixes).

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/console/gcons.c

    rb50b5af2 r04803bf  
    3434
    3535#include <ipc/fb.h>
    36 #include <ipc/ipc.h>
    3736#include <async.h>
    3837#include <stdio.h>
    3938#include <sys/mman.h>
    40 #include <string.h>
     39#include <str.h>
    4140#include <align.h>
    4241#include <bool.h>
     
    5453#define STATUS_HEIGHT  48
    5554
    56 #define MAIN_COLOR  0xffffff
     55#define COLOR_MAIN        0xffffff
     56#define COLOR_FOREGROUND  0x202020
     57#define COLOR_BACKGROUND  0xffffff
     58
     59extern char _binary_gfx_helenos_ppm_start[0];
     60extern int _binary_gfx_helenos_ppm_size;
     61extern char _binary_gfx_nameic_ppm_start[0];
     62extern int _binary_gfx_nameic_ppm_size;
     63
     64extern char _binary_gfx_anim_1_ppm_start[0];
     65extern int _binary_gfx_anim_1_ppm_size;
     66extern char _binary_gfx_anim_2_ppm_start[0];
     67extern int _binary_gfx_anim_2_ppm_size;
     68extern char _binary_gfx_anim_3_ppm_start[0];
     69extern int _binary_gfx_anim_3_ppm_size;
     70extern char _binary_gfx_anim_4_ppm_start[0];
     71extern int _binary_gfx_anim_4_ppm_size;
     72
     73extern char _binary_gfx_cons_selected_ppm_start[0];
     74extern int _binary_gfx_cons_selected_ppm_size;
     75extern char _binary_gfx_cons_idle_ppm_start[0];
     76extern int _binary_gfx_cons_idle_ppm_size;
     77extern char _binary_gfx_cons_has_data_ppm_start[0];
     78extern int _binary_gfx_cons_has_data_ppm_size;
     79extern char _binary_gfx_cons_kernel_ppm_start[0];
     80extern int _binary_gfx_cons_kernel_ppm_size;
    5781
    5882static bool use_gcons = false;
    59 static ipcarg_t xres;
    60 static ipcarg_t yres;
     83static sysarg_t xres;
     84static sysarg_t yres;
    6185
    6286enum butstate {
     
    82106static size_t active_console = 0;
    83107
    84 size_t mouse_x;
    85 size_t mouse_y;
    86 
    87 bool btn_pressed;
    88 size_t btn_x;
    89 size_t btn_y;
     108static sysarg_t mouse_x = 0;
     109static sysarg_t mouse_y= 0;
     110
     111static bool btn_pressed = false;
     112static sysarg_t btn_x = 0;
     113static sysarg_t btn_y = 0;
    90114
    91115static void vp_switch(int vp)
     
    95119
    96120/** Create view port */
    97 static int vp_create(size_t x, size_t y, size_t width, size_t height)
     121static int vp_create(sysarg_t x, sysarg_t y, sysarg_t width, sysarg_t height)
    98122{
    99123        return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
     
    112136
    113137/** Transparent putchar */
    114 static void tran_putch(wchar_t ch, size_t col, size_t row)
     138static void tran_putch(wchar_t ch, sysarg_t col, sysarg_t row)
    115139{
    116140        async_msg_3(fbphone, FB_PUTCHAR, ch, col, row);
     
    132156               
    133157                char data[5];
    134                 snprintf(data, 5, "%u", index + 1);
     158                snprintf(data, 5, "%zu", index + 1);
    135159               
    136160                size_t i;
     
    241265
    242266/** Return x, where left <= x <= right && |a-x| == min(|a-x|) is smallest */
    243 static inline int limit(size_t a, size_t left, size_t right)
     267static inline ssize_t limit(ssize_t a, ssize_t left, ssize_t right)
    244268{
    245269        if (a < left)
     
    259283void gcons_mouse_move(ssize_t dx, ssize_t dy)
    260284{
    261         mouse_x = limit(mouse_x + dx, 0, xres);
    262         mouse_y = limit(mouse_y + dy, 0, yres);
    263        
    264         async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
    265 }
    266 
    267 static int gcons_find_conbut(int x, int y)
    268 {
    269         int status_start = STATUS_START + (xres - 800) / 2;
     285        ssize_t nx = (ssize_t) mouse_x + dx;
     286        ssize_t ny = (ssize_t) mouse_y + dy;
     287       
     288        /* Until gcons is initalized we don't have the screen resolution */
     289        if (xres == 0 || yres == 0)
     290                return;
     291       
     292        mouse_x = (size_t) limit(nx, 0, xres);
     293        mouse_y = (size_t) limit(ny, 0, yres);
     294       
     295        if (active_console != KERNEL_CONSOLE)
     296                async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
     297}
     298
     299static int gcons_find_conbut(sysarg_t x, sysarg_t y)
     300{
     301        sysarg_t status_start = STATUS_START + (xres - 800) / 2;
    270302       
    271303        if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT))
     
    277309        if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
    278310                return -1;
     311       
    279312        if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
    280313                return -1;
    281314       
    282         return (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
     315        sysarg_t btn = (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
     316       
     317        if (btn < CONSOLE_COUNT)
     318                return btn;
     319       
     320        return -1;
    283321}
    284322
     
    286324 *
    287325 * @param state New state (true - pressed, false - depressed)
     326 *
    288327 */
    289328int gcons_mouse_btn(bool state)
    290329{
    291         int conbut;
     330        /* Ignore mouse clicks if no buttons
     331           are drawn at all */
     332        if (xres < 800)
     333                return -1;
    292334       
    293335        if (state) {
    294                 conbut = gcons_find_conbut(mouse_x, mouse_y);
     336                int conbut = gcons_find_conbut(mouse_x, mouse_y);
    295337                if (conbut != -1) {
    296338                        btn_pressed = true;
     
    306348        btn_pressed = false;
    307349       
    308         conbut = gcons_find_conbut(mouse_x, mouse_y);
     350        int conbut = gcons_find_conbut(mouse_x, mouse_y);
    309351        if (conbut == gcons_find_conbut(btn_x, btn_y))
    310352                return conbut;
     
    312354        return -1;
    313355}
    314 
    315356
    316357/** Draw a PPM pixmap to framebuffer
     
    320361 * @param x Coordinate of upper left corner
    321362 * @param y Coordinate of upper left corner
    322  */
    323 static void draw_pixmap(char *logo, size_t size, int x, int y)
    324 {
    325         char *shm;
    326         int rc;
    327        
     363 *
     364 */
     365static void draw_pixmap(char *logo, size_t size, sysarg_t x, sysarg_t y)
     366{
    328367        /* Create area */
    329         shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
     368        char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
    330369            MAP_ANONYMOUS, 0, 0);
    331370        if (shm == MAP_FAILED)
     
    335374       
    336375        /* Send area */
    337         rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
     376        int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (sysarg_t) shm);
    338377        if (rc)
    339378                goto exit;
    340379       
    341         rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
     380        rc = async_share_out_start(fbphone, shm, PROTO_READ);
    342381        if (rc)
    343382                goto drop;
     
    355394}
    356395
    357 extern char _binary_gfx_helenos_ppm_start[0];
    358 extern int _binary_gfx_helenos_ppm_size;
    359 extern char _binary_gfx_nameic_ppm_start[0];
    360 extern int _binary_gfx_nameic_ppm_size;
    361 
    362396/** Redraws console graphics */
    363397void gcons_redraw_console(void)
    364398{
    365         int i;
    366        
    367399        if (!use_gcons)
    368400                return;
    369401       
    370402        vp_switch(0);
    371         set_rgb_color(MAIN_COLOR, MAIN_COLOR);
     403        set_rgb_color(COLOR_MAIN, COLOR_MAIN);
    372404        clear();
    373405        draw_pixmap(_binary_gfx_helenos_ppm_start,
     
    376408            (size_t) &_binary_gfx_nameic_ppm_size, 5, 17);
    377409       
     410        unsigned int i;
    378411        for (i = 0; i < CONSOLE_COUNT; i++)
    379412                redraw_state(i);
     
    392425static int make_pixmap(char *data, size_t size)
    393426{
    394         char *shm;
    395         int rc;
    396         int pxid = -1;
    397        
    398427        /* Create area */
    399         shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
     428        char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
    400429            MAP_ANONYMOUS, 0, 0);
    401430        if (shm == MAP_FAILED)
     
    404433        memcpy(shm, data, size);
    405434       
     435        int pxid = -1;
     436       
    406437        /* Send area */
    407         rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
     438        int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (sysarg_t) shm);
    408439        if (rc)
    409440                goto exit;
    410441       
    411         rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
     442        rc = async_share_out_start(fbphone, shm, PROTO_READ);
    412443        if (rc)
    413444                goto drop;
     
    431462}
    432463
    433 extern char _binary_gfx_anim_1_ppm_start[0];
    434 extern int _binary_gfx_anim_1_ppm_size;
    435 extern char _binary_gfx_anim_2_ppm_start[0];
    436 extern int _binary_gfx_anim_2_ppm_size;
    437 extern char _binary_gfx_anim_3_ppm_start[0];
    438 extern int _binary_gfx_anim_3_ppm_size;
    439 extern char _binary_gfx_anim_4_ppm_start[0];
    440 extern int _binary_gfx_anim_4_ppm_size;
    441 
    442464static void make_anim(void)
    443465{
    444         int an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
     466        int an = async_req_1_0(fbphone, FB_ANIM_CREATE,
     467            cstatus_vp[KERNEL_CONSOLE]);
    445468        if (an < 0)
    446469                return;
    447470       
    448471        int pm = make_pixmap(_binary_gfx_anim_1_ppm_start,
    449             (int) &_binary_gfx_anim_1_ppm_size);
     472            (size_t) &_binary_gfx_anim_1_ppm_size);
    450473        async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
    451474       
    452475        pm = make_pixmap(_binary_gfx_anim_2_ppm_start,
    453             (int) &_binary_gfx_anim_2_ppm_size);
     476            (size_t) &_binary_gfx_anim_2_ppm_size);
    454477        async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
    455478       
    456479        pm = make_pixmap(_binary_gfx_anim_3_ppm_start,
    457             (int) &_binary_gfx_anim_3_ppm_size);
     480            (size_t) &_binary_gfx_anim_3_ppm_size);
    458481        async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
    459482       
    460483        pm = make_pixmap(_binary_gfx_anim_4_ppm_start,
    461             (int) &_binary_gfx_anim_4_ppm_size);
     484            (size_t) &_binary_gfx_anim_4_ppm_size);
    462485        async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
    463486       
     
    466489        animation = an;
    467490}
    468 
    469 extern char _binary_gfx_cons_selected_ppm_start[0];
    470 extern int _binary_gfx_cons_selected_ppm_size;
    471 extern char _binary_gfx_cons_idle_ppm_start[0];
    472 extern int _binary_gfx_cons_idle_ppm_size;
    473 extern char _binary_gfx_cons_has_data_ppm_start[0];
    474 extern int _binary_gfx_cons_has_data_ppm_size;
    475 extern char _binary_gfx_cons_kernel_ppm_start[0];
    476 extern int _binary_gfx_cons_kernel_ppm_size;
    477491
    478492/** Initialize nice graphical console environment */
     
    499513       
    500514        /* Create status buttons */
    501         size_t status_start = STATUS_START + (xres - 800) / 2;
     515        sysarg_t status_start = STATUS_START + (xres - 800) / 2;
    502516        size_t i;
    503517        for (i = 0; i < CONSOLE_COUNT; i++) {
     
    510524               
    511525                vp_switch(cstatus_vp[i]);
    512                 set_rgb_color(0x202020, 0xffffff);
     526                set_rgb_color(COLOR_FOREGROUND, COLOR_BACKGROUND);
    513527        }
    514528       
Note: See TracChangeset for help on using the changeset viewer.