2008-09-24 16:36:38 -04:00
|
|
|
/*
|
|
|
|
* Authored By Neil Roberts <neil@linux.intel.com>
|
2012-04-27 00:14:42 -04:00
|
|
|
* and Jasper St. Pierre <jstpierre@mecheye.net>
|
2008-09-24 16:36:38 -04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Intel Corporation
|
2012-04-27 00:14:42 -04:00
|
|
|
* Copyright (C) 2012 Red Hat, Inc.
|
2008-09-24 16:36:38 -04:00
|
|
|
*
|
|
|
|
* 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
|
2014-01-11 20:42:06 -05:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2008-09-24 16:36:38 -04:00
|
|
|
*/
|
|
|
|
|
2013-03-11 11:52:36 -04:00
|
|
|
/**
|
|
|
|
* SECTION:meta-shaped-texture
|
|
|
|
* @title: MetaShapedTexture
|
|
|
|
* @short_description: An actor to draw a masked texture.
|
|
|
|
*/
|
|
|
|
|
2008-09-30 10:33:18 -04:00
|
|
|
#include <config.h>
|
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
#include <meta/meta-shaped-texture.h>
|
2013-08-16 08:23:40 -04:00
|
|
|
#include "meta-shaped-texture-private.h"
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2008-09-24 16:36:38 -04:00
|
|
|
#include <cogl/cogl.h>
|
2011-12-20 17:21:59 -05:00
|
|
|
#include <gdk/gdk.h> /* for gdk_rectangle_intersect() */
|
2014-08-26 14:50:16 -04:00
|
|
|
|
|
|
|
#include "clutter-utils.h"
|
|
|
|
#include "meta-texture-tower.h"
|
|
|
|
|
2013-11-21 16:25:20 -05:00
|
|
|
#include "meta-cullable.h"
|
2008-09-24 16:36:38 -04:00
|
|
|
|
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);
|
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
|
|
|
|
2012-02-21 10:42:39 -05:00
|
|
|
static gboolean meta_shaped_texture_get_paint_volume (ClutterActor *self, ClutterPaintVolume *volume);
|
|
|
|
|
2013-11-21 16:25:20 -05:00
|
|
|
static void cullable_iface_init (MetaCullableInterface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (MetaShapedTexture, meta_shaped_texture, CLUTTER_TYPE_ACTOR,
|
|
|
|
G_IMPLEMENT_INTERFACE (META_TYPE_CULLABLE, cullable_iface_init));
|
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
|
|
|
|
2014-07-31 05:05:34 -04:00
|
|
|
enum {
|
|
|
|
SIZE_CHANGED,
|
|
|
|
|
|
|
|
LAST_SIGNAL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
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;
|
2012-01-07 17:21:32 -05:00
|
|
|
|
|
|
|
CoglTexture *texture;
|
2013-02-19 19:34:47 -05:00
|
|
|
CoglTexture *mask_texture;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2016-10-20 03:44:27 -04:00
|
|
|
CoglPipeline *base_pipeline;
|
|
|
|
CoglPipeline *masked_pipeline;
|
|
|
|
CoglPipeline *unblended_pipeline;
|
|
|
|
|
|
|
|
gboolean is_y_inverted;
|
|
|
|
|
2014-02-05 14:06:32 -05:00
|
|
|
/* The region containing only fully opaque pixels */
|
2013-08-27 16:17:34 -04:00
|
|
|
cairo_region_t *opaque_region;
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2014-02-05 14:06:32 -05:00
|
|
|
/* MetaCullable regions, see that documentation for more details */
|
|
|
|
cairo_region_t *clip_region;
|
|
|
|
cairo_region_t *unobscured_region;
|
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
guint tex_width, tex_height;
|
2015-06-23 19:23:45 -04:00
|
|
|
guint fallback_width, fallback_height;
|
2008-09-24 16:36:38 -04:00
|
|
|
|
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;
|
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
|
|
|
|
2014-07-31 05:05:34 -04:00
|
|
|
signals[SIZE_CHANGED] = g_signal_new ("size-changed",
|
|
|
|
G_TYPE_FROM_CLASS (gobject_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
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
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
priv->paint_tower = meta_texture_tower_new ();
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2013-02-19 19:34:47 -05:00
|
|
|
priv->texture = NULL;
|
|
|
|
priv->mask_texture = NULL;
|
2010-08-17 17:33:41 -04:00
|
|
|
priv->create_mipmaps = TRUE;
|
2008-09-24 16:36:38 -04:00
|
|
|
}
|
|
|
|
|
2014-02-05 14:06:32 -05:00
|
|
|
static void
|
|
|
|
set_unobscured_region (MetaShapedTexture *self,
|
|
|
|
cairo_region_t *unobscured_region)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv = self->priv;
|
|
|
|
|
|
|
|
g_clear_pointer (&priv->unobscured_region, (GDestroyNotify) cairo_region_destroy);
|
|
|
|
if (unobscured_region)
|
|
|
|
{
|
2015-06-23 19:23:45 -04:00
|
|
|
guint width, height;
|
|
|
|
|
|
|
|
if (priv->texture)
|
|
|
|
{
|
|
|
|
width = priv->tex_width;
|
|
|
|
height = priv->tex_height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = priv->fallback_width;
|
|
|
|
height = priv->fallback_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_rectangle_int_t bounds = { 0, 0, width, height };
|
2014-02-05 14:06:32 -05:00
|
|
|
priv->unobscured_region = cairo_region_copy (unobscured_region);
|
|
|
|
cairo_region_intersect_rectangle (priv->unobscured_region, &bounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-21 16:25:20 -05:00
|
|
|
static void
|
|
|
|
set_clip_region (MetaShapedTexture *self,
|
|
|
|
cairo_region_t *clip_region)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv = self->priv;
|
|
|
|
|
|
|
|
g_clear_pointer (&priv->clip_region, (GDestroyNotify) cairo_region_destroy);
|
|
|
|
if (clip_region)
|
|
|
|
priv->clip_region = cairo_region_copy (clip_region);
|
|
|
|
}
|
|
|
|
|
2016-10-20 03:44:27 -04:00
|
|
|
static void
|
|
|
|
meta_shaped_texture_reset_pipelines (MetaShapedTexture *stex)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv = stex->priv;
|
|
|
|
|
|
|
|
g_clear_pointer (&priv->base_pipeline, cogl_object_unref);
|
|
|
|
g_clear_pointer (&priv->masked_pipeline, cogl_object_unref);
|
|
|
|
g_clear_pointer (&priv->unblended_pipeline, cogl_object_unref);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2013-02-19 19:34:47 -05:00
|
|
|
g_clear_pointer (&priv->texture, cogl_object_unref);
|
2013-09-14 08:20:41 -04:00
|
|
|
g_clear_pointer (&priv->opaque_region, cairo_region_destroy);
|
2009-01-30 06:56:58 -05:00
|
|
|
|
2013-02-19 19:34:47 -05:00
|
|
|
meta_shaped_texture_set_mask_texture (self, NULL);
|
2014-02-05 14:06:32 -05:00
|
|
|
set_unobscured_region (self, NULL);
|
2013-11-21 16:25:20 -05:00
|
|
|
set_clip_region (self, NULL);
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2016-10-20 03:44:27 -04:00
|
|
|
meta_shaped_texture_reset_pipelines (self);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-07-05 17:53:33 -04:00
|
|
|
static CoglPipeline *
|
2016-10-20 03:44:27 -04:00
|
|
|
get_base_pipeline (MetaShapedTexture *stex,
|
|
|
|
CoglContext *ctx)
|
2015-07-05 17:53:33 -04:00
|
|
|
{
|
2016-10-20 03:44:27 -04:00
|
|
|
MetaShapedTexturePrivate *priv = stex->priv;
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
|
|
|
|
if (priv->base_pipeline)
|
|
|
|
return priv->base_pipeline;
|
|
|
|
|
|
|
|
pipeline = cogl_pipeline_new (ctx);
|
|
|
|
cogl_pipeline_set_layer_wrap_mode_s (pipeline, 0,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE);
|
|
|
|
cogl_pipeline_set_layer_wrap_mode_t (pipeline, 0,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE);
|
|
|
|
cogl_pipeline_set_layer_wrap_mode_s (pipeline, 1,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE);
|
|
|
|
cogl_pipeline_set_layer_wrap_mode_t (pipeline, 1,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE);
|
|
|
|
if (!priv->is_y_inverted)
|
2015-07-05 17:53:33 -04:00
|
|
|
{
|
2016-10-20 03:44:27 -04:00
|
|
|
CoglMatrix matrix;
|
|
|
|
|
|
|
|
cogl_matrix_init_identity (&matrix);
|
|
|
|
cogl_matrix_scale (&matrix, 1, -1, 1);
|
|
|
|
cogl_matrix_translate (&matrix, 0, -1, 0);
|
|
|
|
cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix);
|
2015-07-05 17:53:33 -04:00
|
|
|
}
|
2016-10-20 03:44:27 -04:00
|
|
|
|
|
|
|
priv->base_pipeline = pipeline;
|
|
|
|
|
|
|
|
return priv->base_pipeline;
|
2015-07-05 17:53:33 -04:00
|
|
|
}
|
|
|
|
|
2013-08-27 16:03:42 -04:00
|
|
|
static CoglPipeline *
|
2016-10-20 03:44:27 -04:00
|
|
|
get_unmasked_pipeline (MetaShapedTexture *stex,
|
|
|
|
CoglContext *ctx)
|
2013-08-27 16:03:42 -04:00
|
|
|
{
|
2016-10-20 03:44:27 -04:00
|
|
|
return get_base_pipeline (stex, ctx);
|
2013-08-27 16:03:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static CoglPipeline *
|
2016-10-20 03:44:27 -04:00
|
|
|
get_masked_pipeline (MetaShapedTexture *stex,
|
|
|
|
CoglContext *ctx)
|
2013-08-27 16:03:42 -04:00
|
|
|
{
|
2016-10-20 03:44:27 -04:00
|
|
|
MetaShapedTexturePrivate *priv = stex->priv;
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
|
|
|
|
if (priv->masked_pipeline)
|
|
|
|
return priv->masked_pipeline;
|
|
|
|
|
|
|
|
pipeline = cogl_pipeline_copy (get_base_pipeline (stex, ctx));
|
|
|
|
cogl_pipeline_set_layer_combine (pipeline, 1,
|
|
|
|
"RGBA = MODULATE (PREVIOUS, TEXTURE[A])",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
priv->masked_pipeline = pipeline;
|
2013-08-27 16:03:42 -04:00
|
|
|
|
2016-10-20 03:44:27 -04:00
|
|
|
return pipeline;
|
2013-08-27 16:03:42 -04:00
|
|
|
}
|
|
|
|
|
2013-08-27 16:17:34 -04:00
|
|
|
static CoglPipeline *
|
2016-10-20 03:44:27 -04:00
|
|
|
get_unblended_pipeline (MetaShapedTexture *stex,
|
|
|
|
CoglContext *ctx)
|
2013-08-27 16:17:34 -04:00
|
|
|
{
|
2016-10-20 03:44:27 -04:00
|
|
|
MetaShapedTexturePrivate *priv = stex->priv;
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglColor color;
|
|
|
|
|
|
|
|
if (priv->unblended_pipeline)
|
|
|
|
return priv->unblended_pipeline;
|
2013-08-27 16:17:34 -04:00
|
|
|
|
2016-10-20 03:44:27 -04:00
|
|
|
pipeline = cogl_pipeline_copy (get_base_pipeline (stex, ctx));
|
|
|
|
cogl_color_init_from_4ub (&color, 255, 255, 255, 255);
|
|
|
|
cogl_pipeline_set_blend (pipeline,
|
|
|
|
"RGBA = ADD (SRC_COLOR, 0)",
|
|
|
|
NULL);
|
|
|
|
cogl_pipeline_set_color (pipeline, &color);
|
|
|
|
|
|
|
|
priv->unblended_pipeline = pipeline;
|
|
|
|
|
|
|
|
return pipeline;
|
2013-08-27 16:17:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
paint_clipped_rectangle (CoglFramebuffer *fb,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
cairo_rectangle_int_t *rect,
|
|
|
|
ClutterActorBox *alloc)
|
|
|
|
{
|
|
|
|
float coords[8];
|
|
|
|
float x1, y1, x2, y2;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
coords[4] = coords[0];
|
|
|
|
coords[5] = coords[1];
|
|
|
|
coords[6] = coords[2];
|
|
|
|
coords[7] = coords[3];
|
|
|
|
|
|
|
|
cogl_framebuffer_draw_multitextured_rectangle (fb, pipeline,
|
|
|
|
x1, y1, x2, y2,
|
|
|
|
&coords[0], 8);
|
|
|
|
}
|
|
|
|
|
2012-01-07 17:21:32 -05:00
|
|
|
static void
|
|
|
|
set_cogl_texture (MetaShapedTexture *stex,
|
|
|
|
CoglTexture *cogl_tex)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv;
|
|
|
|
guint width, height;
|
|
|
|
|
|
|
|
g_return_if_fail (META_IS_SHAPED_TEXTURE (stex));
|
|
|
|
|
|
|
|
priv = stex->priv;
|
|
|
|
|
|
|
|
if (priv->texture)
|
|
|
|
cogl_object_unref (priv->texture);
|
|
|
|
|
2013-11-26 12:35:12 -05:00
|
|
|
priv->texture = cogl_tex;
|
2012-01-07 17:21:32 -05:00
|
|
|
|
|
|
|
if (cogl_tex != NULL)
|
|
|
|
{
|
2013-11-26 12:35:12 -05:00
|
|
|
cogl_object_ref (cogl_tex);
|
2012-01-07 17:21:32 -05:00
|
|
|
width = cogl_texture_get_width (COGL_TEXTURE (cogl_tex));
|
|
|
|
height = cogl_texture_get_height (COGL_TEXTURE (cogl_tex));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-28 05:08:25 -04:00
|
|
|
width = 0;
|
|
|
|
height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->tex_width != width ||
|
|
|
|
priv->tex_height != height)
|
|
|
|
{
|
|
|
|
priv->tex_width = width;
|
|
|
|
priv->tex_height = height;
|
2016-02-24 13:24:09 -05:00
|
|
|
meta_shaped_texture_set_mask_texture (stex, NULL);
|
2012-01-07 17:21:32 -05:00
|
|
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (stex));
|
2014-07-31 05:05:34 -04:00
|
|
|
g_signal_emit (stex, signals[SIZE_CHANGED], 0);
|
2012-01-07 17:21:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NB: We don't queue a redraw of the actor here because we don't
|
|
|
|
* know how much of the buffer has changed with respect to the
|
|
|
|
* previous buffer. We only queue a redraw in response to surface
|
|
|
|
* damage. */
|
2013-11-04 21:44:25 -05:00
|
|
|
|
|
|
|
if (priv->create_mipmaps)
|
|
|
|
meta_texture_tower_set_base_texture (priv->paint_tower, cogl_tex);
|
2012-01-07 17:21:32 -05:00
|
|
|
}
|
|
|
|
|
2008-09-24 16:36:38 -04:00
|
|
|
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
|
|
|
guint tex_width, tex_height;
|
2013-08-27 16:17:34 -04:00
|
|
|
guchar opacity;
|
2013-08-27 16:03:42 -04:00
|
|
|
CoglContext *ctx;
|
2013-08-27 16:25:40 -04:00
|
|
|
CoglFramebuffer *fb;
|
|
|
|
CoglTexture *paint_tex;
|
|
|
|
ClutterActorBox alloc;
|
2013-10-09 20:38:52 -04:00
|
|
|
CoglPipelineFilter filter;
|
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
|
2013-02-19 19:34:47 -05:00
|
|
|
paint_tex = COGL_TEXTURE (priv->texture);
|
2009-10-30 09:06:28 -04:00
|
|
|
|
2013-02-19 19:34:47 -05:00
|
|
|
if (paint_tex == NULL)
|
2009-10-30 09:06:28 -04:00
|
|
|
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;
|
|
|
|
|
2014-08-24 12:02:53 -04:00
|
|
|
cairo_rectangle_int_t tex_rect = { 0, 0, tex_width, tex_height };
|
|
|
|
|
2013-10-09 20:38:52 -04:00
|
|
|
/* Use nearest-pixel interpolation if the texture is unscaled. This
|
|
|
|
* improves performance, especially with software rendering.
|
|
|
|
*/
|
|
|
|
|
|
|
|
filter = COGL_PIPELINE_FILTER_LINEAR;
|
|
|
|
|
2014-08-28 15:18:23 -04:00
|
|
|
if (meta_actor_painting_untransformed (tex_width, tex_height, NULL, NULL))
|
2013-11-25 15:27:48 -05:00
|
|
|
filter = COGL_PIPELINE_FILTER_NEAREST;
|
2013-10-09 20:38:52 -04:00
|
|
|
|
2013-08-27 16:03:42 -04:00
|
|
|
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
2013-08-27 16:25:40 -04:00
|
|
|
fb = cogl_get_draw_framebuffer ();
|
2013-08-27 16:03:42 -04:00
|
|
|
|
2013-08-27 16:17:34 -04:00
|
|
|
opacity = clutter_actor_get_paint_opacity (actor);
|
|
|
|
clutter_actor_get_allocation_box (actor, &alloc);
|
|
|
|
|
2014-08-24 12:02:53 -04:00
|
|
|
cairo_region_t *blended_region;
|
|
|
|
gboolean use_opaque_region = (priv->opaque_region != NULL && opacity == 255);
|
|
|
|
|
|
|
|
if (use_opaque_region)
|
|
|
|
{
|
|
|
|
if (priv->clip_region != NULL)
|
|
|
|
blended_region = cairo_region_copy (priv->clip_region);
|
|
|
|
else
|
|
|
|
blended_region = cairo_region_create_rectangle (&tex_rect);
|
|
|
|
|
|
|
|
cairo_region_subtract (blended_region, priv->opaque_region);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (priv->clip_region != NULL)
|
|
|
|
blended_region = cairo_region_reference (priv->clip_region);
|
|
|
|
else
|
|
|
|
blended_region = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Limit to how many separate rectangles we'll draw; beyond this just
|
|
|
|
* fall back and draw the whole thing */
|
|
|
|
#define MAX_RECTS 16
|
|
|
|
|
|
|
|
if (blended_region != NULL)
|
|
|
|
{
|
|
|
|
int n_rects = cairo_region_num_rectangles (blended_region);
|
|
|
|
if (n_rects > MAX_RECTS)
|
|
|
|
{
|
|
|
|
/* Fall back to taking the fully blended path. */
|
|
|
|
use_opaque_region = FALSE;
|
|
|
|
|
|
|
|
cairo_region_destroy (blended_region);
|
|
|
|
blended_region = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First, paint the unblended parts, which are part of the opaque region. */
|
|
|
|
if (use_opaque_region)
|
2013-08-27 16:17:34 -04:00
|
|
|
{
|
|
|
|
CoglPipeline *opaque_pipeline;
|
|
|
|
cairo_region_t *region;
|
|
|
|
int n_rects;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (priv->clip_region != NULL)
|
|
|
|
{
|
|
|
|
region = cairo_region_copy (priv->clip_region);
|
|
|
|
cairo_region_intersect (region, priv->opaque_region);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
region = cairo_region_reference (priv->opaque_region);
|
|
|
|
}
|
|
|
|
|
2014-08-24 12:02:53 -04:00
|
|
|
if (!cairo_region_is_empty (region))
|
2013-08-27 16:17:34 -04:00
|
|
|
{
|
2016-10-20 03:44:27 -04:00
|
|
|
opaque_pipeline = get_unblended_pipeline (stex, ctx);
|
2014-08-24 12:02:53 -04:00
|
|
|
cogl_pipeline_set_layer_texture (opaque_pipeline, 0, paint_tex);
|
|
|
|
cogl_pipeline_set_layer_filters (opaque_pipeline, 0, filter, filter);
|
|
|
|
|
|
|
|
n_rects = cairo_region_num_rectangles (region);
|
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
cairo_region_get_rectangle (region, i, &rect);
|
|
|
|
paint_clipped_rectangle (fb, opaque_pipeline, &rect, &alloc);
|
|
|
|
}
|
2013-08-27 16:17:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
cairo_region_destroy (region);
|
|
|
|
}
|
|
|
|
|
2014-08-24 12:02:53 -04:00
|
|
|
/* Now, go ahead and paint the blended parts. */
|
2014-08-25 09:25:55 -04:00
|
|
|
|
|
|
|
/* We have three cases:
|
|
|
|
* 1) blended_region has rectangles - paint the rectangles.
|
|
|
|
* 2) blended_region is empty - don't paint anything
|
|
|
|
* 3) blended_region is NULL - paint fully-blended.
|
|
|
|
*
|
|
|
|
* 1) and 3) are the times where we have to paint stuff. This tests
|
|
|
|
* for 1) and 3).
|
|
|
|
*/
|
|
|
|
if (blended_region == NULL || !cairo_region_is_empty (blended_region))
|
|
|
|
{
|
|
|
|
CoglPipeline *blended_pipeline;
|
|
|
|
|
|
|
|
if (priv->mask_texture == NULL)
|
|
|
|
{
|
2016-10-20 03:44:27 -04:00
|
|
|
blended_pipeline = get_unmasked_pipeline (stex, ctx);
|
2014-08-25 09:25:55 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-20 03:44:27 -04:00
|
|
|
blended_pipeline = get_masked_pipeline (stex, ctx);
|
2014-08-25 09:25:55 -04:00
|
|
|
cogl_pipeline_set_layer_texture (blended_pipeline, 1, priv->mask_texture);
|
|
|
|
cogl_pipeline_set_layer_filters (blended_pipeline, 1, filter, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_pipeline_set_layer_texture (blended_pipeline, 0, paint_tex);
|
|
|
|
cogl_pipeline_set_layer_filters (blended_pipeline, 0, filter, filter);
|
|
|
|
|
|
|
|
CoglColor color;
|
|
|
|
cogl_color_init_from_4ub (&color, opacity, opacity, opacity, opacity);
|
|
|
|
cogl_pipeline_set_color (blended_pipeline, &color);
|
|
|
|
|
|
|
|
if (blended_region != NULL)
|
|
|
|
{
|
2014-08-25 10:52:07 -04:00
|
|
|
/* 1) blended_region is not empty. Paint the rectangles. */
|
2014-08-25 09:25:55 -04:00
|
|
|
int i;
|
|
|
|
int n_rects = cairo_region_num_rectangles (blended_region);
|
|
|
|
|
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
cairo_region_get_rectangle (blended_region, i, &rect);
|
|
|
|
|
|
|
|
if (!gdk_rectangle_intersect (&tex_rect, &rect, &rect))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
paint_clipped_rectangle (fb, blended_pipeline, &rect, &alloc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* 3) blended_region is NULL. Do a full paint. */
|
|
|
|
cogl_framebuffer_draw_rectangle (fb, blended_pipeline,
|
|
|
|
0, 0,
|
|
|
|
alloc.x2 - alloc.x1,
|
|
|
|
alloc.y2 - alloc.y1);
|
|
|
|
}
|
|
|
|
}
|
2009-01-12 08:18:39 -05:00
|
|
|
|
2013-08-27 16:17:34 -04:00
|
|
|
if (blended_region != NULL)
|
|
|
|
cairo_region_destroy (blended_region);
|
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
|
|
|
{
|
2015-06-23 19:18:23 -04:00
|
|
|
MetaShapedTexturePrivate *priv = META_SHAPED_TEXTURE (self)->priv;
|
2015-06-23 19:23:45 -04:00
|
|
|
guint width;
|
2011-10-04 17:35:11 -04:00
|
|
|
|
2015-06-23 19:23:45 -04:00
|
|
|
if (priv->texture)
|
|
|
|
width = priv->tex_width;
|
|
|
|
else
|
|
|
|
width = priv->fallback_width;
|
2011-10-04 17:35:11 -04:00
|
|
|
|
2015-06-23 19:23:45 -04:00
|
|
|
if (min_width_p)
|
|
|
|
*min_width_p = width;
|
2011-10-04 17:35:11 -04:00
|
|
|
if (natural_width_p)
|
2015-06-23 19:23:45 -04:00
|
|
|
*natural_width_p = width;
|
2011-10-04 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_shaped_texture_get_preferred_height (ClutterActor *self,
|
|
|
|
gfloat for_width,
|
|
|
|
gfloat *min_height_p,
|
|
|
|
gfloat *natural_height_p)
|
|
|
|
{
|
2015-06-23 19:18:23 -04:00
|
|
|
MetaShapedTexturePrivate *priv = META_SHAPED_TEXTURE (self)->priv;
|
2015-06-23 19:23:45 -04:00
|
|
|
guint height;
|
2011-10-04 17:35:11 -04:00
|
|
|
|
2015-06-23 19:23:45 -04:00
|
|
|
if (priv->texture)
|
|
|
|
height = priv->tex_height;
|
|
|
|
else
|
|
|
|
height = priv->fallback_height;
|
2011-10-04 17:35:11 -04:00
|
|
|
|
2015-06-23 19:23:45 -04:00
|
|
|
if (min_height_p)
|
|
|
|
*min_height_p = height;
|
2011-10-04 17:35:11 -04:00
|
|
|
if (natural_height_p)
|
2015-06-23 19:23:45 -04:00
|
|
|
*natural_height_p = height;
|
2009-10-30 09:06:28 -04:00
|
|
|
}
|
|
|
|
|
2014-07-31 05:11:43 -04:00
|
|
|
static cairo_region_t *
|
|
|
|
effective_unobscured_region (MetaShapedTexture *self)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv = self->priv;
|
2014-08-26 14:50:16 -04:00
|
|
|
ClutterActor *actor;
|
2014-07-31 05:11:43 -04:00
|
|
|
|
2014-08-26 14:50:16 -04:00
|
|
|
/* Fail if we have any mapped clones. */
|
|
|
|
actor = CLUTTER_ACTOR (self);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (clutter_actor_has_mapped_clones (actor))
|
|
|
|
return NULL;
|
|
|
|
actor = clutter_actor_get_parent (actor);
|
|
|
|
}
|
|
|
|
while (actor != NULL);
|
2014-07-31 05:11:43 -04:00
|
|
|
|
|
|
|
return priv->unobscured_region;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
get_unobscured_bounds (MetaShapedTexture *self,
|
|
|
|
cairo_rectangle_int_t *unobscured_bounds)
|
|
|
|
{
|
|
|
|
cairo_region_t *unobscured_region = effective_unobscured_region (self);
|
|
|
|
|
|
|
|
if (unobscured_region)
|
|
|
|
{
|
|
|
|
cairo_region_get_extents (unobscured_region, unobscured_bounds);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-02-21 10:42:39 -05:00
|
|
|
static gboolean
|
2014-02-05 14:06:32 -05:00
|
|
|
meta_shaped_texture_get_paint_volume (ClutterActor *actor,
|
2012-02-21 10:42:39 -05:00
|
|
|
ClutterPaintVolume *volume)
|
|
|
|
{
|
2014-02-05 14:06:32 -05:00
|
|
|
MetaShapedTexture *self = META_SHAPED_TEXTURE (actor);
|
2014-07-30 11:00:11 -04:00
|
|
|
ClutterActorBox box;
|
2014-02-05 14:06:32 -05:00
|
|
|
cairo_rectangle_int_t unobscured_bounds;
|
|
|
|
|
2014-07-30 11:00:11 -04:00
|
|
|
if (!clutter_actor_has_allocation (actor))
|
2014-02-05 14:06:32 -05:00
|
|
|
return FALSE;
|
|
|
|
|
2014-07-30 11:00:11 -04:00
|
|
|
clutter_actor_get_allocation_box (actor, &box);
|
|
|
|
|
2014-07-31 05:11:43 -04:00
|
|
|
if (get_unobscured_bounds (self, &unobscured_bounds))
|
2014-02-05 14:06:32 -05:00
|
|
|
{
|
2014-07-30 11:00:11 -04:00
|
|
|
box.x1 = MAX (unobscured_bounds.x, box.x1);
|
|
|
|
box.x2 = MIN (unobscured_bounds.x + unobscured_bounds.width, box.x2);
|
|
|
|
box.y1 = MAX (unobscured_bounds.y, box.y1);
|
|
|
|
box.y2 = MIN (unobscured_bounds.y + unobscured_bounds.height, box.y2);
|
2014-02-05 14:06:32 -05:00
|
|
|
}
|
2014-07-31 10:17:56 -04:00
|
|
|
box.x2 = MAX (box.x2, box.x1);
|
|
|
|
box.y2 = MAX (box.y2, box.y1);
|
2014-02-05 14:06:32 -05:00
|
|
|
|
2014-07-30 11:00:11 -04:00
|
|
|
clutter_paint_volume_union_box (volume, &box);
|
2014-02-05 14:06:32 -05:00
|
|
|
return TRUE;
|
2012-02-21 10:42:39 -05:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2013-02-19 19:34:47 -05:00
|
|
|
CoglTexture *base_texture;
|
2010-08-17 17:33:41 -04:00
|
|
|
priv->create_mipmaps = create_mipmaps;
|
2012-01-07 17:21:32 -05:00
|
|
|
base_texture = create_mipmaps ? priv->texture : NULL;
|
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
|
2012-04-27 00:14:42 -04:00
|
|
|
meta_shaped_texture_set_mask_texture (MetaShapedTexture *stex,
|
2013-02-19 19:34:47 -05:00
|
|
|
CoglTexture *mask_texture)
|
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;
|
|
|
|
|
2013-02-19 19:34:47 -05:00
|
|
|
g_clear_pointer (&priv->mask_texture, cogl_object_unref);
|
2010-08-18 16:53:32 -04:00
|
|
|
|
2013-02-19 19:34:47 -05:00
|
|
|
if (mask_texture != NULL)
|
2011-10-04 17:35:11 -04:00
|
|
|
{
|
2012-04-27 00:14:42 -04:00
|
|
|
priv->mask_texture = mask_texture;
|
2013-02-19 19:34:47 -05:00
|
|
|
cogl_object_ref (priv->mask_texture);
|
2011-10-04 17:35:11 -04:00
|
|
|
}
|
2010-08-18 16:53:32 -04:00
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stex));
|
2010-08-18 16:53:32 -04:00
|
|
|
}
|
|
|
|
|
2014-02-05 14:06:32 -05:00
|
|
|
gboolean
|
|
|
|
meta_shaped_texture_is_obscured (MetaShapedTexture *self)
|
|
|
|
{
|
|
|
|
cairo_region_t *unobscured_region = effective_unobscured_region (self);
|
|
|
|
|
|
|
|
if (unobscured_region)
|
|
|
|
return cairo_region_is_empty (unobscured_region);
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-08-27 10:45:15 -04:00
|
|
|
/**
|
|
|
|
* meta_shaped_texture_update_area:
|
|
|
|
* @stex: #MetaShapedTexture
|
|
|
|
* @x: the x coordinate of the damaged area
|
|
|
|
* @y: the y coordinate of the damaged area
|
|
|
|
* @width: the width of the damaged area
|
|
|
|
* @height: the height of the damaged area
|
|
|
|
*
|
|
|
|
* Repairs the damaged area indicated by @x, @y, @width and @height
|
2014-02-05 14:06:32 -05:00
|
|
|
* and potentially queues a redraw.
|
2013-08-27 10:45:15 -04:00
|
|
|
*
|
|
|
|
* Return value: Whether a redraw have been queued or not
|
|
|
|
*/
|
|
|
|
gboolean
|
2012-01-07 17:21:32 -05:00
|
|
|
meta_shaped_texture_update_area (MetaShapedTexture *stex,
|
2013-08-27 10:45:15 -04:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
2014-02-05 14:06:32 -05:00
|
|
|
int height)
|
2012-01-07 17:21:32 -05:00
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv;
|
2014-02-05 14:06:32 -05:00
|
|
|
cairo_region_t *unobscured_region;
|
2014-02-05 14:10:49 -05:00
|
|
|
const cairo_rectangle_int_t clip = { x, y, width, height };
|
2008-09-24 16:36:38 -04:00
|
|
|
|
2012-01-07 17:21:32 -05:00
|
|
|
priv = stex->priv;
|
2011-10-04 17:35:11 -04:00
|
|
|
|
2012-01-07 17:21:32 -05:00
|
|
|
if (priv->texture == NULL)
|
2013-08-27 10:45:15 -04:00
|
|
|
return FALSE;
|
2012-01-07 17:21:32 -05:00
|
|
|
|
|
|
|
meta_texture_tower_update_area (priv->paint_tower, x, y, width, height);
|
|
|
|
|
2014-02-05 14:06:32 -05:00
|
|
|
unobscured_region = effective_unobscured_region (stex);
|
2013-08-27 10:45:15 -04:00
|
|
|
if (unobscured_region)
|
|
|
|
{
|
|
|
|
cairo_region_t *intersection;
|
|
|
|
|
|
|
|
if (cairo_region_is_empty (unobscured_region))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
intersection = cairo_region_copy (unobscured_region);
|
2014-02-05 14:05:18 -05:00
|
|
|
cairo_region_intersect_rectangle (intersection, &clip);
|
2013-08-27 10:45:15 -04:00
|
|
|
|
|
|
|
if (!cairo_region_is_empty (intersection))
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t damage_rect;
|
|
|
|
cairo_region_get_extents (intersection, &damage_rect);
|
|
|
|
clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stex), &damage_rect);
|
|
|
|
cairo_region_destroy (intersection);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_region_destroy (intersection);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-05 13:39:47 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stex), &clip);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-09-24 16:36:38 -04:00
|
|
|
}
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
/**
|
2013-11-04 22:13:33 -05:00
|
|
|
* meta_shaped_texture_set_texture:
|
2011-10-04 17:35:11 -04:00
|
|
|
* @stex: The #MetaShapedTexture
|
2013-11-04 22:13:33 -05:00
|
|
|
* @pixmap: The #CoglTexture to display
|
2011-10-04 17:35:11 -04:00
|
|
|
*/
|
|
|
|
void
|
2013-11-04 22:13:33 -05:00
|
|
|
meta_shaped_texture_set_texture (MetaShapedTexture *stex,
|
|
|
|
CoglTexture *texture)
|
2011-10-04 17:35:11 -04:00
|
|
|
{
|
|
|
|
g_return_if_fail (META_IS_SHAPED_TEXTURE (stex));
|
|
|
|
|
2013-11-04 22:13:33 -05:00
|
|
|
set_cogl_texture (stex, texture);
|
2011-10-04 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
2016-10-20 03:44:27 -04:00
|
|
|
/**
|
|
|
|
* meta_shaped_texture_set_is_y_inverted: (skip)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
meta_shaped_texture_set_is_y_inverted (MetaShapedTexture *stex,
|
|
|
|
gboolean is_y_inverted)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv = stex->priv;
|
|
|
|
|
|
|
|
if (priv->is_y_inverted == is_y_inverted)
|
|
|
|
return;
|
|
|
|
|
|
|
|
meta_shaped_texture_reset_pipelines (stex);
|
|
|
|
|
|
|
|
priv->is_y_inverted = is_y_inverted;
|
|
|
|
}
|
|
|
|
|
2011-10-04 17:35:11 -04:00
|
|
|
/**
|
|
|
|
* meta_shaped_texture_get_texture:
|
|
|
|
* @stex: The #MetaShapedTexture
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the unshaped texture
|
|
|
|
*/
|
2013-02-19 19:34:47 -05:00
|
|
|
CoglTexture *
|
2011-10-04 17:35:11 -04:00
|
|
|
meta_shaped_texture_get_texture (MetaShapedTexture *stex)
|
|
|
|
{
|
2013-02-19 19:34:47 -05:00
|
|
|
g_return_val_if_fail (META_IS_SHAPED_TEXTURE (stex), NULL);
|
|
|
|
return COGL_TEXTURE (stex->priv->texture);
|
2011-10-04 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
2013-08-27 16:17:34 -04:00
|
|
|
/**
|
|
|
|
* meta_shaped_texture_set_opaque_region:
|
|
|
|
* @stex: a #MetaShapedTexture
|
|
|
|
* @opaque_region: (transfer full): the region of the texture that
|
|
|
|
* can have blending turned off.
|
|
|
|
*
|
|
|
|
* As most windows have a large portion that does not require blending,
|
|
|
|
* we can easily turn off blending if we know the areas that do not
|
|
|
|
* require blending. This sets the region where we will not blend for
|
|
|
|
* optimization purposes.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
meta_shaped_texture_set_opaque_region (MetaShapedTexture *stex,
|
|
|
|
cairo_region_t *opaque_region)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (META_IS_SHAPED_TEXTURE (stex));
|
|
|
|
|
|
|
|
priv = stex->priv;
|
|
|
|
|
|
|
|
if (priv->opaque_region)
|
|
|
|
cairo_region_destroy (priv->opaque_region);
|
|
|
|
|
|
|
|
if (opaque_region)
|
|
|
|
priv->opaque_region = cairo_region_reference (opaque_region);
|
|
|
|
else
|
|
|
|
priv->opaque_region = NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-21 16:43:50 -04:00
|
|
|
cairo_region_t *
|
|
|
|
meta_shaped_texture_get_opaque_region (MetaShapedTexture *stex)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv = stex->priv;
|
|
|
|
return priv->opaque_region;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2013-02-19 19:34:47 -05:00
|
|
|
CoglTexture *texture, *mask_texture;
|
2011-12-20 17:21:59 -05:00
|
|
|
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);
|
|
|
|
|
2013-02-19 19:34:47 -05:00
|
|
|
texture = COGL_TEXTURE (stex->priv->texture);
|
2011-12-20 17:21:59 -05:00
|
|
|
|
|
|
|
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;
|
2013-02-19 19:34:47 -05:00
|
|
|
if (mask_texture != NULL)
|
2011-12-20 17:21:59 -05:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2013-11-04 22:13:33 -05:00
|
|
|
|
2015-06-23 19:23:45 -04:00
|
|
|
void
|
|
|
|
meta_shaped_texture_set_fallback_size (MetaShapedTexture *self,
|
|
|
|
guint fallback_width,
|
|
|
|
guint fallback_height)
|
|
|
|
{
|
|
|
|
MetaShapedTexturePrivate *priv = self->priv;
|
|
|
|
|
|
|
|
priv->fallback_width = fallback_width;
|
|
|
|
priv->fallback_height = fallback_height;
|
|
|
|
}
|
|
|
|
|
2013-11-21 16:25:20 -05:00
|
|
|
static void
|
|
|
|
meta_shaped_texture_cull_out (MetaCullable *cullable,
|
|
|
|
cairo_region_t *unobscured_region,
|
|
|
|
cairo_region_t *clip_region)
|
|
|
|
{
|
|
|
|
MetaShapedTexture *self = META_SHAPED_TEXTURE (cullable);
|
|
|
|
MetaShapedTexturePrivate *priv = self->priv;
|
|
|
|
|
2014-02-05 14:06:32 -05:00
|
|
|
set_unobscured_region (self, unobscured_region);
|
2013-11-21 16:25:20 -05:00
|
|
|
set_clip_region (self, clip_region);
|
|
|
|
|
|
|
|
if (clutter_actor_get_paint_opacity (CLUTTER_ACTOR (self)) == 0xff)
|
|
|
|
{
|
|
|
|
if (priv->opaque_region)
|
|
|
|
{
|
2014-02-05 13:20:18 -05:00
|
|
|
if (unobscured_region)
|
|
|
|
cairo_region_subtract (unobscured_region, priv->opaque_region);
|
|
|
|
if (clip_region)
|
|
|
|
cairo_region_subtract (clip_region, priv->opaque_region);
|
2013-11-21 16:25:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_shaped_texture_reset_culling (MetaCullable *cullable)
|
|
|
|
{
|
|
|
|
MetaShapedTexture *self = META_SHAPED_TEXTURE (cullable);
|
|
|
|
set_clip_region (self, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cullable_iface_init (MetaCullableInterface *iface)
|
|
|
|
{
|
|
|
|
iface->cull_out = meta_shaped_texture_cull_out;
|
|
|
|
iface->reset_culling = meta_shaped_texture_reset_culling;
|
|
|
|
}
|
|
|
|
|
2013-11-04 22:13:33 -05:00
|
|
|
ClutterActor *
|
|
|
|
meta_shaped_texture_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (META_TYPE_SHAPED_TEXTURE, NULL);
|
|
|
|
}
|