[cogl] tex-pixmap-x11: remove CoglHandle use + pass context



commit 4e3f9d0fc27b3a84deb5dec84e9ca376828d29b8
Author: Robert Bragg <robert linux intel com>
Date:   Sat Feb 18 16:53:07 2012 +0000

    tex-pixmap-x11: remove CoglHandle use + pass context
    
    This also replaces use of CoglHandle with a CoglTexturePixmapX11 type
    instead.
    
    This patch also ensures the CoglTexturePixmapX11 constructor take an
    explicit CoglContext pointer and can return a GError consistent with
    other CoglTexture constructors.
    
    Reviewed-by: Neil Roberts <neil linux intel com>

 cogl/winsys/cogl-texture-pixmap-x11-private.h |    4 -
 cogl/winsys/cogl-texture-pixmap-x11.c         |   50 ++++++-------
 cogl/winsys/cogl-texture-pixmap-x11.h         |   97 ++++++++++++++++---------
 examples/cogl-x11-tfp.c                       |   12 +++-
 4 files changed, 94 insertions(+), 69 deletions(-)
---
diff --git a/cogl/winsys/cogl-texture-pixmap-x11-private.h b/cogl/winsys/cogl-texture-pixmap-x11-private.h
index 699baf7..92b672c 100644
--- a/cogl/winsys/cogl-texture-pixmap-x11-private.h
+++ b/cogl/winsys/cogl-texture-pixmap-x11-private.h
@@ -38,8 +38,6 @@
 #include "cogl-texture-private.h"
 #include "cogl-texture-pixmap-x11.h"
 
-#define COGL_TEXTURE_PIXMAP_X11(tex) ((CoglTexturePixmapX11 *) tex)
-
 typedef struct _CoglDamageRectangle CoglDamageRectangle;
 
 struct _CoglDamageRectangle
@@ -50,8 +48,6 @@ struct _CoglDamageRectangle
   unsigned int y2;
 };
 
