Re: [patch] Allows linking with gtk+2.0 and gtk+3.0
- From: Jonh Wendell <jwendell gnome org>
- To: "Daniel P. Berrange" <dan berrange com>
- Cc: gtk-vnc-devel List <gtk-vnc-list gnome org>
- Subject: Re: [patch] Allows linking with gtk+2.0 and gtk+3.0
- Date: Wed, 30 Jun 2010 10:42:32 -0300
Em Qua, 2010-06-30 às 13:59 +0100, Daniel P. Berrange escreveu:
> On Wed, Jun 30, 2010 at 09:25:03AM -0300, Jonh Wendell wrote:
> > Em Qua, 2010-06-30 às 12:46 +0100, Daniel P. Berrange escreveu:
> >
> > > > default:
> > > > g_assert_not_reached ();
> > > > }
> > > >
> > > > + #if GTK_CHECK_VERSION (2, 90, 0)
> > > > + 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
> > > > +
> > >
> > > The API docs say this method is 'Since 2.22', so why is the check
> > > doing 2.90 instead of 2.22 ?
> >
> > We rely on gtk+ 2.18 right now. I think our next big step would be to
> > rely on gtk+3. IMHO there's no point in depend on gtk+ 2.22 in the
> > future when we can safely upgrade to gtk+ 3.0.
> >
> > So, my thought was: either we depend on gtk 2.18 or 3.0. No middle term.
>
> This isn't about dependancies though. The patch is actually doing two
> completely separate jobs
>
> 1. Conditional complication that uses methods like gdk_visual_get_byte_order
> instead of struct field access v->byte_order
>
> 2. Changing configure/Makefile to allow linking against GTK2 vs GTK3
>
>
> The first bit of work shouldn't be tied to the second. They should actually
> be separated into separate patches/commits. One patch adds the conditional
> compilation that uses the new APIs for Gtk >= 2.22 (or whenever the API
> in question was introduced). The second patch adds the GTK3 linking
> ability.
>
> Regards,
> Daniel
I got it. Please review these patches.
Thanks,
--
Jonh Wendell
http://www.bani.com.br
>From 4909ce746e31385cb89fcfc7efe551a0748c8358 Mon Sep 17 00:00:00 2001
From: Jonh Wendell <jwendell gnome org>
Date: Wed, 30 Jun 2010 10:38:31 -0300
Subject: [PATCH 1/2] 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));
--
1.7.0.4
>From 85a32e4e243bf57a2bdde9e1bf1f4408d4923e74 Mon Sep 17 00:00:00 2001
From: Jonh Wendell <jwendell gnome org>
Date: Wed, 30 Jun 2010 10:40:09 -0300
Subject: [PATCH 2/2] Allows linking with gtk+2.0 and gtk+3.0
This adds a new configure parameter: --with-gtk=2.0|3.0 (default: 2.0)
---
configure.ac | 32 +++++++++++++++++++++++++++++---
gtk-vnc-1.0.pc.in | 2 +-
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/configure.ac b/configure.ac
index 0075708..c98fce7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,8 +32,6 @@ GOBJECT_REQUIRED=2.10.0
AC_SUBST(GOBJECT_REQUIRED)
GDK_PIXBUF_REQUIRED=2.10.0
AC_SUBST(GDK_PIXBUF_REQUIRED)
-GTK_REQUIRED=2.18.0
-AC_SUBST(GTK_REQUIRED)
GNUTLS_REQUIRED=1.4.0
AC_SUBST(GNUTLS_REQUIRED)
@@ -72,6 +70,33 @@ AM_GLIB_GNU_GETTEXT
dnl *******************************************************************************
+################################################################################
+# GTK+
+################################################################################
+
+AC_MSG_CHECKING([which gtk+ version to compile against])
+AC_ARG_WITH([gtk],
+ [AS_HELP_STRING([--with-gtk=2.0|3.0],[which gtk+ version to compile against (default: 2.0)])],
+ [case "$with_gtk" in
+ 2.0|3.0) ;;
+ *) AC_MSG_ERROR([invalid gtk version specified]) ;;
+ esac],
+ [with_gtk=2.0])
+AC_MSG_RESULT([$with_gtk])
+
+case "$with_gtk" in
+ 2.0) GTK_API_VERSION=2.0
+ GTK_REQUIRED=2.18.0
+ ;;
+ 3.0) GTK_API_VERSION=3.0
+ GTK_REQUIRED=2.90.4
+ ;;
+esac
+
+AC_SUBST([GTK_API_VERSION])
+AC_SUBST([GTK_REQUIRED])
+AM_CONDITIONAL([HAVE_GTK_2],[test "$with_gtk" = "2.0"])
+AM_CONDITIONAL([HAVE_GTK_3],[test "$with_gtk" = "3.0"])
AC_CHECK_HEADERS([pwd.h winsock2.h])
@@ -109,7 +134,7 @@ PKG_CHECK_MODULES(GDK_PIXBUF, gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED)
AC_SUBST(GDK_PIXBUF_CFLAGS)
AC_SUBST(GDK_PIXBUF_LIBS)
-PKG_CHECK_MODULES(GTK, gtk+-2.0 >= $GTK_REQUIRED)
+PKG_CHECK_MODULES(GTK, gtk+-$GTK_API_VERSION >= $GTK_REQUIRED)
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
@@ -362,4 +387,5 @@ Configure summary:
Browser plugin .............: ${enable_plugin}
Scaling support.............: ${with_scaling}
SASL support................: ${enable_sasl}
+ GTK+ version................: ${GTK_API_VERSION}
"
diff --git a/gtk-vnc-1.0.pc.in b/gtk-vnc-1.0.pc.in
index 1f9af79..1859228 100644
--- a/gtk-vnc-1.0.pc.in
+++ b/gtk-vnc-1.0.pc.in
@@ -5,7 +5,7 @@ includedir= includedir@
Name: GTK-VNC
Description: GTK widget for a VNC client
-Requires: gvnc-1.0 = @VERSION@, gtk+-2.0 >= @GTK_REQUIRED@
+Requires: gvnc-1.0 = @VERSION@, gtk+- GTK_API_VERSION@ >= @GTK_REQUIRED@
Version: @VERSION@
Libs: -L${libdir} -lgtk-vnc-1.0
Cflags: -I${includedir}/gtk-vnc-1.0
--
1.7.0.4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]