2013-10-13 07:47:53 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:meta-surface-actor
|
|
|
|
* @title: MetaSurfaceActor
|
|
|
|
* @short_description: An actor representing a surface in the scene graph
|
|
|
|
*
|
|
|
|
* A surface can be either a shaped texture, or a group of shaped texture,
|
|
|
|
* used to draw the content of a window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <clutter/clutter.h>
|
2014-01-22 09:16:56 -05:00
|
|
|
#include <cogl/cogl-wayland-server.h>
|
|
|
|
#include <cogl/cogl-texture-pixmap-x11.h>
|
2013-10-13 07:47:53 -04:00
|
|
|
#include <meta/meta-shaped-texture.h>
|
2014-01-22 09:16:56 -05:00
|
|
|
#include "meta-surface-actor.h"
|
2013-11-22 15:24:06 -05:00
|
|
|
#include "meta-wayland-private.h"
|
2013-11-21 16:25:20 -05:00
|
|
|
#include "meta-cullable.h"
|
2014-01-22 09:16:56 -05:00
|
|
|
|
2013-10-13 07:47:53 -04:00
|
|
|
#include "meta-shaped-texture-private.h"
|
|
|
|
|
|
|
|
struct _MetaSurfaceActorPrivate
|
|
|
|
{
|
2014-02-18 21:27:20 -05:00
|
|
|
MetaWaylandSurface *surface;
|
|
|
|
|
2013-11-19 11:22:49 -05:00
|
|
|
MetaShapedTexture *texture;
|
2014-01-22 09:16:56 -05:00
|
|
|
MetaWaylandBuffer *buffer;
|
2014-02-18 21:27:20 -05:00
|
|
|
|
|
|
|
cairo_region_t *input_region;
|
2013-10-13 07:47:53 -04:00
|
|
|
};
|
|
|
|
|
2013-11-21 16:25:20 -05:00
|
|
|
static void cullable_iface_init (MetaCullableInterface *iface);
|
|
|
|
|
2014-01-22 09:16:56 -05:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (MetaSurfaceActor, meta_surface_actor, CLUTTER_TYPE_ACTOR,
|
|
|
|
G_IMPLEMENT_INTERFACE (META_TYPE_CULLABLE, cullable_iface_init));
|
2013-12-06 11:57:40 -05:00
|
|
|
|
2014-02-05 14:06:32 -05:00
|
|
|
gboolean
|
|
|
|
meta_surface_actor_get_unobscured_bounds (MetaSurfaceActor *self,
|
|
|
|
cairo_rectangle_int_t *unobscured_bounds)
|
|
|
|
{
|
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
|
|
|
return meta_shaped_texture_get_unobscured_bounds (priv->texture, unobscured_bounds);
|
|
|
|
}
|
|
|
|
|
2014-02-18 21:27:20 -05:00
|
|
|
static void
|
|
|
|
meta_surface_actor_pick (ClutterActor *actor,
|
|
|
|
const ClutterColor *color)
|
|
|
|
{
|
|
|
|
MetaSurfaceActor *self = META_SURFACE_ACTOR (actor);
|
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
|
|
|
|
|
|
|
if (!clutter_actor_should_pick_paint (actor))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* If there is no region then use the regular pick */
|
|
|
|
if (priv->input_region == NULL)
|
|
|
|
CLUTTER_ACTOR_CLASS (meta_surface_actor_parent_class)->pick (actor, color);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int n_rects;
|
|
|
|
float *rectangles;
|
|
|
|
int i;
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglContext *ctx;
|
|
|
|
CoglFramebuffer *fb;
|
|
|
|
CoglColor cogl_color;
|
|
|
|
|
|
|
|
n_rects = cairo_region_num_rectangles (priv->input_region);
|
|
|
|
rectangles = g_alloca (sizeof (float) * 4 * n_rects);
|
|
|
|
|
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
int pos = i * 4;
|
|
|
|
|
|
|
|
cairo_region_get_rectangle (priv->input_region, i, &rect);
|
|
|
|
|
|
|
|
rectangles[pos + 0] = rect.x;
|
|
|
|
rectangles[pos + 1] = rect.y;
|
|
|
|
rectangles[pos + 2] = rect.x + rect.width;
|
|
|
|
rectangles[pos + 3] = rect.y + rect.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
|
|
|
fb = cogl_get_draw_framebuffer ();
|
|
|
|
|
|
|
|
cogl_color_init_from_4ub (&cogl_color, color->red, color->green, color->blue, color->alpha);
|
|
|
|
|
|
|
|
pipeline = cogl_pipeline_new (ctx);
|
|
|
|
cogl_pipeline_set_color (pipeline, &cogl_color);
|
|
|
|
cogl_framebuffer_draw_rectangles (fb, pipeline, rectangles, n_rects);
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_surface_actor_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
MetaSurfaceActor *self = META_SURFACE_ACTOR (object);
|
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
|
|
|
|
|
|
|
g_clear_pointer (&priv->input_region, cairo_region_destroy);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_surface_actor_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2013-10-13 07:47:53 -04:00
|
|
|
static void
|
|
|
|
meta_surface_actor_class_init (MetaSurfaceActorClass *klass)
|
|
|
|
{
|
2014-02-18 21:27:20 -05:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->dispose = meta_surface_actor_dispose;
|
|
|
|
actor_class->pick = meta_surface_actor_pick;
|
|
|
|
|
2013-10-13 07:47:53 -04:00
|
|
|
g_type_class_add_private (klass, sizeof (MetaSurfaceActorPrivate));
|
|
|
|
}
|
|
|
|
|
2013-11-21 16:25:20 -05:00
|
|
|
static void
|
|
|
|
meta_surface_actor_cull_out (MetaCullable *cullable,
|
2013-12-06 20:28:39 -05:00
|
|
|
cairo_region_t *unobscured_region,
|
|
|
|
cairo_region_t *clip_region)
|
2013-11-21 16:25:20 -05:00
|
|
|
{
|
|
|
|
meta_cullable_cull_out_children (cullable, unobscured_region, clip_region);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_surface_actor_reset_culling (MetaCullable *cullable)
|
|
|
|
{
|
|
|
|
meta_cullable_reset_culling_children (cullable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cullable_iface_init (MetaCullableInterface *iface)
|
|
|
|
{
|
|
|
|
iface->cull_out = meta_surface_actor_cull_out;
|
|
|
|
iface->reset_culling = meta_surface_actor_reset_culling;
|
|
|
|
}
|
|
|
|
|
2013-10-13 07:47:53 -04:00
|
|
|
static void
|
|
|
|
meta_surface_actor_init (MetaSurfaceActor *self)
|
|
|
|
{
|
|
|
|
MetaSurfaceActorPrivate *priv;
|
|
|
|
|
|
|
|
priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
|
|
|
META_TYPE_SURFACE_ACTOR,
|
|
|
|
MetaSurfaceActorPrivate);
|
|
|
|
|
2013-12-06 14:19:32 -05:00
|
|
|
priv->texture = META_SHAPED_TEXTURE (meta_shaped_texture_new ());
|
|
|
|
clutter_actor_add_child (CLUTTER_ACTOR (self), CLUTTER_ACTOR (priv->texture));
|
2013-10-13 07:47:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
cairo_surface_t *
|
|
|
|
meta_surface_actor_get_image (MetaSurfaceActor *self,
|
|
|
|
cairo_rectangle_int_t *clip)
|
|
|
|
{
|
|
|
|
return meta_shaped_texture_get_image (self->priv->texture, clip);
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaShapedTexture *
|
|
|
|
meta_surface_actor_get_texture (MetaSurfaceActor *self)
|
|
|
|
{
|
|
|
|
return self->priv->texture;
|
|
|
|
}
|
|
|
|
|
2014-01-22 09:16:56 -05:00
|
|
|
static void
|
|
|
|
update_area (MetaSurfaceActor *self,
|
|
|
|
int x, int y, int width, int height)
|
2013-12-06 11:57:40 -05:00
|
|
|
{
|
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
|
|
|
|
2014-01-22 09:16:56 -05:00
|
|
|
if (meta_is_wayland_compositor ())
|
|
|
|
{
|
|
|
|
struct wl_resource *resource = priv->buffer->resource;
|
|
|
|
struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get (resource);
|
|
|
|
|
|
|
|
if (shm_buffer)
|
|
|
|
{
|
|
|
|
CoglTexture2D *texture = COGL_TEXTURE_2D (priv->buffer->texture);
|
|
|
|
cogl_wayland_texture_set_region_from_shm_buffer (texture, x, y, width, height, shm_buffer, x, y, 0, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoglTexturePixmapX11 *texture = COGL_TEXTURE_PIXMAP_X11 (meta_shaped_texture_get_texture (priv->texture));
|
|
|
|
cogl_texture_pixmap_x11_update_area (texture, x, y, width, height);
|
|
|
|
}
|
2013-12-06 11:57:40 -05:00
|
|
|
}
|
|
|
|
|
2013-10-13 07:47:53 -04:00
|
|
|
gboolean
|
2014-02-05 14:06:32 -05:00
|
|
|
meta_surface_actor_damage_all (MetaSurfaceActor *self)
|
2013-10-13 07:47:53 -04:00
|
|
|
{
|
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
2014-01-22 09:16:56 -05:00
|
|
|
CoglTexture *texture = meta_shaped_texture_get_texture (priv->texture);
|
2013-10-13 07:47:53 -04:00
|
|
|
|
2014-01-22 09:16:56 -05:00
|
|
|
update_area (self, 0, 0, cogl_texture_get_width (texture), cogl_texture_get_height (texture));
|
2014-02-05 14:06:32 -05:00
|
|
|
return meta_shaped_texture_update_area (priv->texture, 0, 0, cogl_texture_get_width (texture), cogl_texture_get_height (texture));
|
2013-12-06 11:57:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2014-01-22 09:16:56 -05:00
|
|
|
meta_surface_actor_damage_area (MetaSurfaceActor *self,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
2014-02-05 14:06:32 -05:00
|
|
|
int height)
|
2013-12-06 11:57:40 -05:00
|
|
|
{
|
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
|
|
|
|
2014-01-22 09:16:56 -05:00
|
|
|
update_area (self, x, y, width, height);
|
2014-02-05 14:06:32 -05:00
|
|
|
return meta_shaped_texture_update_area (priv->texture, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_surface_actor_is_obscured (MetaSurfaceActor *self)
|
|
|
|
{
|
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
|
|
|
return meta_shaped_texture_is_obscured (priv->texture);
|
2013-10-13 07:47:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-22 09:16:56 -05:00
|
|
|
meta_surface_actor_attach_wayland_buffer (MetaSurfaceActor *self,
|
|
|
|
MetaWaylandBuffer *buffer)
|
2013-10-13 07:47:53 -04:00
|
|
|
{
|
2013-12-06 12:00:13 -05:00
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
2014-01-22 09:16:56 -05:00
|
|
|
priv->buffer = buffer;
|
2013-11-21 17:45:05 -05:00
|
|
|
|
2014-01-22 09:16:56 -05:00
|
|
|
if (buffer)
|
|
|
|
meta_shaped_texture_set_texture (priv->texture, buffer->texture);
|
|
|
|
else
|
|
|
|
meta_shaped_texture_set_texture (priv->texture, NULL);
|
2013-11-21 17:45:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-22 09:16:56 -05:00
|
|
|
meta_surface_actor_set_texture (MetaSurfaceActor *self,
|
|
|
|
CoglTexture *texture)
|
2013-12-09 16:01:07 -05:00
|
|
|
{
|
2014-01-22 09:16:56 -05:00
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
|
|
|
meta_shaped_texture_set_texture (priv->texture, texture);
|
2013-12-09 16:01:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-22 09:16:56 -05:00
|
|
|
meta_surface_actor_set_input_region (MetaSurfaceActor *self,
|
|
|
|
cairo_region_t *region)
|
2013-12-09 16:01:07 -05:00
|
|
|
{
|
2014-01-22 09:16:56 -05:00
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
2014-02-18 21:27:20 -05:00
|
|
|
|
|
|
|
if (priv->input_region)
|
|
|
|
cairo_region_destroy (priv->input_region);
|
|
|
|
|
|
|
|
if (region)
|
|
|
|
priv->input_region = cairo_region_reference (region);
|
|
|
|
else
|
|
|
|
priv->input_region = NULL;
|
2013-12-09 16:01:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-22 09:16:56 -05:00
|
|
|
meta_surface_actor_set_opaque_region (MetaSurfaceActor *self,
|
|
|
|
cairo_region_t *region)
|
2013-12-09 16:01:07 -05:00
|
|
|
{
|
2014-01-22 09:16:56 -05:00
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
|
|
|
meta_shaped_texture_set_opaque_region (priv->texture, region);
|
2013-11-21 17:45:05 -05:00
|
|
|
}
|
2013-12-06 14:19:32 -05:00
|
|
|
|
2014-02-18 21:27:20 -05:00
|
|
|
MetaWaylandSurface *
|
|
|
|
meta_surface_actor_get_surface (MetaSurfaceActor *self)
|
|
|
|
{
|
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
|
|
|
return priv->surface;
|
|
|
|
}
|
|
|
|
|
2014-01-22 09:16:56 -05:00
|
|
|
MetaSurfaceActor *
|
2014-02-18 21:27:20 -05:00
|
|
|
meta_surface_actor_new (MetaWaylandSurface *surface)
|
2013-12-06 14:19:32 -05:00
|
|
|
{
|
2014-02-18 21:27:20 -05:00
|
|
|
MetaSurfaceActor *self = g_object_new (META_TYPE_SURFACE_ACTOR, NULL);
|
|
|
|
MetaSurfaceActorPrivate *priv = self->priv;
|
|
|
|
|
|
|
|
priv->surface = surface;
|
|
|
|
|
|
|
|
return self;
|
2013-12-06 14:19:32 -05:00
|
|
|
}
|