Skip to contentSkip to conversation

introducing a DisplayAllocator interface

PATCH New Stefano Stabellini 1 participant 1 message Mar 2, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 introducing a DisplayAllocator interface

This patch introduces a new DisplayAllocator interface to allow frontends to allocate the DisplaySurface for the graphic device to use. At the moment it is used only by xenfbfront, to be able to page align the displaysurface and also keep the same backing data across multiple DisplaySurface resize.
Howeveri in the near future it is going to be a useful improvement for SDL as well.

---

console.c +11 -10
diff -r e0cd7e81c839 console.c
@@ -1033,7 +1033,7 @@
         DisplayState *ds = s->ds;
         active_console = s;
         if (ds_get_bits_per_pixel(s->ds)) {
-            ds->surface = qemu_resize_displaysurface(ds->surface, s->g_width,
+            ds->surface = qemu_resize_displaysurface(ds, s->g_width,
                     s->g_height, 32, 4 * s->g_width);
         } else {
             s->ds->surface->width = s->width;
@@ -1247,11 +1247,12 @@
     ds = (DisplayState *) qemu_mallocz(sizeof(DisplayState));
     if (ds == NULL)
         return NULL;
-    ds->surface = qemu_create_displaysurface(640, 480, 32, 640 * 4);
+    ds->allocator = &default_allocator; 
+    ds->surface = qemu_create_displaysurface(ds, 640, 480, 32, 640 * 4);
 
     s = new_console(ds, GRAPHIC_CONSOLE);
     if (s == NULL) {
-        qemu_free_displaysurface(ds->surface);
+        qemu_free_displaysurface(ds);
         qemu_free(ds);
         return NULL;
     }
@@ -1401,7 +1402,7 @@
     s->g_width = width;
     s->g_height = height;
     if (is_graphic_console()) {
-        ds->surface = qemu_resize_displaysurface(ds->surface, width, height, 32, 4 * width);
+        ds->surface = qemu_resize_displaysurface(ds, width, height, 32, 4 * width);
         dpy_resize(ds);
     }
 }
@@ -1524,11 +1525,11 @@
     return pf;
 }
 
-DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int linesize)
+DisplaySurface* defaultallocator_create_displaysurface(int width, int height, int bpp, int linesize)
 {
     DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
     if (surface == NULL) {
-        fprintf(stderr, "qemu_create_displaysurface: malloc failed\n");
+        fprintf(stderr, "defaultallocator_create_displaysurface: malloc failed\n");
         exit(1);
     }
 
@@ -1543,14 +1544,14 @@
 #endif
     surface->data = (uint8_t*) qemu_mallocz(surface->linesize * surface->height);
     if (surface->data == NULL) {
-        fprintf(stderr, "qemu_create_displaysurface: malloc failed\n");
+        fprintf(stderr, "defaultallocator_create_displaysurface: malloc failed\n");
         exit(1);
     }
 
     return surface;
 }
 
-DisplaySurface* qemu_resize_displaysurface(DisplaySurface *surface,
+DisplaySurface* defaultallocator_resize_displaysurface(DisplaySurface *surface,
                                           int width, int height, int bpp, int linesize)
 {
     surface->width = width;
@@ -1562,7 +1563,7 @@
     else
         surface->data = (uint8_t*) qemu_malloc(surface->linesize * surface->height);
     if (surface->data == NULL) {
-        fprintf(stderr, "qemu_resize_displaysurface: malloc failed\n");
+        fprintf(stderr, "defaultallocator_resize_displaysurface: malloc failed\n");
         exit(1);
     }
 #ifdef WORDS_BIGENDIAN
@@ -1595,7 +1596,7 @@
     return surface;
 }
 
-void qemu_free_displaysurface(DisplaySurface *surface)
+void defaultallocator_free_displaysurface(DisplaySurface *surface)
 {
     if (surface == NULL)
         return;
console.h +30 -4
diff -r e0cd7e81c839 console.h
@@ -107,11 +107,19 @@
     struct DisplayChangeListener *next;
 };
 
+struct DisplayAllocator {
+    DisplaySurface* (*create_displaysurface)(int width, int height, int bpp, int linesize);
+    DisplaySurface* (*resize_displaysurface)(DisplaySurface *surface,
+            int width, int height, int bpp, int linesize);
+    void (*free_displaysurface)(DisplaySurface *surface);
+};
+
 struct DisplayState {
     struct DisplaySurface *surface;
     void *opaque;
     struct QEMUTimer *gui_timer;
 
+    struct DisplayAllocator* allocator;
     struct DisplayChangeListener* listeners;
 
     void (*mouse_set)(int x, int y, int on);
@@ -123,14 +131,32 @@
 
 void register_displaystate(DisplayState *ds);
 DisplayState *get_displaystate(void);
-DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int linesize);
-DisplaySurface* qemu_resize_displaysurface(DisplaySurface *surface,
-                                           int width, int height, int bpp, int linesize);
 DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
                                                 int linesize, uint8_t *data);
-void qemu_free_displaysurface(DisplaySurface *surface);
 PixelFormat qemu_different_endianness_pixelformat(int bpp);
 PixelFormat qemu_default_pixelformat(int bpp);
