2008-09-24 16:36:38 -04:00
|
|
|
/*
|
|
|
|
* shaped texture
|
|
|
|
*
|
|
|
|
* An actor to draw a texture clipped to a list of rectangles
|
|
|
|
*
|
|
|
|
* Authored By Neil Roberts <neil@linux.intel.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Intel Corporation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2008-09-30 10:33:18 -04:00
|
|
|
#include <config.h>
|
|
|
|
|
2009-01-28 10:43:36 -05:00
|
|
|
#include "mutter-shaped-texture.h"
|
|
|
|
|
|
|
|
#include <clutter/clutter.h>
|
2008-09-24 16:36:38 -04:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
static void mutter_shaped_texture_dispose (GObject *object);
|
|
|
|
static void mutter_shaped_texture_finalize (GObject *object);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
static void mutter_shaped_texture_paint (ClutterActor *actor);
|
|
|
|
static void mutter_shaped_texture_pick (ClutterActor *actor,
|
|
|
|
const ClutterColor *color);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
static void mutter_shaped_texture_dirty_mask (MutterShapedTexture *stex);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-09-30 10:33:18 -04:00
|
|
|
#ifdef HAVE_GLX_TEXTURE_PIXMAP
|
2008-10-16 07:50:01 -04:00
|
|
|
G_DEFINE_TYPE (MutterShapedTexture, mutter_shaped_texture,
|
2008-09-24 16:48:02 -04:00
|
|
|
CLUTTER_GLX_TYPE_TEXTURE_PIXMAP);
|
2008-09-30 10:33:18 -04:00
|
|
|
#else /* HAVE_GLX_TEXTURE_PIXMAP */
|
2008-10-16 07:50:01 -04:00
|
|
|
G_DEFINE_TYPE (MutterShapedTexture, mutter_shaped_texture,
|
2008-09-30 10:33:18 -04:00
|
|
|
CLUTTER_X11_TYPE_TEXTURE_PIXMAP);
|
|
|
|
#endif /* HAVE_GLX_TEXTURE_PIXMAP */
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
#define MUTTER_SHAPED_TEXTURE_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), MUTTER_TYPE_SHAPED_TEXTURE, \
|
|
|
|
MutterShapedTexturePrivate))
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
struct _MutterShapedTexturePrivate
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
|
|
|
CoglHandle mask_texture;
|
2009-01-30 06:56:58 -05:00
|
|
|
CoglHandle material;
|
2009-06-29 14:30:26 -04:00
|
|
|
CoglHandle material_unshaped;
|
2009-01-30 06:56:58 -05:00
|
|
|
#if 1 /* see workaround comment in mutter_shaped_texture_paint */
|
|
|
|
CoglHandle material_workaround;
|
|
|
|
#endif
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
GdkRegion *clip_region;
|
|
|
|
|
2008-09-24 16:36:38 -04:00
|
|
|
guint mask_width, mask_height;
|
|
|
|
|
|
|
|
GArray *rectangles;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_class_init (MutterShapedTextureClass *klass)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
ClutterActorClass *actor_class = (ClutterActorClass *) klass;
|
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
gobject_class->dispose = mutter_shaped_texture_dispose;
|
|
|
|
gobject_class->finalize = mutter_shaped_texture_finalize;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
actor_class->paint = mutter_shaped_texture_paint;
|
|
|
|
actor_class->pick = mutter_shaped_texture_pick;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
g_type_class_add_private (klass, sizeof (MutterShapedTexturePrivate));
|
2008-09-24 16:36:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_init (MutterShapedTexture *self)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2008-10-16 07:50:01 -04:00
|
|
|
MutterShapedTexturePrivate *priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
priv = self->priv = MUTTER_SHAPED_TEXTURE_GET_PRIVATE (self);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-09-24 17:52:56 -04:00
|
|
|
priv->rectangles = g_array_new (FALSE, FALSE, sizeof (XRectangle));
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
priv->mask_texture = COGL_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_dispose (GObject *object)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2008-10-16 07:50:01 -04:00
|
|
|
MutterShapedTexture *self = (MutterShapedTexture *) object;
|
2009-01-30 06:56:58 -05:00
|
|
|
MutterShapedTexturePrivate *priv = self->priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_dirty_mask (self);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2009-01-30 06:56:58 -05:00
|
|
|
if (priv->material != COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
cogl_material_unref (priv->material);
|
|
|
|
priv->material = COGL_INVALID_HANDLE;
|
|
|
|
}
|
2009-06-29 14:30:26 -04:00
|
|
|
if (priv->material_unshaped != COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
cogl_material_unref (priv->material_unshaped);
|
|
|
|
priv->material_unshaped = COGL_INVALID_HANDLE;
|
|
|
|
}
|
2009-01-30 06:56:58 -05:00
|
|
|
#if 1 /* see comment in mutter_shaped_texture_paint */
|
|
|
|
if (priv->material_workaround != COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
cogl_material_unref (priv->material_workaround);
|
|
|
|
priv->material_workaround = COGL_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
mutter_shaped_texture_set_clip_region (self, NULL);
|
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
G_OBJECT_CLASS (mutter_shaped_texture_parent_class)->dispose (object);
|
2008-09-24 16:36:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_finalize (GObject *object)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2008-10-16 07:50:01 -04:00
|
|
|
MutterShapedTexture *self = (MutterShapedTexture *) object;
|
|
|
|
MutterShapedTexturePrivate *priv = self->priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
g_array_free (priv->rectangles, TRUE);
|
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
G_OBJECT_CLASS (mutter_shaped_texture_parent_class)->finalize (object);
|
2008-09-24 16:36:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_dirty_mask (MutterShapedTexture *stex)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2008-10-16 07:50:01 -04:00
|
|
|
MutterShapedTexturePrivate *priv = stex->priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
if (priv->mask_texture != COGL_INVALID_HANDLE)
|
|
|
|
{
|
2008-11-17 11:15:00 -05:00
|
|
|
GLuint mask_gl_tex;
|
|
|
|
GLenum mask_gl_target;
|
|
|
|
|
|
|
|
cogl_texture_get_gl_texture (priv->mask_texture,
|
|
|
|
&mask_gl_tex, &mask_gl_target);
|
|
|
|
|
|
|
|
if (mask_gl_target == CGL_TEXTURE_RECTANGLE_ARB)
|
|
|
|
glDeleteTextures (1, &mask_gl_tex);
|
|
|
|
|
2008-09-24 16:36:38 -04:00
|
|
|
cogl_texture_unref (priv->mask_texture);
|
|
|
|
priv->mask_texture = COGL_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_ensure_mask (MutterShapedTexture *stex)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2008-10-16 07:50:01 -04:00
|
|
|
MutterShapedTexturePrivate *priv = stex->priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
CoglHandle paint_tex;
|
|
|
|
guint tex_width, tex_height;
|
|
|
|
|
|
|
|
paint_tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (stex));
|
|
|
|
|
|
|
|
if (paint_tex == COGL_INVALID_HANDLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tex_width = cogl_texture_get_width (paint_tex);
|
|
|
|
tex_height = cogl_texture_get_height (paint_tex);
|
|
|
|
|
|
|
|
/* If the mask texture we have was created for a different size then
|
|
|
|
recreate it */
|
|
|
|
if (priv->mask_texture != COGL_INVALID_HANDLE
|
|
|
|
&& (priv->mask_width != tex_width || priv->mask_height != tex_height))
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_dirty_mask (stex);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
/* If we don't have a mask texture yet then create one */
|
|
|
|
if (priv->mask_texture == COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
guchar *mask_data;
|
2008-09-24 17:52:56 -04:00
|
|
|
const XRectangle *rect;
|
2008-11-17 11:15:00 -05:00
|
|
|
GLenum paint_gl_target;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
/* Create data for an empty image */
|
|
|
|
mask_data = g_malloc0 (tex_width * tex_height);
|
2008-09-25 04:29:57 -04:00
|
|
|
|
2008-09-24 16:36:38 -04:00
|
|
|
/* Cut out a hole for each rectangle */
|
2008-09-24 17:52:56 -04:00
|
|
|
for (rect = (XRectangle *) priv->rectangles->data
|
2008-09-24 16:36:38 -04:00
|
|
|
+ priv->rectangles->len;
|
2008-09-24 17:52:56 -04:00
|
|
|
rect-- > (XRectangle *) priv->rectangles->data;)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
|
|
|
gint x1 = rect->x, x2 = x1 + rect->width;
|
|
|
|
gint y1 = rect->y, y2 = y1 + rect->height;
|
|
|
|
guchar *p;
|
|
|
|
|
|
|
|
/* Clip the rectangle to the size of the texture */
|
|
|
|
x1 = CLAMP (x1, 0, (gint) tex_width - 1);
|
|
|
|
x2 = CLAMP (x2, x1, (gint) tex_width);
|
|
|
|
y1 = CLAMP (y1, 0, (gint) tex_height - 1);
|
|
|
|
y2 = CLAMP (y2, y1, (gint) tex_height);
|
|
|
|
|
|
|
|
/* Fill the rectangle */
|
|
|
|
for (p = mask_data + y1 * tex_width + x1;
|
|
|
|
y1 < y2;
|
|
|
|
y1++, p += tex_width)
|
|
|
|
memset (p, 255, x2 - x1);
|
|
|
|
}
|
|
|
|
|
2008-11-17 11:15:00 -05:00
|
|
|
cogl_texture_get_gl_texture (paint_tex, NULL, &paint_gl_target);
|
|
|
|
|
|
|
|
if (paint_gl_target == CGL_TEXTURE_RECTANGLE_ARB)
|
|
|
|
{
|
|
|
|
GLuint tex;
|
|
|
|
|
|
|
|
glGenTextures (1, &tex);
|
|
|
|
glBindTexture (CGL_TEXTURE_RECTANGLE_ARB, tex);
|
|
|
|
glPixelStorei (GL_UNPACK_ROW_LENGTH, tex_width);
|
|
|
|
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
|
|
|
|
glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
|
|
|
|
glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
|
|
|
|
glTexImage2D (CGL_TEXTURE_RECTANGLE_ARB, 0,
|
|
|
|
GL_ALPHA, tex_width, tex_height,
|
|
|
|
0, GL_ALPHA, GL_UNSIGNED_BYTE, mask_data);
|
|
|
|
|
|
|
|
priv->mask_texture
|
|
|
|
= cogl_texture_new_from_foreign (tex,
|
|
|
|
CGL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
tex_width, tex_height,
|
|
|
|
0, 0,
|
|
|
|
COGL_PIXEL_FORMAT_A_8);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
priv->mask_texture = cogl_texture_new_from_data (tex_width, tex_height,
|
2009-06-08 09:54:30 -04:00
|
|
|
COGL_TEXTURE_NONE,
|
2008-11-17 11:15:00 -05:00
|
|
|
COGL_PIXEL_FORMAT_A_8,
|
|
|
|
COGL_PIXEL_FORMAT_ANY,
|
|
|
|
tex_width,
|
|
|
|
mask_data);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
g_free (mask_data);
|
|
|
|
|
|
|
|
priv->mask_width = tex_width;
|
|
|
|
priv->mask_height = tex_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_paint (ClutterActor *actor)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2008-10-16 07:50:01 -04:00
|
|
|
MutterShapedTexture *stex = (MutterShapedTexture *) actor;
|
|
|
|
MutterShapedTexturePrivate *priv = stex->priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
CoglHandle paint_tex;
|
|
|
|
guint tex_width, tex_height;
|
|
|
|
ClutterActorBox alloc;
|
2009-01-30 06:56:58 -05:00
|
|
|
CoglHandle material;
|
2009-01-12 08:18:39 -05:00
|
|
|
#if 1 /* please see comment below about workaround */
|
|
|
|
guint depth;
|
|
|
|
#endif
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
if (priv->clip_region && gdk_region_empty (priv->clip_region))
|
|
|
|
return;
|
|
|
|
|
2008-11-22 11:19:17 -05:00
|
|
|
if (!CLUTTER_ACTOR_IS_REALIZED (CLUTTER_ACTOR (stex)))
|
|
|
|
clutter_actor_realize (CLUTTER_ACTOR (stex));
|
|
|
|
|
|
|
|
paint_tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (stex));
|
|
|
|
|
|
|
|
tex_width = cogl_texture_get_width (paint_tex);
|
|
|
|
tex_height = cogl_texture_get_height (paint_tex);
|
|
|
|
|
|
|
|
if (tex_width == 0 || tex_width == 0) /* no contents yet */
|
|
|
|
return;
|
|
|
|
|
2008-09-24 16:36:38 -04:00
|
|
|
if (paint_tex == COGL_INVALID_HANDLE)
|
|
|
|
return;
|
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
if (priv->rectangles->len < 1)
|
2009-01-12 08:18:39 -05:00
|
|
|
{
|
2009-06-29 14:30:26 -04:00
|
|
|
/* If there are no rectangles use a single-layer texture */
|
2009-01-30 06:56:58 -05:00
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
if (priv->material_unshaped == COGL_INVALID_HANDLE)
|
|
|
|
priv->material_unshaped = cogl_material_new ();
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
material = priv->material_unshaped;
|
|
|
|
}
|
|
|
|
else
|
2009-01-12 08:18:39 -05:00
|
|
|
{
|
2009-06-29 14:30:26 -04:00
|
|
|
mutter_shaped_texture_ensure_mask (stex);
|
2009-01-30 06:56:58 -05:00
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
if (priv->material == COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
priv->material = cogl_material_new ();
|
|
|
|
|
|
|
|
cogl_material_set_layer_combine (priv->material, 1,
|
2009-06-11 15:33:05 -04:00
|
|
|
"RGBA = MODULATE (PREVIOUS, TEXTURE[A])",
|
2009-06-06 13:14:34 -04:00
|
|
|
NULL);
|
2009-06-29 14:30:26 -04:00
|
|
|
}
|
|
|
|
material = priv->material;
|
2009-01-30 06:56:58 -05:00
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
#if 1
|
|
|
|
/* This was added as a workaround. It seems that with the intel
|
|
|
|
* drivers when multi-texturing using an RGB TFP texture, the
|
|
|
|
* texture is actually setup internally as an RGBA texture, where
|
|
|
|
* the alpha channel is mostly 0.0 so you only see a shimmer of the
|
|
|
|
* window. This workaround forcibly defines the alpha channel as
|
|
|
|
* 1.0. Maybe there is some clutter/cogl state that is interacting
|
|
|
|
* with this that is being overlooked, but for now this seems to
|
|
|
|
* work. */
|
|
|
|
g_object_get (stex, "pixmap-depth", &depth, NULL);
|
|
|
|
if (depth == 24)
|
|
|
|
{
|
|
|
|
if (priv->material_workaround == COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
material = priv->material_workaround = cogl_material_new ();
|
|
|
|
|
|
|
|
cogl_material_set_layer_combine (material, 0,
|
|
|
|
"RGB = MODULATE (TEXTURE, PREVIOUS)"
|
|
|
|
"A = REPLACE (PREVIOUS)",
|
|
|
|
NULL);
|
|
|
|
cogl_material_set_layer_combine (material, 1,
|
|
|
|
"RGBA = MODULATE (PREVIOUS, TEXTURE[A])",
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
material = priv->material_workaround;
|
|
|
|
}
|
2009-01-12 08:18:39 -05:00
|
|
|
#endif
|
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
cogl_material_set_layer (material, 1, priv->mask_texture);
|
|
|
|
}
|
|
|
|
|
2009-01-30 06:56:58 -05:00
|
|
|
cogl_material_set_layer (material, 0, paint_tex);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2009-01-30 06:56:58 -05:00
|
|
|
{
|
|
|
|
CoglColor color;
|
2009-06-11 15:33:05 -04:00
|
|
|
guchar opacity = clutter_actor_get_paint_opacity (actor);
|
|
|
|
cogl_color_set_from_4ub (&color, opacity, opacity, opacity, opacity);
|
2009-01-30 06:56:58 -05:00
|
|
|
cogl_material_set_color (material, &color);
|
|
|
|
}
|
2009-01-12 08:18:39 -05:00
|
|
|
|
2009-01-30 06:56:58 -05:00
|
|
|
cogl_set_source (material);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
clutter_actor_get_allocation_box (actor, &alloc);
|
2009-06-29 14:30:26 -04:00
|
|
|
|
|
|
|
if (priv->clip_region)
|
|
|
|
{
|
|
|
|
GdkRectangle *rects;
|
|
|
|
int n_rects;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Limit to how many separate rectangles we'll draw; beyond this just
|
|
|
|
* fall back and draw the whole thing */
|
|
|
|
# define MAX_RECTS 16
|
|
|
|
|
|
|
|
/* Would be nice to be able to check the number of rects first */
|
|
|
|
gdk_region_get_rectangles (priv->clip_region, &rects, &n_rects);
|
|
|
|
if (n_rects > MAX_RECTS)
|
|
|
|
{
|
|
|
|
g_free (rects);
|
|
|
|
/* Fall through to following code */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float coords[MAX_RECTS * 8];
|
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
|
|
|
GdkRectangle *rect = &rects[i];
|
|
|
|
|
|
|
|
coords[i * 8 + 0] = rect->x;
|
|
|
|
coords[i * 8 + 1] = rect->y;
|
|
|
|
coords[i * 8 + 2] = rect->x + rect->width;
|
|
|
|
coords[i * 8 + 3] = rect->y + rect->height;
|
|
|
|
coords[i * 8 + 4] = rect->x / (alloc.x2 - alloc.x1);
|
|
|
|
coords[i * 8 + 5] = rect->y / (alloc.y2 - alloc.y1);
|
|
|
|
coords[i * 8 + 6] = (rect->x + rect->width) / (alloc.x2 - alloc.x1);
|
|
|
|
coords[i * 8 + 7] = (rect->y + rect->height) / (alloc.y2 - alloc.y1);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (rects);
|
|
|
|
|
|
|
|
cogl_rectangles_with_texture_coords (coords, n_rects);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-30 06:56:58 -05:00
|
|
|
cogl_rectangle (0, 0,
|
2009-06-29 14:30:26 -04:00
|
|
|
alloc.x2 - alloc.x1,
|
|
|
|
alloc.y2 - alloc.y1);
|
2008-09-24 16:36:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_pick (ClutterActor *actor,
|
|
|
|
const ClutterColor *color)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2008-10-16 07:50:01 -04:00
|
|
|
MutterShapedTexture *stex = (MutterShapedTexture *) actor;
|
|
|
|
MutterShapedTexturePrivate *priv = stex->priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
/* If there are no rectangles then use the regular pick */
|
2009-01-30 06:56:58 -05:00
|
|
|
if (priv->rectangles->len < 1)
|
2008-10-16 07:50:01 -04:00
|
|
|
CLUTTER_ACTOR_CLASS (mutter_shaped_texture_parent_class)
|
2008-09-24 16:36:38 -04:00
|
|
|
->pick (actor, color);
|
|
|
|
else if (clutter_actor_should_pick_paint (actor))
|
|
|
|
{
|
|
|
|
CoglHandle paint_tex;
|
|
|
|
ClutterActorBox alloc;
|
2008-11-22 11:19:17 -05:00
|
|
|
guint tex_width, tex_height;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
paint_tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (stex));
|
|
|
|
|
|
|
|
if (paint_tex == COGL_INVALID_HANDLE)
|
|
|
|
return;
|
|
|
|
|
2008-11-22 11:19:17 -05:00
|
|
|
tex_width = cogl_texture_get_width (paint_tex);
|
|
|
|
tex_height = cogl_texture_get_height (paint_tex);
|
|
|
|
|
|
|
|
if (tex_width == 0 || tex_width == 0) /* no contents yet */
|
|
|
|
return;
|
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_ensure_mask (stex);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2009-01-28 10:43:36 -05:00
|
|
|
cogl_set_source_color4ub (color->red, color->green, color->blue,
|
|
|
|
color->alpha);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
clutter_actor_get_allocation_box (actor, &alloc);
|
|
|
|
|
|
|
|
/* Paint the mask rectangle in the given color */
|
2009-01-28 10:43:36 -05:00
|
|
|
cogl_set_source_texture (priv->mask_texture);
|
|
|
|
cogl_rectangle_with_texture_coords (0, 0,
|
2009-06-06 13:14:34 -04:00
|
|
|
alloc.x2 - alloc.x1,
|
|
|
|
alloc.y2 - alloc.y1,
|
2009-03-10 08:52:03 -04:00
|
|
|
0, 0, 1, 1);
|
2008-09-24 16:36:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ClutterActor *
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_new (void)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2008-10-16 07:50:01 -04:00
|
|
|
ClutterActor *self = g_object_new (MUTTER_TYPE_SHAPED_TEXTURE, NULL);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_clear_rectangles (MutterShapedTexture *stex)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2008-10-16 07:50:01 -04:00
|
|
|
MutterShapedTexturePrivate *priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
g_return_if_fail (MUTTER_IS_SHAPED_TEXTURE (stex));
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
priv = stex->priv;
|
|
|
|
|
|
|
|
g_array_set_size (priv->rectangles, 0);
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_dirty_mask (stex);
|
2008-09-24 16:36:38 -04:00
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stex));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_add_rectangle (MutterShapedTexture *stex,
|
|
|
|
const XRectangle *rect)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2008-10-16 07:50:01 -04:00
|
|
|
g_return_if_fail (MUTTER_IS_SHAPED_TEXTURE (stex));
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_add_rectangles (stex, 1, rect);
|
2008-09-24 16:36:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_add_rectangles (MutterShapedTexture *stex,
|
|
|
|
size_t num_rects,
|
|
|
|
const XRectangle *rects)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2008-10-16 07:50:01 -04:00
|
|
|
MutterShapedTexturePrivate *priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
g_return_if_fail (MUTTER_IS_SHAPED_TEXTURE (stex));
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
priv = stex->priv;
|
|
|
|
|
|
|
|
g_array_append_vals (priv->rectangles, rects, num_rects);
|
|
|
|
|
2008-10-16 07:50:01 -04:00
|
|
|
mutter_shaped_texture_dirty_mask (stex);
|
2008-09-24 16:36:38 -04:00
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stex));
|
|
|
|
}
|
2009-06-29 14:30:26 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* mutter_shaped_texture_set_clip_region:
|
|
|
|
* @frame: a #TidyTextureframe
|
|
|
|
* @clip_region: (transfer full): the region of the texture that
|
|
|
|
* is visible and should be painted. OWNERSHIP IS ASSUMED BY
|
|
|
|
* THE FUNCTION (for efficiency to avoid a copy.)
|
|
|
|
*
|
|
|
|
* Provides a hint to the texture about what areas of the texture
|
|
|
|
* are not completely obscured and thus need to be painted. This
|
|
|
|
* is an optimization and is not supposed to have any effect on
|
|
|
|
* the output.
|
|
|
|
*
|
|
|
|
* Typically a parent container will set the clip region before
|
|
|
|
* painting its children, and then unset it afterwards.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
mutter_shaped_texture_set_clip_region (MutterShapedTexture *stex,
|
|
|
|
GdkRegion *clip_region)
|
|
|
|
{
|
|
|
|
MutterShapedTexturePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (MUTTER_IS_SHAPED_TEXTURE (stex));
|
|
|
|
|
|
|
|
priv = stex->priv;
|
|
|
|
|
|
|
|
if (priv->clip_region)
|
|
|
|
{
|
|
|
|
gdk_region_destroy (priv->clip_region);
|
|
|
|
priv->clip_region = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->clip_region = clip_region;
|
|
|
|
}
|