console: rework DisplaySurface handling [dcl/ui side]

Replace the dpy_gfx_resize and dpy_gfx_setdata DisplayChangeListener
callbacks with a dpy_gfx_switch callback which notifies the ui code
when the framebuffer backing storage changes.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
diff --git a/ui/cocoa.m b/ui/cocoa.m
index b1fb30e..73843f4 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -988,8 +988,9 @@
     [cocoaView setNeedsDisplayInRect:rect];
 }
 
-static void cocoa_resize(DisplayChangeListener *dcl,
-                         DisplayState *ds)
+static void cocoa_switch(DisplayChangeListener *dcl,
+                         DisplayState *ds,
+                         DisplaySurface *surface)
 {
     COCOA_DEBUG("qemu_cocoa: cocoa_resize\n");
 
@@ -1023,11 +1024,6 @@
     vga_hw_update();
 }
 
-static void cocoa_setdata(DisplayState *ds)
-{
-    [cocoaView updateDataOffset:ds];
-}
-
 static void cocoa_cleanup(void)
 {
     COCOA_DEBUG("qemu_cocoa: cocoa_cleanup\n");
@@ -1037,8 +1033,7 @@
 static const DisplayChangeListenerOps dcl_ops = {
     .dpy_name          = "cocoa",
     .dpy_gfx_update = cocoa_update;
-    .dpy_gfx_resize = cocoa_resize;
-    .dpy_gfx_setdata = cocoa_setdata;
+    .dpy_gfx_switch = cocoa_switch;
     .dpy_refresh = cocoa_refresh;
 };
 
diff --git a/ui/console.c b/ui/console.c
index c2ca9e7..4541b2c 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1372,8 +1372,8 @@
     dcl->ds = ds;
     QLIST_INSERT_HEAD(&ds->listeners, dcl, next);
     gui_setup_refresh(ds);
-    if (dcl->ops->dpy_gfx_resize) {
-        dcl->ops->dpy_gfx_resize(dcl, ds);
+    if (dcl->ops->dpy_gfx_switch) {
+        dcl->ops->dpy_gfx_switch(dcl, ds, ds->surface);
     }
 }
 
@@ -1413,8 +1413,8 @@
 
     s->surface = surface;
     QLIST_FOREACH(dcl, &s->listeners, next) {
-        if (dcl->ops->dpy_gfx_resize) {
-            dcl->ops->dpy_gfx_resize(dcl, s);
+        if (dcl->ops->dpy_gfx_switch) {
+            dcl->ops->dpy_gfx_switch(dcl, s, surface);
         }
     }
     qemu_free_displaysurface(old_surface);
diff --git a/ui/gtk.c b/ui/gtk.c
index b21a94a..967a36c 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -266,8 +266,9 @@
     vga_hw_update();
 }
 
-static void gd_resize(DisplayChangeListener *dcl,
-                      DisplayState *ds)
+static void gd_switch(DisplayChangeListener *dcl,
+                      DisplayState *ds,
+                      DisplaySurface *surface)
 {
     GtkDisplayState *s = container_of(dcl, GtkDisplayState, dcl);
     cairo_format_t kind;
@@ -738,7 +739,7 @@
     s->scale_x += .25;
     s->scale_y += .25;
 
-    gd_resize(&s->dcl, s->ds);
+    gd_switch(&s->dcl, s->ds, s->ds->surface);
 }
 
 static void gd_menu_zoom_out(GtkMenuItem *item, void *opaque)
@@ -754,7 +755,7 @@
     s->scale_x = MAX(s->scale_x, .25);
     s->scale_y = MAX(s->scale_y, .25);
 
-    gd_resize(&s->dcl, s->ds);
+    gd_switch(&s->dcl, s->ds, s->ds->surface);
 }
 
 static void gd_menu_zoom_fixed(GtkMenuItem *item, void *opaque)
@@ -764,7 +765,7 @@
     s->scale_x = 1.0;
     s->scale_y = 1.0;
 
-    gd_resize(&s->dcl, s->ds);
+    gd_switch(&s->dcl, s->ds, s->ds->surface);
 }
 
 static void gd_menu_zoom_fit(GtkMenuItem *item, void *opaque)
@@ -778,7 +779,7 @@
         s->free_scale = FALSE;
     }
 
-    gd_resize(&s->dcl, s->ds);
+    gd_switch(&s->dcl, s->ds, s->ds->surface);
 
     gdk_drawable_get_size(gtk_widget_get_window(s->drawing_area), &ww, &wh);
     gtk_widget_queue_draw_area(s->drawing_area, 0, 0, ww, wh);
@@ -1287,7 +1288,7 @@
 static const DisplayChangeListenerOps dcl_ops = {
     .dpy_name          = "gtk",
     .dpy_gfx_update    = gd_update,
-    .dpy_gfx_resize    = gd_resize,
+    .dpy_gfx_switch    = gd_switch,
     .dpy_refresh       = gd_refresh,
 };
 
diff --git a/ui/sdl.c b/ui/sdl.c
index fc4dc1b..85eefdf 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -117,8 +117,9 @@
     }
 }
 
-static void sdl_resize(DisplayChangeListener *dcl,
-                       DisplayState *ds)
+static void sdl_switch(DisplayChangeListener *dcl,
+                       DisplayState *ds,
+                       DisplaySurface *surface)
 {
     if (!scaling_active) {
         do_sdl_resize(ds_get_width(ds), ds_get_height(ds), 0);
@@ -513,7 +514,7 @@
         case 0x16: /* 'u' key on US keyboard */
             if (scaling_active) {
                 scaling_active = 0;
-                sdl_resize(dcl, ds);
+                sdl_switch(dcl, ds, ds->surface);
                 vga_hw_invalidate();
                 vga_hw_update();
             }
@@ -856,9 +857,8 @@
 static const DisplayChangeListenerOps dcl_ops = {
     .dpy_name          = "sdl",
     .dpy_gfx_update    = sdl_update,
-    .dpy_gfx_resize    = sdl_resize,
+    .dpy_gfx_switch    = sdl_switch,
     .dpy_refresh       = sdl_refresh,
-    .dpy_gfx_setdata   = sdl_setdata,
     .dpy_mouse_set     = sdl_mouse_warp,
     .dpy_cursor_define = sdl_mouse_define,
 };
diff --git a/ui/spice-display.c b/ui/spice-display.c
index b2bda23..cc2a78e 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -367,7 +367,8 @@
     qemu_spice_rect_union(&ssd->dirty, &update_area);
 }
 
-void qemu_spice_display_resize(SimpleSpiceDisplay *ssd)
+void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
+                               DisplaySurface *surface)
 {
     SimpleSpiceUpdate *update;
 
@@ -589,11 +590,12 @@
     qemu_spice_display_update(ssd, x, y, w, h);
 }
 
-static void display_resize(DisplayChangeListener *dcl,
-                           struct DisplayState *ds)
+static void display_switch(DisplayChangeListener *dcl,
+                           struct DisplayState *ds,
+                           struct DisplaySurface *surface)
 {
     SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
-    qemu_spice_display_resize(ssd);
+    qemu_spice_display_switch(ssd, surface);
 }
 
 static void display_refresh(DisplayChangeListener *dcl,
@@ -606,7 +608,7 @@
 static const DisplayChangeListenerOps display_listener_ops = {
     .dpy_name        = "spice",
     .dpy_gfx_update  = display_update,
-    .dpy_gfx_resize  = display_resize,
+    .dpy_gfx_switch  = display_switch,
     .dpy_refresh     = display_refresh,
 };
 
diff --git a/ui/vnc.c b/ui/vnc.c
index a6111d6..f8398c3 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -574,8 +574,9 @@
     return ptr;
 }
 
-static void vnc_dpy_resize(DisplayChangeListener *dcl,
-                           DisplayState *ds)
+static void vnc_dpy_switch(DisplayChangeListener *dcl,
+                           DisplayState *ds,
+                           DisplaySurface *surface)
 {
     VncDisplay *vd = container_of(dcl, VncDisplay, dcl);
     VncState *vs;
@@ -1981,17 +1982,6 @@
     vs->write_pixels = vnc_write_pixels_copy;
 }
 
-static void vnc_dpy_setdata(DisplayChangeListener *dcl,
-                            DisplayState *ds)
-{
-    VncDisplay *vd = container_of(dcl, VncDisplay, dcl);
-
-    qemu_pixman_image_unref(vd->guest.fb);
-    vd->guest.fb = pixman_image_ref(ds->surface->image);
-    vd->guest.format = ds->surface->format;
-    vnc_dpy_update(dcl, ds, 0, 0, ds_get_width(ds), ds_get_height(ds));
-}
-
 static void vnc_colordepth(VncState *vs)
 {
     if (vnc_has_feature(vs, VNC_FEATURE_WMVI)) {
@@ -2696,7 +2686,7 @@
     vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;
     if (vd->timer == NULL && !QTAILQ_EMPTY(&vd->clients)) {
         vd->timer = qemu_new_timer_ms(rt_clock, vnc_refresh, vd);
-        vnc_dpy_resize(&vd->dcl, vd->ds);
+        vnc_dpy_switch(&vd->dcl, vd->ds, vd->ds->surface);
         vnc_refresh(vd);
     }
 }
@@ -2836,8 +2826,7 @@
     .dpy_name          = "vnc",
     .dpy_gfx_copy      = vnc_dpy_copy,
     .dpy_gfx_update    = vnc_dpy_update,
-    .dpy_gfx_resize    = vnc_dpy_resize,
-    .dpy_gfx_setdata   = vnc_dpy_setdata,
+    .dpy_gfx_switch    = vnc_dpy_switch,
     .dpy_mouse_set     = vnc_mouse_set,
     .dpy_cursor_define = vnc_dpy_cursor_define,
 };