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>
This commit is contained in:
Robert Bragg 2012-02-18 16:53:07 +00:00
parent 479c5fd2c9
commit 4e3f9d0fc2
4 changed files with 94 additions and 69 deletions

View File

@ -38,8 +38,6 @@
#include "cogl-texture-private.h" #include "cogl-texture-private.h"
#include "cogl-texture-pixmap-x11.h" #include "cogl-texture-pixmap-x11.h"
#define COGL_TEXTURE_PIXMAP_X11(tex) ((CoglTexturePixmapX11 *) tex)
typedef struct _CoglDamageRectangle CoglDamageRectangle; typedef struct _CoglDamageRectangle CoglDamageRectangle;
struct _CoglDamageRectangle struct _CoglDamageRectangle
@ -50,8 +48,6 @@ struct _CoglDamageRectangle
unsigned int y2; unsigned int y2;
}; };
typedef struct _CoglTexturePixmapX11 CoglTexturePixmapX11;
struct _CoglTexturePixmapX11 struct _CoglTexturePixmapX11
{ {
CoglTexture _parent; CoglTexture _parent;

View File

@ -64,6 +64,12 @@ COGL_TEXTURE_DEFINE (TexturePixmapX11, texture_pixmap_x11);
static const CoglTextureVtable cogl_texture_pixmap_x11_vtable; 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 static void
cogl_damage_rectangle_union (CoglDamageRectangle *damage_rect, cogl_damage_rectangle_union (CoglDamageRectangle *damage_rect,
int x, int x,
@ -263,9 +269,11 @@ set_damage_object_internal (CoglContext *ctx,
tex_pixmap); tex_pixmap);
} }
CoglHandle CoglTexturePixmapX11 *
cogl_texture_pixmap_x11_new (guint32 pixmap, cogl_texture_pixmap_x11_new (CoglContext *ctxt,
gboolean automatic_updates) guint32 pixmap,
gboolean automatic_updates,
GError **error)
{ {
CoglTexturePixmapX11 *tex_pixmap = g_new (CoglTexturePixmapX11, 1); CoglTexturePixmapX11 *tex_pixmap = g_new (CoglTexturePixmapX11, 1);
Display *display = cogl_xlib_get_display (); Display *display = cogl_xlib_get_display ();
@ -277,8 +285,6 @@ cogl_texture_pixmap_x11_new (guint32 pixmap,
int damage_base; int damage_base;
const CoglWinsysVtable *winsys; const CoglWinsysVtable *winsys;
_COGL_GET_CONTEXT (ctxt, COGL_INVALID_HANDLE);
_cogl_texture_init (tex, &cogl_texture_pixmap_x11_vtable); _cogl_texture_init (tex, &cogl_texture_pixmap_x11_vtable);
tex_pixmap->pixmap = pixmap; tex_pixmap->pixmap = pixmap;
@ -294,8 +300,11 @@ cogl_texture_pixmap_x11_new (guint32 pixmap,
&pixmap_border_width, &tex_pixmap->depth)) &pixmap_border_width, &tex_pixmap->depth))
{ {
g_free (tex_pixmap); g_free (tex_pixmap);
g_warning ("Unable to query pixmap size"); g_set_error (error,
return COGL_INVALID_HANDLE; 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 /* 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)) if (!XGetWindowAttributes (display, pixmap_root_window, &window_attributes))
{ {
g_free (tex_pixmap); g_free (tex_pixmap);
g_warning ("Unable to query root window attributes"); g_set_error (error,
return COGL_INVALID_HANDLE; 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; tex_pixmap->visual = window_attributes.visual;
@ -416,17 +428,12 @@ try_alloc_shm (CoglTexturePixmapX11 *tex_pixmap)
} }
void void
cogl_texture_pixmap_x11_update_area (CoglHandle handle, cogl_texture_pixmap_x11_update_area (CoglTexturePixmapX11 *tex_pixmap,
int x, int x,
int y, int y,
int width, int width,
int height) 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 /* 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 texture because we can't determine which will be needed until we
actually render something */ actually render something */
@ -443,30 +450,21 @@ cogl_texture_pixmap_x11_update_area (CoglHandle handle,
} }
gboolean 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; return !!tex_pixmap->winsys;
} }
void void
cogl_texture_pixmap_x11_set_damage_object (CoglHandle handle, cogl_texture_pixmap_x11_set_damage_object (CoglTexturePixmapX11 *tex_pixmap,
guint32 damage, guint32 damage,
CoglTexturePixmapX11ReportLevel CoglTexturePixmapX11ReportLevel
report_level) report_level)
{ {
CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (handle);
int damage_base; int damage_base;
_COGL_GET_CONTEXT (ctxt, NO_RETVAL); _COGL_GET_CONTEXT (ctxt, NO_RETVAL);
if (!cogl_is_texture_pixmap_x11 (tex_pixmap))
return;
damage_base = _cogl_xlib_get_damage_base (); damage_base = _cogl_xlib_get_damage_base ();
if (damage_base >= 0) if (damage_base >= 0)
set_damage_object_internal (ctxt, tex_pixmap, damage, report_level); set_damage_object_internal (ctxt, tex_pixmap, damage, report_level);

View File

@ -26,7 +26,11 @@
#define __COGL_H_INSIDE__ #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 #ifdef COGL_ENABLE_EXPERIMENTAL_API
@ -40,19 +44,9 @@
* pixmap. * pixmap.
*/ */
/* All of the cogl-texture-pixmap-x11 API is currently experimental so typedef struct _CoglTexturePixmapX11 CoglTexturePixmapX11;
* 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 #define COGL_TEXTURE_PIXMAP_X11(X) ((CoglTexturePixmapX11 *)X)
* 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 enum typedef enum
{ {
@ -62,43 +56,71 @@ typedef enum
COGL_TEXTURE_PIXMAP_X11_DAMAGE_NON_EMPTY COGL_TEXTURE_PIXMAP_X11_DAMAGE_NON_EMPTY
} CoglTexturePixmapX11ReportLevel; } 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: * cogl_texture_pixmap_x11_new:
* @context: A #CoglContext
* @pixmap: A X11 pixmap ID * @pixmap: A X11 pixmap ID
* @automatic_updates: Whether to automatically copy the contents of * @automatic_updates: Whether to automatically copy the contents of
* the pixmap to the texture. * the pixmap to the texture.
* @error: A #GError for exceptions
* *
* Creates a texture that contains the contents of @pixmap. If * Creates a texture that contains the contents of @pixmap. If
* @automatic_updates is %TRUE then Cogl will attempt to listen for * @automatic_updates is %TRUE then Cogl will attempt to listen for
* damage events on the pixmap and automatically update the texture * damage events on the pixmap and automatically update the texture
* when it changes. * when it changes.
* *
* Return value: a CoglHandle to a texture * Return value: a new #CoglTexturePixmapX11 instance
* *
* Since: 1.4 * Since: 1.10
* Stability: Unstable * Stability: Unstable
*/ */
CoglHandle CoglTexturePixmapX11 *
cogl_texture_pixmap_x11_new (guint32 pixmap, cogl_texture_pixmap_x11_new (CoglContext *context,
gboolean automatic_updates); guint32 pixmap,
gboolean automatic_updates,
GError **error);
/** /**
* cogl_texture_pixmap_x11_update_area: * 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 * @x: x coordinate of the area to update
* @y: y coordinate of the area to update * @y: y coordinate of the area to update
* @width: width of the area to update * @width: width of the area to update
* @height: height 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 * Forces an update of the given @texture so that it is refreshed with
* refreshed with the contents of the pixmap that was given to * the contents of the pixmap that was given to
* cogl_texture_pixmap_x11_new(). * cogl_texture_pixmap_x11_new().
* *
* Since: 1.4 * Since: 1.4
* Stability: Unstable * Stability: Unstable
*/ */
void void
cogl_texture_pixmap_x11_update_area (CoglHandle handle, cogl_texture_pixmap_x11_update_area (CoglTexturePixmapX11 *texture,
int x, int x,
int y, int y,
int width, int width,
@ -106,12 +128,13 @@ cogl_texture_pixmap_x11_update_area (CoglHandle handle,
/** /**
* cogl_texture_pixmap_x11_is_using_tfp_extension: * 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 * Checks whether the given @texture is using the
* or similar extension to copy the contents of the pixmap to the texture. * GLX_EXT_texture_from_pixmap or similar extension to copy the
* This extension is usually implemented as zero-copy operation so it * contents of the pixmap to the texture. This extension is usually
* implies the updates are working efficiently. * implemented as zero-copy operation so it implies the updates are
* working efficiently.
* *
* Return value: %TRUE if the texture is using an efficient extension * Return value: %TRUE if the texture is using an efficient extension
* and %FALSE otherwise * and %FALSE otherwise
@ -120,18 +143,18 @@ cogl_texture_pixmap_x11_update_area (CoglHandle handle,
* Stability: Unstable * Stability: Unstable
*/ */
gboolean 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: * cogl_texture_pixmap_x11_set_damage_object:
* @handle: A CoglHandle * @texture: A #CoglTexturePixmapX11 instance
* @damage: A X11 Damage object or 0 * @damage: A X11 Damage object or 0
* @report_level: The report level which describes how to interpret * @report_level: The report level which describes how to interpret
* the damage events. This should match the level that the damage * the damage events. This should match the level that the damage
* object was created with. * object was created with.
* *
* Sets the damage object that will be used to track automatic updates * 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 * @damage. Otherwise this damage will replace the one used if %TRUE
* was passed for automatic_updates to cogl_texture_pixmap_x11_new(). * 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 * Stability: Unstable
*/ */
void void
cogl_texture_pixmap_x11_set_damage_object (CoglHandle handle, cogl_texture_pixmap_x11_set_damage_object (CoglTexturePixmapX11 *texture,
guint32 damage, guint32 damage,
CoglTexturePixmapX11ReportLevel CoglTexturePixmapX11ReportLevel
report_level); report_level);
/** /**
* cogl_is_texture_pixmap_x11: * 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 * %FALSE otherwise
* *
* Since: 1.4 * Since: 1.4
* Stability: Unstable * Stability: Unstable
*/ */
gboolean gboolean
cogl_is_texture_pixmap_x11 (CoglHandle handle); cogl_is_texture_pixmap_x11 (void *object);
#endif /* COGL_ENABLE_EXPERIMENTAL_API */ #endif /* COGL_ENABLE_EXPERIMENTAL_API */
G_END_DECLS
#endif /* __COGL_TEXTURE_PIXMAP_X11_H */ #endif /* __COGL_TEXTURE_PIXMAP_X11_H */

View File

@ -59,7 +59,7 @@ main (int argc, char **argv)
int screen; int screen;
Window tfp_xwin; Window tfp_xwin;
Pixmap pixmap; Pixmap pixmap;
CoglHandle tfp; CoglTexturePixmapX11 *tfp;
GC gc; GC gc;
g_print ("NB: Don't use this example as a benchmark since there is " 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); 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); fb = COGL_FRAMEBUFFER (onscreen);
cogl_push_framebuffer (fb); cogl_push_framebuffer (fb);
@ -215,7 +221,7 @@ main (int argc, char **argv)
XFlush (xdpy); XFlush (xdpy);
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1); 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_rectangle (-0.8, 0.8, 0.8, -0.8);
cogl_onscreen_swap_buffers (onscreen); cogl_onscreen_swap_buffers (onscreen);
} }