-typedef struct _CoglTexturePixmapX11 CoglTexturePixmapX11;
-
 struct _CoglTexturePixmapX11
 {
   CoglTexture _parent;
diff --git a/cogl/winsys/cogl-texture-pixmap-x11.c b/cogl/winsys/cogl-texture-pixmap-x11.c
index f6b8768..0723ab3 100644
--- a/cogl/winsys/cogl-texture-pixmap-x11.c
+++ b/cogl/winsys/cogl-texture-pixmap-x11.c
@@ -64,6 +64,12 @@ COGL_TEXTURE_DEFINE (TexturePixmapX11, texture_pixmap_x11);
 
 static const CoglTextureVtable cogl_texture_pixmap_x11_vtable;
 
+GQuark
+cogl_texture_pixmap_x11_error_quark (void)
+{
+  return g_quark_from_static_string ("cogl-texture-pixmap-error-quark");
+}
+
 static void
 cogl_damage_rectangle_union (CoglDamageRectangle *damage_rect,
                              int x,
@@ -263,9 +269,11 @@ set_damage_object_internal (CoglContext *ctx,
                                    tex_pixmap);
 }
 
-CoglHandle
-cogl_texture_pixmap_x11_new (guint32 pixmap,
-                             gboolean automatic_updates)
+CoglTexturePixmapX11 *
+cogl_texture_pixmap_x11_new (CoglContext *ctxt,
+                             guint32 pixmap,
+                             gboolean automatic_updates,
+                             GError **error)
 {
   CoglTexturePixmapX11 *tex_pixmap = g_new (CoglTexturePixmapX11, 1);
   Display *display = cogl_xlib_get_display ();
@@ -277,8 +285,6 @@ cogl_texture_pixmap_x11_new (guint32 pixmap,
   int damage_base;
   const CoglWinsysVtable *winsys;
 
-  _COGL_GET_CONTEXT (ctxt, COGL_INVALID_HANDLE);
-
   _cogl_texture_init (tex, &cogl_texture_pixmap_x11_vtable);
 
   tex_pixmap->pixmap = pixmap;
@@ -294,8 +300,11 @@ cogl_texture_pixmap_x11_new (guint32 pixmap,
                      &pixmap_border_width, &tex_pixmap->depth))
     {
       g_free (tex_pixmap);
-      g_warning ("Unable to query pixmap size");
-      return COGL_INVALID_HANDLE;
+      g_set_error (error,
+                   COGL_TEXTURE_PIXMAP_X11_ERROR,
+                   COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
+                   "Unable to query pixmap size");
+      return NULL;
     }
 
   /* We need a visual to use for shared memory images so we'll query
@@ -303,8 +312,11 @@ cogl_texture_pixmap_x11_new (guint32 pixmap,
   if (!XGetWindowAttributes (display, pixmap_root_window, &window_attributes))
     {
       g_free (tex_pixmap);
-      g_warning ("Unable to query root window attributes");
-      return COGL_INVALID_HANDLE;
+      g_set_error (error,
+                   COGL_TEXTURE_PIXMAP_X11_ERROR,
+                   COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
+                   "Unable to query root window attributes");
+      return NULL;
     }
   tex_pixmap->visual = window_attributes.visual;
 
@@ -416,17 +428,12 @@ try_alloc_shm (CoglTexturePixmapX11 *tex_pixmap)
 }
 
 void
-cogl_texture_pixmap_x11_update_area (CoglHandle handle,
+cogl_texture_pixmap_x11_update_area (CoglTexturePixmapX11 *tex_pixmap,
                                      int x,
                                      int y,
                                      int width,
                                      int height)
 {
-  CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (handle);
-
-  if (!cogl_is_texture_pixmap_x11 (handle))
-    return;
-
   /* We'll queue the update for both the GLX texture and the regular
      texture because we can't determine which will be needed until we
      actually render something */
@@ -443,30 +450,21 @@ cogl_texture_pixmap_x11_update_area (CoglHandle handle,
 }
 
 gboolean
-cogl_texture_pixmap_x11_is_using_tfp_extension (CoglHandle handle)
+cogl_texture_pixmap_x11_is_using_tfp_extension (CoglTexturePixmapX11 *tex_pixmap)
 {
-  CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (handle);
-
-  if (!cogl_is_texture_pixmap_x11 (tex_pixmap))
-    return FALSE;
-
   return !!tex_pixmap->winsys;
 }
 
 void
-cogl_texture_pixmap_x11_set_damage_object (CoglHandle handle,
+cogl_texture_pixmap_x11_set_damage_object (CoglTexturePixmapX11 *tex_pixmap,
                                            guint32 damage,
                                            CoglTexturePixmapX11ReportLevel
                                                                   report_level)
 {
-  CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (handle);
   int damage_base;
 
   _COGL_GET_CONTEXT (ctxt, NO_RETVAL);
 
-  if (!cogl_is_texture_pixmap_x11 (tex_pixmap))
-    return;
-
   damage_base = _cogl_xlib_get_damage_base ();
   if (damage_base >= 0)
     set_damage_object_internal (ctxt, tex_pixmap, damage, report_level);
diff --git a/cogl/winsys/cogl-texture-pixmap-x11.h b/cogl/winsys/cogl-texture-pixmap-x11.h
index fac2b56..604011c 100644
--- a/cogl/winsys/cogl-texture-pixmap-x11.h
+++ b/cogl/winsys/cogl-texture-pixmap-x11.h
@@ -26,7 +26,11 @@
 
 #define __COGL_H_INSIDE__
 
-#include <cogl/cogl-types.h>
+#include <glib.h>
+
+#include <cogl/cogl-context.h>
+
+G_BEGIN_DECLS
 
 #ifdef COGL_ENABLE_EXPERIMENTAL_API
 
@@ -40,19 +44,9 @@
  * pixmap.
  */
 
-/* All of the cogl-texture-pixmap-x11 API is currently experimental so
- * we suffix the actual symbols with _EXP so if somone is monitoring
- * for ABI changes it will hopefully be clearer to them what's going
- * on if any of the symbols dissapear at a later date.
- */
-#define cogl_texture_pixmap_x11_new cogl_texture_pixmap_x11_new_EXP
-#define cogl_texture_pixmap_x11_update_area \
-  cogl_texture_pixmap_x11_update_area_EXP
-#define cogl_texture_pixmap_x11_is_using_tfp_extension \
-  cogl_texture_pixmap_x11_is_using_tfp_extension_EXP
-#define cogl_texture_pixmap_x11_set_damage_object \
-  cogl_texture_pixmap_x11_set_damage_object_EXP
-#define cogl_is_texture_pixmap_x11 cogl_is_texture_pixmap_x11_EXP
+typedef struct _CoglTexturePixmapX11 CoglTexturePixmapX11;
+
+#define COGL_TEXTURE_PIXMAP_X11(X) ((CoglTexturePixmapX11 *)X)
 
 typedef enum
 {
@@ -63,42 +57,70 @@ typedef enum
 } CoglTexturePixmapX11ReportLevel;
 
 /**
+ * COGL_TEXTURE_PIXMAP_X11_ERROR:
+ *
+ * #GError domain for texture-pixmap-x11 errors.
+ *
+ * Since: 1.10
+ */
+#define COGL_TEXTURE_PIXMAP_X11_ERROR (cogl_texture_pixmap_x11_error_quark ())
+
+/**
+ * CoglTexturePixmapX11Error:
+ * @COGL_TEXTURE_PIXMAP_X11_ERROR_X11: An X11 protocol error
+ *
+ * Error codes that can be thrown when performing texture-pixmap-x11
+ * operations.
+ *
+ * Since: 1.10
+ */
+typedef enum {
+  COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
+} CoglTexturePixmapX11Error;
+
+GQuark cogl_texture_pixmap_x11_error_quark (void);
+
+/**
  * cogl_texture_pixmap_x11_new:
+ * @context: A #CoglContext
  * @pixmap: A X11 pixmap ID
  * @automatic_updates: Whether to automatically copy the contents of
  * the pixmap to the texture.
+ * @error: A #GError for exceptions
  *
  * Creates a texture that contains the contents of @pixmap. If
  * @automatic_updates is %TRUE then Cogl will attempt to listen for
  * damage events on the pixmap and automatically update the texture
  * when it changes.
  *
- * Return value: a CoglHandle to a texture
+ * Return value: a new #CoglTexturePixmapX11 instance
  *
- * Since: 1.4
+ * Since: 1.10
  * Stability: Unstable
  */
-CoglHandle
-cogl_texture_pixmap_x11_new (guint32 pixmap,
-                             gboolean automatic_updates);
+CoglTexturePixmapX11 *
+cogl_texture_pixmap_x11_new (CoglContext *context,
+                             guint32 pixmap,
+                             gboolean automatic_updates,
+                             GError **error);
 
 /**
  * cogl_texture_pixmap_x11_update_area:
- * @handle: A CoglHandle to a CoglTexturePixmapX11 instance
+ * @texture: A #CoglTexturePixmapX11 instance
  * @x: x coordinate of the area to update
  * @y: y coordinate of the area to update
  * @width: width of the area to update
  * @height: height of the area to update
  *
- * Forces an update of the texture pointed to by @handle so that it is
- * refreshed with the contents of the pixmap that was given to
+ * Forces an update of the given @texture so that it is refreshed with
+ * the contents of the pixmap that was given to
  * cogl_texture_pixmap_x11_new().
  *
  * Since: 1.4
  * Stability: Unstable
  */
 void
-cogl_texture_pixmap_x11_update_area (CoglHandle handle,
+cogl_texture_pixmap_x11_update_area (CoglTexturePixmapX11 *texture,
                                      int x,
                                      int y,
                                      int width,
@@ -106,12 +128,13 @@ cogl_texture_pixmap_x11_update_area (CoglHandle handle,
 
 /**
  * cogl_texture_pixmap_x11_is_using_tfp_extension:
- * @handle: A CoglHandle to a CoglTexturePixmapX11 instance
+ * @texture: A #CoglTexturePixmapX11 instance
  *
- * Checks whether the texture is using the GLX_EXT_texture_from_pixmap
- * or similar extension to copy the contents of the pixmap to the texture.
- * This extension is usually implemented as zero-copy operation so it
- * implies the updates are working efficiently.
+ * Checks whether the given @texture is using the
+ * GLX_EXT_texture_from_pixmap or similar extension to copy the
+ * contents of the pixmap to the texture.  This extension is usually
+ * implemented as zero-copy operation so it implies the updates are
+ * working efficiently.
  *
  * Return value: %TRUE if the texture is using an efficient extension
  *   and %FALSE otherwise
@@ -120,18 +143,18 @@ cogl_texture_pixmap_x11_update_area (CoglHandle handle,
  * Stability: Unstable
  */
 gboolean
-cogl_texture_pixmap_x11_is_using_tfp_extension (CoglHandle handle);
+cogl_texture_pixmap_x11_is_using_tfp_extension (CoglTexturePixmapX11 *texture);
 
 /**
  * cogl_texture_pixmap_x11_set_damage_object:
- * @handle: A CoglHandle
+ * @texture: A #CoglTexturePixmapX11 instance
  * @damage: A X11 Damage object or 0
  * @report_level: The report level which describes how to interpret
  *   the damage events. This should match the level that the damage
  *   object was created with.
  *
  * Sets the damage object that will be used to track automatic updates
- * to the texture. Damage tracking can be disabled by passing 0 for
+ * to the @texture. Damage tracking can be disabled by passing 0 for
  * @damage. Otherwise this damage will replace the one used if %TRUE
  * was passed for automatic_updates to cogl_texture_pixmap_x11_new().
  *
@@ -142,26 +165,28 @@ cogl_texture_pixmap_x11_is_using_tfp_extension (CoglHandle handle);
  * Stability: Unstable
  */
 void
-cogl_texture_pixmap_x11_set_damage_object (CoglHandle handle,
+cogl_texture_pixmap_x11_set_damage_object (CoglTexturePixmapX11 *texture,
                                            guint32 damage,
                                            CoglTexturePixmapX11ReportLevel
                                                                   report_level);
 
 /**
  * cogl_is_texture_pixmap_x11:
- * @handle: A CoglHandle
+ * @object: A pointer to a #CoglObject
  *
- * Checks whether @handle points to a CoglTexturePixmapX11 instance.
+ * Checks whether @object points to a #CoglTexturePixmapX11 instance.
  *
- * Return value: %TRUE if the handle is a CoglTexturePixmapX11, and
+ * Return value: %TRUE if the object is a #CoglTexturePixmapX11, and
  *   %FALSE otherwise
  *
  * Since: 1.4
  * Stability: Unstable
  */
 gboolean
-cogl_is_texture_pixmap_x11 (CoglHandle handle);
+cogl_is_texture_pixmap_x11 (void *object);
 
 #endif /* COGL_ENABLE_EXPERIMENTAL_API */
 
+G_END_DECLS
+
 #endif /* __COGL_TEXTURE_PIXMAP_X11_H */
diff --git a/examples/cogl-x11-tfp.c b/examples/cogl-x11-tfp.c
index 78aafde..eb1b237 100644
--- a/examples/cogl-x11-tfp.c
+++ b/examples/cogl-x11-tfp.c
@@ -59,7 +59,7 @@ main (int argc, char **argv)
   int screen;
   Window tfp_xwin;
   Pixmap pixmap;
-  CoglHandle tfp;
+  CoglTexturePixmapX11 *tfp;
   GC gc;
 
   g_print ("NB: Don't use this example as a benchmark since there is "
@@ -181,7 +181,13 @@ main (int argc, char **argv)
 
   pixmap = XCompositeNameWindowPixmap (xdpy, tfp_xwin);
 
-  tfp = cogl_texture_pixmap_x11_new (pixmap, TRUE);
+  tfp = cogl_texture_pixmap_x11_new (ctx, pixmap, TRUE, &error);
+  if (!tfp)
+    {
+      fprintf (stderr, "Failed to create CoglTexturePixmapX11: %s",
+               error->message);
+      return 1;
+    }
 
   fb = COGL_FRAMEBUFFER (onscreen);
   cogl_push_framebuffer (fb);
@@ -215,7 +221,7 @@ main (int argc, char **argv)
       XFlush (xdpy);
 
       cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
-      cogl_set_source_texture (tfp);
+      cogl_set_source_texture (COGL_TEXTURE (tfp));
       cogl_rectangle (-0.8, 0.8, 0.8, -0.8);
       cogl_onscreen_swap_buffers (onscreen);
     }



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