qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1 of 2] [UPDATE] DisplayState interface change


From: Stefano Stabellini
Subject: [Qemu-devel] [PATCH 1 of 2] [UPDATE] DisplayState interface change
Date: Thu, 20 Nov 2008 16:58:29 +0000
User-agent: Thunderbird 2.0.0.14 (X11/20080505)

Hi all,
this patch changes the DisplayState interface adding support for
multiple frontends at the same time (sdl and vnc) and implements most
of the benefit of the shared_buf patch without the added complexity.

Currently DisplayState is managed by sdl (or vnc) and sdl (or vnc) is
also responsible for allocating the data and setting the depth.
Vga.c (or another backend) will do any necessary conversion.

The idea is to change it so that is vga.c (or another backend) that
fully manages the DisplayState interface allocating data and setting the
depth (either 16 or 32 bit, if the guest uses a different resolution or
is in text mode, vga.c (or another backend) is in charge of
doing the conversion seamlessly).

The other idea is that DisplayState supports *multiple* frontends
like sdl and vnc; each of them can register some callbacks to be called
when a display event occurs.

Signed-off-by: Stefano Stabellini <address@hidden>

---

diff -r 5c78dd111aae console.c
--- a/console.c Tue Nov 04 09:04:41 2008 +0000
+++ b/console.c Thu Nov 20 16:34:30 2008 +0000
@@ -190,7 +190,7 @@
 {
     unsigned int r, g, b, color;
 
-    switch(ds->depth) {
+    switch(ds->surface->pf.bits_per_pixel) {
 #if 0
     case 8:
         r = (rgba >> 16) & 0xff;
@@ -227,9 +227,9 @@
     uint8_t *d, *d1;
     int x, y, bpp;
 
-    bpp = (ds->depth + 7) >> 3;
-    d1 = ds->data +
-        ds->linesize * posy + bpp * posx;
+    bpp = (ds->surface->pf.bits_per_pixel + 7) >> 3;
+    d1 = ds->surface->data +
+        ds->surface->linesize * posy + bpp * posx;
     for (y = 0; y < height; y++) {
         d = d1;
         switch(bpp) {
@@ -252,7 +252,7 @@
             }
             break;
         }
-        d1 += ds->linesize;
+        d1 += ds->surface->linesize;
     }
 }
 
@@ -263,27 +263,27 @@
     uint8_t *d;
     int wb, y, bpp;
 
-    bpp = (ds->depth + 7) >> 3;
+    bpp = (ds->surface->pf.bits_per_pixel + 7) >> 3;
     wb = w * bpp;
     if (yd <= ys) {
-        s = ds->data +
-            ds->linesize * ys + bpp * xs;
-        d = ds->data +
-            ds->linesize * yd + bpp * xd;
+        s = ds->surface->data +
+            ds->surface->linesize * ys + bpp * xs;
+        d = ds->surface->data +
+            ds->surface->linesize * yd + bpp * xd;
         for (y = 0; y < h; y++) {
             memmove(d, s, wb);
-            d += ds->linesize;
-            s += ds->linesize;
+            d += ds->surface->linesize;
+            s += ds->surface->linesize;
         }
     } else {
-        s = ds->data +
-            ds->linesize * (ys + h - 1) + bpp * xs;
-        d = ds->data +
-            ds->linesize * (yd + h - 1) + bpp * xd;
+        s = ds->surface->data +
+            ds->surface->linesize * (ys + h - 1) + bpp * xs;
+        d = ds->surface->data +
+            ds->surface->linesize * (yd + h - 1) + bpp * xd;
        for (y = 0; y < h; y++) {
             memmove(d, s, wb);
-            d -= ds->linesize;
-            s -= ds->linesize;
+            d -= ds->surface->linesize;
+            s -= ds->surface->linesize;
         }
     }
 }
