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>
|
|
|
|
|
2012-02-21 11:31:53 -05:00
|
|
|
#define CLUTTER_ENABLE_EXPERIMENTAL_API
|
|
|
|
#define COGL_ENABLE_EXPERIMENTAL_API
|
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
#include <meta/meta-shaped-texture.h>
|
2010-10-18 13:27:14 -04:00
|
|
|
#include "meta-texture-tower.h"
|
2011-07-13 10:47:10 -04:00
|
|
|
#include "meta-texture-rectangle.h"
|
2009-01-28 10:43:36 -05:00
|
|
|
|
|
|
|
#include <clutter/clutter.h>
|
2008-09-24 16:36:38 -04:00
|
|
|
#include <cogl/cogl.h>
|
2011-10-04 17:35:11 -04:00
|
|
|
#include <cogl/cogl-texture-pixmap-x11.h>
|
2011-12-20 17:21:59 -05:00
|
|
|
#include <gdk/gdk.h> /* for gdk_rectangle_intersect() */
|
2008-09-24 16:36:38 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
static void meta_shaped_texture_dispose (GObject *object);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
static void meta_shaped_texture_paint (ClutterActor *actor);
|
|
|
|
static void meta_shaped_texture_pick (ClutterActor *actor,
|
|
|
|
const ClutterColor *color);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
static void meta_shaped_texture_get_preferred_width (ClutterActor *self,
|
|
|
|
gfloat for_height,
|
|
|
|
gfloat *min_width_p,
|
|
|
|
gfloat *natural_width_p);
|
|
|
|
|
|
|
|
static void meta_shaped_texture_get_preferred_height (ClutterActor *self,
|
|
|
|
gfloat for_width,
|
|
|
|
gfloat *min_height_p,
|
|
|
|
gfloat *natural_height_p);
|
2009-10-30 09:06:28 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
static void meta_shaped_texture_dirty_mask (MetaShapedTexture *stex);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2012-02-21 10:42:39 -05:00
|
|
|
static gboolean meta_shaped_texture_get_paint_volume (ClutterActor *self, ClutterPaintVolume *volume);
|
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
G_DEFINE_TYPE (MetaShapedTexture, meta_shaped_texture,
|
2011-10-04 17:35:11 -04:00
|
|
|
CLUTTER_TYPE_ACTOR);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
#define META_SHAPED_TEXTURE_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), META_TYPE_SHAPED_TEXTURE, \
|
|
|
|
MetaShapedTexturePrivate))
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
struct _MetaShapedTexturePrivate
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
MetaTextureTower *paint_tower;
|
2011-10-04 17:35:11 -04:00
|
|
|
Pixmap pixmap;
|
|
|
|
CoglHandle texture;
|
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;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
cairo_region_t *clip_region;
|
2011-07-08 15:06:13 -04:00
|
|
|
cairo_region_t *shape_region;
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2011-07-21 17:49:28 -04:00
|
|
|
cairo_region_t *overlay_region;
|
|
|
|
cairo_path_t *overlay_path;
|
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
guint tex_width, tex_height;
|
2008-09-24 16:36:38 -04:00
|
|
|
guint mask_width, mask_height;
|
|
|
|
|
2010-08-17 17:33:41 -04:00
|
|
|
guint create_mipmaps : 1;
|
2008-09-24 16:36:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_shaped_texture_class_init (MetaShapedTextureClass *klass)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
ClutterActorClass *actor_class = (ClutterActorClass *) klass;
|
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
gobject_class->dispose = meta_shaped_texture_dispose;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
actor_class->get_preferred_width = meta_shaped_texture_get_preferred_width;
|
|
|
|
actor_class->get_preferred_height = meta_shaped_texture_get_preferred_height;
|
2010-10-18 13:27:14 -04:00
|
|
|
actor_class->paint = meta_shaped_texture_paint;
|
|
|
|
actor_class->pick = meta_shaped_texture_pick;
|
2012-02-21 10:42:39 -05:00
|
|
|
actor_class->get_paint_volume = meta_shaped_texture_get_paint_volume;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
g_type_class_add_private (klass, sizeof (MetaShapedTexturePrivate));
|
2008-09-24 16:36:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_shaped_texture_init (MetaShapedTexture *self)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
MetaShapedTexturePrivate *priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
priv = self->priv = META_SHAPED_TEXTURE_GET_PRIVATE (self);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2011-07-08 15:06:13 -04:00
|
|
|
priv->shape_region = NULL;
|
2011-07-21 17:49:28 -04:00
|
|
|
priv->overlay_path = NULL;
|
|
|
|
priv->overlay_region = NULL;
|
2010-10-18 13:27:14 -04:00
|
|
|
priv->paint_tower = meta_texture_tower_new ();
|
2011-10-04 17:35:11 -04:00
|
|
|
priv->texture = COGL_INVALID_HANDLE;
|
2008-09-24 16:36:38 -04:00
|
|
|
priv->mask_texture = COGL_INVALID_HANDLE;
|
2010-08-17 17:33:41 -04:00
|
|
|
priv->create_mipmaps = TRUE;
|
2008-09-24 16:36:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_shaped_texture_dispose (GObject *object)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
MetaShapedTexture *self = (MetaShapedTexture *) object;
|
|
|
|
MetaShapedTexturePrivate *priv = self->priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2009-10-30 09:06:28 -04:00
|
|
|
if (priv->paint_tower)
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_texture_tower_free (priv->paint_tower);
|
2009-10-30 09:06:28 -04:00
|
|
|
priv->paint_tower = NULL;
|
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_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)
|
|
|
|
{
|
2010-02-23 12:36:56 -05:00
|
|
|
cogl_handle_unref (priv->material);
|
2009-01-30 06:56:58 -05:00
|
|
|
priv->material = COGL_INVALID_HANDLE;
|
|
|
|
}
|
2009-06-29 14:30:26 -04:00
|
|
|
if (priv->material_unshaped != COGL_INVALID_HANDLE)
|
|
|
|
{
|
2010-02-23 12:36:56 -05:00
|
|
|
cogl_handle_unref (priv->material_unshaped);
|
2009-06-29 14:30:26 -04:00
|
|
|
priv->material_unshaped = COGL_INVALID_HANDLE;
|
|
|
|
}
|
2011-10-04 17:35:11 -04:00
|
|
|
if (priv->texture != COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
cogl_handle_unref (priv->texture);
|
|
|
|
priv->texture = COGL_INVALID_HANDLE;
|
|
|
|
}
|
2009-01-30 06:56:58 -05:00
|
|
|
|
2011-07-08 15:06:13 -04:00
|
|
|
meta_shaped_texture_set_shape_region (self, NULL);
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_shaped_texture_set_clip_region (self, NULL);
|
2011-07-21 17:49:28 -04:00
|
|
|
meta_shaped_texture_set_overlay_path (self, NULL, NULL);
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
G_OBJECT_CLASS (meta_shaped_texture_parent_class)->dispose (object);
|
2008-09-24 16:36:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_shaped_texture_dirty_mask (MetaShapedTexture *stex)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
MetaShapedTexturePrivate *priv = stex->priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2011-08-29 12:38:17 -04:00
|
|
|
if (priv->mask_texture != COGL_INVALID_HANDLE)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2011-08-29 12:38:17 -04:00
|
|
|
cogl_handle_unref (priv->mask_texture);
|
|
|
|
priv->mask_texture = COGL_INVALID_HANDLE;
|
2008-09-24 16:36:38 -04:00
|
|
|
}
|
2011-07-21 17:49:28 -04:00
|
|
|
|
2011-08-29 12:38:17 -04:00
|
|
|
if (priv->material != COGL_INVALID_HANDLE)
|
|
|
|
cogl_material_set_layer (priv->material, 1, COGL_INVALID_HANDLE);
|
2011-07-21 17:49:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
install_overlay_path (MetaShapedTexture *stex,
|
|
|
|
guchar *mask_data,
|
|
|
|
int tex_width,
|
|
|
|
int tex_height,
|
|
|
|
int stride)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv = stex->priv;
|
|
|
|
int i, n_rects;
|
|
|
|
cairo_t *cr;
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
|
|
|
if (priv->overlay_region == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create_for_data (mask_data,
|
|
|
|
CAIRO_FORMAT_A8,
|
|
|
|
tex_width,
|
|
|
|
tex_height,
|
|
|
|
stride);
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
|
|
|
|
|
|
|
|
n_rects = cairo_region_num_rectangles (priv->overlay_region);
|
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
|
|
|
cairo_region_get_rectangle (priv->overlay_region, i, &rect);
|
|
|
|
cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_fill_preserve (cr);
|
|
|
|
if (priv->overlay_path == NULL)
|
|
|
|
{
|
|
|
|
/* If we have an overlay region but not an overlay path, then we
|
|
|
|
* just need to clear the rectangles in the overlay region. */
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
|
|
|
|
cairo_set_source_rgba (cr, 1, 1, 1, 1);
|
|
|
|
|
|
|
|
cairo_append_path (cr, priv->overlay_path);
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
out:
|
|
|
|
cairo_destroy (cr);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
}
|
|
|
|
|
2008-09-24 16:36:38 -04:00
|
|
|
static void
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_shaped_texture_ensure_mask (MetaShapedTexture *stex)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
MetaShapedTexturePrivate *priv = stex->priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
CoglHandle paint_tex;
|
|
|
|
guint tex_width, tex_height;
|
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
paint_tex = priv->texture;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
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))
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_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 */
|
2011-08-29 12:38:17 -04:00
|
|
|
if (priv->mask_texture == COGL_INVALID_HANDLE)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
|
|
|
guchar *mask_data;
|
2011-07-08 15:06:13 -04:00
|
|
|
int i;
|
|
|
|
int n_rects;
|
2011-07-11 12:58:09 -04:00
|
|
|
int stride;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2011-07-21 17:49:28 -04:00
|
|
|
/* If we have no shape region and no (or an empty) overlay region, we
|
|
|
|
* don't need to create a full mask texture, so quit early. */
|
|
|
|
if (priv->shape_region == NULL &&
|
|
|
|
(priv->overlay_region == NULL ||
|
|
|
|
cairo_region_num_rectangles (priv->overlay_region) == 0))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-11 12:58:09 -04:00
|
|
|
stride = cairo_format_stride_for_width (CAIRO_FORMAT_A8, tex_width);
|
|
|
|
|
2008-09-24 16:36:38 -04:00
|
|
|
/* Create data for an empty image */
|
2011-07-11 12:58:09 -04:00
|
|
|
mask_data = g_malloc0 (stride * tex_height);
|
2008-09-25 04:29:57 -04:00
|
|
|
|
2011-07-08 15:06:13 -04:00
|
|
|
n_rects = cairo_region_num_rectangles (priv->shape_region);
|
|
|
|
|
|
|
|
/* Fill in each rectangle. */
|
|
|
|
for (i = 0; i < n_rects; i ++)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2011-07-08 15:06:13 -04:00
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
cairo_region_get_rectangle (priv->shape_region, i, &rect);
|
|
|
|
|
|
|
|
gint x1 = rect.x, x2 = x1 + rect.width;
|
|
|
|
gint y1 = rect.y, y2 = y1 + rect.height;
|
2008-09-24 16:36:38 -04:00
|
|
|
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 */
|
2011-07-11 12:58:09 -04:00
|
|
|
for (p = mask_data + y1 * stride + x1;
|
2008-09-24 16:36:38 -04:00
|
|
|
y1 < y2;
|
2011-07-11 12:58:09 -04:00
|
|
|
y1++, p += stride)
|
2008-09-24 16:36:38 -04:00
|
|
|
memset (p, 255, x2 - x1);
|
|
|
|
}
|
|
|
|
|
2011-07-21 17:49:28 -04:00
|
|
|
install_overlay_path (stex, mask_data, tex_width, tex_height, stride);
|
|
|
|
|
2012-03-23 14:51:25 -04:00
|
|
|
if (meta_texture_rectangle_check (paint_tex))
|
|
|
|
priv->mask_texture = meta_texture_rectangle_new (tex_width, tex_height,
|
|
|
|
COGL_PIXEL_FORMAT_A_8,
|
|
|
|
COGL_PIXEL_FORMAT_A_8,
|
|
|
|
stride,
|
|
|
|
mask_data,
|
|
|
|
NULL /* error */);
|
2008-11-17 11:15:00 -05:00
|
|
|
else
|
2012-04-24 20:48:19 -04:00
|
|
|
{
|
|
|
|
/* Note: we don't allow slicing for this texture because we
|
|
|
|
* need to use it with multi-texturing which doesn't support
|
|
|
|
* sliced textures */
|
|
|
|
priv->mask_texture = cogl_texture_new_from_data (tex_width, tex_height,
|
|
|
|
COGL_TEXTURE_NO_SLICING,
|
|
|
|
COGL_PIXEL_FORMAT_A_8,
|
|
|
|
COGL_PIXEL_FORMAT_ANY,
|
|
|
|
stride,
|
|
|
|
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
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_shaped_texture_paint (ClutterActor *actor)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
MetaShapedTexture *stex = (MetaShapedTexture *) actor;
|
|
|
|
MetaShapedTexturePrivate *priv = stex->priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
CoglHandle paint_tex;
|
|
|
|
guint tex_width, tex_height;
|
|
|
|
ClutterActorBox alloc;
|
2010-09-19 10:17:36 -04:00
|
|
|
|
|
|
|
static CoglHandle material_template = COGL_INVALID_HANDLE;
|
|
|
|
static CoglHandle material_unshaped_template = COGL_INVALID_HANDLE;
|
|
|
|
|
2009-01-30 06:56:58 -05:00
|
|
|
CoglHandle material;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
if (priv->clip_region && cairo_region_is_empty (priv->clip_region))
|
2009-06-29 14:30:26 -04:00
|
|
|
return;
|
|
|
|
|
2008-11-22 11:19:17 -05:00
|
|
|
if (!CLUTTER_ACTOR_IS_REALIZED (CLUTTER_ACTOR (stex)))
|
|
|
|
clutter_actor_realize (CLUTTER_ACTOR (stex));
|
|
|
|
|
2010-08-17 17:33:41 -04:00
|
|
|
/* The GL EXT_texture_from_pixmap extension does allow for it to be
|
|
|
|
* used together with SGIS_generate_mipmap, however this is very
|
|
|
|
* rarely supported. Also, even when it is supported there
|
|
|
|
* are distinct performance implications from:
|
2009-10-30 09:06:28 -04:00
|
|
|
*
|
2010-08-17 17:33:41 -04:00
|
|
|
* - Updating mipmaps that we don't need
|
|
|
|
* - Having to reallocate pixmaps on the server into larger buffers
|
2009-10-30 09:06:28 -04:00
|
|
|
*
|
2010-08-17 17:33:41 -04:00
|
|
|
* So, we just unconditionally use our mipmap emulation code. If we
|
|
|
|
* wanted to use SGIS_generate_mipmap, we'd have to query COGL to
|
|
|
|
* see if it was supported (no API currently), and then if and only
|
|
|
|
* if that was the case, set the clutter texture quality to HIGH.
|
|
|
|
* Setting the texture quality to high without SGIS_generate_mipmap
|
|
|
|
* support for TFP textures will result in fallbacks to XGetImage.
|
2009-10-30 09:06:28 -04:00
|
|
|
*/
|
2010-08-17 17:33:41 -04:00
|
|
|
if (priv->create_mipmaps)
|
2010-10-18 13:27:14 -04:00
|
|
|
paint_tex = meta_texture_tower_get_paint_texture (priv->paint_tower);
|
2010-08-17 17:33:41 -04:00
|
|
|
else
|
2011-10-04 17:35:11 -04:00
|
|
|
paint_tex = priv->texture;
|
2009-10-30 09:06:28 -04:00
|
|
|
|
|
|
|
if (paint_tex == COGL_INVALID_HANDLE)
|
|
|
|
return;
|
2008-11-22 11:19:17 -05:00
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
tex_width = priv->tex_width;
|
|
|
|
tex_height = priv->tex_height;
|
2008-11-22 11:19:17 -05:00
|
|
|
|
2009-08-03 12:11:15 -04:00
|
|
|
if (tex_width == 0 || tex_height == 0) /* no contents yet */
|
2008-11-22 11:19:17 -05:00
|
|
|
return;
|
|
|
|
|
2011-07-08 15:06:13 -04:00
|
|
|
if (priv->shape_region == NULL)
|
2009-01-12 08:18:39 -05:00
|
|
|
{
|
2011-07-08 15:06:13 -04:00
|
|
|
/* No region means an unclipped shape. Use a single-layer texture. */
|
2009-01-30 06:56:58 -05:00
|
|
|
|
2010-09-19 10:17:36 -04:00
|
|
|
if (priv->material_unshaped == COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
if (G_UNLIKELY (material_unshaped_template == COGL_INVALID_HANDLE))
|
|
|
|
material_unshaped_template = cogl_material_new ();
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2010-09-19 10:17:36 -04:00
|
|
|
priv->material_unshaped = cogl_material_copy (material_unshaped_template);
|
|
|
|
}
|
|
|
|
material = priv->material_unshaped;
|
2009-06-29 14:30:26 -04:00
|
|
|
}
|
|
|
|
else
|
2009-01-12 08:18:39 -05:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_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)
|
|
|
|
{
|
2010-09-19 10:17:36 -04:00
|
|
|
if (G_UNLIKELY (material_template == COGL_INVALID_HANDLE))
|
|
|
|
{
|
|
|
|
material_template = cogl_material_new ();
|
|
|
|
cogl_material_set_layer_combine (material_template, 1,
|
2009-06-11 15:33:05 -04:00
|
|
|
"RGBA = MODULATE (PREVIOUS, TEXTURE[A])",
|
2009-06-06 13:14:34 -04:00
|
|
|
NULL);
|
2010-09-19 10:17:36 -04:00
|
|
|
}
|
|
|
|
priv->material = cogl_material_copy (material_template);
|
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
|
|
|
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)
|
|
|
|
{
|
|
|
|
int n_rects;
|
|
|
|
int i;
|
2011-08-29 12:38:17 -04:00
|
|
|
cairo_rectangle_int_t tex_rect = { 0, 0, tex_width, tex_height };
|
2009-06-29 14:30:26 -04:00
|
|
|
|
|
|
|
/* Limit to how many separate rectangles we'll draw; beyond this just
|
|
|
|
* fall back and draw the whole thing */
|
|
|
|
# define MAX_RECTS 16
|
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
n_rects = cairo_region_num_rectangles (priv->clip_region);
|
|
|
|
if (n_rects <= MAX_RECTS)
|
2009-06-29 14:30:26 -04:00
|
|
|
{
|
2010-02-11 10:21:30 -05:00
|
|
|
float coords[8];
|
|
|
|
float x1, y1, x2, y2;
|
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
2010-10-18 11:32:50 -04:00
|
|
|
cairo_rectangle_int_t rect;
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
cairo_region_get_rectangle (priv->clip_region, i, &rect);
|
2010-02-11 10:21:30 -05:00
|
|
|
|
2011-08-29 12:38:17 -04:00
|
|
|
if (!gdk_rectangle_intersect (&tex_rect, &rect, &rect))
|
|
|
|
continue;
|
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
x1 = rect.x;
|
|
|
|
y1 = rect.y;
|
|
|
|
x2 = rect.x + rect.width;
|
|
|
|
y2 = rect.y + rect.height;
|
|
|
|
|
|
|
|
coords[0] = rect.x / (alloc.x2 - alloc.x1);
|
|
|
|
coords[1] = rect.y / (alloc.y2 - alloc.y1);
|
|
|
|
coords[2] = (rect.x + rect.width) / (alloc.x2 - alloc.x1);
|
|
|
|
coords[3] = (rect.y + rect.height) / (alloc.y2 - alloc.y1);
|
2010-02-11 10:21:30 -05:00
|
|
|
|
|
|
|
coords[4] = coords[0];
|
|
|
|
coords[5] = coords[1];
|
|
|
|
coords[6] = coords[2];
|
|
|
|
coords[7] = coords[3];
|
|
|
|
|
|
|
|
cogl_rectangle_with_multitexture_coords (x1, y1, x2, y2,
|
|
|
|
&coords[0], 8);
|
|
|
|
}
|
2009-06-29 14:30:26 -04:00
|
|
|
|
|
|
|
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
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_shaped_texture_pick (ClutterActor *actor,
|
|
|
|
const ClutterColor *color)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
MetaShapedTexture *stex = (MetaShapedTexture *) actor;
|
|
|
|
MetaShapedTexturePrivate *priv = stex->priv;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2011-07-08 15:06:13 -04:00
|
|
|
/* If there is no region then use the regular pick */
|
|
|
|
if (priv->shape_region == NULL)
|
2010-10-18 13:27:14 -04:00
|
|
|
CLUTTER_ACTOR_CLASS (meta_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
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
paint_tex = priv->texture;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2009-08-03 12:11:15 -04:00
|
|
|
if (tex_width == 0 || tex_height == 0) /* no contents yet */
|
|
|
|
return;
|
2008-11-22 11:19:17 -05:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-30 09:06:28 -04:00
|
|
|
static void
|
2011-10-04 17:35:11 -04:00
|
|
|
meta_shaped_texture_get_preferred_width (ClutterActor *self,
|
|
|
|
gfloat for_height,
|
|
|
|
gfloat *min_width_p,
|
|
|
|
gfloat *natural_width_p)
|
2009-10-30 09:06:28 -04:00
|
|
|
{
|
2011-10-04 17:35:11 -04:00
|
|
|
MetaShapedTexturePrivate *priv;
|
2009-10-30 09:06:28 -04:00
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
g_return_if_fail (META_IS_SHAPED_TEXTURE (self));
|
2009-10-30 09:06:28 -04:00
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
priv = META_SHAPED_TEXTURE (self)->priv;
|
|
|
|
|
|
|
|
if (min_width_p)
|
|
|
|
*min_width_p = 0;
|
|
|
|
|
|
|
|
if (natural_width_p)
|
|
|
|
*natural_width_p = priv->tex_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_shaped_texture_get_preferred_height (ClutterActor *self,
|
|
|
|
gfloat for_width,
|
|
|
|
gfloat *min_height_p,
|
|
|
|
gfloat *natural_height_p)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (META_IS_SHAPED_TEXTURE (self));
|
|
|
|
|
|
|
|
priv = META_SHAPED_TEXTURE (self)->priv;
|
|
|
|
|
|
|
|
if (min_height_p)
|
|
|
|
*min_height_p = 0;
|
|
|
|
|
|
|
|
if (natural_height_p)
|
|
|
|
*natural_height_p = priv->tex_height;
|
2009-10-30 09:06:28 -04:00
|
|
|
}
|
|
|
|
|
2012-02-21 10:42:39 -05:00
|
|
|
static gboolean
|
|
|
|
meta_shaped_texture_get_paint_volume (ClutterActor *self,
|
|
|
|
ClutterPaintVolume *volume)
|
|
|
|
{
|
|
|
|
return clutter_paint_volume_set_from_allocation (volume, self);
|
|
|
|
}
|
|
|
|
|
2008-09-24 16:36:38 -04:00
|
|
|
ClutterActor *
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_shaped_texture_new (void)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
ClutterActor *self = g_object_new (META_TYPE_SHAPED_TEXTURE, NULL);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-08-17 17:33:41 -04:00
|
|
|
void
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_shaped_texture_set_create_mipmaps (MetaShapedTexture *stex,
|
|
|
|
gboolean create_mipmaps)
|
2010-08-17 17:33:41 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
MetaShapedTexturePrivate *priv;
|
2010-08-17 17:33:41 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
g_return_if_fail (META_IS_SHAPED_TEXTURE (stex));
|
2010-08-17 17:33:41 -04:00
|
|
|
|
|
|
|
priv = stex->priv;
|
|
|
|
|
|
|
|
create_mipmaps = create_mipmaps != FALSE;
|
|
|
|
|
|
|
|
if (create_mipmaps != priv->create_mipmaps)
|
|
|
|
{
|
|
|
|
CoglHandle base_texture;
|
|
|
|
priv->create_mipmaps = create_mipmaps;
|
|
|
|
base_texture = create_mipmaps ?
|
2011-10-04 17:35:11 -04:00
|
|
|
priv->texture : COGL_INVALID_HANDLE;
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_texture_tower_set_base_texture (priv->paint_tower, base_texture);
|
2010-08-17 17:33:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-18 16:53:32 -04:00
|
|
|
void
|
2011-10-04 17:35:11 -04:00
|
|
|
meta_shaped_texture_set_shape_region (MetaShapedTexture *stex,
|
|
|
|
cairo_region_t *region)
|
2010-08-18 16:53:32 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
MetaShapedTexturePrivate *priv;
|
2010-08-18 16:53:32 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
g_return_if_fail (META_IS_SHAPED_TEXTURE (stex));
|
2010-08-18 16:53:32 -04:00
|
|
|
|
|
|
|
priv = stex->priv;
|
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
if (priv->shape_region != NULL)
|
|
|
|
{
|
|
|
|
cairo_region_destroy (priv->shape_region);
|
|
|
|
priv->shape_region = NULL;
|
|
|
|
}
|
2010-08-18 16:53:32 -04:00
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
if (region != NULL)
|
|
|
|
{
|
|
|
|
cairo_region_reference (region);
|
|
|
|
priv->shape_region = region;
|
|
|
|
}
|
2010-08-18 16:53:32 -04:00
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
meta_shaped_texture_dirty_mask (stex);
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stex));
|
2010-08-18 16:53:32 -04:00
|
|
|
}
|
|
|
|
|
2008-09-24 16:36:38 -04:00
|
|
|
void
|
2011-10-04 17:35:11 -04:00
|
|
|
meta_shaped_texture_update_area (MetaShapedTexture *stex,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height)
|
2008-09-24 16:36:38 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
MetaShapedTexturePrivate *priv;
|
2011-10-04 17:35:11 -04:00
|
|
|
const cairo_rectangle_int_t clip = { x, y, width, height };
|
|
|
|
|
|
|
|
priv = stex->priv;
|
|
|
|
|
|
|
|
if (priv->texture == COGL_INVALID_HANDLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cogl_texture_pixmap_x11_update_area (priv->texture, x, y, width, height);
|
|
|
|
|
|
|
|
meta_texture_tower_update_area (priv->paint_tower, x, y, width, height);
|
|
|
|
|
|
|
|
clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stex), &clip);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_cogl_texture (MetaShapedTexture *stex,
|
|
|
|
CoglHandle cogl_tex)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv;
|
|
|
|
guint width, height;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
g_return_if_fail (META_IS_SHAPED_TEXTURE (stex));
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
priv = stex->priv;
|
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
if (priv->texture != COGL_INVALID_HANDLE)
|
|
|
|
cogl_handle_unref (priv->texture);
|
|
|
|
|
|
|
|
priv->texture = cogl_tex;
|
|
|
|
|
|
|
|
if (priv->material != COGL_INVALID_HANDLE)
|
|
|
|
cogl_material_set_layer (priv->material, 0, cogl_tex);
|
|
|
|
|
|
|
|
if (priv->material_unshaped != COGL_INVALID_HANDLE)
|
|
|
|
cogl_material_set_layer (priv->material_unshaped, 0, cogl_tex);
|
|
|
|
|
|
|
|
if (cogl_tex != COGL_INVALID_HANDLE)
|
2011-07-08 15:06:13 -04:00
|
|
|
{
|
2011-10-04 17:35:11 -04:00
|
|
|
width = cogl_texture_get_width (cogl_tex);
|
|
|
|
height = cogl_texture_get_height (cogl_tex);
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
if (width != priv->tex_width ||
|
|
|
|
height != priv->tex_height)
|
|
|
|
{
|
|
|
|
priv->tex_width = width;
|
|
|
|
priv->tex_height = height;
|
|
|
|
|
|
|
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (stex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2011-07-08 15:06:13 -04:00
|
|
|
{
|
2011-10-04 17:35:11 -04:00
|
|
|
/* size changed to 0 going to an invalid handle */
|
|
|
|
priv->tex_width = 0;
|
|
|
|
priv->tex_height = 0;
|
|
|
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (stex));
|
2011-07-08 15:06:13 -04:00
|
|
|
}
|
2008-09-24 16:36:38 -04:00
|
|
|
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stex));
|
|
|
|
}
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
/**
|
|
|
|
* meta_shaped_texture_set_pixmap:
|
|
|
|
* @stex: The #MetaShapedTexture
|
|
|
|
* @pixmap: The pixmap you want the stex to assume
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
meta_shaped_texture_set_pixmap (MetaShapedTexture *stex,
|
|
|
|
Pixmap pixmap)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (META_IS_SHAPED_TEXTURE (stex));
|
|
|
|
|
|
|
|
priv = stex->priv;
|
|
|
|
|
|
|
|
if (priv->pixmap == pixmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->pixmap = pixmap;
|
|
|
|
|
|
|
|
if (pixmap != None)
|
2012-02-21 11:31:53 -05:00
|
|
|
{
|
|
|
|
CoglContext *ctx =
|
|
|
|
clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
|
|
|
set_cogl_texture (stex, cogl_texture_pixmap_x11_new (ctx, pixmap, FALSE, NULL));
|
|
|
|
}
|
2011-10-04 17:35:11 -04:00
|
|
|
else
|
|
|
|
set_cogl_texture (stex, COGL_INVALID_HANDLE);
|
|
|
|
|
|
|
|
if (priv->create_mipmaps)
|
|
|
|
meta_texture_tower_set_base_texture (priv->paint_tower, priv->texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_shaped_texture_get_texture:
|
|
|
|
* @stex: The #MetaShapedTexture
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the unshaped texture
|
|
|
|
*/
|
|
|
|
CoglHandle
|
|
|
|
meta_shaped_texture_get_texture (MetaShapedTexture *stex)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (META_IS_SHAPED_TEXTURE (stex), COGL_INVALID_HANDLE);
|
|
|
|
return stex->priv->texture;
|
|
|
|
}
|
|
|
|
|
2011-07-21 17:49:28 -04:00
|
|
|
/**
|
|
|
|
* meta_shaped_texture_set_overlay_path:
|
|
|
|
* @stex: a #MetaShapedTexture
|
|
|
|
* @overlay_region: A region containing the parts of the mask to overlay.
|
|
|
|
* All rectangles in this region are wiped clear to full transparency,
|
|
|
|
* and the overlay path is clipped to this region.
|
2011-10-04 17:35:11 -04:00
|
|
|
* @overlay_path: (transfer full): This path will be painted onto the mask
|
2011-07-21 17:49:28 -04:00
|
|
|
* texture with a fully opaque source. Due to the lack of refcounting
|
|
|
|
* in #cairo_path_t, ownership of the path is assumed.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
meta_shaped_texture_set_overlay_path (MetaShapedTexture *stex,
|
|
|
|
cairo_region_t *overlay_region,
|
|
|
|
cairo_path_t *overlay_path)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (META_IS_SHAPED_TEXTURE (stex));
|
|
|
|
|
|
|
|
priv = stex->priv;
|
|
|
|
|
|
|
|
if (priv->overlay_region != NULL)
|
|
|
|
{
|
|
|
|
cairo_region_destroy (priv->overlay_region);
|
|
|
|
priv->overlay_region = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->overlay_path != NULL)
|
|
|
|
{
|
|
|
|
cairo_path_destroy (priv->overlay_path);
|
|
|
|
priv->overlay_path = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_region_reference (overlay_region);
|
|
|
|
priv->overlay_region = overlay_region;
|
|
|
|
|
|
|
|
/* cairo_path_t does not have refcounting. */
|
|
|
|
priv->overlay_path = overlay_path;
|
|
|
|
|
|
|
|
meta_shaped_texture_dirty_mask (stex);
|
|
|
|
}
|
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
/**
|
2010-10-18 13:27:14 -04:00
|
|
|
* meta_shaped_texture_set_clip_region:
|
2011-10-04 17:35:11 -04:00
|
|
|
* @stex: a #MetaShapedTexture
|
2009-06-29 14:30:26 -04:00
|
|
|
* @clip_region: (transfer full): the region of the texture that
|
2011-08-29 12:38:17 -04:00
|
|
|
* is visible and should be painted.
|
2009-06-29 14:30:26 -04:00
|
|
|
*
|
|
|
|
* 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
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_shaped_texture_set_clip_region (MetaShapedTexture *stex,
|
|
|
|
cairo_region_t *clip_region)
|
2009-06-29 14:30:26 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
MetaShapedTexturePrivate *priv;
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
g_return_if_fail (META_IS_SHAPED_TEXTURE (stex));
|
2009-06-29 14:30:26 -04:00
|
|
|
|
|
|
|
priv = stex->priv;
|
|
|
|
|
|
|
|
if (priv->clip_region)
|
|
|
|
{
|
2010-10-18 11:32:50 -04:00
|
|
|
cairo_region_destroy (priv->clip_region);
|
2009-06-29 14:30:26 -04:00
|
|
|
priv->clip_region = NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-29 12:38:17 -04:00
|
|
|
if (clip_region)
|
|
|
|
priv->clip_region = cairo_region_copy (clip_region);
|
|
|
|
else
|
|
|
|
priv->clip_region = NULL;
|
2009-06-29 14:30:26 -04:00
|
|
|
}
|
2011-12-20 17:21:59 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_shaped_texture_get_image:
|
|
|
|
* @stex: A #MetaShapedTexture
|
|
|
|
* @clip: A clipping rectangle, to help prevent extra processing.
|
|
|
|
* In the case that the clipping rectangle is partially or fully
|
|
|
|
* outside the bounds of the texture, the rectangle will be clipped.
|
|
|
|
*
|
|
|
|
* Flattens the two layers of the shaped texture into one ARGB32
|
|
|
|
* image by alpha blending the two images, and returns the flattened
|
|
|
|
* image.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new cairo surface to be freed with
|
|
|
|
* cairo_surface_destroy().
|
|
|
|
*/
|
|
|
|
cairo_surface_t *
|
|
|
|
meta_shaped_texture_get_image (MetaShapedTexture *stex,
|
|
|
|
cairo_rectangle_int_t *clip)
|
|
|
|
{
|
|
|
|
CoglHandle texture, mask_texture;
|
|
|
|
cairo_rectangle_int_t texture_rect = { 0, 0, 0, 0 };
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (META_IS_SHAPED_TEXTURE (stex), NULL);
|
|
|
|
|
|
|
|
texture = stex->priv->texture;
|
|
|
|
|
|
|
|
if (texture == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
texture_rect.width = cogl_texture_get_width (texture);
|
|
|
|
texture_rect.height = cogl_texture_get_height (texture);
|
|
|
|
|
|
|
|
if (clip != NULL)
|
|
|
|
{
|
|
|
|
/* GdkRectangle is just a typedef of cairo_rectangle_int_t,
|
|
|
|
* so we can use the gdk_rectangle_* APIs on these. */
|
|
|
|
if (!gdk_rectangle_intersect (&texture_rect, clip, clip))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clip != NULL)
|
|
|
|
texture = cogl_texture_new_from_sub_texture (texture,
|
|
|
|
clip->x,
|
|
|
|
clip->y,
|
|
|
|
clip->width,
|
|
|
|
clip->height);
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
|
|
|
cogl_texture_get_width (texture),
|
|
|
|
cogl_texture_get_height (texture));
|
|
|
|
|
|
|
|
cogl_texture_get_data (texture, CLUTTER_CAIRO_FORMAT_ARGB32,
|
|
|
|
cairo_image_surface_get_stride (surface),
|
|
|
|
cairo_image_surface_get_data (surface));
|
|
|
|
|
|
|
|
cairo_surface_mark_dirty (surface);
|
|
|
|
|
|
|
|
if (clip != NULL)
|
|
|
|
cogl_object_unref (texture);
|
|
|
|
|
|
|
|
mask_texture = stex->priv->mask_texture;
|
|
|
|
if (mask_texture != COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
cairo_t *cr;
|
|
|
|
cairo_surface_t *mask_surface;
|
|
|
|
|
|
|
|
if (clip != NULL)
|
|
|
|
mask_texture = cogl_texture_new_from_sub_texture (mask_texture,
|
|
|
|
clip->x,
|
|
|
|
clip->y,
|
|
|
|
clip->width,
|
|
|
|
clip->height);
|
|
|
|
|
|
|
|
mask_surface = cairo_image_surface_create (CAIRO_FORMAT_A8,
|
|
|
|
cogl_texture_get_width (mask_texture),
|
|
|
|
cogl_texture_get_height (mask_texture));
|
|
|
|
|
|
|
|
cogl_texture_get_data (mask_texture, COGL_PIXEL_FORMAT_A_8,
|
|
|
|
cairo_image_surface_get_stride (mask_surface),
|
|
|
|
cairo_image_surface_get_data (mask_surface));
|
|
|
|
|
|
|
|
cairo_surface_mark_dirty (mask_surface);
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
cairo_set_source_surface (cr, mask_surface, 0, 0);
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_DEST_IN);
|
|
|
|
cairo_paint (cr);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
cairo_surface_destroy (mask_surface);
|
|
|
|
|
|
|
|
if (clip != NULL)
|
|
|
|
cogl_object_unref (mask_texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|