diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2019-02-03 18:28:22 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2019-02-03 18:28:22 +0100 |
commit | fb7fa435af36197db5493775d01b4339484ae225 (patch) | |
tree | 53730e209810b2b708a38ac642a3283d80c0e285 | |
parent | c2f9a4886c3597a6e15a67323313555bc9752a58 (diff) | |
download | fbida-fb7fa435af36197db5493775d01b4339484ae225.tar.gz |
fmt wireup, framebuffer
-rw-r--r-- | fbtools.c | 37 | ||||
-rw-r--r-- | gfx.c | 13 | ||||
-rw-r--r-- | gfx.h | 3 |
3 files changed, 29 insertions, 24 deletions
@@ -76,21 +76,6 @@ static void fb_linear_palette(int r, int g, int b) p_cmap.len = size; } -static void fb_dither_palette(int r, int g, int b) -{ - int rs, gs, bs, i; - - rs = 256 / (r - 1); - gs = 256 / (g - 1); - bs = 256 / (b - 1); - for (i = 0; i < 256; i++) { - p_red[i] = color_scale(rs * ((i / (g * b)) % r), 255); - p_green[i] = color_scale(gs * ((i / b) % g), 255); - p_blue[i] = color_scale(bs * ((i) % b), 255); - } - p_cmap.len = 256; -} - static void fb_set_palette(void) { if (fb_fix.visual != FB_VISUAL_DIRECTCOLOR && fb_var.bits_per_pixel != 8) @@ -225,6 +210,7 @@ gfxstate* fb_init(const char *device, char *mode) unsigned long page_mask; struct stat st; gfxstate *gfx; + gfxfmt *fmt = NULL; if (NULL == device) { device = getenv("FRAMEBUFFER"); @@ -294,24 +280,26 @@ gfxstate* fb_init(const char *device, char *mode) /* init palette */ switch (fb_var.bits_per_pixel) { - case 8: - fb_dither_palette(8, 8, 4); - break; case 15: + fmt = gfx_fmt_find_pixman(PIXMAN_x1r5g5b5); + fb_linear_palette(5,5,5); + break; case 16: - if (fb_var.green.length == 5) { - fb_linear_palette(5,5,5); - } else { - fb_linear_palette(5,6,5); - } + fmt = gfx_fmt_find_pixman(PIXMAN_r5g6b5); + fb_linear_palette(5,6,5); break; - case 24: case 32: + fmt = gfx_fmt_find_pixman(PIXMAN_x8r8g8b8); fb_linear_palette(8,8,8); break; } fb_set_palette(); + if (!fmt) { + fprintf(stderr,"can't handle framebuffer format\n"); + goto err; + } + /* prepare gfx */ gfx = malloc(sizeof(*gfx)); memset(gfx, 0, sizeof(*gfx)); @@ -320,6 +308,7 @@ gfxstate* fb_init(const char *device, char *mode) gfx->vdisplay = fb_var.yres; gfx->stride = fb_fix.line_length; gfx->mem = fb_mem; + gfx->fmt = fmt; gfx->rlen = fb_var.red.length; gfx->glen = fb_var.green.length; @@ -1,3 +1,4 @@ +#include <stdlib.h> #include <endian.h> #include <fcntl.h> #include <sys/types.h> @@ -49,3 +50,15 @@ gfxfmt fmt_list[] = { }; uint32_t fmt_count = ARRAY_SIZE(fmt_list); + +gfxfmt *gfx_fmt_find_pixman(pixman_format_code_t pixman) +{ + int i; + + for (i = 0; i < fmt_count; i++) { + if (pixman != fmt_list[i].pixman) + continue; + return fmt_list + i; + } + return NULL; +} @@ -28,6 +28,8 @@ struct gfxfmt { extern gfxfmt fmt_list[]; extern uint32_t fmt_count; +gfxfmt *gfx_fmt_find_pixman(pixman_format_code_t pixman); + struct gfxstate { /* info */ uint32_t hdisplay; @@ -35,6 +37,7 @@ struct gfxstate { uint32_t stride; uint8_t *mem; uint8_t *mem2; + gfxfmt *fmt; uint32_t bits_per_pixel; uint32_t rlen, glen, blen, tlen; |