@@ -373,7 +373,7 @@
 
 static inline unsigned int col_expand(DisplayState *ds, unsigned int col)
 {
-    switch(ds->depth) {
+    switch(ds->surface->pf.bits_per_pixel) {
     case 8:
         col |= col << 8;
         col |= col << 16;
@@ -443,13 +443,13 @@
         bgcol = color_table[t_attrib->bold][t_attrib->bgcol];
     }
 
-    bpp = (ds->depth + 7) >> 3;
-    d = ds->data +
-        ds->linesize * y * FONT_HEIGHT + bpp * x * FONT_WIDTH;
-    linesize = ds->linesize;
+    bpp = (ds->surface->pf.bits_per_pixel + 7) >> 3;
+    d = ds->surface->data +
+        ds->surface->linesize * y * FONT_HEIGHT + bpp * x * FONT_WIDTH;
+    linesize = ds->surface->linesize;
     font_ptr = vgafont16 + FONT_HEIGHT * ch;
     xorcol = bgcol ^ fgcol;
-    switch(ds->depth) {
+    switch(ds->surface->pf.bits_per_pixel) {
     case 8:
         for(i = 0; i < FONT_HEIGHT; i++) {
             font_data = *font_ptr++;
@@ -543,7 +543,7 @@
     int y1, y2;
 
     if (s == active_console) {
-        if (!s->ds->depth) {
+        if (!s->ds->surface->pf.bits_per_pixel) {
             text_update_xy(s, x, y);
             return;
         }
@@ -570,7 +570,7 @@
     if (s == active_console) {
         int x = s->x;
 
-        if (!s->ds->depth) {
+        if (!s->ds->surface->pf.depth) {
             s->cursor_invalidate = 1;
             return;
         }
@@ -604,7 +604,7 @@
 
     if (s != active_console)
         return;
-    if (!s->ds->depth) {
+    if (!s->ds->surface->pf.bits_per_pixel) {
         s->text_x[0] = 0;
         s->text_y[0] = 0;
         s->text_x[1] = s->width - 1;
@@ -613,7 +613,7 @@
         return;
     }
 
-    vga_fill_rect(s->ds, 0, 0, s->ds->width, s->ds->height,
+    vga_fill_rect(s->ds, 0, 0, s->ds->surface->width, s->ds->surface->height,
                   color_table[0][COLOR_BLACK]);
     y1 = s->y_displayed;
     for(y = 0; y < s->height; y++) {
@@ -626,7 +626,7 @@
         if (++y1 == s->total_height)
             y1 = 0;
     }
-    dpy_update(s->ds, 0, 0, s->ds->width, s->ds->height);
+    dpy_update(s->ds, 0, 0, s->ds->surface->width, s->ds->surface->height);
     console_show_cursor(s, 1);
 }
 
@@ -689,7 +689,7 @@
             c++;
         }
         if (s == active_console && s->y_displayed == s->y_base) {
-            if (!s->ds->depth) {
+            if (!s->ds->surface->pf.bits_per_pixel) {
                 s->text_x[0] = 0;
                 s->text_y[0] = 0;
                 s->text_x[1] = s->width - 1;
@@ -1044,12 +1044,15 @@
 
     if (index >= MAX_CONSOLES)
         return;
+    active_console->g_width = active_console->ds->surface->width;
+    active_console->g_height = active_console->ds->surface->height;
     s = consoles[index];
     if (s) {
+        DisplayState *ds = s->ds;
         active_console = s;
-        if (s->console_type != TEXT_CONSOLE && s->g_width && s->g_height
-            && (s->g_width != s->ds->width || s->g_height != s->ds->height))
-            dpy_resize(s->ds, s->g_width, s->g_height);
+        ds->surface = qemu_resizeDisplaySurface(ds->surface, s->g_width,
+                                                s->g_height, 32, 4 * 
s->g_width);
+        dpy_resize(s->ds);
         vga_hw_invalidate();
     }
 }
@@ -1158,15 +1161,6 @@
 {
     TextConsole *s = (TextConsole *) opaque;
 
-    if (s->g_width != s->ds->width || s->g_height != s->ds->height) {
-        if (s->console_type == TEXT_CONSOLE_FIXED_SIZE)
-            dpy_resize(s->ds, s->g_width, s->g_height);
-        else {
-            s->g_width = s->ds->width;
-            s->g_height = s->ds->height;
-            text_console_resize(s);
-        }
-    }
     console_refresh(s);
 }
 
@@ -1247,6 +1241,11 @@
     return s;
 }
 
+int is_active_console(QEMUConsole *s)
+{
+    return (active_console == s);
+}
+
 int is_graphic_console(void)
 {
     return active_console && active_console->console_type == GRAPHIC_CONSOLE;
@@ -1302,8 +1301,8 @@
     s->total_height = DEFAULT_BACKSCROLL;
     s->x = 0;
     s->y = 0;
-    width = s->ds->width;
-    height = s->ds->height;
+    width = s->ds->surface->width;
+    height = s->ds->surface->height;
     if (p != 0) {
         width = strtoul(p, (char **)&p, 10);
         if (*p == 'C') {
@@ -1346,13 +1345,12 @@
 
 void qemu_console_resize(QEMUConsole *console, int width, int height)
 {
-    if (console->g_width != width || console->g_height != height
-        || !console->ds->data) {
-        console->g_width = width;
-        console->g_height = height;
-        if (active_console == console) {
-            dpy_resize(console->ds, width, height);
-        }
+    console->g_width = width;
+    console->g_height = height;
+    if (active_console == console) {
+        DisplayState *ds = console->ds;
+        ds->surface = qemu_resizeDisplaySurface(ds->surface, width, height, 
32, 4 * width);
+        dpy_resize(console->ds);
     }
 }
 
@@ -1360,12 +1358,137 @@
                 int dst_x, int dst_y, int w, int h)
 {
     if (active_console == console) {
-        if (console->ds->dpy_copy)
-            console->ds->dpy_copy(console->ds,
-                            src_x, src_y, dst_x, dst_y, w, h);
-        else {
-            /* TODO */
-            console->ds->dpy_update(console->ds, dst_x, dst_y, w, h);
-        }
+            dpy_copy(console->ds, src_x, src_y, dst_x, dst_y, w, h);
     }
 }
+
+static PixelFormat qemu_default_pixelformat(int bpp)
+{
+    PixelFormat pf;
+
+    memset(&pf, 0x00, sizeof(PixelFormat));
+
+    pf.bits_per_pixel = bpp;
+    pf.bytes_per_pixel = bpp / 8;
+    pf.depth = bpp == 32 ? 24 : bpp;
+
+    switch (bpp) {
+        case 8:
+            pf.rmask = 0x000000E0;
+            pf.gmask = 0x0000001C;
+            pf.bmask = 0x00000003;
+            pf.rmax = 7;
+            pf.gmax = 7;
+            pf.bmax = 3;
+            pf.rshift = 5;
+            pf.gshift = 2;
+            pf.bshift = 0;
+            break;
+        case 16:
+            pf.rmask = 0x0000F800;
+            pf.gmask = 0x000007E0;
+            pf.bmask = 0x0000001F;
+            pf.rmax = 31;
+            pf.gmax = 63;
+            pf.bmax = 31;
+            pf.rshift = 11;
+            pf.gshift = 5;
+            pf.bshift = 0;
+            break;
+        case 24:
+        case 32:
+            pf.rmask = 0x00FF0000;
+            pf.gmask = 0x0000FF00;
+            pf.bmask = 0x000000FF;
+            pf.rmax = 255;
+            pf.gmax = 255;
+            pf.bmax = 255;
+            pf.rshift = 16;
+            pf.gshift = 8;
+            pf.bshift = 0;
+            break;
+        default:
+            break;
+    }
+    return pf;
+}
+
+DisplaySurface* qemu_createDisplaySurface(int width, int height, int bpp, int 
linesize)
+{
+    DisplaySurface *surface = (DisplaySurface*) 
qemu_mallocz(sizeof(DisplaySurface));
+    if (surface == NULL) {
+        fprintf(stderr, "qemu_createDisplaySurface: malloc failed\n");
+        exit(1);
+    }
+
+    surface->width = width;
+    surface->height = height;
+    surface->linesize = linesize;
+    surface->pf = qemu_default_pixelformat(bpp);
+#ifdef WORDS_BIGENDIAN
+    surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG;
+#else
+    surface->flags = QEMU_ALLOCATED_FLAG;
+#endif
+    surface->data = (uint8_t*) qemu_mallocz(surface->linesize * 
surface->height);
+    if (surface->data == NULL) {
+        fprintf(stderr, "qemu_createDisplaySurface: malloc failed\n");
+        exit(1);
+    }
+
+    return surface;
+}
+
+DisplaySurface* qemu_resizeDisplaySurface(DisplaySurface *surface,
+                                          int width, int height, int bpp, int 
linesize)
+{
+    surface->width = width;
+    surface->height = height;
+    surface->linesize = linesize;
+    surface->pf = qemu_default_pixelformat(bpp);
+    if (surface->flags & QEMU_ALLOCATED_FLAG)
+        surface->data = (uint8_t*) qemu_reallocz(surface->data, 
surface->linesize * surface->height);
+    else
+        surface->data = (uint8_t*) qemu_mallocz(surface->linesize * 
surface->height);
+    if (surface->data == NULL) {
+        fprintf(stderr, "qemu_createDisplaySurface: malloc failed\n");
+        exit(1);
+    }
+#ifdef WORDS_BIGENDIAN
+    surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG;
+#else
+    surface->flags = QEMU_ALLOCATED_FLAG;
+#endif
+
+    return surface;
+}
+
+DisplaySurface* qemu_createDisplaySurfaceFrom(int width, int height, int bpp,
+                                              int linesize, uint8_t *data)
+{
+    DisplaySurface *surface = (DisplaySurface*) 
qemu_mallocz(sizeof(DisplaySurface));
+    if (surface == NULL) {
+        fprintf(stderr, "qemu_createDisplaySurface: malloc failed\n");
+        exit(1);
+    }
+
+    surface->width = width;
+    surface->height = height;
+    surface->linesize = linesize;
+    surface->pf = qemu_default_pixelformat(bpp);
+#ifdef WORDS_BIGENDIAN
+    surface->flags = QEMU_BIG_ENDIAN_FLAG;
+#endif
+    surface->data = data;
+
+    return surface;
+}
+
+void qemu_freeDisplaySurface(DisplaySurface *surface)
+{
+    if (surface == NULL)
+        return;
+    if (surface->flags & QEMU_ALLOCATED_FLAG)
+        qemu_free(surface->data);
+    qemu_free(surface);
+}
diff -r 5c78dd111aae console.h
--- a/console.h Tue Nov 04 09:04:41 2008 +0000
+++ b/console.h Thu Nov 20 16:34:30 2008 +0000
@@ -73,45 +73,138 @@
 
 /* consoles */
 
-struct DisplayState {
-    uint8_t *data;
-    int linesize;
-    int depth;
-    int bgr; /* BGR color order instead of RGB. Only valid for depth == 32 */
+#define QEMU_BIG_ENDIAN_FLAG    0x01
+#define QEMU_ALLOCATED_FLAG     0x02
+
+struct PixelFormat {
+    uint8_t bits_per_pixel;
+    uint8_t bytes_per_pixel;
+    uint8_t depth; /* color depth in bits */
+    uint32_t rmask, gmask, bmask, amask;
+    uint8_t rshift, gshift, bshift, ashift;
+    uint8_t rmax, gmax, bmax, amax;
+};
+
+struct DisplaySurface {
+    uint8_t flags;
     int width;
     int height;
-    void *opaque;
-    struct QEMUTimer *gui_timer;
+    int linesize;        /* bytes per line */
+    uint8_t *data;
+
+    struct PixelFormat pf;
+};
+
+struct DisplayChangeListener {
+    int idle;
     uint64_t gui_timer_interval;
-    int idle; /* there is nothing to update (window invisible), set by vnc/sdl 
*/
 
     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_resize)(struct DisplayState *s);
+    void (*dpy_setdata)(struct DisplayState *s);
     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);
     void (*dpy_fill)(struct DisplayState *s, int x, int y,
                      int w, int h, uint32_t c);
     void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
+
+    struct DisplayChangeListener *next;
+};
+
+struct DisplayState {
+    struct DisplaySurface *surface;
+    void *opaque;
+    struct QEMUTimer *gui_timer;
+
+    struct DisplayChangeListener* listeners;
+
     void (*mouse_set)(int x, int y, int on);
     void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
                           uint8_t *image, uint8_t *mask);
 };
 
+DisplaySurface* qemu_createDisplaySurface(int width, int height, int bpp, int 
linesize);
+DisplaySurface* qemu_resizeDisplaySurface(DisplaySurface *surface,
+                                          int width, int height, int bpp, int 
linesize);
+DisplaySurface* qemu_createDisplaySurfaceFrom(int width, int height, int bpp,
+                                              int linesize, uint8_t *data);
+void qemu_freeDisplaySurface(DisplaySurface *surface);
+
+static inline int is_buffer_shared(DisplaySurface *surface)
+{
+    return (!(surface->flags & QEMU_ALLOCATED_FLAG));
+}
+
+static inline void register_displaychangelistener(DisplayState *ds, 
DisplayChangeListener *dcl)
+{
+    dcl->next = ds->listeners;
+    ds->listeners = dcl;
+}
+
 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
 {
-    s->dpy_update(s, x, y, w, h);
+    struct DisplayChangeListener *dcl = s->listeners;
+    while (dcl != NULL) {
+        dcl->dpy_update(s, x, y, w, h);
+        dcl = dcl->next;
+    }
 }
 
-static inline void dpy_resize(DisplayState *s, int w, int h)
+static inline void dpy_resize(DisplayState *s)
 {
-    s->dpy_resize(s, w, h);
+    struct DisplayChangeListener *dcl = s->listeners;
+    while (dcl != NULL) {
+        dcl->dpy_resize(s);
+        dcl = dcl->next;
+    }
 }
 
-static inline void dpy_cursor(DisplayState *s, int x, int y)
+static inline void dpy_setdata(DisplayState *s)
 {
-    if (s->dpy_text_cursor)
-        s->dpy_text_cursor(s, x, y);
+    struct DisplayChangeListener *dcl = s->listeners;
+    while (dcl != NULL) {
+        if (dcl->dpy_setdata) dcl->dpy_setdata(s);
+        dcl = dcl->next;
+    }
+}
+
+static inline void dpy_refresh(DisplayState *s)
+{
+    struct DisplayChangeListener *dcl = s->listeners;
+    while (dcl != NULL) {
+        if (dcl->dpy_refresh) dcl->dpy_refresh(s);
+        dcl = dcl->next;
+    }
+}
+
+static inline void dpy_copy(struct DisplayState *s, int src_x, int src_y,
+                             int dst_x, int dst_y, int w, int h) {
+    struct DisplayChangeListener *dcl = s->listeners;
+    while (dcl != NULL) {
+        if (dcl->dpy_copy)
+            dcl->dpy_copy(s, src_x, src_y, dst_x, dst_y, w, h);
+        else /* TODO */
+            dcl->dpy_update(s, dst_x, dst_y, w, h);
+        dcl = dcl->next;
+    }
+}
+
+static inline void dpy_fill(struct DisplayState *s, int x, int y,
+                             int w, int h, uint32_t c) {
+    struct DisplayChangeListener *dcl = s->listeners;
+    while (dcl != NULL) {
+        if (dcl->dpy_fill) dcl->dpy_fill(s, x, y, w, h, c);
+        dcl = dcl->next;
+    }
+}
+
+static inline void dpy_cursor(struct DisplayState *s, int x, int y) {
+    struct DisplayChangeListener *dcl = s->listeners;
+    while (dcl != NULL) {
+        if (dcl->dpy_text_cursor) dcl->dpy_text_cursor(s, x, y);
+        dcl = dcl->next;
+    }
 }
 
 typedef unsigned long console_ch_t;
@@ -136,6 +229,7 @@
 void vga_hw_text_update(console_ch_t *chardata);
 
 int is_graphic_console(void);
+int is_active_console(QEMUConsole *s);
 int is_fixedsize_console(void);
 CharDriverState *text_console_init(DisplayState *ds, const char *p);
 void console_select(unsigned int index);
diff -r 5c78dd111aae curses.c
--- a/curses.c  Tue Nov 04 09:04:41 2008 +0000
+++ b/curses.c  Thu Nov 20 16:34:30 2008 +0000
@@ -97,13 +97,13 @@
     }
 }
 
-static void curses_resize(DisplayState *ds, int w, int h)
+static void curses_resize(DisplayState *ds)
 {
-    if (w == gwidth && h == gheight)
+    if (ds->surface->width == gwidth && ds->surface->height == gheight)
         return;
 
-    gwidth = w;
-    gheight = h;
+    gwidth = ds->surface->width;
+    gheight = ds->surface->height;
 
     curses_calc_pad();
 }
@@ -169,8 +169,8 @@
         clear();
         refresh();
         curses_calc_pad();
-        ds->width = FONT_WIDTH * width;
-        ds->height = FONT_HEIGHT * height;
+        ds->surface->width = FONT_WIDTH * width;
+        ds->surface->height = FONT_HEIGHT * height;
         vga_hw_invalidate();
         invalidate = 0;
     }
@@ -197,8 +197,8 @@
             refresh();
             curses_calc_pad();
             curses_update(ds, 0, 0, width, height);
-            ds->width = FONT_WIDTH * width;
-            ds->height = FONT_HEIGHT * height;
+            ds->surface->width = FONT_WIDTH * width;
+            ds->surface->height = FONT_HEIGHT * height;
             continue;
         }
 #endif
@@ -338,6 +338,7 @@
 
 void curses_display_init(DisplayState *ds, int full_screen)
 {
+    DisplayChangeListener *dcl;
 #ifndef _WIN32
     if (!isatty(1)) {
         fprintf(stderr, "We need a terminal output\n");
@@ -357,18 +358,19 @@
 #endif
 #endif
 
-    ds->data = (void *) screen;
-    ds->linesize = 0;
-    ds->depth = 0;
-    ds->width = 640;
-    ds->height = 400;
-    ds->dpy_update = curses_update;
-    ds->dpy_resize = curses_resize;
-    ds->dpy_refresh = curses_refresh;
-    ds->dpy_text_cursor = curses_cursor_position;
+    dcl = (DisplayChangeListener *) 
qemu_mallocz(sizeof(DisplayChangeListener));
+    if (!dcl)
+        exit(1);
+    dcl->dpy_update = curses_update;
+    dcl->dpy_resize = curses_resize;
+    dcl->dpy_refresh = curses_refresh;
+    dcl->dpy_text_cursor = curses_cursor_position;
+    register_displaychangelistener(ds, dcl);
+    qemu_freeDisplaySurface(ds->surface);
+    ds->surface = qemu_createDisplaySurfaceFrom(80, 25, 0, 0, (uint8_t*) 
screen);
 
     invalidate = 1;
 
     /* Standard VGA initial text mode dimensions */
-    curses_resize(ds, 80, 25);
+    curses_resize(ds);
 }
diff -r 5c78dd111aae hw/blizzard.c
--- a/hw/blizzard.c     Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/blizzard.c     Thu Nov 20 16:34:30 2008 +0000
@@ -166,7 +166,7 @@
         s->my[1] = s->data.y + s->data.dy;
 
     bypp[0] = s->bpp;
-    bypp[1] = (s->state->depth + 7) >> 3;
+    bypp[1] = (s->state->surface->pf.bits_per_pixel + 7) >> 3;
     bypl[0] = bypp[0] * s->data.pitch;
     bypl[1] = bypp[1] * s->x;
     bypl[2] = bypp[0] * s->data.dx;
@@ -895,7 +895,7 @@
     if (!s->enable)
         return;
 
-    if (s->x != s->state->width || s->y != s->state->height) {
+    if (s->x != s->state->surface->width || s->y != s->state->surface->height) 
{
         s->invalidate = 1;
         qemu_console_resize(s->console, s->x, s->y);
     }
@@ -904,8 +904,8 @@
         s->invalidate = 0;
 
         if (s->blank) {
-            bypp = (s->state->depth + 7) >> 3;
-            memset(s->state->data, 0, bypp * s->x * s->y);
+            bypp = (s->state->surface->pf.bits_per_pixel + 7) >> 3;
+            memset(s->state->surface->data, 0, bypp * s->x * s->y);
             return;
         }
 
@@ -918,12 +918,12 @@
     if (s->mx[1] <= s->mx[0])
         return;
 
-    bypp = (s->state->depth + 7) >> 3;
+    bypp = (s->state->surface->pf.bits_per_pixel + 7) >> 3;
     bypl = bypp * s->x;
     bwidth = bypp * (s->mx[1] - s->mx[0]);
     y = s->my[0];
     src = s->fb + bypl * y + bypp * s->mx[0];
-    dst = s->state->data + bypl * y + bypp * s->mx[0];
+    dst = s->state->surface->data + bypl * y + bypp * s->mx[0];
     for (; y < s->my[1]; y ++, src += bypl, dst += bypl)
         memcpy(dst, src, bwidth);
 
@@ -940,8 +940,8 @@
     struct blizzard_s *s = (struct blizzard_s *) opaque;
 
     blizzard_update_display(opaque);
-    if (s && s->state->data)
-        ppm_save(filename, s->state->data, s->x, s->y, s->state->linesize);
+    if (s && s->state->surface->data)
+        ppm_save(filename, s->state->surface->data, s->x, s->y, 
s->state->surface->linesize);
 }
 
 #define DEPTH 8
@@ -962,7 +962,7 @@
     s->state = ds;
     s->fb = qemu_malloc(0x180000);
 
-    switch (s->state->depth) {
+    switch (s->state->surface->pf.bits_per_pixel) {
     case 0:
         s->line_fn_tab[0] = s->line_fn_tab[1] =
                 qemu_mallocz(sizeof(blizzard_fn_t) * 0x10);
diff -r 5c78dd111aae hw/cirrus_vga.c
--- a/hw/cirrus_vga.c   Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/cirrus_vga.c   Thu Nov 20 16:34:30 2008 +0000
@@ -788,22 +788,16 @@
     if (BLTUNSAFE(s))
         return 0;
 
-    if (s->ds->dpy_copy) {
-       cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->start_addr,
-                      s->cirrus_blt_srcaddr - s->start_addr,
-                      s->cirrus_blt_width, s->cirrus_blt_height);
-    } else {
-       (*s->cirrus_rop) (s, s->vram_ptr +
-                (s->cirrus_blt_dstaddr & s->cirrus_addr_mask),
-                         s->vram_ptr +
-                (s->cirrus_blt_srcaddr & s->cirrus_addr_mask),
-                         s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch,
-                         s->cirrus_blt_width, s->cirrus_blt_height);
+    (*s->cirrus_rop) (s, s->vram_ptr +
+            (s->cirrus_blt_dstaddr & s->cirrus_addr_mask),
+            s->vram_ptr +
+            (s->cirrus_blt_srcaddr & s->cirrus_addr_mask),
+            s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch,
+            s->cirrus_blt_width, s->cirrus_blt_height);
 
-       cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
-                                s->cirrus_blt_dstpitch, s->cirrus_blt_width,
-                                s->cirrus_blt_height);
-    }
+    cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
+            s->cirrus_blt_dstpitch, s->cirrus_blt_width,
+            s->cirrus_blt_height);
 
     return 1;
 }
@@ -2321,9 +2315,9 @@
     color1 = s->rgb_to_pixel(c6_to_8(palette[0xf * 3]),
                              c6_to_8(palette[0xf * 3 + 1]),
                              c6_to_8(palette[0xf * 3 + 2]));
-    bpp = ((s->ds->depth + 7) >> 3);
+    bpp = ((s->ds->surface->pf.bits_per_pixel + 7) >> 3);
     d1 += x1 * bpp;
-    switch(s->ds->depth) {
+    switch(s->ds->surface->pf.bits_per_pixel) {
     default:
         break;
     case 8:
diff -r 5c78dd111aae hw/g364fb.c
--- a/hw/g364fb.c       Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/g364fb.c       Thu Nov 20 16:34:30 2008 +0000
@@ -72,7 +72,7 @@
 
 static void g364fb_draw_graphic(G364State *s, int full_update)
 {
-    switch (s->ds->depth) {
+    switch (s->ds->surface->pf.bits_per_pixel) {
         case 8:
             g364fb_draw_graphic8(s, full_update);
             break;
@@ -86,7 +86,7 @@
             g364fb_draw_graphic32(s, full_update);
             break;
         default:
-            printf("g364fb: unknown depth %d\n", s->ds->depth);
+            printf("g364fb: unknown depth %d\n", 
s->ds->surface->pf.bits_per_pixel);
             return;
     }
 
@@ -101,11 +101,11 @@
     if (!full_update)
         return;
 
-    w = s->scr_width * ((s->ds->depth + 7) >> 3);
-    d = s->ds->data;
+    w = s->scr_width * ((s->ds->surface->pf.bits_per_pixel + 7) >> 3);
+    d = s->ds->surface->data;
     for(i = 0; i < s->scr_height; i++) {
         memset(d, 0, w);
-        d += s->ds->linesize;
+        d += s->ds->surface->linesize;
     }
 
     dpy_update(s->ds, 0, 0, s->scr_width, s->scr_height);
@@ -131,7 +131,7 @@
         s->graphic_mode = graphic_mode;
         full_update = 1;
     }
-    if (s->scr_width != s->ds->width || s->scr_height != s->ds->height) {
+    if (s->scr_width != s->ds->surface->width || s->scr_height != 
s->ds->surface->height) {
         qemu_console_resize(s->console, s->scr_width, s->scr_height);
         full_update = 1;
     }
diff -r 5c78dd111aae hw/g364fb_template.h
--- a/hw/g364fb_template.h      Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/g364fb_template.h      Thu Nov 20 16:34:30 2008 +0000
@@ -28,7 +28,7 @@
 
     data_buffer = s->vram_buffer;
     w_display = s->scr_width * PIXEL_WIDTH / 8;
-    data_display = s->ds->data;
+    data_display = s->ds->surface->data;
     for(i = 0; i < s->scr_height; i++) {
         dd = data_display;
         for (j = 0; j < s->scr_width; j++, dd += PIXEL_WIDTH / 8, 
data_buffer++) {
@@ -38,6 +38,6 @@
                 s->palette[index][1],
                 s->palette[index][2]);
         }
-        data_display += s->ds->linesize;
+        data_display += s->ds->surface->linesize;
     }
 }
diff -r 5c78dd111aae hw/jazz_led.c
--- a/hw/jazz_led.c     Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/jazz_led.c     Thu Nov 20 16:34:30 2008 +0000
@@ -155,8 +155,8 @@
     uint8_t *d;
     int x, bpp;
 
-    bpp = (ds->depth + 7) >> 3;
-    d = ds->data + ds->linesize * posy + bpp * posx1;
+    bpp = (ds->surface->pf.bits_per_pixel + 7) >> 3;
+    d = ds->surface->data + ds->surface->linesize * posy + bpp * posx1;
     switch(bpp) {
         case 1:
             for (x = posx1; x <= posx2; x++) {
@@ -184,25 +184,25 @@
     uint8_t *d;
     int y, bpp;
 
-    bpp = (ds->depth + 7) >> 3;
-    d = ds->data + ds->linesize * posy1 + bpp * posx;
+    bpp = (ds->surface->pf.bits_per_pixel + 7) >> 3;
+    d = ds->surface->data + ds->surface->linesize * posy1 + bpp * posx;
     switch(bpp) {
         case 1:
             for (y = posy1; y <= posy2; y++) {
                 *((uint8_t *)d) = color;
-                d += ds->linesize;
+                d += ds->surface->linesize;
             }
             break;
         case 2:
             for (y = posy1; y <= posy2; y++) {
                 *((uint16_t *)d) = color;
-                d += ds->linesize;
+                d += ds->surface->linesize;
             }
             break;
         case 4:
             for (y = posy1; y <= posy2; y++) {
                 *((uint32_t *)d) = color;
-                d += ds->linesize;
+                d += ds->surface->linesize;
             }
             break;
     }
@@ -218,17 +218,17 @@
 
     if (s->state & REDRAW_BACKGROUND) {
         /* clear screen */
-        bpp = (ds->depth + 7) >> 3;
-        d1 = ds->data;
-        for (y = 0; y < ds->height; y++) {
-            memset(d1, 0x00, ds->width * bpp);
-            d1 += ds->linesize;
+        bpp = (ds->surface->pf.bits_per_pixel + 7) >> 3;
+        d1 = ds->surface->data;
+        for (y = 0; y < ds->surface->height; y++) {
+            memset(d1, 0x00, ds->surface->width * bpp);
+            d1 += ds->surface->linesize;
         }
     }
 
     if (s->state & REDRAW_SEGMENTS) {
         /* set colors according to bpp */
-        switch (ds->depth) {
+        switch (ds->surface->pf.bits_per_pixel) {
             case 8:
                 color_segment = rgb_to_pixel8(0xaa, 0xaa, 0xaa);
                 color_led = rgb_to_pixel8(0x00, 0xff, 0x00);
@@ -272,7 +272,7 @@
     }
 
     s->state = REDRAW_NONE;
-    dpy_update(ds, 0, 0, ds->width, ds->height);
+    dpy_update(ds, 0, 0, ds->surface->width, ds->surface->height);
 }
 
 static void jazz_led_invalidate_display(void *opaque)
diff -r 5c78dd111aae hw/musicpal.c
--- a/hw/musicpal.c     Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/musicpal.c     Thu Nov 20 16:34:30 2008 +0000
@@ -801,7 +801,7 @@
         (musicpal_lcd_state *s, int x, int y, type col) \
 { \
     int dx, dy; \
-    type *pixel = &((type *) s->ds->data)[(y * 128 * 3 + x) * 3]; \
+    type *pixel = &((type *) s->ds->surface->data)[(y * 128 * 3 + x) * 3]; \
 \
     for (dy = 0; dy < 3; dy++, pixel += 127 * 3) \
         for (dx = 0; dx < 3; dx++, pixel++) \
@@ -818,7 +818,7 @@
     musicpal_lcd_state *s = opaque;
     int x, y, col;
 
-    switch (s->ds->depth) {
+    switch (s->ds->surface->pf.bits_per_pixel) {
     case 0:
         return;
 #define LCD_REFRESH(depth, func) \
@@ -835,10 +835,10 @@
         break;
     LCD_REFRESH(8, rgb_to_pixel8)
     LCD_REFRESH(16, rgb_to_pixel16)
-    LCD_REFRESH(32, (s->ds->bgr ? rgb_to_pixel32bgr : rgb_to_pixel32))
+    LCD_REFRESH(32, rgb_to_pixel32)
     default:
         cpu_abort(cpu_single_env, "unsupported colour depth %i\n",
-                  s->ds->depth);
+                  s->ds->surface->pf.bits_per_pixel);
     }
 
     dpy_update(s->ds, 0, 0, 128*3, 64*3);
diff -r 5c78dd111aae hw/nseries.c
--- a/hw/nseries.c      Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/nseries.c      Thu Nov 20 16:34:30 2008 +0000
@@ -1361,7 +1361,8 @@
     /* FIXME: We shouldn't really be doing this here.  The LCD controller
        will set the size once configured, so this just sets an initial
        size until the guest activates the display.  */
-    dpy_resize(ds, 800, 480);
+    ds->surface = qemu_resizeDisplaySurface(ds->surface, 800, 480, 32, 4 * 
800);
+    dpy_resize(ds);
 }
 
 static struct arm_boot_info n800_binfo = {
diff -r 5c78dd111aae hw/omap_lcdc.c
--- a/hw/omap_lcdc.c    Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/omap_lcdc.c    Thu Nov 20 16:34:30 2008 +0000
@@ -125,7 +125,7 @@
     uint8_t *s, *d;
 
     if (!omap_lcd || omap_lcd->plm == 1 ||
-                    !omap_lcd->enable || !omap_lcd->state->depth)
+                    !omap_lcd->enable || 
!omap_lcd->state->surface->pf.bits_per_pixel)
         return;
 
     frame_offset = 0;
@@ -145,25 +145,25 @@
     /* Colour depth */
     switch ((omap_lcd->palette[0] >> 12) & 7) {
     case 1:
-        draw_line = draw_line_table2[omap_lcd->state->depth];
+        draw_line = 
draw_line_table2[omap_lcd->state->surface->pf.bits_per_pixel];
         bpp = 2;
         break;
 
     case 2:
-        draw_line = draw_line_table4[omap_lcd->state->depth];
+        draw_line = 
draw_line_table4[omap_lcd->state->surface->pf.bits_per_pixel];
         bpp = 4;
         break;
 
     case 3:
-        draw_line = draw_line_table8[omap_lcd->state->depth];
+        draw_line = 
draw_line_table8[omap_lcd->state->surface->pf.bits_per_pixel];
         bpp = 8;
         break;
 
     case 4 ... 7:
         if (!omap_lcd->tft)
-            draw_line = draw_line_table12[omap_lcd->state->depth];
+            draw_line = 
draw_line_table12[omap_lcd->state->surface->pf.bits_per_pixel];
         else
-            draw_line = draw_line_table16[omap_lcd->state->depth];
+            draw_line = 
draw_line_table16[omap_lcd->state->surface->pf.bits_per_pixel];
         bpp = 16;
         break;
 
@@ -174,8 +174,8 @@
 
     /* Resolution */
     width = omap_lcd->width;
-    if (width != omap_lcd->state->width ||
-            omap_lcd->height != omap_lcd->state->height) {
+    if (width != omap_lcd->state->surface->width ||
+            omap_lcd->height != omap_lcd->state->surface->height) {
         qemu_console_resize(omap_lcd->console,
                             omap_lcd->width, omap_lcd->height);
         omap_lcd->invalidate = 1;
@@ -202,7 +202,7 @@
     if (omap_lcd->dma->dual)
         omap_lcd->dma->current_frame ^= 1;
 
-    if (!omap_lcd->state->depth)
+    if (!omap_lcd->state->surface->pf.bits_per_pixel)
         return;
 
     line = 0;
@@ -217,8 +217,8 @@
     step = width * bpp >> 3;
     scanline = frame_base + step * line;
     s = (uint8_t *) (phys_ram_base + scanline);
-    d = omap_lcd->state->data;
-    linesize = omap_lcd->state->linesize;
+    d = omap_lcd->state->surface->data;
+    linesize = omap_lcd->state->surface->linesize;
 
     dirty[0] = dirty[1] =
             cpu_physical_memory_get_dirty(scanline, VGA_DIRTY_FLAG);
@@ -293,10 +293,10 @@
 static void omap_screen_dump(void *opaque, const char *filename) {
     struct omap_lcd_panel_s *omap_lcd = opaque;
     omap_update_display(opaque);
-    if (omap_lcd && omap_lcd->state->data)
-        ppm_save(filename, omap_lcd->state->data,
+    if (omap_lcd && omap_lcd->state->surface->data)
+        ppm_save(filename, omap_lcd->state->surface->data,
                 omap_lcd->width, omap_lcd->height,
-                omap_lcd->state->linesize);
+                omap_lcd->state->surface->linesize);
 }
 
 static void omap_invalidate_display(void *opaque) {
diff -r 5c78dd111aae hw/palm.c
--- a/hw/palm.c Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/palm.c Thu Nov 20 16:34:30 2008 +0000
@@ -278,7 +278,8 @@
     /* FIXME: We shouldn't really be doing this here.  The LCD controller
        will set the size once configured, so this just sets an initial
        size until the guest activates the display.  */
-    dpy_resize(ds, 320, 320);
+    ds->surface = qemu_resizeDisplaySurface(ds->surface, 320, 320, 32, 4 * 
320);
+    dpy_resize(ds);
 }
 
 QEMUMachine palmte_machine = {
diff -r 5c78dd111aae hw/pl110.c
--- a/hw/pl110.c        Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/pl110.c        Thu Nov 20 16:34:30 2008 +0000
@@ -124,7 +124,7 @@
     if (!pl110_enabled(s))
         return;
 
-    switch (s->ds->depth) {
+    switch (s->ds->surface->pf.bits_per_pixel) {
     case 0:
         return;
     case 8:
@@ -190,7 +190,7 @@
     if (base > 0x80000000)
         base -= 0x80000000;
     src = phys_ram_base + base;
-    dest = s->ds->data;
+    dest = s->ds->surface->data;
     first = -1;
     addr = base;
 
@@ -249,7 +249,7 @@
         b = (raw & 0x1f) << 3;
         /* The I bit is ignored.  */
         raw >>= 6;
-        switch (s->ds->depth) {
+        switch (s->ds->surface->pf.bits_per_pixel) {
         case 8:
             s->pallette[n] = rgb_to_pixel8(r, g, b);
             break;
diff -r 5c78dd111aae hw/pxa2xx_lcd.c
--- a/hw/pxa2xx_lcd.c   Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/pxa2xx_lcd.c   Thu Nov 20 16:34:30 2008 +0000
@@ -650,7 +650,7 @@
             }
             break;
         }
-        switch (s->ds->depth) {
+        switch (s->ds->surface->pf.bits_per_pixel) {
         case 8:
             *dest = rgb_to_pixel8(r, g, b) | alpha;
             break;
@@ -693,7 +693,7 @@
     else if (s->bpp > pxa_lcdc_8bpp)
         src_width *= 2;
 
-    dest = s->ds->data;
+    dest = s->ds->surface->data;
     dest_width = s->xres * s->dest_width;
 
     addr = (ram_addr_t) (fb - phys_ram_base);
@@ -750,7 +750,7 @@
         src_width *= 2;
 
     dest_width = s->yres * s->dest_width;
-    dest = s->ds->data + dest_width * (s->xres - 1);
+    dest = s->ds->surface->data + dest_width * (s->xres - 1);
 
     addr = (ram_addr_t) (fb - phys_ram_base);
     start = addr + s->yres * src_width;
@@ -1006,7 +1006,7 @@
                                       pxa2xx_invalidate_display,
                                       pxa2xx_screen_dump, NULL, s);
 
-    switch (s->ds->depth) {
+    switch (s->ds->surface->pf.bits_per_pixel) {
     case 0:
         s->dest_width = 0;
         break;
diff -r 5c78dd111aae hw/ssd0303.c
--- a/hw/ssd0303.c      Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/ssd0303.c      Thu Nov 20 16:34:30 2008 +0000
@@ -206,7 +206,7 @@
     if (!s->redraw)
         return;
 
-    switch (s->ds->depth) {
+    switch (s->ds->surface->pf.bits_per_pixel) {
     case 0:
         return;
     case 15:
@@ -238,7 +238,7 @@
         colors[0] = colortab + dest_width;
         colors[1] = colortab;
     }
-    dest = s->ds->data;
+    dest = s->ds->surface->data;
     for (y = 0; y < 16; y++) {
         line = (y + s->start_line) & 63;
         src = s->framebuffer + 132 * (line >> 3) + 36;
diff -r 5c78dd111aae hw/ssd0323.c
--- a/hw/ssd0323.c      Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/ssd0323.c      Thu Nov 20 16:34:30 2008 +0000
@@ -187,7 +187,7 @@
     if (!s->redraw)
         return;
 
-    switch (s->ds->depth) {
+    switch (s->ds->surface->pf.bits_per_pixel) {
     case 0:
         return;
     case 15:
@@ -210,7 +210,7 @@
     for (i = 0; i < 16; i++) {
         int n;
         colors[i] = p;
-        switch (s->ds->depth) {
+        switch (s->ds->surface->pf.bits_per_pixel) {
         case 15:
             n = i * 2 + (i >> 3);
             p[0] = n | (n << 5);
@@ -233,7 +233,7 @@
         p += dest_width;
     }
     /* TODO: Implement row/column remapping.  */
-    dest = s->ds->data;
+    dest = s->ds->surface->data;
     for (y = 0; y < 64; y++) {
         line = y;
         src = s->framebuffer + 64 * line;
diff -r 5c78dd111aae hw/tc6393xb.c
--- a/hw/tc6393xb.c     Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/tc6393xb.c     Thu Nov 20 16:34:30 2008 +0000
@@ -430,7 +430,7 @@
 
 static void tc6393xb_draw_graphic(struct tc6393xb_s *s, int full_update)
 {
-    switch (s->ds->depth) {
+    switch (s->ds->surface->pf.bits_per_pixel) {
         case 8:
             tc6393xb_draw_graphic8(s);
             break;
@@ -447,7 +447,7 @@
             tc6393xb_draw_graphic32(s);
             break;
         default:
-            printf("tc6393xb: unknown depth %d\n", s->ds->depth);
+            printf("tc6393xb: unknown depth %d\n", 
s->ds->surface->pf.bits_per_pixel);
             return;
     }
 
@@ -462,11 +462,11 @@
     if (!full_update)
         return;
 
-    w = s->scr_width * ((s->ds->depth + 7) >> 3);
-    d = s->ds->data;
+    w = s->scr_width * ((s->ds->surface->pf.bits_per_pixel + 7) >> 3);
+    d = s->ds->surface->data;
     for(i = 0; i < s->scr_height; i++) {
         memset(d, 0, w);
-        d += s->ds->linesize;
+        d += s->ds->surface->linesize;
     }
 
     dpy_update(s->ds, 0, 0, s->scr_width, s->scr_height);
@@ -485,7 +485,7 @@
         s->blanked = s->blank;
         full_update = 1;
     }
-    if (s->scr_width != s->ds->width || s->scr_height != s->ds->height) {
+    if (s->scr_width != s->ds->surface->width || s->scr_height != 
s->ds->surface->height) {
         qemu_console_resize(s->console, s->scr_width, s->scr_height);
         full_update = 1;
     }
diff -r 5c78dd111aae hw/tc6393xb_template.h
--- a/hw/tc6393xb_template.h    Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/tc6393xb_template.h    Thu Nov 20 16:34:30 2008 +0000
@@ -46,12 +46,12 @@
 
     data_buffer = (uint16_t*)(phys_ram_base + s->vram_addr);
     w_display = s->scr_width * BITS / 8;
-    data_display = s->ds->data;
+    data_display = s->ds->surface->data;
     for(i = 0; i < s->scr_height; i++) {
 #if (BITS == 16)
         memcpy(data_display, data_buffer, s->scr_width * 2);
         data_buffer += s->scr_width;
-        data_display += s->ds->linesize;
+        data_display += s->ds->surface->linesize;
 #else
         int j;
         for (j = 0; j < s->scr_width; j++, data_display += BITS / 8, 
data_buffer++) {
diff -r 5c78dd111aae hw/tcx.c
--- a/hw/tcx.c  Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/tcx.c  Thu Nov 20 16:34:30 2008 +0000
@@ -55,28 +55,19 @@
 {
     int i;
     for(i = start; i < end; i++) {
-        switch(s->ds->depth) {
+        switch(s->ds->surface->pf.bits_per_pixel) {
         default:
         case 8:
             s->palette[i] = rgb_to_pixel8(s->r[i], s->g[i], s->b[i]);
             break;
         case 15:
-            if (s->ds->bgr)
-                s->palette[i] = rgb_to_pixel15bgr(s->r[i], s->g[i], s->b[i]);
-            else
-                s->palette[i] = rgb_to_pixel15(s->r[i], s->g[i], s->b[i]);
+            s->palette[i] = rgb_to_pixel15(s->r[i], s->g[i], s->b[i]);
             break;
         case 16:
-            if (s->ds->bgr)
-                s->palette[i] = rgb_to_pixel16bgr(s->r[i], s->g[i], s->b[i]);
-            else
-                s->palette[i] = rgb_to_pixel16(s->r[i], s->g[i], s->b[i]);
+            s->palette[i] = rgb_to_pixel16(s->r[i], s->g[i], s->b[i]);
             break;
         case 32:
-            if (s->ds->bgr)
-                s->palette[i] = rgb_to_pixel32bgr(s->r[i], s->g[i], s->b[i]);
-            else
-                s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]);
+            s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]);
             break;
         }
     }
@@ -134,12 +125,11 @@
                                      const uint32_t *cplane,
                                      const uint32_t *s24)
 {
-    int x, bgr, r, g, b;
+    int x, r, g, b;
     uint8_t val, *p8;
     uint32_t *p = (uint32_t *)d;
     uint32_t dval;
 
-    bgr = s1->ds->bgr;
     for(x = 0; x < width; x++, s++, s24++) {
         if ((be32_to_cpu(*cplane++) & 0xff000000) == 0x03000000) {
             // 24-bit direct, BGR order
@@ -148,10 +138,7 @@
             b = *p8++;
             g = *p8++;
             r = *p8++;
-            if (bgr)
-                dval = rgb_to_pixel32bgr(r, g, b);
-            else
-                dval = rgb_to_pixel32(r, g, b);
+            dval = rgb_to_pixel32(r, g, b);
         } else {
             val = *s;
             dval = s1->palette[val];
@@ -200,18 +187,18 @@
     uint8_t *d, *s;
     void (*f)(TCXState *s1, uint8_t *dst, const uint8_t *src, int width);
 
-    if (ts->ds->depth == 0)
+    if (ts->ds->surface->pf.bits_per_pixel == 0)
         return;
     page = ts->vram_offset;
     y_start = -1;
     page_min = 0xffffffff;
     page_max = 0;
-    d = ts->ds->data;
+    d = ts->ds->surface->data;
     s = ts->vram;
-    dd = ts->ds->linesize;
+    dd = ts->ds->surface->linesize;
     ds = 1024;
 
-    switch (ts->ds->depth) {
+    switch (ts->ds->surface->pf.bits_per_pixel) {
     case 32:
         f = tcx_draw_line32;
         break;
@@ -278,7 +265,7 @@
     uint8_t *d, *s;
     uint32_t *cptr, *s24;
 
-    if (ts->ds->depth != 32)
+    if (ts->ds->surface->pf.bits_per_pixel != 32)
             return;
     page = ts->vram_offset;
     page24 = ts->vram24_offset;
@@ -286,11 +273,11 @@
     y_start = -1;
     page_min = 0xffffffff;
     page_max = 0;
-    d = ts->ds->data;
+    d = ts->ds->surface->data;
     s = ts->vram;
     s24 = ts->vram24;
     cptr = ts->cplane;
-    dd = ts->ds->linesize;
+    dd = ts->ds->surface->linesize;
     ds = 1024;
 
     for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE,
diff -r 5c78dd111aae hw/vga.c
--- a/hw/vga.c  Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/vga.c  Thu Nov 20 16:34:30 2008 +0000
@@ -1151,24 +1151,15 @@
 
 static inline int get_depth_index(DisplayState *s)
 {
-    switch(s->depth) {
+    switch(s->surface->pf.bits_per_pixel) {
     default:
     case 8:
         return 0;
     case 15:
-        if (s->bgr)
-            return 5;
-        else
             return 1;
     case 16:
-        if (s->bgr)
-            return 6;
-        else
             return 2;
     case 32:
-        if (s->bgr)
-            return 4;
-        else
             return 3;
     }
 }
@@ -1221,6 +1212,10 @@
     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
     0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
 };
+
+typedef unsigned int rgb_to_pixel_dup_func(unsigned int r, unsigned int g, 
unsigned b);
+
+static rgb_to_pixel_dup_func *rgb_to_pixel_dup_table[NB_DEPTHS];
 
 /*
  * Text mode update
@@ -1242,9 +1237,6 @@
     uint32_t *ch_attr_ptr;
     vga_draw_glyph8_func *vga_draw_glyph8;
     vga_draw_glyph9_func *vga_draw_glyph9;
-
-    full_update |= update_palette16(s);
-    palette = s->last_palette;
 
     /* compute font data address (in plane 2) */
     v = s->sr[3];
@@ -1279,7 +1271,6 @@
         cw = 9;
     if (s->sr[1] & 0x08)
         cw = 16; /* NOTE: no 18 pixel wide */
-    x_incr = cw * ((s->ds->depth + 7) >> 3);
     width = (s->cr[0x01] + 1);
     if (s->cr[0x06] == 100) {
         /* ugly hack for CGA 160x100x16 - explain me the logic */
@@ -1296,16 +1287,23 @@
     }
 
     if (width != s->last_width || height != s->last_height ||
-        cw != s->last_cw || cheight != s->last_ch) {
+        cw != s->last_cw || cheight != s->last_ch || s->last_depth) {
         s->last_scr_width = width * cw;
         s->last_scr_height = height * cheight;
         qemu_console_resize(s->console, s->last_scr_width, s->last_scr_height);
+        s->last_depth = 0;
         s->last_width = width;
         s->last_height = height;
         s->last_ch = cheight;
         s->last_cw = cw;
         full_update = 1;
     }
+    s->rgb_to_pixel =
+        rgb_to_pixel_dup_table[get_depth_index(s->ds)];
+    full_update |= update_palette16(s);
+    palette = s->last_palette;
+    x_incr = cw * ((s->ds->surface->pf.bits_per_pixel + 7) >> 3);
+
     cursor_offset = ((s->cr[0x0e] << 8) | s->cr[0x0f]) - s->start_addr;
     if (cursor_offset != s->cursor_offset ||
         s->cr[0xa] != s->cursor_start ||
@@ -1329,8 +1327,8 @@
         vga_draw_glyph8 = vga_draw_glyph8_table[depth_index];
     vga_draw_glyph9 = vga_draw_glyph9_table[depth_index];
 
-    dest = s->ds->data;
-    linesize = s->ds->linesize;
+    dest = s->ds->surface->data;
+    linesize = s->ds->surface->linesize;
     ch_attr_ptr = s->last_ch_attr;
     for(cy = 0; cy < height; cy++) {
         d1 = dest;
@@ -1497,8 +1495,6 @@
     vga_draw_line32_16bgr,
 };
 
-typedef unsigned int rgb_to_pixel_dup_func(unsigned int r, unsigned int g, 
unsigned b);
-
 static rgb_to_pixel_dup_func *rgb_to_pixel_dup_table[NB_DEPTHS] = {
     rgb_to_pixel8_dup,
     rgb_to_pixel15_dup,
@@ -1561,7 +1557,7 @@
  */
 static void vga_draw_graphic(VGAState *s, int full_update)
 {
-    int y1, y, update, page_min, page_max, linesize, y_start, double_scan, 
mask;
+    int y1, y, update, page_min, page_max, linesize, y_start, double_scan, 
mask, depth;
     int width, height, shift_control, line_offset, page0, page1, bwidth, bits;
     int disp_width, multi_scan, multi_run;
     uint8_t *d;
@@ -1641,16 +1637,41 @@
     }
     vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + 
get_depth_index(s->ds)];
 
-    if (disp_width != s->last_width ||
-        height != s->last_height) {
-        qemu_console_resize(s->console, disp_width, height);
+    depth = s->get_bpp(s);
+    if (s->line_offset != s->last_line_offset ||
+        disp_width != s->last_width ||
+        height != s->last_height ||
+        s->last_depth != depth) {
+        if (depth == 16 || depth == 32) {
+            if (is_active_console(s->console)) {
+                qemu_freeDisplaySurface(s->ds->surface);
+                s->ds->surface = qemu_createDisplaySurfaceFrom(disp_width, 
height, depth,
+                                                               s->line_offset,
+                                                               s->vram_ptr + 
(s->start_addr * 4));
+                dpy_resize(s->ds);
+            } else {
+                qemu_console_resize(s->console, disp_width, height);
+            }
+        } else {
+            qemu_console_resize(s->console, disp_width, height);
+        }
         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;
+        s->last_depth = depth;
         full_update = 1;
+    } else if (is_active_console(s->console) && 
is_buffer_shared(s->ds->surface) &&
+               (full_update || s->ds->surface->data != s->vram_ptr + 
(s->start_addr * 4))) {
+        s->ds->surface->data = s->vram_ptr + (s->start_addr * 4);
+        dpy_setdata(s->ds);
     }
-    if (s->cursor_invalidate)
+
+    s->rgb_to_pixel =
+        rgb_to_pixel_dup_table[get_depth_index(s->ds)];
+
+    if (!is_buffer_shared(s->ds->surface) && s->cursor_invalidate)
         s->cursor_invalidate(s);
 
     line_offset = s->line_offset;
@@ -1663,8 +1684,8 @@
     y_start = -1;
     page_min = 0x7fffffff;
     page_max = -1;
-    d = s->ds->data;
-    linesize = s->ds->linesize;
+    d = s->ds->surface->data;
+    linesize = s->ds->surface->linesize;
     y1 = 0;
     for(y = 0; y < height; y++) {
         addr = addr1;
@@ -1696,9 +1717,11 @@
                 page_min = page0;
             if (page1 > page_max)
                 page_max = page1;
-            vga_draw_line(s, d, s->vram_ptr + addr, width);
-            if (s->cursor_draw_line)
-                s->cursor_draw_line(s, d, y);
+            if (!(is_buffer_shared(s->ds->surface))) {
+                vga_draw_line(s, d, s->vram_ptr + addr, width);
+                if (s->cursor_draw_line)
+                    s->cursor_draw_line(s, d, y);
+            }
         } else {
             if (y_start >= 0) {
                 /* flush to display */
@@ -1743,15 +1766,17 @@
         return;
     if (s->last_scr_width <= 0 || s->last_scr_height <= 0)
         return;
-    if (s->ds->depth == 8)
+    s->rgb_to_pixel =
+        rgb_to_pixel_dup_table[get_depth_index(s->ds)];
+    if (s->ds->surface->pf.bits_per_pixel == 8)
         val = s->rgb_to_pixel(0, 0, 0);
     else
         val = 0;
-    w = s->last_scr_width * ((s->ds->depth + 7) >> 3);
-    d = s->ds->data;
+    w = s->last_scr_width * ((s->ds->surface->pf.bits_per_pixel + 7) >> 3);
+    d = s->ds->surface->data;
     for(i = 0; i < s->last_scr_height; i++) {
         memset(d, val, w);
-        d += s->ds->linesize;
+        d += s->ds->surface->linesize;
     }
     dpy_update(s->ds, 0, 0,
                s->last_scr_width, s->last_scr_height);
@@ -1766,12 +1791,9 @@
     VGAState *s = (VGAState *)opaque;
     int full_update, graphic_mode;
 
-    if (s->ds->depth == 0) {
+    if (s->ds->surface->pf.bits_per_pixel == 0) {
         /* nothing to do */
     } else {
-        s->rgb_to_pixel =
-            rgb_to_pixel_dup_table[get_depth_index(s->ds)];
-
         full_update = 0;
         if (!(s->ar_index & 0x20)) {
             graphic_mode = GMODE_BLANK;
@@ -1879,7 +1901,9 @@
             cw != s->last_cw || cheight != s->last_ch) {
             s->last_scr_width = width * cw;
             s->last_scr_height = height * cheight;
-            qemu_console_resize(s->console, width, height);
+            s->ds->surface->width = width;
+            s->ds->surface->height = height;
+           dpy_resize(s->ds);
             s->last_width = width;
             s->last_height = height;
             s->last_ch = cheight;
@@ -1960,7 +1984,9 @@
     s->last_width = 60;
     s->last_height = height = 3;
     dpy_cursor(s->ds, -1, -1);
-    qemu_console_resize(s->console, s->last_width, height);
+    s->ds->surface->width = s->last_width;
+    s->ds->surface->height = height;
+    dpy_resize(s->ds);
 
     for (dst = chardata, i = 0; i < s->last_width * height; i ++)
         console_write_ch(dst ++, ' ');
@@ -2393,12 +2419,8 @@
 {
 }
 
-static void vga_save_dpy_resize(DisplayState *s, int w, int h)
+static void vga_save_dpy_resize(DisplayState *s)
 {
-    s->linesize = w * 4;
-    s->data = qemu_malloc(h * s->linesize);
-    vga_save_w = w;
-    vga_save_h = h;
 }
 
 static void vga_save_dpy_refresh(DisplayState *s)
@@ -2440,25 +2462,28 @@
 {
     VGAState *s = (VGAState *)opaque;
     DisplayState *saved_ds, ds1, *ds = &ds1;
+    DisplayChangeListener dcl;
 
     /* XXX: this is a little hackish */
     vga_invalidate_display(s);
     saved_ds = s->ds;
 
     memset(ds, 0, sizeof(DisplayState));
-    ds->dpy_update = vga_save_dpy_update;
-    ds->dpy_resize = vga_save_dpy_resize;
-    ds->dpy_refresh = vga_save_dpy_refresh;
-    ds->depth = 32;
+    memset(&dcl, 0, sizeof(DisplayChangeListener));
+    dcl.dpy_update = vga_save_dpy_update;
+    dcl.dpy_resize = vga_save_dpy_resize;
+    dcl.dpy_refresh = vga_save_dpy_refresh;
+    register_displaychangelistener(ds, &dcl);
+    ds->surface = qemu_createDisplaySurface(saved_ds->surface->width,
+            saved_ds->surface->height, 32, 4 * saved_ds->surface->width);
 
     s->ds = ds;
     s->graphic_mode = -1;
     vga_update_display(s);
 
-    if (ds->data) {
-        ppm_save(filename, ds->data, vga_save_w, vga_save_h,
-                 s->ds->linesize);
-        qemu_free(ds->data);
-    }
+    ppm_save(filename, ds->surface->data, vga_save_w, vga_save_h,
+            s->ds->surface->linesize);
+
+    qemu_freeDisplaySurface(ds->surface);
     s->ds = saved_ds;
 }
diff -r 5c78dd111aae hw/vga_int.h
--- a/hw/vga_int.h      Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/vga_int.h      Thu Nov 20 16:34:30 2008 +0000
@@ -149,9 +149,11 @@
     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 */           \
+    uint32_t last_depth; /* in bits */                                  \
     uint8_t cursor_start, cursor_end;                                   \
     uint32_t cursor_offset;                                             \
     unsigned int (*rgb_to_pixel)(unsigned int r,                        \
diff -r 5c78dd111aae hw/vmware_vga.c
--- a/hw/vmware_vga.c   Tue Nov 04 09:04:41 2008 +0000
+++ b/hw/vmware_vga.c   Thu Nov 20 16:34:30 2008 +0000
@@ -319,7 +319,7 @@
     width = s->bypp * w;
     start = s->bypp * x + bypl * y;
     src = s->vram + start;
-    dst = s->ds->data + start;
+    dst = s->ds->surface->data + start;
 
     for (; line > 0; line --, src += bypl, dst += bypl)
         memcpy(dst, src, width);
@@ -331,7 +331,7 @@
 static inline void vmsvga_update_screen(struct vmsvga_state_s *s)
 {
 #ifndef DIRECT_VRAM
-    memcpy(s->ds->data, s->vram, s->bypp * s->width * s->height);
+    memcpy(s->ds->surface->data, s->vram, s->bypp * s->width * s->height);
 #endif
 
     dpy_update(s->ds, 0, 0, s->width, s->height);
@@ -373,7 +373,7 @@
                 int x0, int y0, int x1, int y1, int w, int h)
 {
 # ifdef DIRECT_VRAM
-    uint8_t *vram = s->ds->data;
+    uint8_t *vram = s->ds->surface->data;
 # else
     uint8_t *vram = s->vram;
 # endif
@@ -410,7 +410,7 @@
                 uint32_t c, int x, int y, int w, int h)
 {
 # ifdef DIRECT_VRAM
-    uint8_t *vram = s->ds->data;
+    uint8_t *vram = s->ds->surface->data;
 # else
     uint8_t *vram = s->vram;
 # endif
@@ -915,7 +915,7 @@
     s->width = -1;
     s->height = -1;
     s->svgaid = SVGA_ID;
-    s->depth = s->ds->depth ? s->ds->depth : 24;
+    s->depth = s->ds->surface->pf.bits_per_pixel;
     s->bypp = (s->depth + 7) >> 3;
     s->cursor.on = 0;
     s->redraw_fifo_first = 0;
@@ -976,7 +976,7 @@
     }
 
     if (s->depth == 32) {
-        ppm_save(filename, s->vram, s->width, s->height, s->ds->linesize);
+        ppm_save(filename, s->vram, s->width, s->height, 
s->ds->surface->linesize);
     }
 }
 
@@ -994,7 +994,7 @@
     struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
     addr -= s->vram_base;
     if (addr < s->fb_size)
-        return *(uint8_t *) (s->ds->data + addr);
+        return *(uint8_t *) (s->ds->surface->data + addr);
     else
         return *(uint8_t *) (s->vram + addr);
 }
@@ -1004,7 +1004,7 @@
     struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
     addr -= s->vram_base;
     if (addr < s->fb_size)
-        return *(uint16_t *) (s->ds->data + addr);
+        return *(uint16_t *) (s->ds->surface->data + addr);
     else
         return *(uint16_t *) (s->vram + addr);
 }
@@ -1014,7 +1014,7 @@
     struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
     addr -= s->vram_base;
     if (addr < s->fb_size)
-        return *(uint32_t *) (s->ds->data + addr);
+        return *(uint32_t *) (s->ds->surface->data + addr);
     else
         return *(uint32_t *) (s->vram + addr);
 }
@@ -1025,7 +1025,7 @@
     struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
     addr -= s->vram_base;
     if (addr < s->fb_size)
-        *(uint8_t *) (s->ds->data + addr) = value;
+        *(uint8_t *) (s->ds->surface->data + addr) = value;
     else
         *(uint8_t *) (s->vram + addr) = value;
 }
@@ -1036,7 +1036,7 @@
     struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
     addr -= s->vram_base;
     if (addr < s->fb_size)
-        *(uint16_t *) (s->ds->data + addr) = value;
+        *(uint16_t *) (s->ds->surface->data + addr) = value;
     else
         *(uint16_t *) (s->vram + addr) = value;
 }
@@ -1047,7 +1047,7 @@
     struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
     addr -= s->vram_base;
     if (addr < s->fb_size)
-        *(uint32_t *) (s->ds->data + addr) = value;
+        *(uint32_t *) (s->ds->surface->data + addr) = value;
     else
         *(uint32_t *) (s->vram + addr) = value;
 }
diff -r 5c78dd111aae qemu-common.h
--- a/qemu-common.h     Tue Nov 04 09:04:41 2008 +0000
+++ b/qemu-common.h     Thu Nov 20 16:34:30 2008 +0000
@@ -96,6 +96,7 @@
 
 void *qemu_malloc(size_t size);
 void *qemu_realloc(void *ptr, size_t size);
+void *qemu_reallocz(void *ptr, size_t size);
 void *qemu_mallocz(size_t size);
 void qemu_free(void *ptr);
 char *qemu_strdup(const char *str);
@@ -128,6 +129,9 @@
 typedef struct AudioState AudioState;
 typedef struct BlockDriverState BlockDriverState;
 typedef struct DisplayState DisplayState;
+typedef struct DisplayChangeListener DisplayChangeListener;
+typedef struct DisplaySurface DisplaySurface;
+typedef struct PixelFormat PixelFormat;
 typedef struct TextConsole TextConsole;
 typedef TextConsole QEMUConsole;
 typedef struct CharDriverState CharDriverState;
diff -r 5c78dd111aae qemu-malloc.c
--- a/qemu-malloc.c     Tue Nov 04 09:04:41 2008 +0000
+++ b/qemu-malloc.c     Thu Nov 20 16:34:30 2008 +0000
@@ -43,6 +43,16 @@
     return realloc(ptr, size);
 }
 
+void *qemu_reallocz(void *ptr, size_t size)
+{
+    void *res;
+    res = realloc(ptr, size);
+    if (!res)
+        return NULL;
+    memset(res, 0, size);
+    return res;
+}
+
 void *qemu_mallocz(size_t size)
 {
     void *ptr;
diff -r 5c78dd111aae sdl.c
--- a/sdl.c     Tue Nov 04 09:04:41 2008 +0000
+++ b/sdl.c     Thu Nov 20 16:34:30 2008 +0000
@@ -31,7 +31,9 @@
 #include <signal.h>
 #endif
 
-static SDL_Surface *screen;
+static DisplayChangeListener *dcl;
+static SDL_Surface *real_screen;
+static SDL_Surface *guest_screen = NULL;
 static int gui_grab; /* if true, all keyboard/mouse events are grabbed */
 static int last_vm_running;
 static int gui_saved_grab;
@@ -45,6 +47,7 @@
 static int width, height;
 static SDL_Cursor *sdl_cursor_normal;
 static SDL_Cursor *sdl_cursor_hidden;
+static int bgr = 0;
 static int absolute_enabled = 0;
 static int guest_cursor = 0;
 static int guest_x, guest_y;
@@ -52,11 +55,34 @@
 
 static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
 {
+    SDL_Rect rec;
+    rec.x = x;
+    rec.y = y;
+    rec.w = w;
+    rec.h = h;
     //    printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
-    SDL_UpdateRect(screen, x, y, w, h);
+
+    SDL_BlitSurface(guest_screen, &rec, real_screen, &rec);
+    SDL_Flip(real_screen);
 }
 
-static void sdl_resize(DisplayState *ds, int w, int h)
+static void sdl_setdata(DisplayState *ds)
+{
+    SDL_Rect rec;
+    rec.x = 0;
+    rec.y = 0;
+    rec.w = real_screen->w;
+    rec.h = real_screen->h;
+
+    if (guest_screen != NULL) SDL_FreeSurface(guest_screen);
+
+    guest_screen = SDL_CreateRGBSurfaceFrom(ds->surface->data, 
ds->surface->width, ds->surface->height,
+                                            ds->surface->pf.bits_per_pixel, 
ds->surface->linesize,
+                                            ds->surface->pf.rmask, 
ds->surface->pf.gmask,
+                                            ds->surface->pf.bmask, 
ds->surface->pf.amask);
+}
+
+static void sdl_resize(DisplayState *ds)
 {
     int flags;
 
@@ -68,45 +94,28 @@
     if (gui_noframe)
         flags |= SDL_NOFRAME;
 
-    width = w;
-    height = h;
-
  again:
-    screen = SDL_SetVideoMode(w, h, 0, flags);
-    if (!screen) {
+    real_screen = SDL_SetVideoMode(ds->surface->width, ds->surface->height, 0, 
flags);
+    if (!real_screen) {
         fprintf(stderr, "Could not open SDL display\n");
         exit(1);
     }
-    if (!screen->pixels && (flags & SDL_HWSURFACE) && (flags & 
SDL_FULLSCREEN)) {
+    if (!real_screen->pixels && (flags & SDL_HWSURFACE) && (flags & 
SDL_FULLSCREEN)) {
         flags &= ~SDL_HWSURFACE;
         goto again;
     }
 
-    if (!screen->pixels) {
+    if (!real_screen->pixels) {
         fprintf(stderr, "Could not open SDL display\n");
         exit(1);
     }
-    ds->data = screen->pixels;
-    ds->linesize = screen->pitch;
-    ds->depth = screen->format->BitsPerPixel;
-    /* SDL BitsPerPixel never indicates any values other than
-       multiples of 8, so we need to check for strange depths. */
-    if (ds->depth == 16) {
-        uint32_t mask;
+    if (real_screen->format->Bshift > real_screen->format->Rshift) {
+        bgr = 1;
+    } else {
+        bgr = 0;
+    }
 
-        mask = screen->format->Rmask;
-        mask |= screen->format->Gmask;
-        mask |= screen->format->Bmask;
-        if ((mask & 0x8000) == 0)
-            ds->depth = 15;
-    }
-    if (ds->depth == 32 && screen->format->Rshift == 0) {
-        ds->bgr = 1;
-    } else {
-        ds->bgr = 0;
-    }
-    ds->width = w;
-    ds->height = h;
+    sdl_setdata(ds);
 }
 
 /* generic keyboard conversion */
@@ -339,7 +348,7 @@
 static void toggle_full_screen(DisplayState *ds)
 {
     gui_fullscreen = !gui_fullscreen;
-    sdl_resize(ds, screen->w, screen->h);
+    sdl_resize(ds);
     if (gui_fullscreen) {
         gui_saved_grab = gui_grab;
         sdl_grab_start();
@@ -368,7 +377,7 @@
     while (SDL_PollEvent(ev)) {
         switch (ev->type) {
         case SDL_VIDEOEXPOSE:
-            sdl_update(ds, 0, 0, screen->w, screen->h);
+            sdl_update(ds, 0, 0, real_screen->w, real_screen->h);
             break;
         case SDL_KEYDOWN:
         case SDL_KEYUP:
@@ -523,12 +532,12 @@
             if (ev->active.state & SDL_APPACTIVE) {
                 if (ev->active.gain) {
                     /* Back to default interval */
-                    ds->gui_timer_interval = 0;
-                    ds->idle = 0;
+                    dcl->gui_timer_interval = 0;
+                    dcl->idle = 0;
                 } else {
                     /* Sleeping interval */
-                    ds->gui_timer_interval = 500;
-                    ds->idle = 1;
+                    dcl->gui_timer_interval = 500;
+                    dcl->idle = 1;
                 }
             }
             break;
@@ -541,7 +550,7 @@
 static void sdl_fill(DisplayState *ds, int x, int y, int w, int h, uint32_t c)
 {
     SDL_Rect dst = { x, y, w, h };
-    SDL_FillRect(screen, &dst, c);
+    SDL_FillRect(real_screen, &dst, c);
 }
 
 static void sdl_mouse_warp(int x, int y, int on)
@@ -637,14 +646,18 @@
         exit(1);
     }
 
-    ds->dpy_update = sdl_update;
-    ds->dpy_resize = sdl_resize;
-    ds->dpy_refresh = sdl_refresh;
-    ds->dpy_fill = sdl_fill;
+    dcl = qemu_mallocz(sizeof(DisplayChangeListener));
+    if (!dcl)
+        exit(1);
+    dcl->dpy_update = sdl_update;
+    dcl->dpy_resize = sdl_resize;
+    dcl->dpy_refresh = sdl_refresh;
+    dcl->dpy_setdata = sdl_setdata;
+    dcl->dpy_fill = sdl_fill;
     ds->mouse_set = sdl_mouse_warp;
     ds->cursor_define = sdl_mouse_define;
+    register_displaychangelistener(ds, dcl);
 
-    sdl_resize(ds, 640, 400);
     sdl_update_caption();
     SDL_EnableKeyRepeat(250, 50);
     gui_grab = 0;
diff -r 5c78dd111aae vl.c
--- a/vl.c      Tue Nov 04 09:04:41 2008 +0000
+++ b/vl.c      Thu Nov 20 16:34:30 2008 +0000
@@ -182,6 +182,7 @@
 DisplayState display_state;
 int nographic;
 static int curses;
+static int sdl;
 const char* keyboard_layout = NULL;
 int64_t ticks_per_sec;
 ram_addr_t ram_size;
@@ -2506,20 +2507,21 @@
 {
 }
 
-static void dumb_resize(DisplayState *ds, int w, int h)
+static void dumb_resize(DisplayState *ds)
 {
 }
 
 static void dumb_display_init(DisplayState *ds)
 {
-    ds->data = NULL;
-    ds->linesize = 0;
-    ds->depth = 0;
-    ds->dpy_update = dumb_update;
-    ds->dpy_resize = dumb_resize;
-    ds->dpy_refresh = NULL;
-    ds->gui_timer_interval = 0;
-    ds->idle = 1;
+    DisplayChangeListener *dcl = qemu_mallocz(sizeof(DisplayChangeListener));
+    if (!dcl)
+        exit(1);
+    dcl->dpy_update = dumb_update;
+    dcl->dpy_resize = dumb_resize;
+    dcl->dpy_refresh = NULL;
+    dcl->idle = 1;
+    dcl->gui_timer_interval = 500;
+    register_displaychangelistener(ds, dcl);
 }
 
 /***********************************************************/
@@ -4192,13 +4194,19 @@
 
 static void gui_update(void *opaque)
 {
+    uint64_t interval = GUI_REFRESH_INTERVAL;
     DisplayState *ds = opaque;
-    ds->dpy_refresh(ds);
-    qemu_mod_timer(ds->gui_timer,
-        (ds->gui_timer_interval ?
-           ds->gui_timer_interval :
-           GUI_REFRESH_INTERVAL)
-       + qemu_get_clock(rt_clock));
+    DisplayChangeListener *dcl = ds->listeners;
+
+    dpy_refresh(ds);
+
+    while (dcl != NULL) {
+        if (dcl->gui_timer_interval &&
+            dcl->gui_timer_interval < interval)
+            interval = dcl->gui_timer_interval;
+        dcl = dcl->next;
+    }
+    qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock));
 }
 
 struct vm_change_state_entry {
@@ -4685,6 +4693,7 @@
            "-no-frame       open SDL window without a frame and window 
decorations\n"
            "-alt-grab       use Ctrl-Alt-Shift to grab mouse (instead of 
Ctrl-Alt)\n"
            "-no-quit        disable SDL window close capability\n"
+           "-sdl            enable SDL\n"
 #endif
 #ifdef TARGET_I386
            "-no-fd-bootchk  disable boot signature checking for floppy disks\n"
@@ -4884,6 +4893,7 @@
     QEMU_OPTION_no_frame,
     QEMU_OPTION_alt_grab,
     QEMU_OPTION_no_quit,
+    QEMU_OPTION_sdl,
     QEMU_OPTION_pidfile,
     QEMU_OPTION_no_kqemu,
     QEMU_OPTION_kernel_kqemu,
@@ -4988,6 +4998,7 @@
     { "no-frame", 0, QEMU_OPTION_no_frame },
     { "alt-grab", 0, QEMU_OPTION_alt_grab },
     { "no-quit", 0, QEMU_OPTION_no_quit },
+    { "sdl", 0, QEMU_OPTION_sdl },
 #endif
     { "pidfile", HAS_ARG, QEMU_OPTION_pidfile },
     { "win2k-hack", 0, QEMU_OPTION_win2k_hack },
@@ -5292,6 +5303,7 @@
     const char *kernel_filename, *kernel_cmdline;
     const char *boot_devices = "";
     DisplayState *ds = &display_state;
+    DisplayChangeListener *dcl;
     int cyls, heads, secs, translation;
     const char *net_clients[MAX_NET_CLIENTS];
     int nb_net_clients;
@@ -5776,6 +5788,9 @@
                 break;
             case QEMU_OPTION_no_quit:
                 no_quit = 1;
+                break;
+            case QEMU_OPTION_sdl:
+                sdl = 1;
                 break;
 #endif
             case QEMU_OPTION_pidfile:
@@ -6142,6 +6157,7 @@
 
     /* terminal init */
     memset(&display_state, 0, sizeof(display_state));
+    ds->surface = qemu_createDisplaySurface(640, 480, 32, 640 * 4);
     if (nographic) {
         if (curses) {
             fprintf(stderr, "fatal: -nographic can't be used with -curses\n");
@@ -6149,26 +6165,30 @@
         }
         /* nearly nothing to do */
         dumb_display_init(ds);
-    } else if (vnc_display != NULL) {
-        vnc_display_init(ds);
-        if (vnc_display_open(ds, vnc_display) < 0)
-            exit(1);
-    } else
+    } else { 
 #if defined(CONFIG_CURSES)
-    if (curses) {
-        curses_display_init(ds, full_screen);
-    } else
-#endif
-    {
+            if (curses) {
+                /* At the moment curses cannot be used with other displays */
+                curses_display_init(ds, full_screen);
+            } else
+#endif
+            {
+                if (vnc_display != NULL) {
+                    vnc_display_init(ds);
+                    if (vnc_display_open(ds, vnc_display) < 0)
+                        exit(1);
+                }
+                if (sdl || !vnc_display)
 #if defined(CONFIG_SDL)
-        sdl_display_init(ds, full_screen, no_frame);
+                    sdl_display_init(ds, full_screen, no_frame);
 #elif defined(CONFIG_COCOA)
-        cocoa_display_init(ds, full_screen);
-#else
-        dumb_display_init(ds);
-#endif
-    }
-
+                    cocoa_display_init(ds, full_screen);
+#else
+                    dumb_display_init(ds);
+#endif
+            }
+    }
+    dpy_resize(ds);
 #ifndef _WIN32
     /* must be after terminal init, SDL library changes signal handlers */
     termsig_setup();
@@ -6242,11 +6262,14 @@
         }
     }
 
-    if (display_state.dpy_refresh) {
-        display_state.gui_timer = qemu_new_timer(rt_clock, gui_update, 
&display_state);
-        qemu_mod_timer(display_state.gui_timer, qemu_get_clock(rt_clock));
-    }
-
+    dcl = ds->listeners;
+    while (dcl != NULL) {
+        if (dcl->dpy_refresh != NULL) {
+            display_state.gui_timer = qemu_new_timer(rt_clock, gui_update, 
&display_state);
+            qemu_mod_timer(display_state.gui_timer, qemu_get_clock(rt_clock));
+        }
+        dcl = dcl->next;
+    }
 #ifdef CONFIG_GDBSTUB
     if (use_gdbstub) {
         /* XXX: use standard host:port notation and modify options
diff -r 5c78dd111aae vnc.c
--- a/vnc.c     Tue Nov 04 09:04:41 2008 +0000
+++ b/vnc.c     Thu Nov 20 16:34:30 2008 +0000
@@ -176,6 +176,7 @@
 };
 
 static VncState *vnc_state; /* needed for info vnc */
+static DisplayChangeListener *dcl;
 
 void do_info_vnc(void)
 {
@@ -209,7 +210,7 @@
 static void vnc_update_client(void *opaque);
 static void vnc_client_read(void *opaque);
 
-static void vnc_colordepth(DisplayState *ds, int depth);
+static void vnc_colordepth(DisplayState *ds);
 
 static inline void vnc_set_bit(uint32_t *d, int k)
 {
@@ -287,41 +288,36 @@
     vnc_write_s32(vs, encoding);
 }
 
-static void vnc_dpy_resize(DisplayState *ds, int w, int h)
+static void vnc_dpy_resize(DisplayState *ds)
 {
     int size_changed;
     VncState *vs = ds->opaque;
 
-    ds->data = qemu_realloc(ds->data, w * h * vs->depth);
-    vs->old_data = qemu_realloc(vs->old_data, w * h * vs->depth);
+    vs->old_data = qemu_realloc(vs->old_data, ds->surface->linesize * 
ds->surface->height);
 
-    if (ds->data == NULL || vs->old_data == NULL) {
+    if (vs->old_data == NULL) {
        fprintf(stderr, "vnc: memory allocation failed\n");
        exit(1);
     }
 
-    if (ds->depth != vs->depth * 8) {
-        ds->depth = vs->depth * 8;
+    if (ds->surface->pf.bytes_per_pixel != vs->depth)
         console_color_init(ds);
-    }
-    size_changed = ds->width != w || ds->height != h;
-    ds->width = w;
-    ds->height = h;
-    ds->linesize = w * vs->depth;
+    vnc_colordepth(ds);
+    size_changed = ds->surface->width != vs->width || ds->surface->height != 
vs->height;
     if (size_changed) {
-        vs->width = ds->width;
-        vs->height = ds->height;
+        vs->width = ds->surface->width;
+        vs->height = ds->surface->height;
         if (vs->csock != -1 && vs->has_resize) {
             vnc_write_u8(vs, 0);  /* msg id */
             vnc_write_u8(vs, 0);
             vnc_write_u16(vs, 1); /* number of rects */
-            vnc_framebuffer_update(vs, 0, 0, ds->width, ds->height, -223);
+            vnc_framebuffer_update(vs, 0, 0, ds->surface->width, 
ds->surface->height, -223);
             vnc_flush(vs);
         }
     }
 
     memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
-    memset(vs->old_data, 42, vs->ds->linesize * vs->ds->height);
+    memset(vs->old_data, 42, ds->surface->linesize * ds->surface->height);
 }
 
 /* fastest code */
@@ -414,10 +410,10 @@
 
     vnc_framebuffer_update(vs, x, y, w, h, 0);
 
-    row = vs->ds->data + y * vs->ds->linesize + x * vs->depth;
+    row = vs->ds->surface->data + y * vs->ds->surface->linesize + x * 
vs->depth;
     for (i = 0; i < h; i++) {
        vs->write_pixels(vs, row, w * vs->depth);
-       row += vs->ds->linesize;
+       row += vs->ds->surface->linesize;
     }
 }
 
@@ -490,12 +486,8 @@
 
 static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int 
dst_y, int w, int h)
 {
-    int src, dst;
-    uint8_t *src_row;
-    uint8_t *dst_row;
-    char *old_row;
     int y = 0;
-    int pitch = ds->linesize;
+    int pitch = ds->surface->linesize;
     VncState *vs = ds->opaque;
 
     vnc_update_client(vs);
@@ -503,21 +495,6 @@
     if (dst_y > src_y) {
        y = h - 1;
        pitch = -pitch;
-    }
-
-    src = (ds->linesize * (src_y + y) + vs->depth * src_x);
-    dst = (ds->linesize * (dst_y + y) + vs->depth * dst_x);
-
-    src_row = ds->data + src;
-    dst_row = ds->data + dst;
-    old_row = vs->old_data + dst;
-
-    for (y = 0; y < h; y++) {
-       memmove(old_row, src_row, w * vs->depth);
-       memmove(dst_row, src_row, w * vs->depth);
-       src_row += pitch;
-       dst_row += pitch;
-       old_row += pitch;
     }
 
     vnc_write_u8(vs, 0);  /* msg id */
@@ -563,7 +540,7 @@
 
        /* Walk through the dirty map and eliminate tiles that
           really aren't dirty */
-       row = vs->ds->data;
+       row = vs->ds->surface->data;
        old_row = vs->old_data;
 
        for (y = 0; y < vs->height; y++) {
@@ -575,7 +552,7 @@
                ptr = row;
                old_ptr = (char*)old_row;
 
-               for (x = 0; x < vs->ds->width; x += 16) {
+               for (x = 0; x < vs->ds->surface->width; x += 16) {
                    if (memcmp(old_ptr, ptr, 16 * vs->depth) == 0) {
                        vnc_clear_bit(vs->dirty_row[y], (x / 16));
                    } else {
@@ -588,8 +565,8 @@
                }
            }
 
-           row += vs->ds->linesize;
-           old_row += vs->ds->linesize;
+           row += vs->ds->surface->linesize;
+           old_row += vs->ds->surface->linesize;
        }
 
        if (!has_dirty) {
@@ -701,7 +678,7 @@
        qemu_set_fd_handler2(vs->csock, NULL, NULL, NULL, NULL);
        closesocket(vs->csock);
        vs->csock = -1;
-       vs->ds->idle = 1;
+       dcl->idle = 1;
        buffer_reset(&vs->input);
        buffer_reset(&vs->output);
        vs->need_update = 0;
@@ -918,7 +895,7 @@
        vnc_write_u8(vs, 0);
        vnc_write_u16(vs, 1);
        vnc_framebuffer_update(vs, absolute, 0,
-                              vs->ds->width, vs->ds->height, -257);
+                              vs->ds->surface->width, vs->ds->surface->height, 
-257);
        vnc_flush(vs);
     }
     vs->absolute = absolute;
@@ -941,8 +918,8 @@
        dz = 1;
 
     if (vs->absolute) {
-       kbd_mouse_event(x * 0x7FFF / (vs->ds->width - 1),
-                       y * 0x7FFF / (vs->ds->height - 1),
+       kbd_mouse_event(x * 0x7FFF / (vs->ds->surface->width - 1),
+                       y * 0x7FFF / (vs->ds->surface->height - 1),
                        dz, buttons);
     } else if (vs->has_pointer_type_change) {
        x -= 0x7FFF;
@@ -1106,25 +1083,25 @@
                                       int x_position, int y_position,
                                       int w, int h)
 {
-    if (x_position > vs->ds->width)
-        x_position = vs->ds->width;
-    if (y_position > vs->ds->height)
-        y_position = vs->ds->height;
-    if (x_position + w >= vs->ds->width)
-        w = vs->ds->width  - x_position;
-    if (y_position + h >= vs->ds->height)
-        h = vs->ds->height - y_position;
+    if (x_position > vs->ds->surface->width)
+        x_position = vs->ds->surface->width;
+    if (y_position > vs->ds->surface->height)
+        y_position = vs->ds->surface->height;
+    if (x_position + w >= vs->ds->surface->width)
+        w = vs->ds->surface->width  - x_position;
+    if (y_position + h >= vs->ds->surface->height)
+        h = vs->ds->surface->height - y_position;
 
     int i;
     vs->need_update = 1;
     if (!incremental) {
-       char *old_row = vs->old_data + y_position * vs->ds->linesize;
+       char *old_row = vs->old_data + y_position * vs->ds->surface->linesize;
 
        for (i = 0; i < h; i++) {
             vnc_set_bits(vs->dirty_row[y_position + i],
-                         (vs->ds->width / 16), VNC_DIRTY_WORDS);
-           memset(old_row, 42, vs->ds->width * vs->depth);
-           old_row += vs->ds->linesize;
+                         (vs->ds->surface->width / 16), VNC_DIRTY_WORDS);
+           memset(old_row, 42, vs->ds->surface->width * vs->depth);
+           old_row += vs->ds->surface->linesize;
        }
     }
 }
@@ -1134,7 +1111,7 @@
     vnc_write_u8(vs, 0);
     vnc_write_u8(vs, 0);
     vnc_write_u16(vs, 1);
-    vnc_framebuffer_update(vs, 0, 0, vs->ds->width, vs->ds->height, -258);
+    vnc_framebuffer_update(vs, 0, 0, vs->ds->surface->width, 
vs->ds->surface->height, -258);
     vnc_flush(vs);
 }
 
@@ -1147,7 +1124,7 @@
     vs->has_pointer_type_change = 0;
     vs->has_WMVi = 0;
     vs->absolute = -1;
-    vs->ds->dpy_copy = NULL;
+    dcl->dpy_copy = NULL;
 
     for (i = n_encodings - 1; i >= 0; i--) {
        switch (encodings[i]) {
@@ -1155,7 +1132,7 @@
            vs->has_hextile = 0;
            break;
        case 1: /* CopyRect */
-           vs->ds->dpy_copy = vnc_copy;
+           dcl->dpy_copy = vnc_copy;
            break;
        case 5: /* Hextile */
            vs->has_hextile = 1;
@@ -1305,23 +1282,15 @@
     vnc_write(vs, pad, 3);           /* padding */
 }
 
-static void vnc_colordepth(DisplayState *ds, int depth)
+static void vnc_dpy_setdata(DisplayState *ds)
+{
+    /* We don't have to do anything */
+}
+
+static void vnc_colordepth(DisplayState *ds)
 {
     int host_big_endian_flag;
     struct VncState *vs = ds->opaque;
-
-    switch (depth) {
-        case 24:
-            if (ds->depth == 32) return;
-            depth = 32;
-            break;
-        case 15:
-        case 8:
-        case 0:
-            return;
-        default:
-            break;
-    }
 
 #ifdef WORDS_BIGENDIAN
     host_big_endian_flag = 1;
@@ -1329,9 +1298,9 @@
     host_big_endian_flag = 0;
 #endif   
     
-    switch (depth) {
+    switch (ds->surface->pf.bits_per_pixel) {
         case 8:
-            vs->depth = depth / 8;
+            vs->depth = 1;
             vs->server_red_max = 7;
             vs->server_green_max = 7;
             vs->server_blue_max = 3;
@@ -1340,7 +1309,7 @@
             vs->server_blue_shift = 0;
             break;
         case 16:
-            vs->depth = depth / 8;
+            vs->depth = 2;
             vs->server_red_max = 31;
             vs->server_green_max = 63;
             vs->server_blue_max = 31;
@@ -1366,7 +1335,7 @@
         vnc_write_u8(vs, 0);  /* msg id */
         vnc_write_u8(vs, 0);
         vnc_write_u16(vs, 1); /* number of rects */
-        vnc_framebuffer_update(vs, 0, 0, ds->width, ds->height, 0x574D5669);
+        vnc_framebuffer_update(vs, 0, 0, ds->surface->width, 
ds->surface->height, 0x574D5669);
         pixel_format_message(vs);
         vnc_flush(vs);
     } else {
@@ -1497,10 +1466,10 @@
     char buf[1024];
     int size;
 
-    vs->width = vs->ds->width;
-    vs->height = vs->ds->height;
-    vnc_write_u16(vs, vs->ds->width);
-    vnc_write_u16(vs, vs->ds->height);
+    vs->width = vs->ds->surface->width;
+    vs->height = vs->ds->surface->height;
+    vnc_write_u16(vs, vs->ds->surface->width);
+    vnc_write_u16(vs, vs->ds->surface->height);
 
     pixel_format_message(vs);
 
@@ -2110,17 +2079,17 @@
 static void vnc_connect(VncState *vs)
 {
     VNC_DEBUG("New client on socket %d\n", vs->csock);
-    vs->ds->idle = 0;
+    dcl->idle = 0;
     socket_set_nonblock(vs->csock);
     qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
     vnc_write(vs, "RFB 003.008\n", 12);
     vnc_flush(vs);
     vnc_read_when(vs, protocol_version, 12);
-    memset(vs->old_data, 0, vs->ds->linesize * vs->ds->height);
+    memset(vs->old_data, 0, vs->ds->surface->linesize * 
vs->ds->surface->height);
     memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
     vs->has_resize = 0;
     vs->has_hextile = 0;
-    vs->ds->dpy_copy = NULL;
+    dcl->dpy_copy = NULL;
     vnc_update_client(vs);
 }
 
@@ -2146,11 +2115,12 @@
     VncState *vs;
 
     vs = qemu_mallocz(sizeof(VncState));
-    if (!vs)
+    dcl = qemu_mallocz(sizeof(DisplayChangeListener));
+    if (!vs || !dcl)
        exit(1);
 
     ds->opaque = vs;
-    ds->idle = 1;
+    dcl->idle = 1;
     vnc_state = vs;
     vs->display = NULL;
     vs->password = NULL;
@@ -2172,13 +2142,11 @@
 
     vs->timer = qemu_new_timer(rt_clock, vnc_update_client, vs);
 
-    vs->ds->data = NULL;
-    vs->ds->dpy_update = vnc_dpy_update;
-    vs->ds->dpy_resize = vnc_dpy_resize;
-    vs->ds->dpy_refresh = NULL;
-
-    vnc_colordepth(vs->ds, 32);
-    vnc_dpy_resize(vs->ds, 640, 400);
+    dcl->dpy_update = vnc_dpy_update;
+    dcl->dpy_resize = vnc_dpy_resize;
+    dcl->dpy_setdata = vnc_dpy_setdata;
+    dcl->dpy_refresh = NULL;
+    register_displaychangelistener(ds, dcl);
 }
 
 #ifdef CONFIG_VNC_TLS
diff -r 5c78dd111aae vnchextile.h
--- a/vnchextile.h      Tue Nov 04 09:04:41 2008 +0000
+++ b/vnchextile.h      Thu Nov 20 16:34:30 2008 +0000
@@ -13,7 +13,7 @@
                                              void *last_fg_,
                                              int *has_bg, int *has_fg)
 {
-    uint8_t *row = (vs->ds->data + y * vs->ds->linesize + x * vs->depth);
+    uint8_t *row = (vs->ds->surface->data + y * vs->ds->surface->linesize + x 
* vs->depth);
     pixel_t *irow = (pixel_t *)row;
     int j, i;
     pixel_t *last_bg = (pixel_t *)last_bg_;
@@ -57,7 +57,7 @@
        }
        if (n_colors > 2)
            break;
-       irow += vs->ds->linesize / sizeof(pixel_t);
+       irow += vs->ds->surface->linesize / sizeof(pixel_t);
     }
 
     if (n_colors > 1 && fg_count > bg_count) {
@@ -105,7 +105,7 @@
                n_data += 2;
                n_subtiles++;
            }
-           irow += vs->ds->linesize / sizeof(pixel_t);
+           irow += vs->ds->surface->linesize / sizeof(pixel_t);
        }
        break;
     case 3:
@@ -161,7 +161,7 @@
                n_data += 2;
                n_subtiles++;
            }
-           irow += vs->ds->linesize / sizeof(pixel_t);
+           irow += vs->ds->surface->linesize / sizeof(pixel_t);
        }
 
        /* A SubrectsColoured subtile invalidates the foreground color */
@@ -198,7 +198,7 @@
     } else {
        for (j = 0; j < h; j++) {
            vs->write_pixels(vs, row, w * vs->depth);
-           row += vs->ds->linesize;
+           row += vs->ds->surface->linesize;
        }
     }
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]