2008-02-20 07:43:54 -05:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Authored By Johan Bilien <johan.bilien@nokia.com>
|
2008-04-29 12:30:47 -04:00
|
|
|
* Matthew Allum <mallum@o-hand.com>
|
|
|
|
* Robert Bragg <bob@o-hand.com>
|
2008-02-20 07:43:54 -05: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
|
2010-03-01 07:56:10 -05:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2008-02-20 07:43:54 -05:00
|
|
|
*/
|
|
|
|
|
2009-05-12 09:15:18 -04:00
|
|
|
/* TODO:
|
2008-04-30 19:07:23 -04:00
|
|
|
* - Automagically handle named pixmaps, and window resizes (i.e
|
2008-05-06 15:57:05 -04:00
|
|
|
* essentially handle window id's being passed in) ?
|
2008-04-30 19:07:23 -04:00
|
|
|
*/
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
/**
|
|
|
|
* 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)
|
2008-12-04 12:24:33 -05:00
|
|
|
*
|
|
|
|
* The GL_ARB_texture_non_power_of_two extension will be used if it is
|
|
|
|
* available. Otherwise it will try to use the
|
|
|
|
* GL_ARB_texture_rectangle extension. If both are available you can
|
|
|
|
* force it to prefer the rectangle extension by setting the
|
|
|
|
* CLUTTER_PIXMAP_TEXTURE_RECTANGLE to 'force'. To prevent it ever
|
|
|
|
* using the rectangle extension you can set it to 'disable'.
|
2008-02-20 07:43:54 -05:00
|
|
|
*/
|
|
|
|
|
2008-04-30 19:07:23 -04:00
|
|
|
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2008-12-04 12:24:33 -05:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
#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-30 19:07:23 -04:00
|
|
|
#include "../clutter-debug.h"
|
2009-11-30 12:47:55 -05:00
|
|
|
#include "../clutter-private.h"
|
2008-02-20 07:43:54 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
#include "cogl/cogl.h"
|
2008-02-20 07:43:54 -05:00
|
|
|
|
2008-04-15 17:18:13 -04:00
|
|
|
typedef void (*BindTexImage) (Display *display,
|
|
|
|
GLXDrawable drawable,
|
|
|
|
int buffer,
|
|
|
|
int *attribList);
|
|
|
|
typedef void (*ReleaseTexImage) (Display *display,
|
|
|
|
GLXDrawable drawable,
|
|
|
|
int buffer);
|
|
|
|
|
2008-10-31 12:59:51 -04:00
|
|
|
typedef void (*GenerateMipmap) (GLenum target);
|
|
|
|
|
2008-12-04 12:24:33 -05:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
CLUTTER_GLX_RECTANGLE_DISALLOW,
|
|
|
|
CLUTTER_GLX_RECTANGLE_ALLOW,
|
|
|
|
CLUTTER_GLX_RECTANGLE_FORCE
|
|
|
|
} RectangleState;
|
2008-10-31 12:59:51 -04:00
|
|
|
|
2009-11-30 12:47:55 -05:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_AUTO_REDRAW,
|
|
|
|
};
|
|
|
|
|
2008-04-15 17:18:13 -04:00
|
|
|
static BindTexImage _gl_bind_tex_image = NULL;
|
|
|
|
static ReleaseTexImage _gl_release_tex_image = NULL;
|
2008-10-31 12:59:51 -04:00
|
|
|
static GenerateMipmap _gl_generate_mipmap = NULL;
|
2008-04-15 17:18:13 -04:00
|
|
|
static gboolean _have_tex_from_pixmap_ext = FALSE;
|
|
|
|
static gboolean _ext_check_done = FALSE;
|
2008-12-04 12:24:33 -05:00
|
|
|
static gboolean _have_tex_rectangle = FALSE;
|
|
|
|
static RectangleState _rectangle_state = CLUTTER_GLX_RECTANGLE_ALLOW;
|
2008-02-20 07:43:54 -05:00
|
|
|
|
|
|
|
struct _ClutterGLXTexturePixmapPrivate
|
|
|
|
{
|
|
|
|
GLXPixmap glx_pixmap;
|
2008-04-15 17:18:13 -04:00
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
gboolean use_fallback;
|
|
|
|
|
|
|
|
gboolean bound;
|
2008-10-31 12:59:51 -04:00
|
|
|
gint can_mipmap;
|
2008-11-07 11:31:56 -05:00
|
|
|
gint mipmap_generate_queued;
|
2008-12-04 12:24:33 -05:00
|
|
|
|
|
|
|
gboolean using_rectangle;
|
2008-02-20 07:43:54 -05:00
|
|
|
};
|
|
|
|
|
2009-05-12 09:15:18 -04:00
|
|
|
static void
|
2008-04-15 17:18:13 -04:00
|
|
|
clutter_glx_texture_pixmap_update_area (ClutterX11TexturePixmap *texture,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
|
|
|
|
2009-05-12 09:15:18 -04:00
|
|
|
static void
|
2008-04-15 17:18:13 -04:00
|
|
|
clutter_glx_texture_pixmap_create_glx_pixmap (ClutterGLXTexturePixmap *tex);
|
2008-02-20 07:43:54 -05:00
|
|
|
|
2008-04-29 12:30:47 -04:00
|
|
|
static ClutterX11TexturePixmapClass *parent_class = NULL;
|
|
|
|
|
2008-04-15 17:18:13 -04:00
|
|
|
G_DEFINE_TYPE (ClutterGLXTexturePixmap, \
|
|
|
|
clutter_glx_texture_pixmap, \
|
|
|
|
CLUTTER_X11_TYPE_TEXTURE_PIXMAP);
|
2008-02-20 07:43:54 -05:00
|
|
|
|
2008-04-29 12:30:47 -04:00
|
|
|
static gboolean
|
|
|
|
texture_bind (ClutterGLXTexturePixmap *tex)
|
2008-02-20 07:43:54 -05:00
|
|
|
{
|
2009-03-19 13:48:15 -04:00
|
|
|
GLuint handle = 0;
|
|
|
|
GLenum target = 0;
|
2008-04-29 12:30:47 -04:00
|
|
|
CoglHandle cogl_tex;
|
2009-02-27 13:39:53 -05:00
|
|
|
cogl_tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE(tex));
|
2008-04-15 17:18:13 -04:00
|
|
|
|
2009-03-19 13:48:15 -04:00
|
|
|
if (!cogl_texture_get_gl_texture (cogl_tex, &handle, &target))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* FIXME: fire off an error here? */
|
|
|
|
glBindTexture (target, handle);
|
|
|
|
|
2008-04-29 12:30:47 -04:00
|
|
|
return TRUE;
|
2008-02-20 07:43:54 -05:00
|
|
|
}
|
|
|
|
|
2008-11-07 11:31:56 -05:00
|
|
|
static void
|
|
|
|
on_glx_texture_pixmap_pre_paint (ClutterGLXTexturePixmap *texture,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
if (texture->priv->mipmap_generate_queued)
|
|
|
|
{
|
|
|
|
GLuint handle = 0;
|
|
|
|
GLenum target = 0;
|
|
|
|
CoglHandle cogl_tex;
|
2009-05-12 09:15:18 -04:00
|
|
|
cogl_tex = clutter_texture_get_cogl_texture
|
2008-11-07 11:31:56 -05:00
|
|
|
(CLUTTER_TEXTURE(texture));
|
|
|
|
|
|
|
|
texture_bind (texture);
|
|
|
|
|
|
|
|
cogl_texture_get_gl_texture (cogl_tex, &handle, &target);
|
2009-05-12 09:15:18 -04:00
|
|
|
|
2008-11-07 11:31:56 -05:00
|
|
|
_gl_generate_mipmap (target);
|
|
|
|
|
|
|
|
texture->priv->mipmap_generate_queued = 0;
|
|
|
|
}
|
|
|
|
|
2009-06-04 11:04:57 -04:00
|
|
|
/* Disable mipmaps if we can't support them */
|
|
|
|
if (clutter_texture_get_filter_quality (CLUTTER_TEXTURE (texture))
|
|
|
|
== CLUTTER_TEXTURE_QUALITY_HIGH
|
|
|
|
&& !texture->priv->can_mipmap)
|
|
|
|
{
|
|
|
|
CoglHandle material
|
|
|
|
= clutter_texture_get_cogl_material (CLUTTER_TEXTURE (texture));
|
|
|
|
|
|
|
|
cogl_material_set_layer_filters (material, 0,
|
|
|
|
COGL_MATERIAL_FILTER_LINEAR,
|
|
|
|
COGL_MATERIAL_FILTER_LINEAR);
|
|
|
|
}
|
2008-11-07 11:31:56 -05:00
|
|
|
}
|
|
|
|
|
2008-02-20 07:43:54 -05: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);
|
|
|
|
|
2008-11-07 11:31:56 -05:00
|
|
|
g_signal_connect (CLUTTER_ACTOR(self),
|
|
|
|
"paint", G_CALLBACK (on_glx_texture_pixmap_pre_paint),
|
|
|
|
NULL);
|
|
|
|
|
2008-06-26 05:47:58 -04:00
|
|
|
if (_ext_check_done == FALSE)
|
|
|
|
{
|
2008-12-04 12:24:33 -05:00
|
|
|
const char *gl_extensions = NULL;
|
2008-06-26 05:47:58 -04:00
|
|
|
const gchar *glx_extensions = NULL;
|
2008-12-04 12:24:33 -05:00
|
|
|
const char *rect_env;
|
2008-06-26 05:47:58 -04:00
|
|
|
|
|
|
|
glx_extensions =
|
|
|
|
glXQueryExtensionsString (clutter_x11_get_default_display (),
|
|
|
|
clutter_x11_get_default_screen ());
|
|
|
|
|
|
|
|
/* Check for the texture from pixmap extension */
|
2010-02-05 11:32:19 -05:00
|
|
|
if (_cogl_check_extension ("GLX_EXT_texture_from_pixmap",
|
|
|
|
glx_extensions))
|
2008-06-26 05:47:58 -04:00
|
|
|
{
|
|
|
|
_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;
|
|
|
|
}
|
|
|
|
|
2008-10-31 12:59:51 -04:00
|
|
|
_gl_generate_mipmap =
|
|
|
|
(GenerateMipmap)cogl_get_proc_address ("glGenerateMipmapEXT");
|
|
|
|
|
2008-12-04 12:24:33 -05:00
|
|
|
gl_extensions = (char *) glGetString (GL_EXTENSIONS);
|
2010-02-05 11:32:19 -05:00
|
|
|
_have_tex_rectangle = _cogl_check_extension ("GL_ARB_texture_rectangle",
|
2008-12-04 12:24:33 -05:00
|
|
|
gl_extensions);
|
|
|
|
|
|
|
|
if ((rect_env = g_getenv ("CLUTTER_PIXMAP_TEXTURE_RECTANGLE")))
|
|
|
|
{
|
2009-05-25 07:42:17 -04:00
|
|
|
if (g_ascii_strcasecmp (rect_env, "force") == 0)
|
2008-12-04 12:24:33 -05:00
|
|
|
_rectangle_state = CLUTTER_GLX_RECTANGLE_FORCE;
|
2009-05-25 07:42:17 -04:00
|
|
|
else if (g_ascii_strcasecmp (rect_env, "disable") == 0)
|
2008-12-04 12:24:33 -05:00
|
|
|
_rectangle_state = CLUTTER_GLX_RECTANGLE_DISALLOW;
|
|
|
|
else if (rect_env[0])
|
|
|
|
g_warning ("Unknown value for CLUTTER_PIXMAP_TEXTURE_RECTANGLE, "
|
|
|
|
"should be 'force' or 'disable'");
|
|
|
|
}
|
|
|
|
|
2008-06-26 05:47:58 -04:00
|
|
|
_ext_check_done = TRUE;
|
|
|
|
}
|
2008-02-20 07:43:54 -05:00
|
|
|
}
|
|
|
|
|
2008-12-04 12:24:33 -05:00
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_free_rectangle (ClutterGLXTexturePixmap *texture)
|
|
|
|
{
|
|
|
|
ClutterGLXTexturePixmapPrivate *priv = texture->priv;
|
|
|
|
CoglHandle cogl_tex;
|
|
|
|
|
|
|
|
/* Cogl won't free the GL texture resource if it was created with
|
|
|
|
new_from_foreign so we need to free it manually */
|
|
|
|
if (priv->using_rectangle)
|
|
|
|
{
|
|
|
|
cogl_tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (texture));
|
|
|
|
|
|
|
|
if (cogl_tex != COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
GLuint gl_handle;
|
|
|
|
GLenum gl_target;
|
|
|
|
|
|
|
|
cogl_texture_get_gl_texture (cogl_tex, &gl_handle, &gl_target);
|
|
|
|
|
2010-01-12 09:43:36 -05:00
|
|
|
if (gl_target == GL_TEXTURE_RECTANGLE_ARB)
|
2008-12-04 12:24:33 -05:00
|
|
|
glDeleteTextures (1, &gl_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->using_rectangle = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_dispose (GObject *object)
|
|
|
|
{
|
2008-12-04 12:24:33 -05:00
|
|
|
ClutterGLXTexturePixmap *texture = CLUTTER_GLX_TEXTURE_PIXMAP (object);
|
|
|
|
ClutterGLXTexturePixmapPrivate *priv = texture->priv;
|
2008-04-15 17:18:13 -04:00
|
|
|
|
2008-12-04 12:24:33 -05:00
|
|
|
clutter_glx_texture_pixmap_free_rectangle (texture);
|
2008-02-20 07:43:54 -05:00
|
|
|
|
|
|
|
if (priv->glx_pixmap != None)
|
|
|
|
{
|
2008-04-01 09:36:19 -04:00
|
|
|
clutter_x11_trap_x_errors ();
|
2008-04-15 17:18:13 -04:00
|
|
|
|
2009-06-08 03:38:50 -04:00
|
|
|
glXDestroyPixmap (clutter_x11_get_default_display(),
|
2008-02-20 07:43:54 -05:00
|
|
|
priv->glx_pixmap);
|
2008-04-15 17:18:13 -04:00
|
|
|
XSync (clutter_x11_get_default_display(), FALSE);
|
|
|
|
|
2008-04-01 09:36:19 -04:00
|
|
|
clutter_x11_untrap_x_errors ();
|
2008-04-15 17:18:13 -04:00
|
|
|
|
2008-02-20 07:43:54 -05: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);
|
2009-06-06 12:07:42 -04:00
|
|
|
if (CLUTTER_ACTOR_IS_REALIZED (texture))
|
|
|
|
clutter_glx_texture_pixmap_create_glx_pixmap (texture);
|
2008-02-20 07:43:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-04 12:24:33 -05:00
|
|
|
static gboolean
|
|
|
|
should_use_rectangle (void)
|
|
|
|
{
|
|
|
|
/* Use the rectangle only if it is available and either:
|
|
|
|
|
|
|
|
the CLUTTER_PIXMAP_TEXTURE_RECTANGLE environment variable is
|
|
|
|
set to 'force'
|
|
|
|
|
|
|
|
*or*
|
|
|
|
|
|
|
|
the env var is set to 'allow' (which is the default) and NPOTs
|
|
|
|
textures are not available */
|
|
|
|
return _have_tex_rectangle
|
|
|
|
&& ((_rectangle_state == CLUTTER_GLX_RECTANGLE_ALLOW
|
|
|
|
&& !clutter_feature_available (CLUTTER_FEATURE_TEXTURE_NPOT))
|
|
|
|
|| _rectangle_state == CLUTTER_GLX_RECTANGLE_FORCE);
|
|
|
|
}
|
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
static gboolean
|
2008-04-29 12:30:47 -04:00
|
|
|
create_cogl_texture (ClutterTexture *texture,
|
|
|
|
guint width,
|
|
|
|
guint height)
|
|
|
|
{
|
2008-12-04 12:24:33 -05:00
|
|
|
ClutterGLXTexturePixmap *texture_glx = CLUTTER_GLX_TEXTURE_PIXMAP (texture);
|
|
|
|
ClutterGLXTexturePixmapPrivate *priv = texture_glx->priv;
|
2009-01-12 08:02:19 -05:00
|
|
|
CoglHandle handle;
|
|
|
|
gboolean using_rectangle;
|
|
|
|
GLint gl_format;
|
2009-01-14 10:04:28 -05:00
|
|
|
CoglPixelFormat cogl_format = COGL_PIXEL_FORMAT_RGBA_8888;
|
2009-01-12 08:02:19 -05:00
|
|
|
guint depth;
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (texture_glx), "pixmap-depth", &depth, NULL);
|
|
|
|
if (depth == 32)
|
|
|
|
{
|
|
|
|
gl_format = GL_RGBA;
|
|
|
|
cogl_format = COGL_PIXEL_FORMAT_RGBA_8888;
|
|
|
|
}
|
|
|
|
else if (depth == 24)
|
|
|
|
{
|
|
|
|
gl_format = GL_RGB;
|
|
|
|
cogl_format = COGL_PIXEL_FORMAT_RGB_888;
|
|
|
|
}
|
|
|
|
else
|
2009-05-06 23:35:01 -04:00
|
|
|
{
|
|
|
|
g_critical ("Can't create a TFP cogl texture for pixmap with depth < 24");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-12-04 12:24:33 -05:00
|
|
|
|
|
|
|
/* We want to use the GL_ARB_texture_rectangle extension on some
|
|
|
|
chipsets because GL_ARB_texture_non_power_of_two is not always
|
|
|
|
supported or might be buggy */
|
|
|
|
if (should_use_rectangle ())
|
|
|
|
{
|
|
|
|
GLuint tex = 0;
|
|
|
|
|
|
|
|
using_rectangle = TRUE;
|
|
|
|
|
|
|
|
glGenTextures (1, &tex);
|
2010-01-12 09:43:36 -05:00
|
|
|
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, tex);
|
|
|
|
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0,
|
2009-05-06 23:35:01 -04:00
|
|
|
gl_format, width, height,
|
2009-01-12 08:02:19 -05:00
|
|
|
0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
2008-12-04 12:24:33 -05:00
|
|
|
|
2010-01-12 09:43:36 -05:00
|
|
|
handle = cogl_texture_new_from_foreign (tex, GL_TEXTURE_RECTANGLE_ARB,
|
2008-12-04 12:24:33 -05:00
|
|
|
width, height,
|
|
|
|
0, 0,
|
2009-05-09 14:39:01 -04:00
|
|
|
cogl_format | COGL_BGR_BIT |
|
|
|
|
COGL_PREMULT_BIT);
|
2008-12-04 12:24:33 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
handle
|
|
|
|
= cogl_texture_new_with_size (width, height,
|
[cogl] Remove max_waste argument from Texture ctors
The CoglTexture constructors expose the "max-waste" argument for
controlling the maximum amount of wasted areas for slicing or,
if set to -1, disables slicing.
Slicing is really relevant only for large images that are never
repeated, so it's a useful feature only in controlled use cases.
Specifying the amount of wasted area is, on the other hand, just
a way to mess up this feature; 99% the times, you either pull this
number out of thin air, hoping it's right, or you try to do the
right thing and you choose the wrong number anyway.
Instead, we can use the CoglTextureFlags to control whether the
texture should not be sliced (useful for Clutter-GST and for the
texture-from-pixmap actors) and provide a reasonable value for
enabling the slicing ourself. At some point, we might even
provide a way to change the default at compile time or at run time,
for particular platforms.
Since max_waste is gone, the :tile-waste property of ClutterTexture
becomes read-only, and it proxies the cogl_texture_get_max_waste()
function.
Inside Clutter, the only cases where the max_waste argument was
not set to -1 are in the Pango glyph cache (which is a POT texture
anyway) and inside the test cases where we want to force slicing;
for the latter we can create larger textures that will be bigger than
the threshold we set.
Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
Signed-off-by: Robert Bragg <robert@linux.intel.com>
Signed-off-by: Neil Roberts <neil@linux.intel.com>
2009-05-23 14:18:18 -04:00
|
|
|
COGL_TEXTURE_NO_SLICING,
|
2009-05-09 14:39:01 -04:00
|
|
|
cogl_format | COGL_BGR_BIT |
|
|
|
|
COGL_PREMULT_BIT);
|
2008-04-29 12:30:47 -04:00
|
|
|
|
2008-12-04 12:24:33 -05:00
|
|
|
using_rectangle = FALSE;
|
|
|
|
}
|
2008-04-29 12:30:47 -04:00
|
|
|
|
|
|
|
if (handle)
|
|
|
|
{
|
2008-12-04 12:24:33 -05:00
|
|
|
clutter_glx_texture_pixmap_free_rectangle (texture_glx);
|
|
|
|
priv->using_rectangle = using_rectangle;
|
|
|
|
|
2008-04-29 12:30:47 -04:00
|
|
|
clutter_texture_set_cogl_texture (texture, handle);
|
2010-02-10 17:47:49 -05:00
|
|
|
cogl_handle_unref(handle);
|
2008-10-31 12:59:51 -04:00
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
return TRUE;
|
2008-04-29 12:30:47 -04:00
|
|
|
}
|
2008-05-06 15:57:05 -04:00
|
|
|
|
|
|
|
return FALSE;
|
2008-04-29 12:30:47 -04:00
|
|
|
}
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_realize (ClutterActor *actor)
|
|
|
|
{
|
2009-06-06 12:07:42 -04:00
|
|
|
ClutterGLXTexturePixmap *texture;
|
2008-04-15 17:18:13 -04:00
|
|
|
ClutterGLXTexturePixmapPrivate *priv;
|
2008-02-20 07:43:54 -05:00
|
|
|
|
2009-06-06 12:07:42 -04:00
|
|
|
texture = CLUTTER_GLX_TEXTURE_PIXMAP (actor);
|
|
|
|
priv = texture->priv;
|
2009-05-12 09:15:18 -04:00
|
|
|
|
2009-06-06 12:07:42 -04:00
|
|
|
clutter_glx_texture_pixmap_create_glx_pixmap (texture);
|
2008-04-29 12:30:47 -04:00
|
|
|
|
2009-06-06 12:07:42 -04:00
|
|
|
if (priv->use_fallback)
|
2008-05-06 15:57:05 -04:00
|
|
|
{
|
|
|
|
CLUTTER_ACTOR_CLASS (clutter_glx_texture_pixmap_parent_class)->
|
|
|
|
realize (actor);
|
|
|
|
return;
|
|
|
|
}
|
2008-04-30 19:07:23 -04:00
|
|
|
|
|
|
|
CLUTTER_NOTE (TEXTURE, "texture pixmap realised");
|
2008-02-20 07:43:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_unrealize (ClutterActor *actor)
|
|
|
|
{
|
2008-12-04 12:24:33 -05:00
|
|
|
ClutterGLXTexturePixmap *texture = CLUTTER_GLX_TEXTURE_PIXMAP (actor);
|
|
|
|
ClutterGLXTexturePixmapPrivate *priv = texture->priv;
|
2008-04-15 17:18:13 -04:00
|
|
|
Display *dpy;
|
|
|
|
|
|
|
|
dpy = clutter_x11_get_default_display();
|
2008-02-20 07:43:54 -05:00
|
|
|
|
2008-12-04 12:24:33 -05:00
|
|
|
clutter_glx_texture_pixmap_free_rectangle (texture);
|
|
|
|
|
2008-04-15 17:18:13 -04:00
|
|
|
if (!_have_tex_from_pixmap_ext)
|
2008-02-20 07:43:54 -05:00
|
|
|
{
|
|
|
|
CLUTTER_ACTOR_CLASS (clutter_glx_texture_pixmap_parent_class)->
|
|
|
|
unrealize (actor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CLUTTER_ACTOR_IS_REALIZED (actor))
|
|
|
|
return;
|
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
if (priv->glx_pixmap && priv->bound)
|
2008-02-20 07:43:54 -05:00
|
|
|
{
|
2008-04-15 17:18:13 -04: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-05-06 15:57:05 -04:00
|
|
|
|
|
|
|
priv->bound = FALSE;
|
2008-02-20 07:43:54 -05:00
|
|
|
}
|
2009-05-12 09:15:18 -04:00
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GLXFBConfig *
|
2008-10-31 12:59:51 -04:00
|
|
|
get_fbconfig_for_depth (ClutterGLXTexturePixmap *texture, guint depth)
|
2008-02-20 07:43:54 -05:00
|
|
|
{
|
|
|
|
GLXFBConfig *fbconfigs, *ret = NULL;
|
|
|
|
int n_elements, i, found;
|
2008-04-15 17:18:13 -04:00
|
|
|
Display *dpy;
|
2008-02-20 07:43:54 -05:00
|
|
|
int db, stencil, alpha, mipmap, rgba, value;
|
|
|
|
|
2008-10-31 12:59:51 -04:00
|
|
|
static GLXFBConfig *cached_config = NULL;
|
|
|
|
static gboolean have_cached_config = FALSE;
|
|
|
|
static int cached_mipmap = 0;
|
|
|
|
|
|
|
|
if (have_cached_config)
|
|
|
|
{
|
|
|
|
texture->priv->can_mipmap = cached_mipmap;
|
|
|
|
return cached_config;
|
|
|
|
}
|
|
|
|
|
2008-04-15 17:18:13 -04:00
|
|
|
dpy = clutter_x11_get_default_display ();
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
fbconfigs = glXGetFBConfigs (dpy,
|
2008-04-15 17:18:13 -04:00
|
|
|
clutter_x11_get_default_screen (),
|
2008-02-20 07:43:54 -05: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;
|
|
|
|
|
2008-10-31 12:59:51 -04:00
|
|
|
if (_gl_generate_mipmap)
|
|
|
|
{
|
|
|
|
glXGetFBConfigAttrib (dpy,
|
|
|
|
fbconfigs[i],
|
|
|
|
GLX_BIND_TO_MIPMAP_TEXTURE_EXT,
|
|
|
|
&value);
|
|
|
|
|
|
|
|
if (value < mipmap)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mipmap = value;
|
|
|
|
}
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
found = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found != n_elements)
|
|
|
|
{
|
|
|
|
ret = g_malloc (sizeof (GLXFBConfig));
|
|
|
|
*ret = fbconfigs[found];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_elements)
|
|
|
|
XFree (fbconfigs);
|
|
|
|
|
2008-10-31 12:59:51 -04:00
|
|
|
have_cached_config = TRUE;
|
|
|
|
cached_config = ret;
|
|
|
|
texture->priv->can_mipmap = cached_mipmap = mipmap;
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:30:47 -04:00
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_free_glx_pixmap (ClutterGLXTexturePixmap *texture)
|
|
|
|
{
|
|
|
|
ClutterGLXTexturePixmapPrivate *priv = texture->priv;
|
|
|
|
Display *dpy;
|
|
|
|
|
|
|
|
dpy = clutter_x11_get_default_display ();
|
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
if (priv->glx_pixmap &&
|
2008-04-29 12:30:47 -04:00
|
|
|
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 ())
|
2008-04-30 19:07:23 -04:00
|
|
|
CLUTTER_NOTE (TEXTURE, "Failed to release?");
|
2008-04-29 12:30:47 -04:00
|
|
|
|
2008-04-30 19:07:23 -04:00
|
|
|
CLUTTER_NOTE (TEXTURE, "Destroyed pxm: %li", priv->glx_pixmap);
|
2008-05-06 15:57:05 -04:00
|
|
|
|
|
|
|
priv->bound = FALSE;
|
2008-04-29 12:30:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
clutter_x11_trap_x_errors ();
|
2008-05-06 15:57:05 -04:00
|
|
|
if (priv->glx_pixmap)
|
2009-06-08 03:38:50 -04:00
|
|
|
glXDestroyPixmap (dpy, priv->glx_pixmap);
|
2008-04-29 12:30:47 -04:00
|
|
|
XSync (dpy, FALSE);
|
|
|
|
clutter_x11_untrap_x_errors ();
|
2008-05-06 15:57:05 -04:00
|
|
|
priv->glx_pixmap = None;
|
2008-04-29 12:30:47 -04:00
|
|
|
}
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_create_glx_pixmap (ClutterGLXTexturePixmap *texture)
|
|
|
|
{
|
|
|
|
ClutterGLXTexturePixmapPrivate *priv = texture->priv;
|
2008-05-06 15:57:05 -04:00
|
|
|
GLXPixmap glx_pixmap = None;
|
2008-06-10 06:49:21 -04:00
|
|
|
int attribs[7], i = 0, mipmap = 0;
|
2008-02-20 07:43:54 -05:00
|
|
|
GLXFBConfig *fbconfig;
|
2008-04-15 17:18:13 -04:00
|
|
|
Display *dpy;
|
2008-02-20 07:43:54 -05:00
|
|
|
guint depth;
|
2009-06-06 12:07:42 -04:00
|
|
|
Pixmap pixmap = None;
|
|
|
|
guint pixmap_width = 0, pixmap_height = 0;
|
2008-06-03 12:25:17 -04:00
|
|
|
ClutterBackendGLX *backend_glx;
|
2008-06-10 06:49:21 -04:00
|
|
|
ClutterTextureQuality quality;
|
2008-04-15 17:18:13 -04:00
|
|
|
|
|
|
|
backend_glx = CLUTTER_BACKEND_GLX(clutter_get_default_backend ());
|
|
|
|
|
|
|
|
dpy = clutter_x11_get_default_display ();
|
2008-02-20 07:43:54 -05:00
|
|
|
|
2009-06-06 12:07:42 -04:00
|
|
|
if (!_have_tex_from_pixmap_ext)
|
2008-07-08 07:58:08 -04:00
|
|
|
goto cleanup;
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
g_object_get (texture,
|
2008-05-06 15:57:05 -04:00
|
|
|
"pixmap-width", &pixmap_width,
|
2008-04-29 12:30:47 -04:00
|
|
|
"pixmap-height", &pixmap_height,
|
2008-05-06 15:57:05 -04:00
|
|
|
"pixmap-depth", &depth,
|
|
|
|
"pixmap", &pixmap,
|
2008-02-20 07:43:54 -05:00
|
|
|
NULL);
|
2008-06-03 12:25:17 -04:00
|
|
|
|
2008-04-29 12:30:47 -04:00
|
|
|
if (!pixmap)
|
2008-05-06 15:57:05 -04:00
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-02-20 07:43:54 -05:00
|
|
|
|
2009-06-06 12:07:42 -04:00
|
|
|
CLUTTER_NOTE (TEXTURE, "Creating GLXPixmap");
|
|
|
|
|
2008-10-31 12:59:51 -04:00
|
|
|
fbconfig = get_fbconfig_for_depth (texture, depth);
|
2008-02-20 07:43:54 -05:00
|
|
|
|
|
|
|
if (!fbconfig)
|
|
|
|
{
|
2008-04-30 19:07:23 -04:00
|
|
|
g_warning ("Could not find an FBConfig for selected pixmap");
|
2008-05-06 15:57:05 -04:00
|
|
|
goto cleanup;
|
2008-02-20 07:43:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
attribs[i++] = GLX_TEXTURE_FORMAT_EXT;
|
|
|
|
|
|
|
|
if (depth == 24)
|
|
|
|
{
|
|
|
|
attribs[i++] = GLX_TEXTURE_FORMAT_RGB_EXT;
|
|
|
|
}
|
|
|
|
else if (depth == 32)
|
|
|
|
{
|
|
|
|
attribs[i++] = GLX_TEXTURE_FORMAT_RGBA_EXT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-06 12:07:42 -04:00
|
|
|
g_warning ("Pixmap with depth below 24 are not supported");
|
2008-05-06 15:57:05 -04:00
|
|
|
goto cleanup;
|
2008-02-20 07:43:54 -05:00
|
|
|
}
|
|
|
|
|
2008-06-30 12:06:36 -04:00
|
|
|
quality = clutter_texture_get_filter_quality (CLUTTER_TEXTURE (texture));
|
2008-06-10 06:49:21 -04:00
|
|
|
|
2008-10-31 12:59:51 -04:00
|
|
|
if (quality == CLUTTER_TEXTURE_QUALITY_HIGH && priv->can_mipmap)
|
|
|
|
mipmap = priv->can_mipmap;
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
attribs[i++] = GLX_MIPMAP_TEXTURE_EXT;
|
2008-06-10 06:49:21 -04:00
|
|
|
attribs[i++] = mipmap;
|
2008-02-20 07:43:54 -05:00
|
|
|
|
|
|
|
attribs[i++] = GLX_TEXTURE_TARGET_EXT;
|
2008-05-06 15:57:05 -04:00
|
|
|
|
2008-12-04 12:24:33 -05:00
|
|
|
attribs[i++] = (should_use_rectangle ()
|
|
|
|
? GLX_TEXTURE_RECTANGLE_EXT : GLX_TEXTURE_2D_EXT);
|
2008-05-06 15:57:05 -04:00
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
attribs[i++] = None;
|
|
|
|
|
2008-12-18 12:54:35 -05:00
|
|
|
/* Note: some drivers (e.g. Nvidia) get upset if you effectivly create a glx
|
|
|
|
* pixmap for the same server side object, even though you might have unique
|
|
|
|
* client side names, we currently avoid hitting this problem by destroying
|
|
|
|
* the current glx pixmap first */
|
|
|
|
if (priv->glx_pixmap)
|
|
|
|
clutter_glx_texture_pixmap_free_glx_pixmap (texture);
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
clutter_x11_trap_x_errors ();
|
|
|
|
glx_pixmap = glXCreatePixmap (dpy,
|
|
|
|
*fbconfig,
|
|
|
|
pixmap,
|
|
|
|
attribs);
|
|
|
|
XSync (dpy, FALSE);
|
2008-04-29 12:30:47 -04:00
|
|
|
if (clutter_x11_untrap_x_errors ())
|
2008-06-30 12:06:36 -04:00
|
|
|
{
|
|
|
|
CLUTTER_NOTE (TEXTURE, "Failed to create GLXPixmap");
|
|
|
|
|
|
|
|
/* Make sure we don't think the call actually succeeded */
|
|
|
|
glx_pixmap = None;
|
|
|
|
}
|
2008-02-20 07:43:54 -05:00
|
|
|
|
2009-06-06 12:07:42 -04:00
|
|
|
if (!create_cogl_texture (CLUTTER_TEXTURE (texture),
|
|
|
|
pixmap_width, pixmap_height))
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (TEXTURE, "Unable to create texture for pixmap");
|
|
|
|
|
2009-06-08 06:56:59 -04:00
|
|
|
glXDestroyPixmap (dpy, glx_pixmap);
|
2009-06-06 12:07:42 -04:00
|
|
|
glx_pixmap = None;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
cleanup:
|
|
|
|
|
|
|
|
if (priv->glx_pixmap)
|
|
|
|
clutter_glx_texture_pixmap_free_glx_pixmap (texture);
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
if (glx_pixmap != None)
|
|
|
|
{
|
2009-06-06 12:07:42 -04:00
|
|
|
priv->use_fallback = FALSE;
|
2008-04-29 12:30:47 -04:00
|
|
|
priv->glx_pixmap = glx_pixmap;
|
2009-05-12 09:15:18 -04:00
|
|
|
|
2008-04-30 19:07:23 -04:00
|
|
|
CLUTTER_NOTE (TEXTURE, "Created GLXPixmap");
|
|
|
|
|
2009-06-06 12:07:42 -04:00
|
|
|
clutter_glx_texture_pixmap_update_area (CLUTTER_X11_TEXTURE_PIXMAP (texture),
|
|
|
|
0, 0,
|
|
|
|
pixmap_width, pixmap_height);
|
|
|
|
|
2008-11-07 11:31:56 -05:00
|
|
|
/* Get ready to queue initial mipmap generation */
|
|
|
|
if (_gl_generate_mipmap
|
|
|
|
&& priv->can_mipmap
|
|
|
|
&& clutter_texture_get_filter_quality (CLUTTER_TEXTURE (texture))
|
|
|
|
== CLUTTER_TEXTURE_QUALITY_HIGH)
|
|
|
|
{
|
|
|
|
priv->mipmap_generate_queued++;
|
|
|
|
}
|
|
|
|
|
2008-04-30 19:07:23 -04:00
|
|
|
return;
|
|
|
|
}
|
2008-05-06 15:57:05 -04:00
|
|
|
else
|
|
|
|
{
|
2009-06-06 12:07:42 -04:00
|
|
|
if (pixmap)
|
|
|
|
CLUTTER_NOTE (TEXTURE, "Falling back to X11 manual mechansim");
|
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
priv->use_fallback = TRUE;
|
2008-07-08 07:58:08 -04:00
|
|
|
priv->glx_pixmap = None;
|
2008-05-06 15:57:05 -04:00
|
|
|
}
|
2008-02-20 07:43:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_glx_texture_pixmap_update_area (ClutterX11TexturePixmap *texture,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
2008-12-04 12:24:33 -05:00
|
|
|
ClutterGLXTexturePixmap *texture_glx = CLUTTER_GLX_TEXTURE_PIXMAP (texture);
|
2009-11-30 12:47:55 -05:00
|
|
|
ClutterGLXTexturePixmapPrivate *priv = texture_glx->priv;
|
|
|
|
Display *dpy;
|
2008-02-20 07:43:54 -05:00
|
|
|
|
2008-06-30 12:06:36 -04:00
|
|
|
CLUTTER_NOTE (TEXTURE, "Updating texture pixmap");
|
2008-04-29 12:30:47 -04:00
|
|
|
|
2008-04-15 17:18:13 -04:00
|
|
|
dpy = clutter_x11_get_default_display();
|
2008-02-20 07:43:54 -05:00
|
|
|
|
2008-04-29 12:30:47 -04:00
|
|
|
if (!CLUTTER_ACTOR_IS_REALIZED (texture))
|
|
|
|
return;
|
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
if (priv->use_fallback)
|
2008-02-20 07:43:54 -05:00
|
|
|
{
|
2008-06-30 12:06:36 -04:00
|
|
|
CLUTTER_NOTE (TEXTURE, "Falling back to X11");
|
2008-12-04 12:24:33 -05:00
|
|
|
|
|
|
|
clutter_glx_texture_pixmap_free_rectangle (texture_glx);
|
|
|
|
|
2008-04-29 12:30:47 -04:00
|
|
|
parent_class->update_area (texture,
|
2008-05-06 15:57:05 -04:00
|
|
|
x, y,
|
|
|
|
width, height);
|
2008-02-20 07:43:54 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
if (priv->glx_pixmap == None)
|
|
|
|
return;
|
2009-05-12 09:15:18 -04:00
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
if (texture_bind (CLUTTER_GLX_TEXTURE_PIXMAP(texture)))
|
2008-02-20 07:43:54 -05:00
|
|
|
{
|
2008-06-03 12:25:17 -04:00
|
|
|
CLUTTER_NOTE (TEXTURE, "Really updating via GLX");
|
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
clutter_x11_trap_x_errors ();
|
2009-05-12 09:15:18 -04:00
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
(_gl_bind_tex_image) (dpy,
|
|
|
|
priv->glx_pixmap,
|
|
|
|
GLX_FRONT_LEFT_EXT,
|
|
|
|
NULL);
|
2009-05-12 09:15:18 -04:00
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
XSync (clutter_x11_get_default_display(), FALSE);
|
2009-05-12 09:15:18 -04:00
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
/* Note above fires X error for non name pixmaps - but
|
2009-05-12 09:15:18 -04:00
|
|
|
* things still seem to work - i.e pixmap updated
|
2008-05-06 15:57:05 -04:00
|
|
|
*/
|
|
|
|
if (clutter_x11_untrap_x_errors ())
|
|
|
|
CLUTTER_NOTE (TEXTURE, "Update bind_tex_image failed");
|
2008-04-29 12:30:47 -04:00
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
priv->bound = TRUE;
|
2008-10-31 12:59:51 -04:00
|
|
|
|
|
|
|
if (_gl_generate_mipmap
|
|
|
|
&& priv->can_mipmap
|
|
|
|
&& clutter_texture_get_filter_quality (CLUTTER_TEXTURE (texture))
|
|
|
|
== CLUTTER_TEXTURE_QUALITY_HIGH)
|
|
|
|
{
|
|
|
|
/* FIXME: It may make more sense to set a flag here and only
|
|
|
|
* generate the mipmap on a pre paint.. compressing need
|
2009-05-12 09:15:18 -04:00
|
|
|
* to call generate mipmap
|
2008-10-31 12:59:51 -04:00
|
|
|
* May break clones however..
|
|
|
|
*/
|
2008-11-07 11:31:56 -05:00
|
|
|
priv->mipmap_generate_queued++;
|
2008-10-31 12:59:51 -04:00
|
|
|
}
|
|
|
|
|
2008-04-30 19:07:23 -04:00
|
|
|
}
|
2008-05-06 15:57:05 -04:00
|
|
|
else
|
|
|
|
g_warning ("Failed to bind initial tex");
|
|
|
|
|
2009-11-30 12:47:55 -05:00
|
|
|
priv->bind_tex_image_queued = TRUE;
|
2008-02-20 07:43:54 -05:00
|
|
|
}
|
|
|
|
|
2008-04-29 12:30:47 -04: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;
|
|
|
|
|
|
|
|
x11_texture_class->update_area = clutter_glx_texture_pixmap_update_area;
|
|
|
|
}
|
|
|
|
|
2008-05-06 15:57:05 -04:00
|
|
|
/**
|
|
|
|
* clutter_glx_texture_pixmap_using_extension:
|
|
|
|
* @texture: A #ClutterGLXTexturePixmap
|
|
|
|
*
|
2010-03-02 04:53:55 -05:00
|
|
|
* Checks whether @texture is using the GLX_EXT_texture_from_pixmap
|
|
|
|
* extension; this extension can be optionally (though it is strongly
|
|
|
|
* encouraged) implemented as a zero-copy between a GLX pixmap and
|
|
|
|
* a GL texture.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the texture is using the
|
|
|
|
* GLX_EXT_texture_from_pixmap OpenGL extension or falling back to the
|
|
|
|
* slower software mechanism.
|
2008-05-06 15:57:05 -04:00
|
|
|
*
|
|
|
|
* Since: 0.8
|
2010-03-02 04:53:55 -05:00
|
|
|
*/
|
2008-05-06 15:57:05 -04:00
|
|
|
gboolean
|
|
|
|
clutter_glx_texture_pixmap_using_extension (ClutterGLXTexturePixmap *texture)
|
|
|
|
{
|
|
|
|
ClutterGLXTexturePixmapPrivate *priv;
|
|
|
|
|
|
|
|
priv = CLUTTER_GLX_TEXTURE_PIXMAP (texture)->priv;
|
|
|
|
|
2009-05-12 09:15:18 -04:00
|
|
|
return (_have_tex_from_pixmap_ext && !priv->use_fallback);
|
|
|
|
/* Assume NPOT TFP's are supported even if regular NPOT isn't advertised
|
2008-07-09 20:12:23 -04:00
|
|
|
* but tfp is. Seemingly some Intel drivers do this ?
|
|
|
|
*/
|
|
|
|
/* && clutter_feature_available (COGL_FEATURE_TEXTURE_NPOT)); */
|
2008-05-06 15:57:05 -04:00
|
|
|
}
|
2008-04-29 12:30:47 -04:00
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
/**
|
|
|
|
* clutter_glx_texture_pixmap_new_with_pixmap:
|
|
|
|
* @pixmap: the X Pixmap to which this texture should be bound
|
|
|
|
*
|
2010-03-02 04:53:55 -05:00
|
|
|
* Creates a new #ClutterGLXTexturePixmap for @pixmap
|
|
|
|
*
|
2008-02-20 07:43:54 -05:00
|
|
|
* Return value: A new #ClutterGLXTexturePixmap bound to the given X Pixmap
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
2010-03-02 04:53:55 -05:00
|
|
|
*/
|
|
|
|
ClutterActor *
|
2008-04-15 17:18:13 -04:00
|
|
|
clutter_glx_texture_pixmap_new_with_pixmap (Pixmap pixmap)
|
2008-02-20 07:43:54 -05:00
|
|
|
{
|
2010-03-02 04:53:55 -05:00
|
|
|
return g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP,
|
|
|
|
"pixmap", pixmap,
|
|
|
|
NULL);
|
2008-02-20 07:43:54 -05:00
|
|
|
}
|
|
|
|
|
2008-06-30 10:36:49 -04:00
|
|
|
/**
|
|
|
|
* clutter_glx_texture_pixmap_new_with_window:
|
|
|
|
* @window: the X window to which this texture should be bound
|
|
|
|
*
|
2010-03-02 04:53:55 -05:00
|
|
|
* Creates a new #ClutterGLXTexturePixmap for @window
|
|
|
|
*
|
2008-06-30 10:36:49 -04:00
|
|
|
* Return value: A new #ClutterGLXTexturePixmap bound to the given X window
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
**/
|
2010-03-02 04:53:55 -05:00
|
|
|
ClutterActor *
|
2008-06-30 10:36:49 -04:00
|
|
|
clutter_glx_texture_pixmap_new_with_window (Window window)
|
|
|
|
{
|
2010-03-02 04:53:55 -05:00
|
|
|
return g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP,
|
|
|
|
"window", window,
|
|
|
|
NULL);
|
2008-06-30 10:36:49 -04:00
|
|
|
}
|
|
|
|
|
2008-02-20 07:43:54 -05:00
|
|
|
/**
|
|
|
|
* clutter_glx_texture_pixmap_new:
|
|
|
|
*
|
2010-03-02 04:53:55 -05:00
|
|
|
* Creates a new, empty #ClutterGLXTexturePixmap
|
|
|
|
*
|
2008-02-20 07:43:54 -05:00
|
|
|
* Return value: A new #ClutterGLXTexturePixmap
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
2010-03-02 04:53:55 -05:00
|
|
|
*/
|
2008-02-20 07:43:54 -05:00
|
|
|
ClutterActor *
|
|
|
|
clutter_glx_texture_pixmap_new (void)
|
|
|
|
{
|
2010-03-02 04:53:55 -05:00
|
|
|
return g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP, NULL);
|
2008-02-20 07:43:54 -05:00
|
|
|
}
|