ia64/xen-unstable

changeset 17364:baff5b3aaf13

ioemu rendering fixes

- no need to call the colourdepth callback in text mode: the buffer
cannot be shared anyway;

- line size changes are currently undetected: since we added a
linesize parameter to the resize callback, we also need to detect
line size changes and call dpy_resize accordingly;

- 8 bit colour depth with the shared framebuffer is broken: in order
to fix it I disabled the shared buffer in vnc for the 8bit colour
depth case (it has to be done in software anyway..) and implemented
paletted colours in both opengl and sdl;

- opengl rendering is broken when there is padding in the framebuffer
lines: removing unnecessary GL_UNPACK_ALIGNMENT settings so that the
GL_UNPACK_ROW_LENGTH parameter can work properly.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Apr 01 17:22:52 2008 +0100 (2008-04-01)
parents 69c951243105
children 720552439f74
files tools/ioemu/hw/vga.c tools/ioemu/hw/vga_int.h tools/ioemu/sdl.c tools/ioemu/vl.h tools/ioemu/vnc.c
line diff
     1.1 --- a/tools/ioemu/hw/vga.c	Tue Apr 01 17:21:05 2008 +0100
     1.2 +++ b/tools/ioemu/hw/vga.c	Tue Apr 01 17:22:52 2008 +0100
     1.3 @@ -1486,7 +1486,7 @@ void check_sse2(void)
     1.4  static void vga_draw_graphic(VGAState *s, int full_update)
     1.5  {
     1.6      int y1, y, update, linesize, y_start, double_scan, mask, depth;
     1.7 -    int width, height, shift_control, line_offset, bwidth, changed_flag;
     1.8 +    int width, height, shift_control, line_offset, bwidth, ds_depth;
     1.9      ram_addr_t page0, page1;
    1.10      int disp_width, multi_scan, multi_run;
    1.11      uint8_t *d;
    1.12 @@ -1499,13 +1499,13 @@ static void vga_draw_graphic(VGAState *s
    1.13      s->get_resolution(s, &width, &height);
    1.14      disp_width = width;
    1.15  
    1.16 -    changed_flag = 0;
    1.17 +    ds_depth = s->ds->depth;
    1.18      depth = s->get_bpp(s);
    1.19      if (s->ds->dpy_colourdepth != NULL && 
    1.20 -            (s->ds->depth != depth || !s->ds->shared_buf)) {
    1.21 +            (ds_depth != depth || !s->ds->shared_buf))
    1.22          s->ds->dpy_colourdepth(s->ds, depth);
    1.23 -        changed_flag = 1;
    1.24 -    }
    1.25 +    if (ds_depth != s->ds->depth) full_update = 1;
    1.26 +
    1.27      s->rgb_to_pixel = 
    1.28          rgb_to_pixel_dup_table[get_depth_index(s->ds)];
    1.29  
    1.30 @@ -1569,17 +1569,18 @@ static void vga_draw_graphic(VGAState *s
    1.31      }
    1.32  
    1.33      vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
    1.34 -    if (disp_width != s->last_width ||
    1.35 +    if (s->line_offset != s->last_line_offset || 
    1.36 +        disp_width != s->last_width ||
    1.37          height != s->last_height) {
    1.38          dpy_resize(s->ds, disp_width, height, s->line_offset);
    1.39          s->last_scr_width = disp_width;
    1.40          s->last_scr_height = height;
    1.41          s->last_width = disp_width;
    1.42          s->last_height = height;
    1.43 +        s->last_line_offset = s->line_offset; 
    1.44          full_update = 1;
    1.45 -        changed_flag = 1;
    1.46      }
    1.47 -    if (s->ds->shared_buf && (changed_flag || s->ds->data != s->vram_ptr + (s->start_addr * 4)))
    1.48 +    if (s->ds->shared_buf && (full_update || s->ds->data != s->vram_ptr + (s->start_addr * 4)))
    1.49          s->ds->dpy_setdata(s->ds, s->vram_ptr + (s->start_addr * 4));
    1.50      if (!s->ds->shared_buf && s->cursor_invalidate)
    1.51          s->cursor_invalidate(s);
    1.52 @@ -2072,6 +2073,7 @@ void vga_common_init(VGAState *s, Displa
    1.53      s->vram_offset = vga_ram_offset;
    1.54      s->vram_size = vga_ram_size;
    1.55      s->ds = ds;
    1.56 +    ds->palette = s->last_palette;
    1.57      s->get_bpp = vga_get_bpp;
    1.58      s->get_offsets = vga_get_offsets;
    1.59      s->get_resolution = vga_get_resolution;
     2.1 --- a/tools/ioemu/hw/vga_int.h	Tue Apr 01 17:21:05 2008 +0100
     2.2 +++ b/tools/ioemu/hw/vga_int.h	Tue Apr 01 17:22:52 2008 +0100
     2.3 @@ -129,6 +129,7 @@
     2.4      uint32_t line_compare;                                              \
     2.5      uint32_t start_addr;                                                \
     2.6      uint32_t plane_updated;                                             \
     2.7 +    uint32_t last_line_offset;                                          \
     2.8      uint8_t last_cw, last_ch;                                           \
     2.9      uint32_t last_width, last_height; /* in chars or pixels */          \
    2.10      uint32_t last_scr_width, last_scr_height; /* in pixels */           \
     3.1 --- a/tools/ioemu/sdl.c	Tue Apr 01 17:21:05 2008 +0100
     3.2 +++ b/tools/ioemu/sdl.c	Tue Apr 01 17:22:52 2008 +0100
     3.3 @@ -85,19 +85,33 @@ static void opengl_setdata(DisplayState 
     3.4      glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
     3.5      switch (ds->depth) {
     3.6          case 8:
     3.7 -            tex_format = GL_RGB;
     3.8 -            tex_type = GL_UNSIGNED_BYTE_3_3_2;
     3.9 -            glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
    3.10 +            if (ds->palette == NULL) {
    3.11 +                tex_format = GL_RGB;
    3.12 +                tex_type = GL_UNSIGNED_BYTE_3_3_2;
    3.13 +            } else {
    3.14 +                int i;
    3.15 +                GLushort paletter[256], paletteg[256], paletteb[256];
    3.16 +                for (i = 0; i < 256; i++) {
    3.17 +                    uint8_t rgb = ds->palette[i] >> 16;
    3.18 +                    paletter[i] = ((rgb & 0xe0) >> 5) * 65535 / 7;
    3.19 +                    paletteg[i] = ((rgb & 0x1c) >> 2) * 65535 / 7;
    3.20 +                    paletteb[i] = (rgb & 0x3) * 65535 / 3;
    3.21 +                }
    3.22 +                glPixelMapusv(GL_PIXEL_MAP_I_TO_R, 256, paletter);
    3.23 +                glPixelMapusv(GL_PIXEL_MAP_I_TO_G, 256, paletteg);
    3.24 +                glPixelMapusv(GL_PIXEL_MAP_I_TO_B, 256, paletteb);
    3.25 +
    3.26 +                tex_format = GL_COLOR_INDEX;
    3.27 +                tex_type = GL_UNSIGNED_BYTE;
    3.28 +            }
    3.29              break;
    3.30          case 16:
    3.31              tex_format = GL_RGB;
    3.32              tex_type = GL_UNSIGNED_SHORT_5_6_5;
    3.33 -            glPixelStorei (GL_UNPACK_ALIGNMENT, 2);
    3.34              break;
    3.35          case 24:
    3.36              tex_format = GL_BGR;
    3.37              tex_type = GL_UNSIGNED_BYTE;
    3.38 -            glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
    3.39              break;
    3.40          case 32:
    3.41              if (!ds->bgr) {
    3.42 @@ -107,7 +121,6 @@ static void opengl_setdata(DisplayState 
    3.43                  tex_format = GL_RGBA;
    3.44                  tex_type = GL_UNSIGNED_BYTE;                
    3.45              }
    3.46 -            glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
    3.47              break;
    3.48      }   
    3.49      glPixelStorei(GL_UNPACK_ROW_LENGTH, (ds->linesize * 8) / ds->depth);
    3.50 @@ -184,6 +197,17 @@ static void sdl_setdata(DisplayState *ds
    3.51              return;
    3.52      }
    3.53      shared = SDL_CreateRGBSurfaceFrom(pixels, width, height, ds->depth, ds->linesize, rmask , gmask, bmask, amask);
    3.54 +    if (ds->depth == 8 && ds->palette != NULL) {
    3.55 +        SDL_Color palette[256];
    3.56 +        int i;
    3.57 +        for (i = 0; i < 256; i++) {
    3.58 +            uint8_t rgb = ds->palette[i] >> 16;
    3.59 +            palette[i].r = ((rgb & 0xe0) >> 5) * 255 / 7;
    3.60 +            palette[i].g = ((rgb & 0x1c) >> 2) * 255 / 7;
    3.61 +            palette[i].b = (rgb & 0x3) * 255 / 3;
    3.62 +        }
    3.63 +        SDL_SetColors(shared, palette, 0, 256);
    3.64 +    }
    3.65      ds->data = pixels;
    3.66  }
    3.67  
    3.68 @@ -273,7 +297,10 @@ static void sdl_resize(DisplayState *ds,
    3.69  
    3.70  static void sdl_colourdepth(DisplayState *ds, int depth)
    3.71  {
    3.72 -    if (!depth || !ds->depth) return;
    3.73 +    if (!depth || !ds->depth) {
    3.74 +        ds->shared_buf = 0;
    3.75 +        return;
    3.76 +    }
    3.77      ds->shared_buf = 1;
    3.78      ds->depth = depth;
    3.79      ds->linesize = width * depth / 8;
     4.1 --- a/tools/ioemu/vl.h	Tue Apr 01 17:21:05 2008 +0100
     4.2 +++ b/tools/ioemu/vl.h	Tue Apr 01 17:22:52 2008 +0100
     4.3 @@ -937,6 +937,7 @@ struct DisplayState {
     4.4      int width;
     4.5      int height;
     4.6      void *opaque;
     4.7 +    uint32_t *palette;
     4.8      uint64_t gui_timer_interval;
     4.9  
    4.10      int switchbpp;
     5.1 --- a/tools/ioemu/vnc.c	Tue Apr 01 17:21:05 2008 +0100
     5.2 +++ b/tools/ioemu/vnc.c	Tue Apr 01 17:22:52 2008 +0100
     5.3 @@ -1640,6 +1640,7 @@ static void vnc_dpy_colourdepth(DisplayS
     5.4              if (ds->depth == 32) return;
     5.5              depth = 32;
     5.6              break;
     5.7 +        case 8:
     5.8          case 0:
     5.9              ds->shared_buf = 0;
    5.10              return;