Changeset a7d2d78 in mainline for console/gcons.c


Ignore:
Timestamp:
2006-06-03T22:49:28Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2400469
Parents:
1f36e90
Message:

Completed graphical console.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • console/gcons.c

    r1f36e90 ra7d2d78  
    3333#include <sys/mman.h>
    3434#include <string.h>
     35#include <align.h>
    3536
    3637#include "console.h"
     
    3839
    3940#define CONSOLE_TOP      65
    40 #define CONSOLE_MARGIN   10
    41 
    42 #define STATUS_START    120
    43 #define STATUS_SPACE    5
    44 #define STATUS_WIDTH    40
    45 #define STATUS_HEIGHT   30
     41#define CONSOLE_MARGIN   6
     42
     43#define STATUS_START    110
     44#define STATUS_TOP      8
     45#define STATUS_SPACE    3
     46#define STATUS_WIDTH    48
     47#define STATUS_HEIGHT   48
    4648
    4749#define MAIN_COLOR      0xffffff
     
    5052static ipcarg_t xres,yres;
    5153
     54enum butstate {
     55        CONS_DISCONNECTED = 0,
     56        CONS_SELECTED,
     57        CONS_IDLE,
     58        CONS_HAS_DATA,
     59        CONS_KERNEL,
     60        CONS_DISCONNECTED_SEL,
     61        CONS_LAST
     62};
     63
    5264static int console_vp;
    5365static int cstatus_vp[CONSOLE_COUNT];
    54 static int console_has_input[CONSOLE_COUNT];
    5566static int cstat_row, cstat_col; /* Size of cstatus buttons */
     67static enum butstate console_state[CONSOLE_COUNT];
    5668
    5769static int fbphone;
    5870
    59 enum butstate {
    60         CONS_ACTIVE = 0,
    61         CONS_IDLE,
    62         CONS_HAS_INPUT,
    63         CONS_DISCONNECTED
    64 };
    65 
    66 static struct {
    67         int fgcolor;
    68         int bgcolor;
    69 } stat_colors[] = {
    70         {0xd0d0d0, 0x808080},
    71         {0xd0d0d0, 0x0},
    72         {0xd0d0d0, 0xa04040},
    73         {0xd0d0d0, 0x0}
    74 };
     71/** List of pixmaps identifying these icons */
     72static int ic_pixmaps[CONS_LAST] = {-1,-1,-1,-1,-1,-1};
    7573
    7674static int active_console = 0;
     
    107105}
    108106
    109 static void draw_stat(int consnum, enum butstate state)
     107static void redraw_state(int consnum)
    110108{
    111109        char data[5];
    112110        int i;
    113        
     111        enum butstate state = console_state[consnum];
     112
    114113        vp_switch(cstatus_vp[consnum]);
    115         set_style(stat_colors[state].fgcolor, stat_colors[state].bgcolor);
    116         clear();
    117         if (state != CONS_DISCONNECTED) {
    118                 snprintf(data, 5, "%d", consnum+1);
    119                 for (i=0;data[i];i++)
    120                         putch(data[i], 0, i);
     114        if (ic_pixmaps[state] != -1)
     115                nsend_call_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum], ic_pixmaps[state]);
     116
     117        if (state != CONS_DISCONNECTED && state != CONS_KERNEL && state != CONS_DISCONNECTED_SEL) {
     118                snprintf(data, 5, "%d", consnum+1);
     119                for (i=0;data[i];i++)
     120                        putch(data[i], 1, 2+i);
     121        }
     122}
     123
     124/** Notification run on changing console (except kernel console) */
     125void gcons_change_console(int consnum)
     126{
     127        int i;
     128
     129        if (!use_gcons)
     130                return;
     131
     132        if (active_console == KERNEL_CONSOLE) {
     133                for (i=0; i < CONSOLE_COUNT; i++)
     134                        redraw_state(i);
     135        } else {
     136                if (console_state[active_console] == CONS_DISCONNECTED_SEL)
     137                        console_state[active_console] = CONS_DISCONNECTED;
     138                else
     139                        console_state[active_console] = CONS_IDLE;
     140                redraw_state(active_console);
    121141        }
    122 }
    123 
    124 void gcons_change_console(int consnum)
    125 {
    126         if (!use_gcons)
    127                 return;
    128 
    129         if (active_console != -1)
    130                 draw_stat(active_console, CONS_IDLE);
    131142        active_console = consnum;
    132         draw_stat(consnum, CONS_ACTIVE);
    133         console_has_input[consnum] = 0;
     143
     144        if (console_state[consnum] == CONS_DISCONNECTED) {
     145                console_state[consnum] = CONS_DISCONNECTED_SEL;
     146                redraw_state(consnum);
     147        } else
     148                console_state[consnum] = CONS_SELECTED;
     149        redraw_state(consnum);
    134150
    135151        vp_switch(console_vp);
     
    142158                return;
    143159
    144         if (consnum == active_console || console_has_input[consnum])
    145                 return;
    146 
    147         console_has_input[consnum] = 1;
    148 
    149         if (active_console == -1)
    150                 return;
    151 
    152         draw_stat(consnum, CONS_HAS_INPUT);
     160        if (consnum == active_console || console_state[consnum] == CONS_HAS_DATA)
     161                return;
     162
     163        console_state[consnum] = CONS_HAS_DATA;
     164
     165        if (active_console == KERNEL_CONSOLE)
     166                return;
     167
     168        redraw_state(consnum);
    153169       
    154170        vp_switch(console_vp);
    155 
     171}
     172
     173void gcons_notify_connect(int consnum)
     174{
     175        if (!use_gcons)
     176                return;
     177        if (active_console == consnum)
     178                console_state[consnum] = CONS_SELECTED;
     179        else
     180                console_state[consnum] = CONS_IDLE;
     181
     182        if (active_console == KERNEL_CONSOLE)
     183                return;
     184
     185        redraw_state(consnum);
     186        vp_switch(console_vp);
    156187}
    157188
     
    159190void gcons_in_kernel(void)
    160191{
    161         draw_stat(active_console, CONS_IDLE);
    162         active_console = -1; /* Set to kernel console */
     192        if (console_state[active_console] = CONS_DISCONNECTED_SEL)
     193                console_state[active_console] = CONS_DISCONNECTED;
     194        else
     195                console_state[active_console] = CONS_IDLE;
     196        redraw_state(active_console);
     197
     198        active_console = KERNEL_CONSOLE; /* Set to kernel console */
    163199        vp_switch(0);
    164200}
     
    190226                goto drop;
    191227        /* Draw logo */
    192         send_call_2(fbphone, FB_DRAW_PPM, x, y);
     228        nsend_call_2(fbphone, FB_DRAW_PPM, x, y);
    193229drop:
    194230        /* Drop area */
     
    203239extern char _binary_nameic_ppm_start[0];
    204240extern int _binary_nameic_ppm_size;
    205 void gcons_redraw_console(void)
     241static void gcons_redraw_console(void)
    206242{
    207243        int i;
     
    214250        set_style(MAIN_COLOR, MAIN_COLOR);
    215251        clear();
    216         draw_pixmap(_binary_helenos_ppm_start, (size_t)&_binary_helenos_ppm_size, xres-64, 0);
    217         draw_pixmap(_binary_nameic_ppm_start, (size_t)&_binary_nameic_ppm_size, 5, 10);
     252        draw_pixmap(_binary_helenos_ppm_start, (size_t)&_binary_helenos_ppm_size, xres-66, 2);
     253        draw_pixmap(_binary_nameic_ppm_start, (size_t)&_binary_nameic_ppm_size, 5, 17);
    218254
    219255
    220256        for (i=0;i < CONSOLE_COUNT; i++)
    221                 draw_stat(i, i == active_console ? CONS_ACTIVE : CONS_DISCONNECTED);
     257                redraw_state(i);
    222258        vp_switch(console_vp);
    223259}
    224260
     261static int make_pixmap(char *data, int size)
     262{
     263        char *shm;
     264        int rc;
     265        int pxid = -1;
     266
     267        /* Create area */
     268        shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
     269        if (shm == MAP_FAILED)
     270                return -1;
     271
     272        memcpy(shm, data, size);
     273        /* Send area */
     274        rc = sync_send_2(fbphone, FB_PREPARE_SHM, (ipcarg_t)shm, 0, NULL, NULL);
     275        if (rc)
     276                goto exit;
     277        rc = sync_send_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t)shm, 0, PROTO_READ, NULL, NULL, NULL);
     278        if (rc)
     279                goto drop;
     280
     281        /* Obtain pixmap */
     282        rc = sync_send(fbphone, FB_SHM2PIXMAP, 0, NULL);
     283        if (rc < 0)
     284                goto drop;
     285        pxid = rc;
     286drop:
     287        /* Drop area */
     288        nsend_call(fbphone, FB_DROP_SHM, 0);
     289exit:       
     290        /* Remove area */
     291        munmap(shm, size);
     292
     293        return pxid;
     294}
     295
     296extern char _binary_cons_selected_ppm_start[0];
     297extern int _binary_cons_selected_ppm_size;
     298extern char _binary_cons_idle_ppm_start[0];
     299extern int _binary_cons_idle_ppm_size;
     300extern char _binary_cons_has_data_ppm_start[0];
     301extern int _binary_cons_has_data_ppm_size;
     302extern char _binary_cons_kernel_ppm_start[0];
     303extern int _binary_cons_kernel_ppm_size;
    225304/** Initialize nice graphical console environment */
    226305void gcons_init(int phone)
     
    239318
    240319        /* create console viewport */
    241         console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP, xres-2*CONSOLE_MARGIN,
    242                                yres-(CONSOLE_TOP+CONSOLE_MARGIN));
     320        /* Align width & height to character size */
     321        console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP,
     322                               ALIGN_DOWN(xres-2*CONSOLE_MARGIN, 8),
     323                               ALIGN_DOWN(yres-(CONSOLE_TOP+CONSOLE_MARGIN),16));
    243324        if (console_vp < 0)
    244325                return;
     
    247328        for (i=0; i < CONSOLE_COUNT; i++) {
    248329                cstatus_vp[i] = vp_create(STATUS_START+CONSOLE_MARGIN+i*(STATUS_WIDTH+STATUS_SPACE),
    249                                           CONSOLE_MARGIN, STATUS_WIDTH, STATUS_HEIGHT);
     330                                          STATUS_TOP, STATUS_WIDTH, STATUS_HEIGHT);
    250331                if (cstatus_vp[i] < 0)
    251332                        return;
     333                vp_switch(cstatus_vp[i]);
     334                set_style(0x202020, 0xffffff);
    252335        }
    253336       
     337        /* Initialize icons */
     338        ic_pixmaps[CONS_SELECTED] = make_pixmap(_binary_cons_selected_ppm_start,
     339                                              (int)&_binary_cons_selected_ppm_size);
     340        ic_pixmaps[CONS_IDLE] = make_pixmap(_binary_cons_idle_ppm_start,
     341                                              (int)&_binary_cons_idle_ppm_size);
     342        ic_pixmaps[CONS_HAS_DATA] = make_pixmap(_binary_cons_has_data_ppm_start,
     343                                                (int)&_binary_cons_has_data_ppm_size);
     344        ic_pixmaps[CONS_DISCONNECTED] = make_pixmap(_binary_cons_idle_ppm_start,
     345                                              (int)&_binary_cons_idle_ppm_size);
     346        ic_pixmaps[CONS_KERNEL] = make_pixmap(_binary_cons_kernel_ppm_start,
     347                                              (int)&_binary_cons_kernel_ppm_size);
     348        ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED];
     349
    254350        use_gcons = 1;
     351        console_state[0] = CONS_DISCONNECTED_SEL;
     352        console_state[KERNEL_CONSOLE] = CONS_KERNEL;
    255353        gcons_redraw_console();
    256354}
Note: See TracChangeset for help on using the changeset viewer.