From ee60128334f8acb17dc8cdf408b6c6aedff7648f Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 30 Sep 2008 15:33:18 +0100 Subject: [PATCH] Support for GL ES in the Clutter compositor. Check for whether clutter/glx/clutter-glx-texture-pixmap.h is available in the configure script and if not use ClutterX11TexturePixmap directly. glGetTexLevelParameter isn't available on GL ES so instead it checks whether NPOTs textures are available and assumes the next power of two size if not. --- configure.in | 13 ++++++ src/compositor/compositor-clutter.c | 13 ++++-- src/compositor/shaped-texture.c | 67 ++++++++++++++++++++++------- src/compositor/shaped-texture.h | 11 +++++ 4 files changed, 84 insertions(+), 20 deletions(-) diff --git a/configure.in b/configure.in index 262bfa0ef..1a4157d85 100644 --- a/configure.in +++ b/configure.in @@ -304,6 +304,19 @@ if test x$have_clutter = xyes; then METACITY_PC_MODULES="$METACITY_PC_MODULES $CLUTTER_PACKAGE " PKG_CHECK_MODULES(CLUTTER, $CLUTTER_PACKAGE) AC_DEFINE(WITH_CLUTTER, , [Building with Clutter compositor]) + + dnl Check for the clutter-glx-texture-pixmap header + metacity_save_cppflags="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $CLUTTER_CFLAGS" + AC_CHECK_HEADER([clutter/glx/clutter-glx-texture-pixmap.h], + [have_glx_texture_pixmap=yes], + [have_glx_texture_pixmap=no]) + CPPFLAGS="$metacity_save_cppflags" + + if test x$have_glx_texture_pixmap = xyes; then + AC_DEFINE(HAVE_GLX_TEXTURE_PIXMAP, , + [Is ClutterGLXTexturePixmap available?]) + fi fi AC_MSG_CHECKING([Xcursor]) diff --git a/src/compositor/compositor-clutter.c b/src/compositor/compositor-clutter.c index b67c918b7..bdee11bf4 100644 --- a/src/compositor/compositor-clutter.c +++ b/src/compositor/compositor-clutter.c @@ -31,7 +31,9 @@ #include #include #include +#ifdef HAVE_GLX_TEXTURE_PIXMAP #include +#endif /* HAVE_GLX_TEXTURE_PIXMAP */ #include #define SHADOW_RADIUS 8 @@ -1266,10 +1268,13 @@ repair_win (MetaCompWindow *cw) * If we are using TFP we update the whole texture (this simply trigers * the texture rebind). */ - if (full || - (CLUTTER_GLX_IS_TEXTURE_PIXMAP (priv->actor) && - clutter_glx_texture_pixmap_using_extension ( - CLUTTER_GLX_TEXTURE_PIXMAP (priv->actor)))) + if (full +#ifdef HAVE_GLX_TEXTURE_PIXMAP + || (CLUTTER_GLX_IS_TEXTURE_PIXMAP (priv->actor) && + clutter_glx_texture_pixmap_using_extension + (CLUTTER_GLX_TEXTURE_PIXMAP (priv->actor))) +#endif /* HAVE_GLX_TEXTURE_PIXMAP */ + ) { XDamageSubtract (xdisplay, priv->damage, None, None); diff --git a/src/compositor/shaped-texture.c b/src/compositor/shaped-texture.c index a245b655d..38ceb697a 100644 --- a/src/compositor/shaped-texture.c +++ b/src/compositor/shaped-texture.c @@ -23,8 +23,13 @@ * 02111-1307, USA. */ +#include + #include +#include +#ifdef HAVE_GLX_TEXTURE_PIXMAP #include +#endif /* HAVE_GLX_TEXTURE_PIXMAP */ #include #include @@ -39,8 +44,13 @@ static void meta_shaped_texture_pick (ClutterActor *actor, static void meta_shaped_texture_dirty_mask (MetaShapedTexture *stex); +#ifdef HAVE_GLX_TEXTURE_PIXMAP G_DEFINE_TYPE (MetaShapedTexture, meta_shaped_texture, CLUTTER_GLX_TYPE_TEXTURE_PIXMAP); +#else /* HAVE_GLX_TEXTURE_PIXMAP */ +G_DEFINE_TYPE (MetaShapedTexture, meta_shaped_texture, + CLUTTER_X11_TYPE_TEXTURE_PIXMAP); +#endif /* HAVE_GLX_TEXTURE_PIXMAP */ #define META_SHAPED_TEXTURE_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), META_TYPE_SHAPED_TEXTURE, \ @@ -67,7 +77,7 @@ struct _MetaShapedTexturePrivate CoglHandle mask_texture; guint mask_width, mask_height; - GLint mask_gl_width, mask_gl_height; + guint mask_gl_width, mask_gl_height; GLfloat mask_tex_coords[8]; GArray *rectangles; @@ -183,6 +193,39 @@ meta_shaped_texture_set_coord_array (GLfloat x1, GLfloat y1, coords[7] = y1; } +static void +meta_shaped_texture_get_gl_size (CoglHandle tex, + guint *width, + guint *height) +{ + /* glGetTexLevelParameteriv isn't supported on GL ES so we need to + calculate the size that Cogl has used */ + + /* If NPOTs textures are supported then assume the GL texture is + exactly the right size */ + if ((cogl_get_features () & COGL_FEATURE_TEXTURE_NPOT)) + { + *width = cogl_texture_get_width (tex); + *height = cogl_texture_get_height (tex); + } + /* Otherwise assume that Cogl has used the next power of two */ + else + { + guint tex_width = cogl_texture_get_width (tex); + guint tex_height = cogl_texture_get_height (tex); + guint real_width = 1; + guint real_height = 1; + + while (real_width < tex_width) + real_width <<= 1; + while (real_height < tex_height) + real_height <<= 1; + + *width = real_width; + *height = real_height; + } +} + static void meta_shaped_texture_ensure_mask (MetaShapedTexture *stex) { @@ -250,14 +293,9 @@ meta_shaped_texture_ensure_mask (MetaShapedTexture *stex) cogl_texture_get_gl_texture (priv->mask_texture, &mask_gl_tex, NULL); - glBindTexture (GL_TEXTURE_2D, mask_gl_tex); - - glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, - GL_TEXTURE_WIDTH, - &priv->mask_gl_width); - glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, - GL_TEXTURE_HEIGHT, - &priv->mask_gl_height); + meta_shaped_texture_get_gl_size (priv->mask_texture, + &priv->mask_gl_width, + &priv->mask_gl_height); if ((guint) priv->mask_gl_width == tex_width && (guint) priv->mask_gl_height == tex_height) @@ -284,7 +322,7 @@ meta_shaped_texture_paint (ClutterActor *actor) GLboolean vertex_array_was_enabled, tex_coord_array_was_enabled; GLboolean color_array_was_enabled; GLuint paint_gl_tex, mask_gl_tex; - GLint paint_gl_width, paint_gl_height; + guint paint_gl_width, paint_gl_height; GLfloat vertex_coords[8], paint_tex_coords[8]; ClutterActorBox alloc; static const ClutterColor white = { 0xff, 0xff, 0xff, 0xff }; @@ -338,12 +376,9 @@ meta_shaped_texture_paint (ClutterActor *actor) /* We need the actual size of the texture so that we can calculate the right texture coordinates if NPOTs textures are not supported and Cogl has oversized the texture */ - glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, - GL_TEXTURE_WIDTH, - &paint_gl_width); - glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, - GL_TEXTURE_HEIGHT, - &paint_gl_height); + meta_shaped_texture_get_gl_size (paint_tex, + &paint_gl_width, + &paint_gl_height); /* Put the mask texture in the second texture unit */ tst_active_texture (GL_TEXTURE1); diff --git a/src/compositor/shaped-texture.h b/src/compositor/shaped-texture.h index f837bf6c9..188eedda6 100644 --- a/src/compositor/shaped-texture.h +++ b/src/compositor/shaped-texture.h @@ -27,7 +27,10 @@ #define __META_SHAPED_TEXTURE_H__ #include +#include +#ifdef HAVE_GLX_TEXTURE_PIXMAP #include +#endif /* HAVE_GLX_TEXTURE_PIXMAP */ G_BEGIN_DECLS @@ -58,12 +61,20 @@ typedef struct _MetaShapedTexturePrivate MetaShapedTexturePrivate; struct _MetaShapedTextureClass { +#ifdef HAVE_GLX_TEXTURE_PIXMAP ClutterGLXTexturePixmapClass parent_class; +#else + ClutterX11TexturePixmapClass parent_class; +#endif }; struct _MetaShapedTexture { +#ifdef HAVE_GLX_TEXTURE_PIXMAP ClutterGLXTexturePixmap parent; +#else + ClutterX11TexturePixmap parent; +#endif MetaShapedTexturePrivate *priv; };