2008-02-20 12:43:54 +00:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Authored By Johan Bilien <johan.bilien@nokia.com>
|
2008-04-29 16:30:47 +00:00
|
|
|
* Matthew Allum <mallum@o-hand.com>
|
|
|
|
* Robert Bragg <bob@o-hand.com>
|
2008-02-20 12:43:54 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007 OpenedHand
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:clutter-glx-texture-pixmap
|
|
|
|
* @short_description: A texture which displays the content of an X Pixmap.
|
|
|
|
*
|
|
|
|
* #ClutterGLXTexturePixmap is a class for displaying the content of an
|
|
|
|
* X Pixmap as a ClutterActor. Used together with the X Composite extension,
|
|
|
|
* it allows to display the content of X Windows inside Clutter.
|
|
|
|
*
|
|
|
|
* The class requires the GLX_EXT_texture_from_pixmap OpenGL extension
|
|
|
|
* (http://people.freedesktop.org/~davidr/GLX_EXT_texture_from_pixmap.txt)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../x11/clutter-x11-texture-pixmap.h"
|
|
|
|
#include "clutter-glx-texture-pixmap.h"
|
|
|
|
#include "clutter-glx.h"
|
|
|
|
#include "clutter-backend-glx.h"
|
|
|
|
|
|
|
|
#include "../clutter-util.h"
|
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
#include "cogl/cogl.h"
|
2008-02-20 12:43:54 +00:00
|
|
|
|
2008-04-15 21:18:13 +00:00
|
|
|
typedef void (*BindTexImage) (Display *display,
|
|
|
|
GLXDrawable drawable,
|
|
|
|
int buffer,
|
|
|
|
int *attribList);
|
|
|
|
typedef void (*ReleaseTexImage) (Display *display,
|
|
|
|
GLXDrawable drawable,
|
|
|
|
int buffer);
|
|
|
|
|
|
|
|
static BindTexImage _gl_bind_tex_image = NULL;
|
|
|
|
static ReleaseTexImage _gl_release_tex_image = NULL;
|
|
|
|
static gboolean _have_tex_from_pixmap_ext = FALSE;
|
|
|
|
static gboolean _ext_check_done = FALSE;
|
2008-02-20 12:43:54 +00:00
|
|
|
|
|
|
|
struct _ClutterGLXTexturePixmapPrivate
|
|
|
|
{
|
|
|
|
COGLenum target_type;
|
|
|
|
guint texture_id;
|
|
|
|
GLXPixmap glx_pixmap;
|
|
|
|
gboolean bound;
|
2008-04-15 21:18:13 +00:00
|
|
|
|
2008-02-20 12:43:54 +00:00
|
|
|
};
|
|
|
|
|
2008-04-15 21:18:13 +00:00
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_update_area (ClutterX11TexturePixmap *texture,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_create_glx_pixmap (ClutterGLXTexturePixmap *tex);
|
2008-02-20 12:43:54 +00:00
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
static ClutterX11TexturePixmapClass *parent_class = NULL;
|
|
|
|
|
2008-04-15 21:18:13 +00:00
|
|
|
G_DEFINE_TYPE (ClutterGLXTexturePixmap, \
|
|
|
|
clutter_glx_texture_pixmap, \
|
|
|
|
CLUTTER_X11_TYPE_TEXTURE_PIXMAP);
|
2008-02-20 12:43:54 +00:00
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
static gboolean
|
|
|
|
texture_bind (ClutterGLXTexturePixmap *tex)
|
2008-02-20 12:43:54 +00:00
|
|
|
{
|
2008-04-29 16:30:47 +00:00
|
|
|
GLuint handle = 0;
|
|
|
|
GLenum target = 0;
|
|
|
|
CoglHandle cogl_tex;
|
|
|
|
cogl_tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE(tex));
|
2008-02-20 12:43:54 +00:00
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
if (!cogl_texture_get_gl_texture (cogl_tex, &handle, &target))
|
|
|
|
return FALSE;
|
2008-02-20 12:43:54 +00:00
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
glEnable(target);
|
2008-02-20 12:43:54 +00:00
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
/* FIXME: fire off an error here? */
|
|
|
|
glBindTexture (target, handle);
|
2008-04-15 21:18:13 +00:00
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
return TRUE;
|
2008-02-20 12:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_init (ClutterGLXTexturePixmap *self)
|
|
|
|
{
|
|
|
|
ClutterGLXTexturePixmapPrivate *priv;
|
|
|
|
|
|
|
|
priv = self->priv =
|
|
|
|
G_TYPE_INSTANCE_GET_PRIVATE (self,
|
|
|
|
CLUTTER_GLX_TYPE_TEXTURE_PIXMAP,
|
|
|
|
ClutterGLXTexturePixmapPrivate);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_dispose (GObject *object)
|
|
|
|
{
|
2008-04-15 21:18:13 +00:00
|
|
|
ClutterGLXTexturePixmapPrivate *priv;
|
|
|
|
|
|
|
|
priv = CLUTTER_GLX_TEXTURE_PIXMAP (object)->priv;
|
2008-02-20 12:43:54 +00:00
|
|
|
|
|
|
|
if (priv->glx_pixmap != None)
|
|
|
|
{
|
2008-04-01 13:36:19 +00:00
|
|
|
clutter_x11_trap_x_errors ();
|
2008-04-15 21:18:13 +00:00
|
|
|
|
|
|
|
glXDestroyGLXPixmap (clutter_x11_get_default_display(),
|
2008-02-20 12:43:54 +00:00
|
|
|
priv->glx_pixmap);
|
2008-04-15 21:18:13 +00:00
|
|
|
XSync (clutter_x11_get_default_display(), FALSE);
|
|
|
|
|
2008-04-01 13:36:19 +00:00
|
|
|
clutter_x11_untrap_x_errors ();
|
2008-04-15 21:18:13 +00:00
|
|
|
|
2008-02-20 12:43:54 +00:00
|
|
|
priv->glx_pixmap = None;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_glx_texture_pixmap_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_notify (GObject *object, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
if (g_str_equal (pspec->name, "pixmap"))
|
|
|
|
{
|
|
|
|
ClutterGLXTexturePixmap *texture = CLUTTER_GLX_TEXTURE_PIXMAP (object);
|
2008-04-29 16:30:47 +00:00
|
|
|
printf("notify\n");
|
|
|
|
|
2008-02-20 12:43:54 +00:00
|
|
|
clutter_glx_texture_pixmap_create_glx_pixmap (texture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
static void
|
|
|
|
create_cogl_texture (ClutterTexture *texture,
|
|
|
|
guint width,
|
|
|
|
guint height)
|
|
|
|
{
|
|
|
|
CoglHandle handle;
|
|
|
|
|
|
|
|
handle = cogl_texture_new_with_size (width, height,
|
|
|
|
64,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888|COGL_BGR_BIT);
|
|
|
|
|
|
|
|
printf("handle: %i, width: %i, height: %i\n",
|
|
|
|
(int)handle, width, height);
|
|
|
|
|
|
|
|
if (handle)
|
|
|
|
{
|
|
|
|
clutter_texture_set_cogl_texture (texture, handle);
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_SET_FLAGS (texture, CLUTTER_ACTOR_REALIZED);
|
|
|
|
|
|
|
|
printf("realised, updating\n");
|
|
|
|
|
|
|
|
clutter_glx_texture_pixmap_update_area
|
|
|
|
(CLUTTER_X11_TEXTURE_PIXMAP (texture),
|
|
|
|
0, 0,
|
|
|
|
width, height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_warning ("unable to realize");
|
|
|
|
}
|
|
|
|
|
2008-02-20 12:43:54 +00:00
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_realize (ClutterActor *actor)
|
|
|
|
{
|
2008-04-15 21:18:13 +00:00
|
|
|
ClutterGLXTexturePixmapPrivate *priv;
|
2008-04-29 16:30:47 +00:00
|
|
|
Pixmap pixmap;
|
|
|
|
guint pixmap_width, pixmap_height;
|
|
|
|
printf("realise\n");
|
2008-04-15 21:18:13 +00:00
|
|
|
|
|
|
|
priv = CLUTTER_GLX_TEXTURE_PIXMAP (actor)->priv;
|
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
if (!_have_tex_from_pixmap_ext
|
|
|
|
|| !clutter_feature_available (CLUTTER_FEATURE_TEXTURE_RECTANGLE))
|
2008-02-20 12:43:54 +00:00
|
|
|
{
|
2008-04-29 16:30:47 +00:00
|
|
|
/* Fall back */
|
|
|
|
/* FIXME: Also check for sliced npots ? */
|
|
|
|
|
|
|
|
g_warning("Falling back....");
|
2008-02-20 12:43:54 +00:00
|
|
|
CLUTTER_ACTOR_CLASS (clutter_glx_texture_pixmap_parent_class)->
|
2008-04-15 21:18:13 +00:00
|
|
|
realize (actor);
|
2008-02-20 12:43:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_get (actor,
|
2008-04-29 16:30:47 +00:00
|
|
|
"pixmap", &pixmap,
|
|
|
|
"pixmap-width", &pixmap_width,
|
|
|
|
"pixmap-height", &pixmap_height,
|
2008-02-20 12:43:54 +00:00
|
|
|
NULL);
|
2008-04-25 13:37:36 +00:00
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
if (!pixmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
create_cogl_texture (CLUTTER_TEXTURE (actor), pixmap_width, pixmap_height);
|
2008-02-20 12:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_unrealize (ClutterActor *actor)
|
|
|
|
{
|
2008-04-15 21:18:13 +00:00
|
|
|
ClutterGLXTexturePixmapPrivate *priv;
|
|
|
|
Display *dpy;
|
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
printf("unrealise\n");
|
|
|
|
|
2008-04-15 21:18:13 +00:00
|
|
|
priv = CLUTTER_GLX_TEXTURE_PIXMAP (actor)->priv;
|
|
|
|
dpy = clutter_x11_get_default_display();
|
2008-02-20 12:43:54 +00:00
|
|
|
|
2008-04-15 21:18:13 +00:00
|
|
|
if (!_have_tex_from_pixmap_ext)
|
2008-02-20 12:43:54 +00:00
|
|
|
{
|
|
|
|
CLUTTER_ACTOR_CLASS (clutter_glx_texture_pixmap_parent_class)->
|
|
|
|
unrealize (actor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CLUTTER_ACTOR_IS_REALIZED (actor))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->bound && priv->glx_pixmap)
|
|
|
|
{
|
2008-04-15 21:18:13 +00:00
|
|
|
clutter_x11_trap_x_errors ();
|
|
|
|
|
|
|
|
(_gl_release_tex_image) (dpy,
|
|
|
|
priv->glx_pixmap,
|
|
|
|
GLX_FRONT_LEFT_EXT);
|
|
|
|
|
|
|
|
XSync (clutter_x11_get_default_display(), FALSE);
|
|
|
|
clutter_x11_untrap_x_errors ();
|
2008-02-20 12:43:54 +00:00
|
|
|
}
|
2008-04-25 13:37:36 +00:00
|
|
|
|
2008-02-20 12:43:54 +00:00
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GLXFBConfig *
|
|
|
|
get_fbconfig_for_depth (guint depth)
|
|
|
|
{
|
|
|
|
GLXFBConfig *fbconfigs, *ret = NULL;
|
|
|
|
int n_elements, i, found;
|
2008-04-15 21:18:13 +00:00
|
|
|
Display *dpy;
|
2008-02-20 12:43:54 +00:00
|
|
|
int db, stencil, alpha, mipmap, rgba, value;
|
|
|
|
|
2008-04-15 21:18:13 +00:00
|
|
|
dpy = clutter_x11_get_default_display ();
|
|
|
|
|
2008-02-20 12:43:54 +00:00
|
|
|
fbconfigs = glXGetFBConfigs (dpy,
|
2008-04-15 21:18:13 +00:00
|
|
|
clutter_x11_get_default_screen (),
|
2008-02-20 12:43:54 +00:00
|
|
|
&n_elements);
|
|
|
|
|
|
|
|
db = G_MAXSHORT;
|
|
|
|
stencil = G_MAXSHORT;
|
|
|
|
mipmap = 0;
|
|
|
|
rgba = 0;
|
|
|
|
|
|
|
|
found = n_elements;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_elements; i++)
|
|
|
|
{
|
|
|
|
XVisualInfo *vi;
|
|
|
|
int visual_depth;
|
|
|
|
|
|
|
|
vi = glXGetVisualFromFBConfig (dpy,
|
|
|
|
fbconfigs[i]);
|
|
|
|
if (vi == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
visual_depth = vi->depth;
|
|
|
|
|
|
|
|
XFree (vi);
|
|
|
|
|
|
|
|
if (visual_depth != depth)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
glXGetFBConfigAttrib (dpy,
|
|
|
|
fbconfigs[i],
|
|
|
|
GLX_ALPHA_SIZE,
|
|
|
|
&alpha);
|
|
|
|
glXGetFBConfigAttrib (dpy,
|
|
|
|
fbconfigs[i],
|
|
|
|
GLX_BUFFER_SIZE,
|
|
|
|
&value);
|
|
|
|
if (value != depth && (value - alpha) != depth)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
value = 0;
|
|
|
|
if (depth == 32)
|
|
|
|
{
|
|
|
|
glXGetFBConfigAttrib (dpy,
|
|
|
|
fbconfigs[i],
|
|
|
|
GLX_BIND_TO_TEXTURE_RGBA_EXT,
|
|
|
|
&value);
|
|
|
|
if (value)
|
|
|
|
rgba = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
{
|
|
|
|
if (rgba)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
glXGetFBConfigAttrib (dpy,
|
|
|
|
fbconfigs[i],
|
|
|
|
GLX_BIND_TO_TEXTURE_RGB_EXT,
|
|
|
|
&value);
|
|
|
|
if (!value)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
glXGetFBConfigAttrib (dpy,
|
|
|
|
fbconfigs[i],
|
|
|
|
GLX_DOUBLEBUFFER,
|
|
|
|
&value);
|
|
|
|
if (value > db)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
db = value;
|
|
|
|
|
|
|
|
glXGetFBConfigAttrib (dpy,
|
|
|
|
fbconfigs[i],
|
|
|
|
GLX_STENCIL_SIZE,
|
|
|
|
&value);
|
|
|
|
if (value > stencil)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
stencil = value;
|
|
|
|
|
|
|
|
found = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found != n_elements)
|
|
|
|
{
|
|
|
|
ret = g_malloc (sizeof (GLXFBConfig));
|
|
|
|
*ret = fbconfigs[found];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_elements)
|
|
|
|
XFree (fbconfigs);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_free_glx_pixmap (ClutterGLXTexturePixmap *texture)
|
|
|
|
{
|
|
|
|
ClutterGLXTexturePixmapPrivate *priv = texture->priv;
|
|
|
|
Display *dpy;
|
|
|
|
|
|
|
|
dpy = clutter_x11_get_default_display ();
|
|
|
|
|
|
|
|
if (_have_tex_from_pixmap_ext &&
|
|
|
|
CLUTTER_ACTOR_IS_REALIZED (texture) &&
|
|
|
|
priv->bound)
|
|
|
|
{
|
|
|
|
texture_bind (texture);
|
|
|
|
|
|
|
|
clutter_x11_trap_x_errors ();
|
|
|
|
|
|
|
|
(_gl_release_tex_image) (dpy,
|
|
|
|
priv->glx_pixmap,
|
|
|
|
GLX_FRONT_LEFT_EXT);
|
|
|
|
|
|
|
|
XSync (clutter_x11_get_default_display(), FALSE);
|
|
|
|
|
|
|
|
if (clutter_x11_untrap_x_errors ())
|
|
|
|
g_warning ("Failed to unbind texture pixmap");
|
|
|
|
|
|
|
|
|
|
|
|
printf("Destroyed pxm: %li\n", priv->glx_pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_x11_trap_x_errors ();
|
|
|
|
glXDestroyGLXPixmap (dpy, priv->glx_pixmap);
|
|
|
|
XSync (dpy, FALSE);
|
|
|
|
clutter_x11_untrap_x_errors ();
|
|
|
|
}
|
|
|
|
|
2008-02-20 12:43:54 +00:00
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_create_glx_pixmap (ClutterGLXTexturePixmap *texture)
|
|
|
|
{
|
|
|
|
ClutterGLXTexturePixmapPrivate *priv = texture->priv;
|
|
|
|
GLXPixmap glx_pixmap;
|
|
|
|
int attribs[7], i = 0;
|
|
|
|
GLXFBConfig *fbconfig;
|
2008-04-15 21:18:13 +00:00
|
|
|
Display *dpy;
|
2008-02-20 12:43:54 +00:00
|
|
|
guint depth;
|
|
|
|
Pixmap pixmap;
|
2008-04-29 16:30:47 +00:00
|
|
|
guint pixmap_width, pixmap_height;
|
2008-04-15 21:18:13 +00:00
|
|
|
ClutterBackendGLX *backend_glx;
|
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
printf("create\n");
|
|
|
|
|
2008-04-15 21:18:13 +00:00
|
|
|
backend_glx = CLUTTER_BACKEND_GLX(clutter_get_default_backend ());
|
|
|
|
|
|
|
|
dpy = clutter_x11_get_default_display ();
|
2008-02-20 12:43:54 +00:00
|
|
|
|
|
|
|
g_object_get (texture,
|
2008-04-29 16:30:47 +00:00
|
|
|
"pixmap-width", &pixmap_width,
|
|
|
|
"pixmap-height", &pixmap_height,
|
2008-04-15 21:18:13 +00:00
|
|
|
"pixmap-depth", &depth,
|
2008-02-20 12:43:54 +00:00
|
|
|
"pixmap", &pixmap,
|
|
|
|
NULL);
|
2008-04-29 16:30:47 +00:00
|
|
|
if (!pixmap)
|
|
|
|
return;
|
2008-02-20 12:43:54 +00:00
|
|
|
|
|
|
|
fbconfig = get_fbconfig_for_depth (depth);
|
|
|
|
|
|
|
|
if (!fbconfig)
|
|
|
|
{
|
|
|
|
g_critical ("Could not find an FBConfig for selected pixmap");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
attribs[i++] = GLX_TEXTURE_FORMAT_EXT;
|
|
|
|
|
|
|
|
if (depth == 24)
|
|
|
|
{
|
|
|
|
attribs[i++] = GLX_TEXTURE_FORMAT_RGB_EXT;
|
2008-04-29 16:30:47 +00:00
|
|
|
printf("depth: %i\n", 24);
|
2008-02-20 12:43:54 +00:00
|
|
|
}
|
|
|
|
else if (depth == 32)
|
|
|
|
{
|
|
|
|
attribs[i++] = GLX_TEXTURE_FORMAT_RGBA_EXT;
|
2008-04-29 16:30:47 +00:00
|
|
|
printf("depth: %i\n", 32);
|
2008-02-20 12:43:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_critical ("Pixmap with depth bellow 24 are not supported");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
attribs[i++] = GLX_MIPMAP_TEXTURE_EXT;
|
|
|
|
attribs[i++] = 0;
|
|
|
|
|
|
|
|
attribs[i++] = GLX_TEXTURE_TARGET_EXT;
|
|
|
|
attribs[i++] = GLX_TEXTURE_RECTANGLE_EXT;
|
2008-04-25 13:37:36 +00:00
|
|
|
|
2008-02-20 12:43:54 +00:00
|
|
|
attribs[i++] = None;
|
|
|
|
|
|
|
|
clutter_x11_trap_x_errors ();
|
|
|
|
glx_pixmap = glXCreatePixmap (dpy,
|
|
|
|
*fbconfig,
|
|
|
|
pixmap,
|
|
|
|
attribs);
|
|
|
|
XSync (dpy, FALSE);
|
2008-04-29 16:30:47 +00:00
|
|
|
if (clutter_x11_untrap_x_errors ())
|
|
|
|
g_warning ("glx pixmap creation failed");
|
2008-02-20 12:43:54 +00:00
|
|
|
|
|
|
|
g_free (fbconfig);
|
|
|
|
|
|
|
|
if (glx_pixmap != None)
|
|
|
|
{
|
|
|
|
if (priv->glx_pixmap)
|
2008-04-29 16:30:47 +00:00
|
|
|
clutter_glx_texture_pixmap_free_glx_pixmap (texture);
|
|
|
|
|
|
|
|
priv->glx_pixmap = glx_pixmap;
|
2008-04-15 21:18:13 +00:00
|
|
|
|
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
if (!clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (texture)))
|
|
|
|
{
|
|
|
|
create_cogl_texture (texture,
|
|
|
|
pixmap_width,
|
|
|
|
pixmap_height);
|
2008-02-20 12:43:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
printf("Created pxm: %li\n", priv->glx_pixmap);
|
2008-02-20 12:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_update_area (ClutterX11TexturePixmap *texture,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
ClutterGLXTexturePixmapPrivate *priv;
|
2008-04-15 21:18:13 +00:00
|
|
|
Display *dpy;
|
2008-02-20 12:43:54 +00:00
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
printf("update area\n");
|
|
|
|
|
2008-02-20 12:43:54 +00:00
|
|
|
priv = CLUTTER_GLX_TEXTURE_PIXMAP (texture)->priv;
|
2008-04-15 21:18:13 +00:00
|
|
|
dpy = clutter_x11_get_default_display();
|
2008-02-20 12:43:54 +00:00
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
|
|
|
|
if (!CLUTTER_ACTOR_IS_REALIZED (texture))
|
|
|
|
return;
|
|
|
|
|
2008-04-15 21:18:13 +00:00
|
|
|
if (!_have_tex_from_pixmap_ext)
|
2008-02-20 12:43:54 +00:00
|
|
|
{
|
2008-04-29 16:30:47 +00:00
|
|
|
parent_class->update_area (texture,
|
2008-04-15 21:18:13 +00:00
|
|
|
x, y,
|
|
|
|
width, height);
|
2008-02-20 12:43:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-04-29 16:30:47 +00:00
|
|
|
}
|
2008-02-20 12:43:54 +00:00
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_paint (ClutterActor *self)
|
|
|
|
{
|
|
|
|
ClutterGLXTexturePixmapPrivate *priv;
|
2008-02-20 12:43:54 +00:00
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
priv = CLUTTER_GLX_TEXTURE_PIXMAP (self)->priv;
|
2008-02-20 12:43:54 +00:00
|
|
|
|
2008-04-15 21:18:13 +00:00
|
|
|
if (_have_tex_from_pixmap_ext)
|
2008-02-20 12:43:54 +00:00
|
|
|
{
|
2008-04-29 16:30:47 +00:00
|
|
|
Display *dpy;
|
|
|
|
|
|
|
|
dpy = clutter_x11_get_default_display();
|
|
|
|
|
|
|
|
if (texture_bind (CLUTTER_GLX_TEXTURE_PIXMAP(self)))
|
|
|
|
{
|
|
|
|
printf("no fallback pxm: %li\n", priv->glx_pixmap);
|
|
|
|
|
2008-04-15 21:18:13 +00:00
|
|
|
clutter_x11_trap_x_errors ();
|
|
|
|
|
|
|
|
(_gl_bind_tex_image) (dpy,
|
|
|
|
priv->glx_pixmap,
|
|
|
|
GLX_FRONT_LEFT_EXT,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
XSync (clutter_x11_get_default_display(), FALSE);
|
|
|
|
|
|
|
|
if (clutter_x11_untrap_x_errors ())
|
|
|
|
g_warning ("Failed to bind texture pixmap");
|
2008-02-20 12:43:54 +00:00
|
|
|
|
|
|
|
priv->bound = TRUE;
|
|
|
|
}
|
2008-04-29 16:30:47 +00:00
|
|
|
else
|
|
|
|
g_warning ("Failed to bind initial tex");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_CLASS (clutter_glx_texture_pixmap_parent_class)->paint(self);
|
2008-02-20 12:43:54 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 16:30:47 +00:00
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_class_init (ClutterGLXTexturePixmapClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
|
|
|
ClutterX11TexturePixmapClass *x11_texture_class =
|
|
|
|
CLUTTER_X11_TEXTURE_PIXMAP_CLASS (klass);
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (ClutterGLXTexturePixmapPrivate));
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent(klass);
|
|
|
|
|
|
|
|
object_class->dispose = clutter_glx_texture_pixmap_dispose;
|
|
|
|
object_class->notify = clutter_glx_texture_pixmap_notify;
|
|
|
|
|
|
|
|
actor_class->realize = clutter_glx_texture_pixmap_realize;
|
|
|
|
actor_class->unrealize = clutter_glx_texture_pixmap_unrealize;
|
|
|
|
actor_class->paint = clutter_glx_texture_pixmap_paint;
|
|
|
|
|
|
|
|
x11_texture_class->update_area = clutter_glx_texture_pixmap_update_area;
|
|
|
|
|
|
|
|
if (_ext_check_done == FALSE)
|
|
|
|
{
|
|
|
|
const gchar *glx_extensions = NULL;
|
|
|
|
|
|
|
|
glx_extensions =
|
|
|
|
glXQueryExtensionsString (clutter_x11_get_default_display (),
|
|
|
|
clutter_x11_get_default_screen ());
|
|
|
|
printf("GLX extension string:%s\n", glx_extensions);
|
|
|
|
|
|
|
|
/* Check for the texture from pixmap extension */
|
|
|
|
if (cogl_check_extension ("GLX_EXT_texture_from_pixmap", glx_extensions))
|
|
|
|
{
|
|
|
|
_gl_bind_tex_image =
|
|
|
|
(BindTexImage)cogl_get_proc_address ("glXBindTexImageEXT");
|
|
|
|
_gl_release_tex_image =
|
|
|
|
(ReleaseTexImage)cogl_get_proc_address ("glXReleaseTexImageEXT");
|
|
|
|
|
|
|
|
if (_gl_bind_tex_image && _gl_release_tex_image)
|
|
|
|
_have_tex_from_pixmap_ext = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_ext_check_done = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 12:43:54 +00:00
|
|
|
/**
|
|
|
|
* clutter_glx_texture_pixmap_new_with_pixmap:
|
|
|
|
* @pixmap: the X Pixmap to which this texture should be bound
|
|
|
|
* @width: the width of the X pixmap
|
|
|
|
* @height: the height of the X pixmap
|
|
|
|
* @depth: the depth of the X pixmap
|
|
|
|
*
|
|
|
|
* Return value: A new #ClutterGLXTexturePixmap bound to the given X Pixmap
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
**/
|
|
|
|
ClutterActor *
|
2008-04-15 21:18:13 +00:00
|
|
|
clutter_glx_texture_pixmap_new_with_pixmap (Pixmap pixmap)
|
2008-02-20 12:43:54 +00:00
|
|
|
{
|
|
|
|
ClutterActor *actor;
|
|
|
|
|
|
|
|
actor = g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP,
|
|
|
|
"pixmap", pixmap,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_glx_texture_pixmap_new:
|
|
|
|
*
|
|
|
|
* Return value: A new #ClutterGLXTexturePixmap
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
**/
|
|
|
|
ClutterActor *
|
|
|
|
clutter_glx_texture_pixmap_new (void)
|
|
|
|
{
|
|
|
|
ClutterActor *actor;
|
|
|
|
|
|
|
|
actor = g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP, NULL);
|
|
|
|
|
|
|
|
return actor;
|
|
|
|
}
|