+
+extern struct DisplayAllocator default_allocator;
+DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da);
+DisplaySurface* defaultallocator_create_displaysurface(int width, int height, int bpp, int linesize);
+DisplaySurface* defaultallocator_resize_displaysurface(DisplaySurface *surface,
+        int width, int height, int bpp, int linesize);
+void defaultallocator_free_displaysurface(DisplaySurface *surface);
+
+static inline DisplaySurface* qemu_create_displaysurface(DisplayState *ds, int width, int height, int bpp, int linesize)
+{
+    return ds->allocator->create_displaysurface(width, height, bpp, linesize);    
+}
+
+static inline DisplaySurface* qemu_resize_displaysurface(DisplayState *ds, int width, int height, int bpp, int linesize)
+{
+    return ds->allocator->resize_displaysurface(ds->surface, width, height, bpp, linesize);
+}
+
+static inline void qemu_free_displaysurface(DisplayState *ds)
+{
+    ds->allocator->free_displaysurface(ds->surface);
+}
 
 static inline int is_buffer_shared(DisplaySurface *surface)
 {
curses.c +1 -1
diff -r e0cd7e81c839 curses.c
@@ -368,7 +368,7 @@
     dcl->dpy_refresh = curses_refresh;
     dcl->dpy_text_cursor = curses_cursor_position;
     register_displaychangelistener(ds, dcl);
-    qemu_free_displaysurface(ds->surface);
+    qemu_free_displaysurface(ds);
     ds->surface = qemu_create_displaysurface_from(640, 400, 0, 0, (uint8_t*) screen);
 
     invalidate = 1;
hw/nseries.c +1 -1
diff -r e0cd7e81c839 hw/nseries.c
@@ -1362,7 +1362,7 @@
     /* 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.  */
-    ds->surface = qemu_resize_displaysurface(ds->surface, 800, 480, 32, 4 * 800);
+    ds->surface = qemu_resize_displaysurface(ds, 800, 480, 32, 4 * 800);
     dpy_resize(ds);
 }
 
hw/palm.c +1 -1
diff -r e0cd7e81c839 hw/palm.c
@@ -279,7 +279,7 @@
     /* 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.  */
-    ds->surface = qemu_resize_displaysurface(ds->surface, 320, 320, 32, 4 * 320);
+    ds->surface = qemu_resize_displaysurface(ds, 320, 320, 32, 4 * 320);
     dpy_resize(ds);
 }
 
hw/vga.c +3 -3
diff -r e0cd7e81c839 hw/vga.c
@@ -1628,7 +1628,7 @@
         if (depth == 32) {
 #endif
             if (is_graphic_console()) {
-                qemu_free_displaysurface(s->ds->surface);
+                qemu_free_displaysurface(s->ds);
                 s->ds->surface = qemu_create_displaysurface_from(disp_width, height, depth,
                                                                s->line_offset,
                                                                s->vram_ptr + (s->start_addr * 4));
@@ -2769,7 +2769,7 @@
     dcl.dpy_resize = vga_save_dpy_resize;
     dcl.dpy_refresh = vga_save_dpy_refresh;
     register_displaychangelistener(ds, &dcl);
-    ds->surface = qemu_create_displaysurface(w, h, 32, 4 * w);
+    ds->surface = qemu_create_displaysurface(ds, w, h, 32, 4 * w);
  
     s->ds = ds;
     s->graphic_mode = -1;
@@ -2777,6 +2777,6 @@
 
     ppm_save(filename, ds->surface);
 
-    qemu_free_displaysurface(ds->surface);
+    qemu_free_displaysurface(ds);
     s->ds = saved_ds;
 }
qemu-common.h +1 -0
diff -r e0cd7e81c839 qemu-common.h
@@ -133,6 +133,7 @@
 typedef struct DisplayState DisplayState;
 typedef struct DisplayChangeListener DisplayChangeListener;
 typedef struct DisplaySurface DisplaySurface;
+typedef struct DisplayAllocator DisplayAllocator;
 typedef struct PixelFormat PixelFormat;
 typedef struct TextConsole TextConsole;
 typedef TextConsole QEMUConsole;
vl.c +17 -4
diff -r e0cd7e81c839 vl.c
@@ -6243,6 +6243,12 @@
 /***********************************************************/
 /* register display */
 
+struct DisplayAllocator default_allocator = {
+    defaultallocator_create_displaysurface,
+    defaultallocator_resize_displaysurface,
+    defaultallocator_free_displaysurface
+};
+
 void register_displaystate(DisplayState *ds)
 {
     DisplayState **s;
@@ -6258,6 +6264,12 @@
     return display_state;
 }
 
+DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da)
+{
+    if(ds->allocator ==  &default_allocator) ds->allocator = da;
+    return ds->allocator;
+}
+
 /* dumb display */
 
 static void dumb_display_init(void)
@@ -6267,7 +6279,8 @@
         fprintf(stderr, "dumb_display_init: DisplayState allocation failed\n");
         exit(1);
     }
-    ds->surface = qemu_create_displaysurface(640, 480, 32, 640 * 4);
+    ds->allocator = &default_allocator;
+    ds->surface = qemu_create_displaysurface(ds, 640, 480, 32, 640 * 4);
     register_displaystate(ds);
 }
 
@@ -10107,6 +10120,9 @@
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model,
 		  direct_pci);
 
+    if (loadvm)
+        do_loadvm(loadvm);
+
     /* init USB devices */
     if (usb_enabled) {
         for(i = 0; i < usb_devices_index; i++) {
@@ -10219,9 +10235,6 @@
     }
 #endif
 
-    if (loadvm)
-        do_loadvm(loadvm);
-
     if (incoming) {
         autostart = 0; /* fixme how to deal with -daemonize */
         qemu_start_incoming_migration(incoming);
xenfbfront.c +72 -1

84 lines not on this page · raw message