Skip to contentSkip to conversation

ioemu rendering fixes

PATCH In review Stefano Stabellini 1 participant 2 messages Apr 1, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ioemu rendering fixes

Hi all,
I am attaching a patch that fixes some issues regarding ioemu rendering. If you prefer smaller patches, I can split it.
The changes are the following:

- 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.

Best Regards,

Stefano Stabellini

tools/ioemu/hw/vga.c +11 -12
diff -r b5fea3aeb04b tools/ioemu/hw/vga.c
@@ -1086,9 +1086,6 @@ static void vga_draw_text(VGAState *s, i
     vga_draw_glyph8_func *vga_draw_glyph8;
     vga_draw_glyph9_func *vga_draw_glyph9;
 
-    depth = s->get_bpp(s);
-    if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth)
-        s->ds->dpy_colourdepth(s->ds, depth);
     s->rgb_to_pixel = 
         rgb_to_pixel_dup_table[get_depth_index(s->ds)];
 
@@ -1486,7 +1483,7 @@ static void vga_draw_graphic(VGAState *s
 static void vga_draw_graphic(VGAState *s, int full_update)
 {
     int y1, y, update, linesize, y_start, double_scan, mask, depth;
-    int width, height, shift_control, line_offset, bwidth, changed_flag;
+    int width, height, shift_control, line_offset, bwidth, ds_depth;
     ram_addr_t page0, page1;
     int disp_width, multi_scan, multi_run;
     uint8_t *d;
@@ -1499,13 +1496,13 @@ static void vga_draw_graphic(VGAState *s
     s->get_resolution(s, &width, &height);
     disp_width = width;
 
-    changed_flag = 0;
+    ds_depth = s->ds->depth;
     depth = s->get_bpp(s);
     if (s->ds->dpy_colourdepth != NULL && 
-            (s->ds->depth != depth || !s->ds->shared_buf)) {
+            (ds_depth != depth || !s->ds->shared_buf))
         s->ds->dpy_colourdepth(s->ds, depth);
-        changed_flag = 1;
-    }
+    if (ds_depth != s->ds->depth) full_update = 1;
+
     s->rgb_to_pixel = 
         rgb_to_pixel_dup_table[get_depth_index(s->ds)];
 
@@ -1569,17 +1566,18 @@ static void vga_draw_graphic(VGAState *s
     }
 
     vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
-    if (disp_width != s->last_width ||
+    if (s->line_offset != s->last_line_offset || 
+        disp_width != s->last_width ||
         height != s->last_height) {
         dpy_resize(s->ds, disp_width, height, s->line_offset);
         s->last_scr_width = disp_width;
         s->last_scr_height = height;
         s->last_width = disp_width;
         s->last_height = height;
+        s->last_line_offset = s->line_offset; 
         full_update = 1;
-        changed_flag = 1;
-    }
-    if (s->ds->shared_buf && (changed_flag || s->ds->data != s->vram_ptr + (s->start_addr * 4)))
+    }
+    if (s->ds->shared_buf && (full_update || s->ds->data != s->vram_ptr + (s->start_addr * 4)))
         s->ds->dpy_setdata(s->ds, s->vram_ptr + (s->start_addr * 4));
     if (!s->ds->shared_buf && s->cursor_invalidate)
         s->cursor_invalidate(s);
@@ -2072,6 +2070,7 @@ void vga_common_init(VGAState *s, Displa
     s->vram_offset = vga_ram_offset;
     s->vram_size = vga_ram_size;
     s->ds = ds;
+    ds->palette = s->last_palette;
     s->get_bpp = vga_get_bpp;
     s->get_offsets = vga_get_offsets;
     s->get_resolution = vga_get_resolution;
tools/ioemu/hw/vga_int.h +1 -0
diff -r b5fea3aeb04b tools/ioemu/hw/vga_int.h
@@ -129,6 +129,7 @@
     uint32_t line_compare;                                              \
     uint32_t start_addr;                                                \
     uint32_t plane_updated;                                             \
+    uint32_t last_line_offset;                                          \
     uint8_t last_cw, last_ch;                                           \
     uint32_t last_width, last_height; /* in chars or pixels */          \
     uint32_t last_scr_width, last_scr_height; /* in pixels */           \
tools/ioemu/sdl.c +30 -6
diff -r b5fea3aeb04b tools/ioemu/sdl.c
@@ -85,19 +85,33 @@ static void opengl_setdata(DisplayState 
     glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
     switch (ds->depth) {
         case 8:
-            tex_format = GL_RGB;
-            tex_type = GL_UNSIGNED_BYTE_3_3_2;
-            glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
+            if (ds->palette == NULL) {
+                tex_format = GL_RGB;
+                tex_type = GL_UNSIGNED_BYTE_3_3_2;
+            } else {
+                int i;
+                GLushort paletter[256], paletteg[256], paletteb[256];
+                for (i = 0; i < 256; i++) {
+                    uint8_t rgb = ds->palette[i] >> 16;
+                    paletter[i] = ((rgb & 0xe0) >> 5) * 65535 / 7;
+                    paletteg[i] = ((rgb & 0x1c) >> 2) * 65535 / 7;
+                    paletteb[i] = (rgb & 0x3) * 65535 / 3;
+                }
+                glPixelMapusv(GL_PIXEL_MAP_I_TO_R, 256, paletter);
+                glPixelMapusv(GL_PIXEL_MAP_I_TO_G, 256, paletteg);
+                glPixelMapusv(GL_PIXEL_MAP_I_TO_B, 256, paletteb);
+
+                tex_format = GL_COLOR_INDEX;
+                tex_type = GL_UNSIGNED_BYTE;
+            }
             break;
         case 16:
             tex_format = GL_RGB;
             tex_type = GL_UNSIGNED_SHORT_5_6_5;
-            glPixelStorei (GL_UNPACK_ALIGNMENT, 2);
             break;
         case 24:
             tex_format = GL_BGR;
             tex_type = GL_UNSIGNED_BYTE;
-            glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
             break;
         case 32:
             if (!ds->bgr) {
@@ -107,7 +121,6 @@ static void opengl_setdata(DisplayState 
                 tex_format = GL_RGBA;
                 tex_type = GL_UNSIGNED_BYTE;                
             }
-            glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
             break;
     }   
     glPixelStorei(GL_UNPACK_ROW_LENGTH, (ds->linesize * 8) / ds->depth);
@@ -184,6 +197,17 @@ static void sdl_setdata(DisplayState *ds
             return;
     }
     shared = SDL_CreateRGBSurfaceFrom(pixels, width, height, ds->depth, ds->linesize, rmask , gmask, bmask, amask);
+    if (ds->depth == 8 && ds->palette != NULL) {
+        SDL_Color palette[256];
+        int i;
+        for (i = 0; i < 256; i++) {
+            uint8_t rgb = ds->palette[i] >> 16;
+            palette[i].r = ((rgb & 0xe0) >> 5) * 255 / 7;
+            palette[i].g = ((rgb & 0x1c) >> 2) * 255 / 7;
+            palette[i].b = (rgb & 0x3) * 255 / 3;
+        }
+        SDL_SetColors(shared, palette, 0, 256);
+    }
     ds->data = pixels;
 }
 
tools/ioemu/vl.h +1 -0
diff -r b5fea3aeb04b tools/ioemu/vl.h
@@ -937,6 +937,7 @@ struct DisplayState {
     int width;
     int height;
     void *opaque;
+    uint32_t *palette;
     uint64_t gui_timer_interval;
 
     int switchbpp;
tools/ioemu/vnc.c +1 -0
diff -r b5fea3aeb04b tools/ioemu/vnc.c
@@ -1640,6 +1640,7 @@ static void vnc_dpy_colourdepth(DisplayS
             if (ds->depth == 32) return;
             depth = 32;
             break;
+        case 8:
         case 0:
             ds->shared_buf = 0;
             return;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 7 lines · Stefano Stabellini

Hi all,
I am attaching a patch that fixes some issues regarding ioemu rendering. If you prefer smaller patches, I can split it.
The changes are the following:

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

Samuel helped me realize that this callback is useful when switching back from graphical mode to text mode. In fact the mistake is that in this case sdl colourdepth doesn't disable buffer sharing.

I am resending the patch fixed.

tools/ioemu/hw/vga.c +11 -9
diff -r db943e8d1051 tools/ioemu/hw/vga.c
@@ -1486,7 +1486,7 @@ static void vga_draw_graphic(VGAState *s
 static void vga_draw_graphic(VGAState *s, int full_update)
 {
     int y1, y, update, linesize, y_start, double_scan, mask, depth;
-    int width, height, shift_control, line_offset, bwidth, changed_flag;
+    int width, height, shift_control, line_offset, bwidth, ds_depth;
     ram_addr_t page0, page1;
     int disp_width, multi_scan, multi_run;
     uint8_t *d;
@@ -1499,13 +1499,13 @@ static void vga_draw_graphic(VGAState *s
     s->get_resolution(s, &width, &height);
     disp_width = width;
 
-    changed_flag = 0;
+    ds_depth = s->ds->depth;
     depth = s->get_bpp(s);
     if (s->ds->dpy_colourdepth != NULL && 
-            (s->ds->depth != depth || !s->ds->shared_buf)) {
+            (ds_depth != depth || !s->ds->shared_buf))
         s->ds->dpy_colourdepth(s->ds, depth);
-        changed_flag = 1;
-    }
+    if (ds_depth != s->ds->depth) full_update = 1;
+
     s->rgb_to_pixel = 
         rgb_to_pixel_dup_table[get_depth_index(s->ds)];
 
@@ -1569,17 +1569,18 @@ static void vga_draw_graphic(VGAState *s
     }
 
     vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
-    if (disp_width != s->last_width ||
+    if (s->line_offset != s->last_line_offset || 
+        disp_width != s->last_width ||
         height != s->last_height) {
         dpy_resize(s->ds, disp_width, height, s->line_offset);
         s->last_scr_width = disp_width;
         s->last_scr_height = height;
         s->last_width = disp_width;
         s->last_height = height;
+        s->last_line_offset = s->line_offset; 
         full_update = 1;
-        changed_flag = 1;
-    }
-    if (s->ds->shared_buf && (changed_flag || s->ds->data != s->vram_ptr + (s->start_addr * 4)))
+    }
+    if (s->ds->shared_buf && (full_update || s->ds->data != s->vram_ptr + (s->start_addr * 4)))
         s->ds->dpy_setdata(s->ds, s->vram_ptr + (s->start_addr * 4));
     if (!s->ds->shared_buf && s->cursor_invalidate)
         s->cursor_invalidate(s);
@@ -2072,6 +2073,7 @@ void vga_common_init(VGAState *s, Displa
     s->vram_offset = vga_ram_offset;
     s->vram_size = vga_ram_size;
     s->ds = ds;
+    ds->palette = s->last_palette;
     s->get_bpp = vga_get_bpp;
     s->get_offsets = vga_get_offsets;
     s->get_resolution = vga_get_resolution;
tools/ioemu/hw/vga_int.h +1 -0
diff -r db943e8d1051 tools/ioemu/hw/vga_int.h
@@ -129,6 +129,7 @@
     uint32_t line_compare;                                              \
     uint32_t start_addr;                                                \
     uint32_t plane_updated;                                             \
+    uint32_t last_line_offset;                                          \
     uint8_t last_cw, last_ch;                                           \
     uint32_t last_width, last_height; /* in chars or pixels */          \
     uint32_t last_scr_width, last_scr_height; /* in pixels */           \
tools/ioemu/sdl.c +34 -7

73 lines not on this page · raw message

tools/ioemu/vl.h +1 -0
diff -r db943e8d1051 tools/ioemu/vl.h
@@ -937,6 +937,7 @@ struct DisplayState {
     int width;
     int height;
     void *opaque;
+    uint32_t *palette;
     uint64_t gui_timer_interval;
 
     int switchbpp;
tools/ioemu/vnc.c +1 -0
diff -r db943e8d1051 tools/ioemu/vnc.c
@@ -1640,6 +1640,7 @@ static void vnc_dpy_colourdepth(DisplayS
             if (ds->depth == 32) return;
             depth = 32;
             break;
+        case 8:
         case 0:
             ds->shared_buf = 0;
             return;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel