[gtk-vnc] src: pass the framebuffer object into update handlers



commit 9acd169371dfb13076d174fef3abaec5ae97aa50
Author: Daniel P. Berrangé <dan berrange com>
Date:   Tue Dec 8 12:55:36 2020 +0000

    src: pass the framebuffer object into update handlers
    
    We can't assume there will be only one framebuffer going forward, so
    need to pass around an instance explicitly.
    
    Signed-off-by: Daniel P. Berrangé <berrange redhat com>

 src/vncconnection.c | 111 ++++++++++++++++++++++++++++------------------------
 1 file changed, 59 insertions(+), 52 deletions(-)
---
diff --git a/src/vncconnection.c b/src/vncconnection.c
index e16fbe4..3866ab0 100644
--- a/src/vncconnection.c
+++ b/src/vncconnection.c
@@ -2166,6 +2166,7 @@ static gboolean vnc_connection_validate_boundary(VncConnection *conn,
 
 
 static void vnc_connection_raw_update(VncConnection *conn,
+                                      VncFramebuffer *fb,
                                       guint16 x, guint16 y,
                                       guint16 width, guint16 height)
 {
@@ -2176,10 +2177,10 @@ static void vnc_connection_raw_update(VncConnection *conn,
        directly from the source framebuffer and a read directly
        into the client framebuffer
     */
-    if (vnc_framebuffer_perfect_format_match(priv->fb)) {
+    if (vnc_framebuffer_perfect_format_match(fb)) {
         int i;
-        int rowstride = vnc_framebuffer_get_rowstride(priv->fb);
-        guint8 *dst = vnc_framebuffer_get_buffer(priv->fb);
+        int rowstride = vnc_framebuffer_get_rowstride(fb);
+        guint8 *dst = vnc_framebuffer_get_buffer(fb);
 
         dst += (y * rowstride) + (x * (priv->fmt.bits_per_pixel/8));
 
@@ -2195,43 +2196,43 @@ static void vnc_connection_raw_update(VncConnection *conn,
         dst = g_malloc(width * (priv->fmt.bits_per_pixel / 8));
         for (i = 0; i < height; i++) {
             vnc_connection_read(conn, dst, width * (priv->fmt.bits_per_pixel / 8));
-            vnc_framebuffer_blt(priv->fb, dst, 0, x, y + i, width, 1);
+            vnc_framebuffer_blt(fb, dst, 0, x, y + i, width, 1);
         }
         g_free(dst);
     }
 }
 
 static void vnc_connection_copyrect_update(VncConnection *conn,
+                                           VncFramebuffer *fb,
                                            guint16 dst_x, guint16 dst_y,
                                            guint16 width, guint16 height)
 {
-    VncConnectionPrivate *priv = conn->priv;
     int src_x, src_y;
 
     src_x = vnc_connection_read_u16(conn);
     src_y = vnc_connection_read_u16(conn);
 
-    if (!vnc_connection_validate_boundary(conn, priv->fb,
+    if (!vnc_connection_validate_boundary(conn, fb,
                                           src_x, src_y, width, height))
         return;
 
-    vnc_framebuffer_copyrect(priv->fb,
+    vnc_framebuffer_copyrect(fb,
                              src_x, src_y,
                              dst_x, dst_y,
                              width, height);
 }
 
 static void vnc_connection_hextile_rect(VncConnection *conn,
+                                        VncFramebuffer *fb,
                                         guint8 flags,
                                         guint16 x, guint16 y,
                                         guint16 width, guint16 height,
                                         guint8 *fg, guint8 *bg)
 {
-    VncConnectionPrivate *priv = conn->priv;
     int i;
 
     if (flags & 0x01) {
-        vnc_connection_raw_update(conn, x, y, width, height);
+        vnc_connection_raw_update(conn, fb, x, y, width, height);
     } else {
         /* Background Specified */
         if (flags & 0x02)
@@ -2241,7 +2242,7 @@ static void vnc_connection_hextile_rect(VncConnection *conn,
         if (flags & 0x04)
             vnc_connection_read_pixel(conn, fg);
 
-        vnc_framebuffer_fill(priv->fb, bg, x, y, width, height);
+        vnc_framebuffer_fill(fb, bg, x, y, width, height);
 
         /* AnySubrects */
         if (flags & 0x08) {
@@ -2257,12 +2258,12 @@ static void vnc_connection_hextile_rect(VncConnection *conn,
                 xy = vnc_connection_read_u8(conn);
                 wh = vnc_connection_read_u8(conn);
 
-                if (!vnc_connection_validate_boundary(conn, priv->fb,
+                if (!vnc_connection_validate_boundary(conn, fb,
                                                       x + nibhi(xy), y + niblo(xy),
                                                       nibhi(wh) + 1, niblo(wh) + 1))
                     return;
 
-                vnc_framebuffer_fill(priv->fb, fg,
+                vnc_framebuffer_fill(fb, fg,
                                      x + nibhi(xy), y + niblo(xy),
                                      nibhi(wh) + 1, niblo(wh) + 1);
             }
@@ -2272,6 +2273,7 @@ static void vnc_connection_hextile_rect(VncConnection *conn,
 
 
 static void vnc_connection_hextile_update(VncConnection *conn,
+                                          VncFramebuffer *fb,
                                           guint16 x, guint16 y,
                                           guint16 width, guint16 height)
 {
@@ -2287,7 +2289,7 @@ static void vnc_connection_hextile_update(VncConnection *conn,
             int h = MIN(16, height - j);
 
             flags = vnc_connection_read_u8(conn);
-            vnc_connection_hextile_rect(conn, flags,
+            vnc_connection_hextile_rect(conn, fb, flags,
                                         x + i, y + j,
                                         w, h,
                                         fg, bg);
@@ -2296,17 +2298,17 @@ static void vnc_connection_hextile_update(VncConnection *conn,
 }
 
 static void vnc_connection_rre_update(VncConnection *conn,
+                                      VncFramebuffer *fb,
                                       guint16 x, guint16 y,
                                       guint16 width, guint16 height)
 {
-    VncConnectionPrivate *priv = conn->priv;
     guint8 bg[4];
     guint32 num;
     guint32 i;
 
     num = vnc_connection_read_u32(conn);
     vnc_connection_read_pixel(conn, bg);
-    vnc_framebuffer_fill(priv->fb, bg, x, y, width, height);
+    vnc_framebuffer_fill(fb, bg, x, y, width, height);
 
     for (i = 0; i < num; i++) {
         guint8 fg[4];
@@ -2318,11 +2320,11 @@ static void vnc_connection_rre_update(VncConnection *conn,
         sub_w = vnc_connection_read_u16(conn);
         sub_h = vnc_connection_read_u16(conn);
 
-        if (!vnc_connection_validate_boundary(conn, priv->fb,
+        if (!vnc_connection_validate_boundary(conn, fb,
                                               x + sub_x, y + sub_y, sub_w, sub_h))
             break;
 
-        vnc_framebuffer_fill(priv->fb, fg,
+        vnc_framebuffer_fill(fb, fg,
                              x + sub_x, y + sub_y, sub_w, sub_h);
     }
 }
@@ -2362,10 +2364,10 @@ static void vnc_connection_read_cpixel(VncConnection *conn, guint8 *pixel)
 }
 
 static void vnc_connection_zrle_update_tile_blit(VncConnection *conn,
+                                                 VncFramebuffer *fb,
                                                  guint16 x, guint16 y,
                                                  guint16 width, guint16 height)
 {
-    VncConnectionPrivate *priv = conn->priv;
     guint8 *blit_data;
     int i, bpp;
 
@@ -2376,7 +2378,7 @@ static void vnc_connection_zrle_update_tile_blit(VncConnection *conn,
     for (i = 0; i < width * height; i++)
         vnc_connection_read_cpixel(conn, blit_data + (i * bpp));
 
-    vnc_framebuffer_blt(priv->fb, blit_data, width * bpp, x, y, width, height);
+    vnc_framebuffer_blt(fb, blit_data, width * bpp, x, y, width, height);
 
     g_free(blit_data);
 }
@@ -2405,6 +2407,7 @@ static guint8 vnc_connection_read_zrle_pi(VncConnection *conn, int palette_size)
 }
 
 static void vnc_connection_zrle_update_tile_palette(VncConnection *conn,
+                                                    VncFramebuffer *fb,
                                                     guint8 palette_size,
                                                     guint16 x, guint16 y,
                                                     guint16 width, guint16 height)
@@ -2423,7 +2426,7 @@ static void vnc_connection_zrle_update_tile_palette(VncConnection *conn,
         for (i = 0; i < width; i++) {
             int ind = vnc_connection_read_zrle_pi(conn, palette_size);
 
-            vnc_framebuffer_set_pixel_at(priv->fb, palette[ind & 0x7F],
+            vnc_framebuffer_set_pixel_at(fb, palette[ind & 0x7F],
                                          x + i, y + j);
         }
     }
@@ -2443,10 +2446,10 @@ static int vnc_connection_read_zrle_rl(VncConnection *conn)
 }
 
 static void vnc_connection_zrle_update_tile_rle(VncConnection *conn,
+                                                VncFramebuffer *fb,
                                                 guint16 x, guint16 y,
                                                 guint16 width, guint16 height)
 {
-    VncConnectionPrivate *priv = conn->priv;
     int i, j, rl = 0;
     guint8 pixel[4];
 
@@ -2456,18 +2459,18 @@ static void vnc_connection_zrle_update_tile_rle(VncConnection *conn,
                 vnc_connection_read_cpixel(conn, pixel);
                 rl = vnc_connection_read_zrle_rl(conn);
             }
-            vnc_framebuffer_set_pixel_at(priv->fb, pixel, x + i, y + j);
+            vnc_framebuffer_set_pixel_at(fb, pixel, x + i, y + j);
             rl -= 1;
         }
     }
 }
 
 static void vnc_connection_zrle_update_tile_prle(VncConnection *conn,
+                                                 VncFramebuffer *fb,
                                                  guint8 palette_size,
                                                  guint16 x, guint16 y,
                                                  guint16 width, guint16 height)
 {
-    VncConnectionPrivate *priv = conn->priv;
     int i, j, rl = 0;
     guint8 palette[128][4];
     guint8 pi = 0;
@@ -2486,45 +2489,47 @@ static void vnc_connection_zrle_update_tile_prle(VncConnection *conn,
                     rl = 1;
             }
 
-            vnc_framebuffer_set_pixel_at(priv->fb, palette[pi], x + i, y + j);
+            vnc_framebuffer_set_pixel_at(fb, palette[pi], x + i, y + j);
             rl -= 1;
         }
     }
 }
 
-static void vnc_connection_zrle_update_tile(VncConnection *conn, guint16 x, guint16 y,
+static void vnc_connection_zrle_update_tile(VncConnection *conn,
+                                            VncFramebuffer *fb,
+                                            guint16 x, guint16 y,
                                             guint16 width, guint16 height)
 {
-    VncConnectionPrivate *priv = conn->priv;
     guint8 subencoding = vnc_connection_read_u8(conn);
     guint8 pixel[4];
 
     if (subencoding == 0 ) {
         /* Raw pixel data */
-        vnc_connection_zrle_update_tile_blit(conn, x, y, width, height);
+        vnc_connection_zrle_update_tile_blit(conn, fb, x, y, width, height);
     } else if (subencoding == 1) {
         /* Solid tile of a single color */
         vnc_connection_read_cpixel(conn, pixel);
-        vnc_framebuffer_fill(priv->fb, pixel, x, y, width, height);
+        vnc_framebuffer_fill(fb, pixel, x, y, width, height);
     } else if ((subencoding >= 2) && (subencoding <= 16)) {
         /* Packed palette types */
-        vnc_connection_zrle_update_tile_palette(conn, subencoding,
+        vnc_connection_zrle_update_tile_palette(conn, fb, subencoding,
                                                 x, y, width, height);
     } else if ((subencoding >= 17) && (subencoding <= 127)) {
         /* FIXME raise error? */
     } else if (subencoding == 128) {
         /* Plain RLE */
-        vnc_connection_zrle_update_tile_rle(conn, x, y, width, height);
+        vnc_connection_zrle_update_tile_rle(conn, fb, x, y, width, height);
     } else if (subencoding == 129) {
 
     } else if (subencoding >= 130) {
         /* Palette RLE */
-        vnc_connection_zrle_update_tile_prle(conn, subencoding - 128,
+        vnc_connection_zrle_update_tile_prle(conn, fb, subencoding - 128,
                                              x, y, width, height);
     }
 }
 
 static void vnc_connection_zrle_update(VncConnection *conn,
+                                       VncFramebuffer *fb,
                                        guint16 x, guint16 y,
                                        guint16 width, guint16 height)
 {
@@ -2550,7 +2555,7 @@ static void vnc_connection_zrle_update(VncConnection *conn,
 
             w = MIN(width - i, 64);
             h = MIN(height - j, 64);
-            vnc_connection_zrle_update_tile(conn, x + i, y + j, w, h);
+            vnc_connection_zrle_update_tile(conn, fb, x + i, y + j, w, h);
         }
     }
 
@@ -2616,17 +2621,17 @@ static void vnc_connection_read_tpixel(VncConnection *conn, guint8 *pixel)
 }
 
 static void vnc_connection_tight_update_copy(VncConnection *conn,
+                                             VncFramebuffer *fb,
                                              guint16 x, guint16 y,
                                              guint16 width, guint16 height)
 {
-    VncConnectionPrivate *priv = conn->priv;
     guint8 pixel[4];
     int i, j;
 
     for (j = 0; j < height; j++) {
         for (i = 0; i < width; i++) {
             vnc_connection_read_tpixel(conn, pixel);
-            vnc_framebuffer_set_pixel_at(priv->fb, pixel, x + i, y + j);
+            vnc_framebuffer_set_pixel_at(fb, pixel, x + i, y + j);
         }
     }
 }
@@ -2644,11 +2649,11 @@ static int vnc_connection_tight_get_pi(VncConnection *conn, guint8 *ra,
 }
 
 static void vnc_connection_tight_update_palette(VncConnection *conn,
+                                                VncFramebuffer *fb,
                                                 int palette_size, guint8 *palette,
                                                 guint16 x, guint16 y,
                                                 guint16 width, guint16 height)
 {
-    VncConnectionPrivate *priv = conn->priv;
     int i, j;
 
     for (j = 0; j < height; j++) {
@@ -2658,7 +2663,7 @@ static void vnc_connection_tight_update_palette(VncConnection *conn,
             guint8 ind;
 
             ind = vnc_connection_tight_get_pi(conn, &ra, i, palette_size);
-            vnc_framebuffer_set_pixel_at(priv->fb, &palette[ind * 4], x + i, y + j);
+            vnc_framebuffer_set_pixel_at(fb, &palette[ind * 4], x + i, y + j);
         }
     }
 }
@@ -2681,6 +2686,7 @@ static void vnc_connection_tight_sum_pixel(VncConnection *conn,
 }
 
 static void vnc_connection_tight_update_gradient(VncConnection *conn,
+                                                 VncFramebuffer *fb,
                                                  guint16 x, guint16 y,
                                                  guint16 width, guint16 height)
 {
@@ -2688,7 +2694,6 @@ static void vnc_connection_tight_update_gradient(VncConnection *conn,
     guint8 zero_pixel[4];
     guint8 *last_row, *row;
     int bpp;
-    VncConnectionPrivate *priv = conn->priv;
 
     bpp = vnc_connection_pixel_size(conn);
     last_row = g_malloc(width * bpp);
@@ -2726,7 +2731,7 @@ static void vnc_connection_tight_update_gradient(VncConnection *conn,
         }
 
         /* write out row of pixel data */
-        vnc_framebuffer_blt(priv->fb, row, width * bpp, x, y + j, width, 1);
+        vnc_framebuffer_blt(fb, row, width * bpp, x, y + j, width, 1);
 
         /* swap last row and current row */
         tmp_row = last_row;
@@ -2739,11 +2744,12 @@ static void vnc_connection_tight_update_gradient(VncConnection *conn,
 }
 
 
-static void vnc_connection_tight_update_jpeg(VncConnection *conn, guint16 x, guint16 y,
+static void vnc_connection_tight_update_jpeg(VncConnection *conn,
+                                             VncFramebuffer *fb,
+                                             guint16 x, guint16 y,
                                              guint16 width, guint16 height,
                                              guint8 *data, size_t length)
 {
-    VncConnectionPrivate *priv = conn->priv;
     GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
     GdkPixbuf *p;
 
@@ -2757,7 +2763,7 @@ static void vnc_connection_tight_update_jpeg(VncConnection *conn, guint16 x, gui
     p = g_object_ref(gdk_pixbuf_loader_get_pixbuf(loader));
     g_object_unref(loader);
 
-    vnc_framebuffer_rgb24_blt(priv->fb,
+    vnc_framebuffer_rgb24_blt(fb,
                               gdk_pixbuf_get_pixels(p),
                               gdk_pixbuf_get_rowstride(p),
                               x, y, width, height);
@@ -2766,6 +2772,7 @@ static void vnc_connection_tight_update_jpeg(VncConnection *conn, guint16 x, gui
 }
 
 static void vnc_connection_tight_update(VncConnection *conn,
+                                        VncFramebuffer *fb,
                                         guint16 x, guint16 y,
                                         guint16 width, guint16 height)
 {
@@ -2828,15 +2835,15 @@ static void vnc_connection_tight_update(VncConnection *conn,
 
         switch (filter_id) {
         case 0: /* copy */
-            vnc_connection_tight_update_copy(conn, x, y, width, height);
+            vnc_connection_tight_update_copy(conn, fb, x, y, width, height);
             break;
         case 1: /* palette */
-            vnc_connection_tight_update_palette(conn, palette_size,
+            vnc_connection_tight_update_palette(conn, fb, palette_size,
                                                 (guint8 *)palette,
                                                 x, y, width, height);
             break;
         case 2: /* gradient */
-            vnc_connection_tight_update_gradient(conn, x, y, width, height);
+            vnc_connection_tight_update_gradient(conn, fb, x, y, width, height);
             break;
         default: /* error */
             vnc_connection_set_error(conn, "Unexpected tight filter id %d",
@@ -2858,7 +2865,7 @@ static void vnc_connection_tight_update(VncConnection *conn,
         /* fill */
         /* FIXME check each width; endianness */
         vnc_connection_read_tpixel(conn, pixel);
-        vnc_framebuffer_fill(priv->fb, pixel, x, y, width, height);
+        vnc_framebuffer_fill(fb, pixel, x, y, width, height);
     } else if (ccontrol == 9) {
         /* jpeg */
         guint32 length;
@@ -2867,7 +2874,7 @@ static void vnc_connection_tight_update(VncConnection *conn,
         length = vnc_connection_read_cint(conn);
         jpeg_data = g_malloc(length);
         vnc_connection_read(conn, jpeg_data, length);
-        vnc_connection_tight_update_jpeg(conn, x, y, width, height,
+        vnc_connection_tight_update_jpeg(conn, fb, x, y, width, height,
                                          jpeg_data, length);
         g_free(jpeg_data);
     } else {
@@ -3124,42 +3131,42 @@ static gboolean vnc_connection_framebuffer_update(VncConnection *conn, gint32 et
         if (!vnc_connection_validate_boundary(conn, priv->fb,
                                               x, y, width, height))
             break;
-        vnc_connection_raw_update(conn, x, y, width, height);
+        vnc_connection_raw_update(conn, priv->fb, x, y, width, height);
         vnc_connection_update(conn, x, y, width, height);
         break;
     case VNC_CONNECTION_ENCODING_COPY_RECT:
         if (!vnc_connection_validate_boundary(conn, priv->fb,
                                               x, y, width, height))
             break;
-        vnc_connection_copyrect_update(conn, x, y, width, height);
+        vnc_connection_copyrect_update(conn, priv->fb, x, y, width, height);
         vnc_connection_update(conn, x, y, width, height);
         break;
     case VNC_CONNECTION_ENCODING_RRE:
         if (!vnc_connection_validate_boundary(conn, priv->fb,
                                               x, y, width, height))
             break;
-        vnc_connection_rre_update(conn, x, y, width, height);
+        vnc_connection_rre_update(conn, priv->fb, x, y, width, height);
         vnc_connection_update(conn, x, y, width, height);
         break;
     case VNC_CONNECTION_ENCODING_HEXTILE:
         if (!vnc_connection_validate_boundary(conn, priv->fb,
                                               x, y, width, height))
             break;
-        vnc_connection_hextile_update(conn, x, y, width, height);
+        vnc_connection_hextile_update(conn, priv->fb, x, y, width, height);
         vnc_connection_update(conn, x, y, width, height);
         break;
     case VNC_CONNECTION_ENCODING_ZRLE:
         if (!vnc_connection_validate_boundary(conn, priv->fb,
                                               x, y, width, height))
             break;
-        vnc_connection_zrle_update(conn, x, y, width, height);
+        vnc_connection_zrle_update(conn, priv->fb, x, y, width, height);
         vnc_connection_update(conn, x, y, width, height);
         break;
     case VNC_CONNECTION_ENCODING_TIGHT:
         if (!vnc_connection_validate_boundary(conn, priv->fb,
                                               x, y, width, height))
             break;
-        vnc_connection_tight_update(conn, x, y, width, height);
+        vnc_connection_tight_update(conn, priv->fb, x, y, width, height);
         vnc_connection_update(conn, x, y, width, height);
         break;
     case VNC_CONNECTION_ENCODING_DESKTOP_RESIZE:


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