Skip to contentSkip to conversation

qemu sdl blitting

PATCH In review Stefano Stabellini 1 participant 3 messages Feb 29, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu sdl blitting

Hi all,
right now qemu takes care of converting pixels between the guest pixel format and the sdl pixel format, after that qemu also memcpy the converted pixels to the sdl buffer in video ram.
This process can be improved using the SDL blit capabilities: the patch I am attaching creates an SDL Surface from the Cirrus VGA framebuffer and uses SDL blitting functions to convert and write pixels to video ram. SDL blitting functions are optimized and can even be hardware accelerated on some platforms.

Best Regards,

Stefano Stabelllini

tools/ioemu/hw/vga.c +9 -6
diff -r 2a8eaba24bf0 tools/ioemu/hw/vga.c
@@ -1481,7 +1481,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;
+    int width, height, shift_control, line_offset, bwidth, changed_flag;
     ram_addr_t page0, page1;
     int disp_width, multi_scan, multi_run;
     uint8_t *d;
@@ -1554,10 +1554,12 @@ static void vga_draw_graphic(VGAState *s
     }
     vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
 
+    changed_flag = 0;
     depth = s->get_bpp(s);
-    if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth) {
-        if (depth != 24 || s->ds->depth != 32)
+    if (s->ds->dpy_colourdepth != NULL &&
+            (s->ds->depth != depth || !s->ds->shared_buf)) {
             s->ds->dpy_colourdepth(s->ds, depth);
+            changed_flag = 1;
     }
     if (disp_width != s->last_width ||
         height != s->last_height) {
@@ -1567,9 +1569,10 @@ static void vga_draw_graphic(VGAState *s
         s->last_width = disp_width;
         s->last_height = height;
         full_update = 1;
-    }
-    if (s->ds->shared_buf && s->ds->data != s->vram_ptr + (s->start_addr * 4))
-        s->ds->data = s->vram_ptr + (s->start_addr * 4);
+        changed_flag = 1;
+    }
+    if (s->ds->shared_buf && (changed_flag || 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);
     
tools/ioemu/sdl.c +64 -11

107 lines not on this page · raw message

tools/ioemu/vl.h +1 -0
diff -r 2a8eaba24bf0 tools/ioemu/vl.h
@@ -940,6 +940,7 @@ struct DisplayState {
     void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
     void (*dpy_resize)(struct DisplayState *s, int w, int h);
     void (*dpy_colourdepth)(struct DisplayState *s, int depth);
+    void (*dpy_setdata)(DisplayState *ds, void *pixels);
     void (*dpy_refresh)(struct DisplayState *s);
     void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y, int dst_x, int dst_y, int w, int h);
 };
tools/ioemu/vnc.c +7 -0
diff -r 2a8eaba24bf0 tools/ioemu/vnc.c
@@ -1621,6 +1621,11 @@ static void pixel_format_message (VncSta
     vnc_write(vs, pad, 3);           /* padding */
 }
 
+static void vnc_dpy_setdata(DisplayState *ds, void *pixels)
+{
+    ds->data = pixels;
+}
+
 static void vnc_dpy_colourdepth(DisplayState *ds, int depth)
 {
     int host_big_endian_flag;
@@ -1628,6 +1633,7 @@ static void vnc_dpy_colourdepth(DisplayS
 
     switch (depth) {
         case 24:
+            if (ds->depth == 32) return;
             ds->shared_buf = 0;
             depth = 32;
             break;
@@ -2480,6 +2486,7 @@ void vnc_display_init(DisplayState *ds)
     vs->ds->dpy_update = vnc_dpy_update;
     vs->ds->dpy_resize = vnc_dpy_resize;
     vs->ds->dpy_colourdepth = vnc_dpy_colourdepth;
+    vs->ds->dpy_setdata = vnc_dpy_setdata;
     vs->ds->dpy_refresh = vnc_dpy_refresh;
 
     vs->ds->width = 640;

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

#1 lore raw
Quoted 4 lines · Stefano Stabellini

Hi all,
right now qemu takes care of converting pixels between the guest pixel format and the sdl pixel format, after that qemu also memcpy the converted pixels to the sdl buffer in video ram.
This process can be improved using the SDL blit capabilities: the patch I am attaching creates an SDL Surface from the Cirrus VGA framebuffer and uses SDL blitting functions to convert and write pixels to video ram. SDL blitting functions are optimized and can even be hardware accelerated on some platforms.

#2 lore raw
In reply to Stefano Stabellini

I found a little mistake in the patch (a break statement missing), so I am reposting it fixed.

tools/ioemu/hw/vga.c +10 -7
diff -r 9049b0b62e08 tools/ioemu/hw/vga.c
@@ -1481,7 +1481,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;
+    int width, height, shift_control, line_offset, bwidth, changed_flag;
     ram_addr_t page0, page1;
     int disp_width, multi_scan, multi_run;
     uint8_t *d;
@@ -1554,10 +1554,12 @@ static void vga_draw_graphic(VGAState *s
     }
     vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
 
+    changed_flag = 0;
     depth = s->get_bpp(s);
-    if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth) {
-        if (depth != 24 || s->ds->depth != 32)
-            s->ds->dpy_colourdepth(s->ds, depth);
+    if (s->ds->dpy_colourdepth != NULL && 
+            (s->ds->depth != depth || !s->ds->shared_buf)) {
+        s->ds->dpy_colourdepth(s->ds, depth);
+        changed_flag = 1;
     }
     if (disp_width != s->last_width ||
         height != s->last_height) {
@@ -1567,9 +1569,10 @@ static void vga_draw_graphic(VGAState *s
         s->last_width = disp_width;
         s->last_height = height;
         full_update = 1;
-    }
-    if (s->ds->shared_buf && s->ds->data != s->vram_ptr + (s->start_addr * 4))
-        s->ds->data = s->vram_ptr + (s->start_addr * 4);
+        changed_flag = 1;
+    }
+    if (s->ds->shared_buf && (changed_flag || 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);
     
tools/ioemu/sdl.c +64 -11

107 lines not on this page · raw message

tools/ioemu/vl.h +1 -0
diff -r 9049b0b62e08 tools/ioemu/vl.h
@@ -942,6 +942,7 @@ struct DisplayState {
     void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
     void (*dpy_resize)(struct DisplayState *s, int w, int h);
     void (*dpy_colourdepth)(struct DisplayState *s, int depth);
+    void (*dpy_setdata)(DisplayState *ds, void *pixels);
     void (*dpy_refresh)(struct DisplayState *s);
     void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y, int dst_x, int dst_y, int w, int h);
 };
tools/ioemu/vnc.c +7 -0
diff -r 9049b0b62e08 tools/ioemu/vnc.c
@@ -1621,6 +1621,11 @@ static void pixel_format_message (VncSta
     vnc_write(vs, pad, 3);           /* padding */
 }
 
+static void vnc_dpy_setdata(DisplayState *ds, void *pixels)
+{
+    ds->data = pixels;
+}
+
 static void vnc_dpy_colourdepth(DisplayState *ds, int depth)
 {
     int host_big_endian_flag;
@@ -1628,6 +1633,7 @@ static void vnc_dpy_colourdepth(DisplayS
 
     switch (depth) {
         case 24:
+            if (ds->depth == 32) return;
             ds->shared_buf = 0;
             depth = 32;
             break;
@@ -2480,6 +2486,7 @@ void vnc_display_init(DisplayState *ds)
     vs->ds->dpy_update = vnc_dpy_update;
     vs->ds->dpy_resize = vnc_dpy_resize;
     vs->ds->dpy_colourdepth = vnc_dpy_colourdepth;
+    vs->ds->dpy_setdata = vnc_dpy_setdata;
     vs->ds->dpy_refresh = vnc_dpy_refresh;
 
     vs->ds->width = 640;

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