[gtk-vnc] Prepare for gtk+ >= 2.22



commit 4909ce746e31385cb89fcfc7efe551a0748c8358
Author: Jonh Wendell <jwendell gnome org>
Date:   Wed Jun 30 10:38:31 2010 -0300

    Prepare for gtk+ >= 2.22
    
    This uses accessors instead of accessing struct members

 src/vncdisplay.c          |   25 ++++++++++----
 src/vncdisplay.h          |    2 +-
 src/vncimageframebuffer.c |   78 ++++++++++++++++++++++++++++++++-------------
 3 files changed, 75 insertions(+), 30 deletions(-)
---
diff --git a/src/vncdisplay.c b/src/vncdisplay.c
index 36cf783..c28a7aa 100644
--- a/src/vncdisplay.c
+++ b/src/vncdisplay.c
@@ -1029,7 +1029,6 @@ static gboolean vnc_display_set_preferred_pixel_format(VncDisplay *display)
 		fmt.green_shift = 8;
 		fmt.blue_shift = 0;
 		fmt.true_color_flag = 1;
-		fmt.byte_order = v->byte_order == GDK_LSB_FIRST ? G_BIG_ENDIAN : G_LITTLE_ENDIAN;
 		break;
 
 	case VNC_DISPLAY_DEPTH_COLOR_MEDIUM:
@@ -1042,7 +1041,6 @@ static gboolean vnc_display_set_preferred_pixel_format(VncDisplay *display)
 		fmt.green_shift = 6;
 		fmt.blue_shift = 1;
 		fmt.true_color_flag = 1;
-		fmt.byte_order = v->byte_order == GDK_LSB_FIRST ? G_BIG_ENDIAN : G_LITTLE_ENDIAN;
 		break;
 
 	case VNC_DISPLAY_DEPTH_COLOR_LOW:
@@ -1055,7 +1053,6 @@ static gboolean vnc_display_set_preferred_pixel_format(VncDisplay *display)
 		fmt.green_shift = 2;
 		fmt.blue_shift = 0;
 		fmt.true_color_flag = 1;
-		fmt.byte_order = v->byte_order == GDK_LSB_FIRST ? G_BIG_ENDIAN : G_LITTLE_ENDIAN;
 		break;
 
 	case VNC_DISPLAY_DEPTH_COLOR_ULTRA_LOW:
@@ -1068,13 +1065,18 @@ static gboolean vnc_display_set_preferred_pixel_format(VncDisplay *display)
 		fmt.green_shift = 6;
 		fmt.blue_shift = 5;
 		fmt.true_color_flag = 1;
-		fmt.byte_order = v->byte_order == GDK_LSB_FIRST ? G_BIG_ENDIAN : G_LITTLE_ENDIAN;
 		break;
 
 	default:
 		g_assert_not_reached ();
 	}
 
+	#if GTK_CHECK_VERSION (2, 21, 1)
+	fmt.byte_order = gdk_visual_get_byte_order (v) == GDK_LSB_FIRST ? G_BIG_ENDIAN : G_LITTLE_ENDIAN;
+	#else
+	fmt.byte_order = v->byte_order == GDK_LSB_FIRST ? G_BIG_ENDIAN : G_LITTLE_ENDIAN;
+	#endif
+
 	VNC_DEBUG ("Set depth color to %d (%d bpp)", fmt.depth, fmt.bits_per_pixel);
 	if (!vnc_connection_set_pixel_format(priv->conn, &fmt))
 		return FALSE;
@@ -1998,22 +2000,31 @@ GdkPixbuf *vnc_display_get_pixbuf(VncDisplay *obj)
 	VncDisplayPrivate *priv = obj->priv;
 	GdkPixbuf *pixbuf;
 	GdkImage *image;
+	gint w, h;
 
 	if (!priv->conn ||
 	    !vnc_connection_is_initialized(priv->conn))
 		return NULL;
 
 	image = vnc_image_framebuffer_get_image(priv->fb);
+	#if GTK_CHECK_VERSION(2, 21, 1)
+	w = gdk_image_get_width (image);
+	h = gdk_image_get_height (image);
+	#else
+	w = image->width;
+	h = image->height;
+	#endif
 
 	pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
-				image->width, image->height);
+				w,
+				h);
 
 	if (!gdk_pixbuf_get_from_image(pixbuf,
 				       image,
 				       gdk_colormap_get_system(),
 				       0, 0, 0, 0,
-				       image->width,
-				       image->height))
+				       w,
+				       h))
 		return NULL;
 
 	return pixbuf;
diff --git a/src/vncdisplay.h b/src/vncdisplay.h
index dc043d1..2ed2a6c 100644
--- a/src/vncdisplay.h
+++ b/src/vncdisplay.h
@@ -22,7 +22,7 @@
 #ifndef VNC_DISPLAY_H
 #define VNC_DISPLAY_H
 
