Changeset a7d2d78 in mainline


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.

Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • console/Makefile

    r1f36e90 ra7d2d78  
    4848        gcons.c
    4949
    50 IMAGES = helenos.ppm nameic.ppm
     50IMAGES = helenos.ppm nameic.ppm cons_selected.ppm cons_idle.ppm \
     51        cons_has_data.ppm cons_kernel.ppm
    5152
    5253ARCH_SOURCES =
  • console/console.c

    r1f36e90 ra7d2d78  
    227227                return;
    228228
    229         if (newcons == -1) {
    230                 if (active_console == -1)
     229        if (newcons == KERNEL_CONSOLE) {
     230                if (active_console == KERNEL_CONSOLE)
    231231                        return;
    232                 active_console = -1;
     232                active_console = KERNEL_CONSOLE;
    233233                curs_visibility(0);
    234234
     
    307307                        if ((c >= '0') && (c < '0' + CONSOLE_COUNT)) {
    308308                                if (c == '0')
    309                                         change_console(-1);
     309                                        change_console(KERNEL_CONSOLE);
    310310                                else
    311311                                        change_console(c - '1');
     
    343343                return;
    344344        }
    345 
     345       
     346        gcons_notify_connect(consnum);
    346347        connections[consnum].used = 1;
    347348        connections[consnum].client_phone = IPC_GET_ARG3(call);
  • console/console.h

    r1f36e90 ra7d2d78  
    3030#define __CONSOLE_H__
    3131
     32#define KERNEL_CONSOLE 9
     33
    3234#define CONSOLE_COUNT 12
    3335
  • 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}
  • console/gcons.h

    r1f36e90 ra7d2d78  
    3434void gcons_notify_char(int consnum);
    3535void gcons_in_kernel(void);
     36void gcons_notify_connect(int consnum);
    3637
    3738#endif
  • fb/fb.c

    r1f36e90 ra7d2d78  
    5555/* Pixel specific fuctions */
    5656
    57 typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color);
    58 typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y);
     57typedef void (*conv2scr_fn_t)(void *, int);
     58typedef int (*conv2rgb_fn_t)(void *);
    5959
    6060struct {
     
    6666        unsigned int pixelbytes ;
    6767
    68         putpixel_fn_t putpixel;
    69         getpixel_fn_t getpixel;
     68        conv2scr_fn_t rgb2scr;
     69        conv2rgb_fn_t scr2rgb;
    7070} screen;
    7171
     
    9191        unsigned int width;
    9292        unsigned int height;
    93         void *data;
     93        __u8 *data;
    9494} pixmap_t;
    9595static pixmap_t pixmaps[MAX_PIXMAPS];
     
    111111#define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
    112112
    113 /** Put pixel - 24-bit depth, 1 free byte */
    114 static void putpixel_4byte(unsigned int x, unsigned int y, int color)
    115 {
    116         *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color;
    117 }
    118 
    119 /** Return pixel color - 24-bit depth, 1 free byte */
    120 static int getpixel_4byte(unsigned int x, unsigned int y)
    121 {
    122         return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff;
    123 }
    124 
    125 /** Put pixel - 24-bit depth */
    126 static void putpixel_3byte(unsigned int x, unsigned int y, int color)
    127 {
    128         unsigned int startbyte = POINTPOS(x, y);
    129 
     113/* Conversion routines between different color representations */
     114static void rgb_4byte(void *dst, int rgb)
     115{
     116        *(int *)dst = rgb;
     117}
     118
     119static int byte4_rgb(void *src)
     120{
     121        return (*(int *)src) & 0xffffff;
     122}
     123
     124static void rgb_3byte(void *dst, int rgb)
     125{
     126        __u8 *scr = dst;
    130127#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
    131         screen.fbaddress[startbyte] = RED(color, 8);
    132         screen.fbaddress[startbyte + 1] = GREEN(color, 8);
    133         screen.fbaddress[startbyte + 2] = BLUE(color, 8);
     128        scr[0] = RED(rgb, 8);
     129        scr[1] = GREEN(rgb, 8);
     130        scr[2] = BLUE(rgb, 8);
    134131#else
    135         screen.fbaddress[startbyte + 2] = RED(color, 8);
    136         screen.fbaddress[startbyte + 1] = GREEN(color, 8);
    137         screen.fbaddress[startbyte + 0] = BLUE(color, 8);
     132        scr[2] = RED(rgb, 8);
     133        scr[1] = GREEN(rgb, 8);
     134        scr[0] = BLUE(rgb, 8);
    138135#endif
    139136
    140 }
    141 
    142 /** Return pixel color - 24-bit depth */
    143 static int getpixel_3byte(unsigned int x, unsigned int y)
    144 {
    145         unsigned int startbyte = POINTPOS(x, y);
    146 
    147 
    148 
     137
     138}
     139
     140static int byte3_rgb(void *src)
     141{
     142        __u8 *scr = src;
    149143#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
    150         return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2];
     144        return scr[0] << 16 | scr[1] << 8 | scr[2];
    151145#else
    152         return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0];
    153 #endif
    154                                                                
    155 
    156 }
    157 
    158 /** Put pixel - 16-bit depth (5:6:5) */
    159 static void putpixel_2byte(unsigned int x, unsigned int y, int color)
     146        return scr[2] << 16 | scr[1] << 8 | scr[0];
     147#endif 
     148}
     149
     150/**  16-bit depth (5:6:5) */
     151static void rgb_2byte(void *dst, int rgb)
    160152{
    161153        /* 5-bit, 6-bits, 5-bits */
    162         *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5);
    163 }
    164 
    165 /** Return pixel color - 16-bit depth (5:6:5) */
    166 static int getpixel_2byte(unsigned int x, unsigned int y)
    167 {
    168         int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y)));
     154        *((__u16 *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5);
     155}
     156
     157/** 16-bit depth (5:6:5) */
     158static int byte2_rgb(void *src)
     159{
     160        int color = *(__u16 *)(src);
    169161        return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
    170162}
    171163
    172164/** Put pixel - 8-bit depth (3:2:3) */
    173 static void putpixel_1byte(unsigned int x, unsigned int y, int color)
    174 {
    175         screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3);
     165static void rgb_1byte(void *dst, int rgb)
     166{
     167        *(__u8 *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
    176168}
    177169
    178170/** Return pixel color - 8-bit depth (3:2:3) */
    179 static int getpixel_1byte(unsigned int x, unsigned int y)
    180 {
    181         int color = screen.fbaddress[POINTPOS(x, y)];
     171static int byte1_rgb(void *src)
     172{
     173        int color = *(__u8 *)src;
    182174        return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
    183175}
     
    192184static void putpixel(int vp, unsigned int x, unsigned int y, int color)
    193185{
    194         screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color);
     186        int dx = viewports[vp].x + x;
     187        int dy = viewports[vp].y + y;
     188        (*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)],color);
    195189}
    196190/** Get pixel from viewport */
    197191static int getpixel(int vp, unsigned int x, unsigned int y)
    198192{
    199         return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y);
     193        int dx = viewports[vp].x + x;
     194        int dy = viewports[vp].y + y;
     195
     196        return (*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx,dy)]);
    200197}
    201198
     
    359356        switch (bpp) {
    360357                case 8:
    361                         screen.putpixel = putpixel_1byte;
    362                         screen.getpixel = getpixel_1byte;
     358                        screen.rgb2scr = rgb_1byte;
     359                        screen.scr2rgb = byte1_rgb;
    363360                        screen.pixelbytes = 1;
    364361                        break;
    365362                case 16:
    366                         screen.putpixel = putpixel_2byte;
    367                         screen.getpixel = getpixel_2byte;
     363                        screen.rgb2scr = rgb_2byte;
     364                        screen.scr2rgb = byte2_rgb;
    368365                        screen.pixelbytes = 2;
    369366                        break;
    370367                case 24:
    371                         screen.putpixel = putpixel_3byte;
    372                         screen.getpixel = getpixel_3byte;
     368                        screen.rgb2scr = rgb_3byte;
     369                        screen.scr2rgb = byte3_rgb;
    373370                        screen.pixelbytes = 3;
    374371                        break;
    375372                case 32:
    376                         screen.putpixel = putpixel_4byte;
    377                         screen.getpixel = getpixel_4byte;
     373                        screen.rgb2scr = rgb_4byte;
     374                        screen.scr2rgb = byte4_rgb;
    378375                        screen.pixelbytes = 4;
    379376                        break;
     
    478475}
    479476
     477
     478/** Return first free pixmap */
     479static int find_free_pixmap(void)
     480{
     481        int i;
     482       
     483        for (i=0;i < MAX_PIXMAPS;i++)
     484                if (!pixmaps[i].data)
     485                        return i;
     486        return -1;
     487}
     488
     489static void putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color)
     490{
     491        pixmap_t *pmap = &pixmaps[pm];
     492        int pos = (y * pmap->width + x) * screen.pixelbytes;
     493
     494        (*screen.rgb2scr)(&pmap->data[pos],color);
     495}
     496
     497/** Create a new pixmap and return appropriate ID */
     498static int shm2pixmap(char *shm, size_t size)
     499{
     500        int pm;
     501        pixmap_t *pmap;
     502
     503        pm = find_free_pixmap();
     504        if (pm == -1)
     505                return ELIMIT;
     506        pmap = &pixmaps[pm];
     507       
     508        if (ppm_get_data(shm, size, &pmap->width, &pmap->height))
     509                return EINVAL;
     510       
     511        pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes);
     512        if (!pmap->data)
     513                return ENOMEM;
     514
     515        ppm_draw(shm, size, 0, 0, pmap->width, pmap->height,
     516                 putpixel_pixmap, pm);
     517
     518        return pm;
     519}
     520
    480521/** Handle shared memory communication calls
    481522 *
     
    503544        static size_t intersize = 0;
    504545
    505         static char *pixmap = NULL;
    506         static ipcarg_t pixmap_id = 0;
    507         static size_t pixmap_size;
     546        static char *shm = NULL;
     547        static ipcarg_t shm_id = 0;
     548        static size_t shm_size;
    508549
    509550        int handled = 1;
     
    515556        case IPC_M_AS_AREA_SEND:
    516557                /* We accept one area for data interchange */
    517                 if (IPC_GET_ARG1(*call) == pixmap_id) {
     558                if (IPC_GET_ARG1(*call) == shm_id) {
    518559                        void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));
    519                         pixmap_size = IPC_GET_ARG2(*call);
     560                        shm_size = IPC_GET_ARG2(*call);
    520561                        if (!ipc_answer_fast(callid, 0, (sysarg_t)dest, 0))
    521                                 pixmap = dest;
     562                                shm = dest;
    522563                        else
    523                                 pixmap_id = 0;
    524                         if (pixmap[0] != 'P')
     564                                shm_id = 0;
     565                        if (shm[0] != 'P')
    525566                                while (1)
    526567                                        ;
     
    532573                return 1;
    533574        case FB_PREPARE_SHM:
    534                 if (pixmap_id)
     575                if (shm_id)
    535576                        retval = EBUSY;
    536577                else
    537                         pixmap_id = IPC_GET_ARG1(*call);
     578                        shm_id = IPC_GET_ARG1(*call);
    538579                break;
    539580               
    540581        case FB_DROP_SHM:
    541                 if (pixmap) {
    542                         as_area_destroy(pixmap);
    543                         pixmap = NULL;
    544                 }
    545                 pixmap_id = 0;
     582                if (shm) {
     583                        as_area_destroy(shm);
     584                        shm = NULL;
     585                }
     586                shm_id = 0;
    546587                break;
    547                
     588
     589        case FB_SHM2PIXMAP:
     590                if (!shm) {
     591                        retval = EINVAL;
     592                        break;
     593                }
     594                retval = shm2pixmap(shm, shm_size);
     595                break;
    548596        case FB_DRAW_PPM:
    549                 if (!pixmap) {
     597                if (!shm) {
    550598                        retval = EINVAL;
    551599                        break;
     
    558606                }
    559607               
    560                 draw_ppm(pixmap, pixmap_size, IPC_GET_ARG1(*call), IPC_GET_ARG2(*call),
     608                ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), IPC_GET_ARG2(*call),
    561609                         vport->width - x, vport->height - y, putpixel, vp);
    562610                break;
     
    579627                ipc_answer_fast(callid, retval, 0, 0);
    580628        return handled;
    581 }
    582 
    583 /** Return first free pixmap */
    584 static int find_free_pixmap(void)
    585 {
    586         int i;
    587        
    588         for (i=0;i < MAX_PIXMAPS;i++)
    589                 if (!pixmaps[i].data)
    590                         return i;
    591         return -1;
    592629}
    593630
  • fb/ppm.c

    r1f36e90 ra7d2d78  
    5757}
    5858
     59int ppm_get_data(unsigned char *data, size_t dtsz, int *width, int *height)
     60{
     61        /* Read magic */
     62        if (data[0] != 'P' || data[1] != '6')
     63                return EINVAL;
     64
     65        data+=2;
     66        skip_whitespace(&data);
     67        read_num(&data, width);
     68        skip_whitespace(&data);
     69        read_num(&data,height);
     70
     71        return 0;
     72}
     73
    5974/** Draw PPM pixmap
    6075 *
     
    6782 * @param putpixel Putpixel function used to print bitmap
    6883 */
    69 int draw_ppm(unsigned char *data, size_t datasz, unsigned int sx,
     84int ppm_draw(unsigned char *data, size_t datasz, unsigned int sx,
    7085             unsigned int sy,
    7186             unsigned int maxwidth, unsigned int maxheight,
     
    105120                        continue;
    106121                }
    107                 color = ((data[0]*coef) << 16) + ((data[1]*coef) << 8) + data[0]*coef;
     122                color = ((data[0]*coef) << 16) + ((data[1]*coef) << 8) + data[2]*coef;
    108123               
    109124                (*putpixel)(vp, sx+(i % width), sy+(i / width), color);
  • fb/ppm.h

    r1f36e90 ra7d2d78  
    3030#define _PPM_H_
    3131
    32 int draw_ppm(unsigned char *data, size_t datasz, unsigned int sx,
     32int ppm_draw(unsigned char *data, size_t datasz, unsigned int sx,
    3333             unsigned int sy,
    3434             unsigned int maxwidth, unsigned int maxheight,
    3535             void (*putpixel)(int,unsigned int, unsigned int, int),int vp);
     36int ppm_get_data(unsigned char *data, size_t dtsz, int *width, int *height);
    3637
    3738#endif
Note: See TracChangeset for help on using the changeset viewer.