Changeset 67b05ff in mainline for uspace/srv/hid/console/gcons.c


Ignore:
Timestamp:
2011-08-10T18:34:23Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c6f08726
Parents:
62e29ae
Message:

cherrypick from fb server rewrite: store images as Truevision TGA (instead of PPM) and use a library to decode them into image maps

File:
1 edited

Legend:

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

    r62e29ae r67b05ff  
    4141#include <align.h>
    4242#include <bool.h>
     43#include <imgmap.h>
    4344
    4445#include "console.h"
    4546#include "gcons.h"
     47#include "images.h"
    4648
    4749#define CONSOLE_TOP     66
     
    5759#define COLOR_FOREGROUND  0x202020
    5860#define COLOR_BACKGROUND  0xffffff
    59 
    60 extern char _binary_gfx_helenos_ppm_start[0];
    61 extern int _binary_gfx_helenos_ppm_size;
    62 extern char _binary_gfx_nameic_ppm_start[0];
    63 extern int _binary_gfx_nameic_ppm_size;
    6461
    6562extern char _binary_gfx_anim_1_ppm_start[0];
     
    8481static sysarg_t xres;
    8582static sysarg_t yres;
     83
     84static imgmap_t *helenos_img;
     85static imgmap_t *nameic_img;
    8686
    8787enum butstate {
     
    358358}
    359359
    360 /** Draw a PPM pixmap to framebuffer
    361  *
    362  * @param logo Pointer to PPM data
    363  * @param size Size of PPM data
    364  * @param x Coordinate of upper left corner
    365  * @param y Coordinate of upper left corner
    366  *
    367  */
    368 static void draw_pixmap(char *logo, size_t size, sysarg_t x, sysarg_t y)
     360/** Draw an image map to framebuffer
     361 *
     362 * @param img  Image map
     363 * @param x    Coordinate of upper left corner
     364 * @param y    Coordinate of upper left corner
     365 *
     366 */
     367static void draw_imgmap(imgmap_t *img, sysarg_t x, sysarg_t y)
     368{
     369        if (img == NULL)
     370                return;
     371       
     372        /* Create area */
     373        char *shm = mmap(NULL, img->size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
     374            MAP_ANONYMOUS, 0, 0);
     375        if (shm == MAP_FAILED)
     376                return;
     377       
     378        memcpy(shm, img, img->size);
     379       
     380        /* Send area */
     381        int rc = async_obsolete_req_1_0(fbphone, FB_PREPARE_SHM, (sysarg_t) shm);
     382        if (rc)
     383                goto exit;
     384       
     385        rc = async_obsolete_share_out_start(fbphone, shm, PROTO_READ);
     386        if (rc)
     387                goto drop;
     388       
     389        /* Draw logo */
     390        async_obsolete_msg_2(fbphone, FB_DRAW_PPM, x, y);
     391       
     392drop:
     393        /* Drop area */
     394        async_obsolete_msg_0(fbphone, FB_DROP_SHM);
     395       
     396exit:
     397        /* Remove area */
     398        munmap(shm, img->size);
     399}
     400
     401/** Redraws console graphics */
     402void gcons_redraw_console(void)
     403{
     404        if (!use_gcons)
     405                return;
     406       
     407        vp_switch(0);
     408        set_rgb_color(COLOR_MAIN, COLOR_MAIN);
     409        clear();
     410        draw_imgmap(helenos_img, xres - 66, 2);
     411        draw_imgmap(nameic_img, 5, 17);
     412       
     413        unsigned int i;
     414        for (i = 0; i < CONSOLE_COUNT; i++)
     415                redraw_state(i);
     416       
     417        vp_switch(console_vp);
     418}
     419
     420/** Creates a pixmap on framebuffer
     421 *
     422 * @param data PPM data
     423 * @param size PPM data size
     424 *
     425 * @return Pixmap identification
     426 *
     427 */
     428static int make_pixmap(char *data, size_t size)
    369429{
    370430        /* Create area */
     
    372432            MAP_ANONYMOUS, 0, 0);
    373433        if (shm == MAP_FAILED)
    374                 return;
    375        
    376         memcpy(shm, logo, size);
     434                return -1;
     435       
     436        memcpy(shm, data, size);
     437       
     438        int pxid = -1;
    377439       
    378440        /* Send area */
     
    385447                goto drop;
    386448       
    387         /* Draw logo */
    388         async_obsolete_msg_2(fbphone, FB_DRAW_PPM, x, y);
    389        
    390 drop:
    391         /* Drop area */
    392         async_obsolete_msg_0(fbphone, FB_DROP_SHM);
    393        
    394 exit:
    395         /* Remove area */
    396         munmap(shm, size);
    397 }
    398 
    399 /** Redraws console graphics */
    400 void gcons_redraw_console(void)
    401 {
    402         if (!use_gcons)
    403                 return;
    404        
    405         vp_switch(0);
    406         set_rgb_color(COLOR_MAIN, COLOR_MAIN);
    407         clear();
    408         draw_pixmap(_binary_gfx_helenos_ppm_start,
    409             (size_t) &_binary_gfx_helenos_ppm_size, xres - 66, 2);
    410         draw_pixmap(_binary_gfx_nameic_ppm_start,
    411             (size_t) &_binary_gfx_nameic_ppm_size, 5, 17);
    412        
    413         unsigned int i;
    414         for (i = 0; i < CONSOLE_COUNT; i++)
    415                 redraw_state(i);
    416        
    417         vp_switch(console_vp);
    418 }
    419 
    420 /** Creates a pixmap on framebuffer
    421  *
    422  * @param data PPM data
    423  * @param size PPM data size
    424  *
    425  * @return Pixmap identification
    426  *
    427  */
    428 static int make_pixmap(char *data, size_t size)
    429 {
    430         /* Create area */
    431         char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
    432             MAP_ANONYMOUS, 0, 0);
    433         if (shm == MAP_FAILED)
    434                 return -1;
    435        
    436         memcpy(shm, data, size);
    437        
    438         int pxid = -1;
    439        
    440         /* Send area */
    441         int rc = async_obsolete_req_1_0(fbphone, FB_PREPARE_SHM, (sysarg_t) shm);
    442         if (rc)
    443                 goto exit;
    444        
    445         rc = async_obsolete_share_out_start(fbphone, shm, PROTO_READ);
    446         if (rc)
    447                 goto drop;
    448        
    449449        /* Obtain pixmap */
    450450        rc = async_obsolete_req_0_0(fbphone, FB_SHM2PIXMAP);
     
    504504        if ((xres < 800) || (yres < 600))
    505505                return;
     506       
     507        /* Create image maps */
     508        helenos_img = imgmap_decode_tga((void *) helenos_tga);
     509        nameic_img = imgmap_decode_tga((void *) nameic_tga);
    506510       
    507511        /* Create console viewport */
Note: See TracChangeset for help on using the changeset viewer.