-#include <gtk/gtkdrawingarea.h>
+#include <gtk/gtk.h>
 #include <glib.h>
 #include <vncgrabsequence.h>
 
diff --git a/src/vncimageframebuffer.c b/src/vncimageframebuffer.c
index 1cae118..9f06843 100644
--- a/src/vncimageframebuffer.c
+++ b/src/vncimageframebuffer.c
@@ -22,6 +22,7 @@
 #include <config.h>
 
 #include <string.h>
+#include <gtk/gtk.h>
 
 #include "vncimageframebuffer.h"
 #include "vncutil.h"
@@ -132,33 +133,66 @@ VncImageFramebuffer *vnc_image_framebuffer_new(GdkImage *image,
 					       const VncPixelFormat *remoteFormat)
 {
         VncPixelFormat localFormat;
+        guint32 red_mask, green_mask, blue_mask;
+        gint red_shift, green_shift, blue_shift, w, h;
+        guint16 bpp, bpl, depth;
+        gpointer pixels;
+        GdkByteOrder byte_order;
+
+	#if GTK_CHECK_VERSION (2, 21, 1)
+	GdkVisual *visual = gdk_image_get_visual (image);
+	gdk_visual_get_red_pixel_details (visual, &red_mask, &red_shift, NULL);
+	gdk_visual_get_green_pixel_details (visual, &green_mask, &green_shift, NULL);
+	gdk_visual_get_blue_pixel_details (visual, &blue_mask, &blue_shift, NULL);
+	bpp = gdk_image_get_bytes_per_pixel (image);
+	depth = gdk_image_get_depth (image);
+	byte_order = gdk_image_get_byte_order (image);
+	bpl = gdk_image_get_bytes_per_line (image);
+	w = gdk_image_get_width (image);
+	h = gdk_image_get_height (image);
+	pixels = gdk_image_get_pixels (image);
+	#else
+	red_mask = image->visual->red_mask;
+	red_shift = image->visual->red_shift;
+	green_mask = image->visual->green_mask;
+	green_shift = image->visual->green_shift;
+	blue_mask = image->visual->blue_mask;
+	blue_shift = image->visual->blue_shift;
+	bpp = image->bpp;
+	depth = image->depth;
+	byte_order = image->byte_order;
+	bpl = image->bpl;
+	w = image->width;
+	h = image->height;
+	pixels = image->mem;
+	#endif
 
 	VNC_DEBUG("Visual mask: %3d %3d %3d\n      shift: %3d %3d %3d",
-		   image->visual->red_mask,
-		   image->visual->green_mask,
-		   image->visual->blue_mask,
-		   image->visual->red_shift,
-		   image->visual->green_shift,
-		   image->visual->blue_shift);
-
-	localFormat.red_max = image->visual->red_mask >> image->visual->red_shift;
-	localFormat.green_max = image->visual->green_mask >> image->visual->green_shift;
-	localFormat.blue_max = image->visual->blue_mask >> image->visual->blue_shift;
-	localFormat.red_shift = image->visual->red_shift;
-	localFormat.green_shift = image->visual->green_shift;
-	localFormat.blue_shift = image->visual->blue_shift;
-	localFormat.depth = image->depth;
-	localFormat.bits_per_pixel = image->bpp * 8;
-	localFormat.byte_order = image->byte_order == GDK_LSB_FIRST ? G_LITTLE_ENDIAN : G_BIG_ENDIAN;
-
-	memset(image->mem, 0, image->bpl * image->height);
+		   red_mask,
+		   green_mask,
+		   blue_mask,
+		   red_shift,
+		   green_shift,
+		   blue_shift);
+
+	localFormat.red_max = red_mask >> red_shift;
+	localFormat.green_max = green_mask >> green_shift;
+	localFormat.blue_max = blue_mask >> blue_shift;
+	localFormat.red_shift = red_shift;
+	localFormat.green_shift = green_shift;
+	localFormat.blue_shift = blue_shift;
+	localFormat.depth = depth;
+	localFormat.bits_per_pixel = bpp * 8;
+	localFormat.byte_order = byte_order == GDK_LSB_FIRST ? G_LITTLE_ENDIAN : G_BIG_ENDIAN;
+
+	memset(pixels, 0, bpl * h);
 
 	return VNC_IMAGE_FRAMEBUFFER(g_object_new(VNC_TYPE_IMAGE_FRAMEBUFFER,
 						  "image", image,
-						  "buffer", (guint8 *)image->mem,
-						  "width", image->width,
-						  "height", image->height,
-						  "rowstride", image->bpl,
+						  "buffer", (guint8 *)pixels,
+						  "width", w,
+						  "height", h,
+						  "rowstride", bpl,
 						  "local-format", &localFormat,
 						  "remote-format", remoteFormat,
 						  NULL));



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