2011-05-13 11:54:11 -04:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Intel Corporation.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:clutter-wayland-surface
|
|
|
|
* @Title: ClutterWaylandSurface
|
|
|
|
* @short_description: An actor which displays the content of a client surface
|
|
|
|
*
|
|
|
|
* #ClutterWaylandSurface is an actor for displaying the contents of a client
|
|
|
|
* surface. It is intended to support developers implementing Clutter based
|
|
|
|
* wayland compositors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CLUTTER_ENABLE_EXPERIMENTAL_API
|
|
|
|
|
|
|
|
#include "clutter-wayland-surface.h"
|
|
|
|
|
|
|
|
#include "clutter-actor-private.h"
|
|
|
|
#include "clutter-marshal.h"
|
|
|
|
#include "clutter-paint-volume-private.h"
|
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-backend.h"
|
|
|
|
|
|
|
|
#include <cogl/cogl.h>
|
2012-03-20 09:50:42 -04:00
|
|
|
#include <cogl/cogl-wayland-server.h>
|
2011-05-13 11:54:11 -04:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_SURFACE = 1,
|
2012-01-09 11:13:03 -05:00
|
|
|
PROP_SURFACE_WIDTH,
|
2012-01-10 17:39:53 -05:00
|
|
|
PROP_SURFACE_HEIGHT,
|
|
|
|
PROP_COGL_TEXTURE,
|
|
|
|
PROP_LAST
|
2011-05-13 11:54:11 -04:00
|
|
|
};
|
|
|
|
|
2012-01-10 17:39:53 -05:00
|
|
|
static GParamSpec *obj_props[PROP_LAST];
|
|
|
|
|
2011-05-13 11:54:11 -04:00
|
|
|
enum
|
|
|
|
{
|
2012-01-10 19:08:05 -05:00
|
|
|
QUEUE_DAMAGE_REDRAW,
|
|
|
|
|
2011-05-13 11:54:11 -04:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0, };
|
|
|
|
|
|
|
|
struct _ClutterWaylandSurfacePrivate
|
|
|
|
{
|
|
|
|
struct wl_surface *surface;
|
|
|
|
CoglTexture2D *buffer;
|
|
|
|
int width, height;
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
};
|
|
|
|
|
2013-07-03 09:14:01 -04:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (ClutterWaylandSurface,
|
|
|
|
clutter_wayland_surface,
|
|
|
|
CLUTTER_TYPE_ACTOR)
|
2011-05-13 11:54:11 -04:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_wayland_surface_get_paint_volume (ClutterActor *self,
|
|
|
|
ClutterPaintVolume *volume)
|
|
|
|
{
|
|
|
|
return clutter_paint_volume_set_from_allocation (volume, self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_wayland_surface_queue_damage_redraw (ClutterWaylandSurface *texture,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurfacePrivate *priv = texture->priv;
|
|
|
|
ClutterActor *self = CLUTTER_ACTOR (texture);
|
|
|
|
ClutterActorBox allocation;
|
|
|
|
float scale_x;
|
|
|
|
float scale_y;
|
2011-12-12 11:44:47 -05:00
|
|
|
cairo_rectangle_int_t clip;
|
2011-05-13 11:54:11 -04:00
|
|
|
|
2011-12-12 11:44:47 -05:00
|
|
|
/* NB: clutter_actor_queue_redraw_with_clip expects a box in the actor's
|
2011-05-13 11:54:11 -04:00
|
|
|
* coordinate space so we need to convert from surface coordinates to
|
|
|
|
* actor coordinates...
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Calling clutter_actor_get_allocation_box() is enormously expensive
|
|
|
|
* if the actor has an out-of-date allocation, since it triggers
|
2011-12-12 11:44:47 -05:00
|
|
|
* a full redraw. clutter_actor_queue_redraw_with_clip() would redraw
|
2011-05-13 11:54:11 -04:00
|
|
|
* the whole stage anyways in that case, so just go ahead and do
|
|
|
|
* it here.
|
|
|
|
*/
|
|
|
|
if (!clutter_actor_has_allocation (self))
|
|
|
|
{
|
|
|
|
clutter_actor_queue_redraw (self);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->width == 0 || priv->height == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
clutter_actor_get_allocation_box (self, &allocation);
|
|
|
|
|
|
|
|
scale_x = (allocation.x2 - allocation.x1) / priv->width;
|
|
|
|
scale_y = (allocation.y2 - allocation.y1) / priv->height;
|
|
|
|
|
2011-12-12 11:44:47 -05:00
|
|
|
clip.x = x * scale_x;
|
|
|
|
clip.y = y * scale_y;
|
|
|
|
clip.width = width * scale_x;
|
|
|
|
clip.height = height * scale_y;
|
|
|
|
clutter_actor_queue_redraw_with_clip (self, &clip);
|
2011-05-13 11:54:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_pipeline (ClutterWaylandSurface *self)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurfacePrivate *priv = self->priv;
|
|
|
|
|
|
|
|
if (priv->pipeline)
|
|
|
|
{
|
|
|
|
cogl_object_unref (priv->pipeline);
|
|
|
|
priv->pipeline = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
opacity_change_cb (ClutterWaylandSurface *self)
|
|
|
|
{
|
|
|
|
free_pipeline (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_wayland_surface_init (ClutterWaylandSurface *self)
|
|
|
|
{
|
2013-07-03 09:14:01 -04:00
|
|
|
ClutterWaylandSurfacePrivate *priv;
|
|
|
|
|
|
|
|
priv = clutter_wayland_surface_get_instance_private (self);
|
2011-05-13 11:54:11 -04:00
|
|
|
priv->surface = NULL;
|
|
|
|
priv->width = 0;
|
|
|
|
priv->height = 0;
|
|
|
|
|
|
|
|
self->priv = priv;
|
|
|
|
|
|
|
|
g_signal_connect (self, "notify::opacity", G_CALLBACK (opacity_change_cb), NULL);
|
|
|
|
}
|
|
|
|
|
2012-01-09 14:11:43 -05:00
|
|
|
static void
|
|
|
|
free_surface_buffers (ClutterWaylandSurface *self)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurfacePrivate *priv = self->priv;
|
|
|
|
|
|
|
|
if (priv->buffer)
|
|
|
|
{
|
|
|
|
cogl_object_unref (priv->buffer);
|
|
|
|
priv->buffer = NULL;
|
|
|
|
free_pipeline (self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-13 11:54:11 -04:00
|
|
|
static void
|
|
|
|
clutter_wayland_surface_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurface *self = CLUTTER_WAYLAND_SURFACE (object);
|
|
|
|
ClutterWaylandSurfacePrivate *priv = self->priv;
|
|
|
|
|
2012-01-09 14:11:43 -05:00
|
|
|
free_pipeline (self);
|
|
|
|
free_surface_buffers (self);
|
|
|
|
priv->surface = NULL;
|
|
|
|
|
2011-05-13 11:54:11 -04:00
|
|
|
G_OBJECT_CLASS (clutter_wayland_surface_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_size (ClutterWaylandSurface *self,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurfacePrivate *priv = self->priv;
|
|
|
|
|
|
|
|
if (priv->width != width)
|
|
|
|
{
|
|
|
|
priv->width = width;
|
2012-01-10 17:39:53 -05:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_SURFACE_WIDTH]);
|
2011-05-13 11:54:11 -04:00
|
|
|
}
|
|
|
|
if (priv->height != height)
|
|
|
|
{
|
|
|
|
priv->height = height;
|
2012-01-10 17:39:53 -05:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_SURFACE_HEIGHT]);
|
2011-05-13 11:54:11 -04:00
|
|
|
}
|
2012-01-09 14:03:59 -05:00
|
|
|
|
|
|
|
clutter_actor_set_size (CLUTTER_ACTOR (self), priv->width, priv->height);
|
2011-05-13 11:54:11 -04:00
|
|
|
}
|
|
|
|
|
2012-04-19 11:00:23 -04:00
|
|
|
/**
|
|
|
|
* clutter_wayland_surface_get_surface:
|
|
|
|
* @self: a #ClutterWaylandSurface
|
|
|
|
*
|
|
|
|
* Retrieves a point to the Wayland surface used by the actor.
|
|
|
|
*
|
|
|
|
* Return value: (transfer none): a wl_surface pointer, or %NULL
|
|
|
|
*
|
|
|
|
* Since: 1.10
|
|
|
|
*/
|
2012-01-09 14:16:21 -05:00
|
|
|
struct wl_surface *
|
|
|
|
clutter_wayland_surface_get_surface (ClutterWaylandSurface *self)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurfacePrivate *priv = self->priv;
|
|
|
|
return priv->surface;
|
|
|
|
}
|
|
|
|
|
2012-04-19 11:00:23 -04:00
|
|
|
/**
|
|
|
|
* clutter_wayland_surface_set_surface:
|
|
|
|
* @self: a #ClutterWaylandSurface
|
|
|
|
* @surface: a Wayland wl_surface pointer
|
|
|
|
*
|
|
|
|
* Sets the Wayland surface to be used by the actor.
|
|
|
|
*
|
|
|
|
* Since: 1.10
|
|
|
|
*/
|
2012-01-09 14:16:21 -05:00
|
|
|
void
|
2011-05-13 11:54:11 -04:00
|
|
|
clutter_wayland_surface_set_surface (ClutterWaylandSurface *self,
|
|
|
|
struct wl_surface *surface)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurfacePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_WAYLAND_IS_SURFACE (self));
|
|
|
|
|
|
|
|
priv = self->priv;
|
|
|
|
|
2012-01-09 14:14:09 -05:00
|
|
|
if (priv->surface == surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->surface)
|
|
|
|
{
|
|
|
|
free_pipeline (self);
|
|
|
|
free_surface_buffers (self);
|
2012-01-10 19:08:05 -05:00
|
|
|
g_signal_emit (self, signals[QUEUE_DAMAGE_REDRAW],
|
|
|
|
0,
|
|
|
|
0, 0, priv->width, priv->height);
|
2012-01-09 14:14:09 -05:00
|
|
|
}
|
|
|
|
|
2011-05-13 11:54:11 -04:00
|
|
|
priv->surface = surface;
|
|
|
|
|
|
|
|
/* XXX: should we freeze/thaw notifications? */
|
|
|
|
|
2012-01-10 17:39:53 -05:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_SURFACE]);
|
2011-05-13 11:54:11 -04:00
|
|
|
|
|
|
|
/* We have to wait until the next attach event to find out the surface
|
|
|
|
* geometry... */
|
|
|
|
set_size (self, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_wayland_surface_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurface *self = CLUTTER_WAYLAND_SURFACE (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_SURFACE:
|
|
|
|
clutter_wayland_surface_set_surface (self, g_value_get_pointer (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_wayland_surface_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurface *self = CLUTTER_WAYLAND_SURFACE (object);
|
|
|
|
ClutterWaylandSurfacePrivate *priv = self->priv;
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_SURFACE:
|
|
|
|
g_value_set_pointer (value, priv->surface);
|
|
|
|
break;
|
2012-01-09 11:13:03 -05:00
|
|
|
case PROP_SURFACE_WIDTH:
|
2011-05-13 11:54:11 -04:00
|
|
|
g_value_set_uint (value, priv->width);
|
|
|
|
break;
|
2012-01-09 11:13:03 -05:00
|
|
|
case PROP_SURFACE_HEIGHT:
|
2011-05-13 11:54:11 -04:00
|
|
|
g_value_set_uint (value, priv->height);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_wayland_surface_paint (ClutterActor *self)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurfacePrivate *priv;
|
|
|
|
ClutterActorBox box;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_WAYLAND_IS_SURFACE (self));
|
|
|
|
|
|
|
|
priv = CLUTTER_WAYLAND_SURFACE (self)->priv;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (priv->pipeline == NULL))
|
|
|
|
{
|
2012-02-21 08:22:17 -05:00
|
|
|
CoglContext *ctx =
|
|
|
|
clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
2011-05-13 11:54:11 -04:00
|
|
|
guint8 paint_opacity = clutter_actor_get_paint_opacity (self);
|
|
|
|
|
2012-02-21 08:22:17 -05:00
|
|
|
priv->pipeline = cogl_pipeline_new (ctx);
|
2011-05-13 11:54:11 -04:00
|
|
|
cogl_pipeline_set_color4ub (priv->pipeline,
|
|
|
|
paint_opacity,
|
|
|
|
paint_opacity,
|
|
|
|
paint_opacity,
|
|
|
|
paint_opacity);
|
|
|
|
cogl_pipeline_set_layer_texture (priv->pipeline, 0,
|
|
|
|
COGL_TEXTURE (priv->buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_set_source (priv->pipeline);
|
|
|
|
clutter_actor_get_allocation_box (self, &box);
|
|
|
|
cogl_rectangle (0, 0, box.x2 - box.x1, box.y2 - box.y1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_wayland_surface_get_preferred_width (ClutterActor *self,
|
|
|
|
gfloat for_height,
|
|
|
|
gfloat *min_width_p,
|
|
|
|
gfloat *natural_width_p)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurfacePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_WAYLAND_IS_SURFACE (self));
|
|
|
|
|
|
|
|
priv = CLUTTER_WAYLAND_SURFACE (self)->priv;
|
|
|
|
|
|
|
|
if (min_width_p)
|
|
|
|
*min_width_p = 0;
|
|
|
|
|
|
|
|
if (natural_width_p)
|
|
|
|
*natural_width_p = priv->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_wayland_surface_get_preferred_height (ClutterActor *self,
|
|
|
|
gfloat for_width,
|
|
|
|
gfloat *min_height_p,
|
|
|
|
gfloat *natural_height_p)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurfacePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_WAYLAND_IS_SURFACE (self));
|
|
|
|
|
|
|
|
priv = CLUTTER_WAYLAND_SURFACE (self)->priv;
|
|
|
|
|
|
|
|
if (min_height_p)
|
|
|
|
*min_height_p = 0;
|
|
|
|
|
|
|
|
if (natural_height_p)
|
|
|
|
*natural_height_p = priv->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_wayland_surface_has_overlaps (ClutterActor *self)
|
|
|
|
{
|
|
|
|
/* Rectangles never need an offscreen redirect because there are
|
|
|
|
never any overlapping primitives */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_wayland_surface_class_init (ClutterWaylandSurfaceClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
|
|
|
GParamSpec *pspec;
|
|
|
|
|
|
|
|
actor_class->get_paint_volume = clutter_wayland_surface_get_paint_volume;
|
|
|
|
actor_class->paint = clutter_wayland_surface_paint;
|
|
|
|
actor_class->get_preferred_width =
|
|
|
|
clutter_wayland_surface_get_preferred_width;
|
|
|
|
actor_class->get_preferred_height =
|
|
|
|
clutter_wayland_surface_get_preferred_height;
|
|
|
|
actor_class->has_overlaps = clutter_wayland_surface_has_overlaps;
|
|
|
|
|
|
|
|
object_class->dispose = clutter_wayland_surface_dispose;
|
|
|
|
object_class->set_property = clutter_wayland_surface_set_property;
|
|
|
|
object_class->get_property = clutter_wayland_surface_get_property;
|
|
|
|
|
|
|
|
pspec = g_param_spec_pointer ("surface",
|
|
|
|
P_("Surface"),
|
|
|
|
P_("The underlying wayland surface"),
|
|
|
|
CLUTTER_PARAM_READWRITE|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY);
|
2012-01-10 17:39:53 -05:00
|
|
|
obj_props[PROP_SURFACE] = pspec;
|
2011-05-13 11:54:11 -04:00
|
|
|
g_object_class_install_property (object_class, PROP_SURFACE, pspec);
|
|
|
|
|
2012-01-09 11:13:03 -05:00
|
|
|
pspec = g_param_spec_uint ("surface-width",
|
2011-05-13 11:54:11 -04:00
|
|
|
P_("Surface width"),
|
|
|
|
P_("The width of the underlying wayland surface"),
|
|
|
|
0, G_MAXUINT,
|
|
|
|
0,
|
|
|
|
G_PARAM_READABLE);
|
2012-01-10 17:39:53 -05:00
|
|
|
obj_props[PROP_SURFACE_WIDTH] = pspec;
|
2012-01-09 11:13:03 -05:00
|
|
|
g_object_class_install_property (object_class, PROP_SURFACE_WIDTH, pspec);
|
2011-05-13 11:54:11 -04:00
|
|
|
|
2012-01-09 11:13:03 -05:00
|
|
|
pspec = g_param_spec_uint ("surface-height",
|
2011-05-13 11:54:11 -04:00
|
|
|
P_("Surface height"),
|
|
|
|
P_("The height of the underlying wayland surface"),
|
|
|
|
0, G_MAXUINT,
|
|
|
|
0,
|
|
|
|
G_PARAM_READABLE);
|
2012-01-10 17:39:53 -05:00
|
|
|
obj_props[PROP_SURFACE_HEIGHT] = pspec;
|
2012-01-09 11:13:03 -05:00
|
|
|
g_object_class_install_property (object_class, PROP_SURFACE_HEIGHT, pspec);
|
2012-01-10 17:39:53 -05:00
|
|
|
|
|
|
|
pspec = g_param_spec_boxed ("cogl-texture",
|
|
|
|
P_("Cogl Texture"),
|
|
|
|
P_("The underlying Cogl texture handle used to draw this actor"),
|
|
|
|
COGL_TYPE_HANDLE,
|
|
|
|
CLUTTER_PARAM_READWRITE);
|
|
|
|
obj_props[PROP_COGL_TEXTURE] = pspec;
|
|
|
|
g_object_class_install_property (object_class, PROP_COGL_TEXTURE, pspec);
|
2012-01-10 19:08:05 -05:00
|
|
|
|
|
|
|
/**
|
2012-04-19 11:00:23 -04:00
|
|
|
* ClutterWaylandSurface::queue-damage-redraw:
|
2012-01-10 19:08:05 -05:00
|
|
|
* @texture: the object which received the signal
|
|
|
|
* @x: The top left x position of the damage region
|
|
|
|
* @y: The top left y position of the damage region
|
|
|
|
* @width: The width of the damage region
|
|
|
|
* @height: The height of the damage region
|
|
|
|
*
|
|
|
|
* ::queue-damage-redraw is emitted to notify that some sub-region
|
|
|
|
* of the texture has been changed. This usually means a redraw
|
|
|
|
* needs to be queued for the actor.
|
|
|
|
*
|
|
|
|
* The default handler will queue a clipped redraw in response to
|
|
|
|
* the damage, using the assumption that the pixmap is being painted
|
|
|
|
* to a rectangle covering the transformed allocation of the actor.
|
|
|
|
* If you sub-class and change the paint method so this isn't true
|
|
|
|
* then you must also provide your own damage signal handler to
|
|
|
|
* queue a redraw that blocks this default behaviour.
|
|
|
|
*
|
|
|
|
* Since: 1.10
|
|
|
|
*/
|
|
|
|
signals[QUEUE_DAMAGE_REDRAW] =
|
|
|
|
g_signal_new (g_intern_static_string ("queue-damage-redraw"),
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (ClutterWaylandSurfaceClass, queue_damage_redraw),
|
|
|
|
NULL, NULL,
|
|
|
|
_clutter_marshal_VOID__INT_INT_INT_INT,
|
|
|
|
G_TYPE_NONE, 4,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT);
|
|
|
|
klass->queue_damage_redraw = clutter_wayland_surface_queue_damage_redraw;
|
2011-05-13 11:54:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_wayland_surface_new:
|
|
|
|
* @surface: the Wayland surface this actor should represent
|
|
|
|
*
|
|
|
|
* Creates a new #ClutterWaylandSurface for @surface
|
|
|
|
*
|
|
|
|
* Return value: A new #ClutterWaylandSurface representing @surface
|
|
|
|
*
|
|
|
|
* Since: 1.8
|
|
|
|
* Stability: unstable
|
|
|
|
*/
|
|
|
|
ClutterActor *
|
|
|
|
clutter_wayland_surface_new (struct wl_surface *surface)
|
|
|
|
{
|
|
|
|
ClutterActor *actor;
|
|
|
|
|
|
|
|
actor = g_object_new (CLUTTER_WAYLAND_TYPE_SURFACE,
|
|
|
|
"surface", surface,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_wayland_surface_attach_buffer:
|
|
|
|
* @self: A #ClutterWaylandSurface actor
|
2013-07-04 08:28:45 -04:00
|
|
|
* @buffer: A compositor side resource representing a wl_buffer
|
2011-05-13 11:54:11 -04:00
|
|
|
* @error: A #GError
|
|
|
|
*
|
|
|
|
* This associates a client's buffer with the #ClutterWaylandSurface
|
|
|
|
* actor @self. This will automatically result in @self being re-drawn
|
|
|
|
* with the new buffer contents.
|
|
|
|
*
|
|
|
|
* Since: 1.8
|
|
|
|
* Stability: unstable
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
clutter_wayland_surface_attach_buffer (ClutterWaylandSurface *self,
|
2013-07-04 08:28:45 -04:00
|
|
|
struct wl_resource *buffer,
|
2011-05-13 11:54:11 -04:00
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurfacePrivate *priv;
|
|
|
|
ClutterBackend *backend = clutter_get_default_backend ();
|
|
|
|
CoglContext *context = clutter_backend_get_cogl_context (backend);
|
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_WAYLAND_IS_SURFACE (self), TRUE);
|
|
|
|
|
|
|
|
priv = self->priv;
|
|
|
|
|
|
|
|
free_surface_buffers (self);
|
|
|
|
|
|
|
|
priv->buffer =
|
|
|
|
cogl_wayland_texture_2d_new_from_buffer (context, buffer, error);
|
|
|
|
|
2012-01-10 17:39:53 -05:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_COGL_TEXTURE]);
|
|
|
|
|
2012-02-13 08:20:02 -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 ever queue a redraw in response to
|
|
|
|
* surface damage. */
|
|
|
|
|
2011-05-13 11:54:11 -04:00
|
|
|
if (!priv->buffer)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-07-04 08:28:45 -04:00
|
|
|
set_size (self,
|
|
|
|
cogl_texture_get_width (COGL_TEXTURE (priv->buffer)),
|
|
|
|
cogl_texture_get_height (COGL_TEXTURE (priv->buffer)));
|
|
|
|
|
2011-05-13 11:54:11 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_wayland_surface_damage_buffer:
|
|
|
|
* @self: A #ClutterWaylandSurface actor
|
2013-07-04 08:28:45 -04:00
|
|
|
* @buffer: A wayland resource for a buffer
|
2011-05-13 11:54:11 -04:00
|
|
|
* @x: The x coordinate of the damaged rectangle
|
|
|
|
* @y: The y coordinate of the damaged rectangle
|
|
|
|
* @width: The width of the damaged rectangle
|
|
|
|
* @height: The height of the damaged rectangle
|
|
|
|
*
|
|
|
|
* This marks a region of the given @buffer has having been changed by
|
|
|
|
* the client. This will automatically result in the corresponding damaged
|
|
|
|
* region of the actor @self being redrawn.
|
|
|
|
*
|
|
|
|
* If multiple regions are changed then this should be called multiple
|
|
|
|
* times with different damage rectangles.
|
|
|
|
*
|
|
|
|
* Since: 1.8
|
|
|
|
* Stability: unstable
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_wayland_surface_damage_buffer (ClutterWaylandSurface *self,
|
2013-07-04 08:28:45 -04:00
|
|
|
struct wl_resource *buffer,
|
2011-05-13 11:54:11 -04:00
|
|
|
gint32 x,
|
|
|
|
gint32 y,
|
|
|
|
gint32 width,
|
|
|
|
gint32 height)
|
|
|
|
{
|
|
|
|
ClutterWaylandSurfacePrivate *priv;
|
2013-07-04 08:28:45 -04:00
|
|
|
struct wl_shm_buffer *shm_buffer;
|
2011-05-13 11:54:11 -04:00
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_WAYLAND_IS_SURFACE (self));
|
|
|
|
|
|
|
|
priv = self->priv;
|
|
|
|
|
2013-07-04 08:28:45 -04:00
|
|
|
shm_buffer = wl_shm_buffer_get (buffer);
|
|
|
|
|
|
|
|
if (priv->buffer && shm_buffer)
|
2011-05-13 11:54:11 -04:00
|
|
|
{
|
|
|
|
CoglPixelFormat format;
|
|
|
|
|
2013-07-04 08:28:45 -04:00
|
|
|
switch (wl_shm_buffer_get_format (shm_buffer))
|
2011-05-13 11:54:11 -04:00
|
|
|
{
|
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
2012-01-12 15:36:16 -05:00
|
|
|
case WL_SHM_FORMAT_ARGB8888:
|
2011-05-13 11:54:11 -04:00
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_8888_PRE;
|
|
|
|
break;
|
2012-01-12 15:36:16 -05:00
|
|
|
case WL_SHM_FORMAT_XRGB8888:
|
2011-05-13 11:54:11 -04:00
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_8888;
|
|
|
|
break;
|
|
|
|
#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2012-01-12 15:36:16 -05:00
|
|
|
case WL_SHM_FORMAT_ARGB8888:
|
2011-05-13 11:54:11 -04:00
|
|
|
format = COGL_PIXEL_FORMAT_BGRA_8888_PRE;
|
|
|
|
break;
|
2012-01-12 15:36:16 -05:00
|
|
|
case WL_SHM_FORMAT_XRGB8888:
|
2011-05-13 11:54:11 -04:00
|
|
|
format = COGL_PIXEL_FORMAT_BGRA_8888;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
g_warn_if_reached ();
|
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_8888;
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_texture_set_region (COGL_TEXTURE (priv->buffer),
|
|
|
|
x, y,
|
|
|
|
x, y,
|
|
|
|
width, height,
|
|
|
|
width, height,
|
|
|
|
format,
|
2013-07-04 08:28:45 -04:00
|
|
|
wl_shm_buffer_get_stride (shm_buffer),
|
|
|
|
wl_shm_buffer_get_data (shm_buffer));
|
2011-05-13 11:54:11 -04:00
|
|
|
}
|
|
|
|
|
2012-01-10 19:08:05 -05:00
|
|
|
g_signal_emit (self, signals[QUEUE_DAMAGE_REDRAW],
|
|
|
|
0,
|
|
|
|
x, y, width, height);
|
2011-05-13 11:54:11 -04:00
|
|
|
}
|
2012-01-10 17:39:53 -05:00
|
|
|
|
2012-04-19 11:00:23 -04:00
|
|
|
/**
|
|
|
|
* clutter_wayland_surface_get_cogl_texture:
|
|
|
|
* @self: a #ClutterWaylandSurface
|
|
|
|
*
|
|
|
|
* Retrieves the Cogl texture with the contents of the Wayland surface.
|
|
|
|
*
|
|
|
|
* Return value: (transfer none): a Cogl texture, or %NULL
|
|
|
|
*
|
|
|
|
* Since: 1.10
|
|
|
|
*/
|
2012-01-10 17:39:53 -05:00
|
|
|
CoglTexture *
|
|
|
|
clutter_wayland_surface_get_cogl_texture (ClutterWaylandSurface *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_WAYLAND_IS_SURFACE (self), NULL);
|
|
|
|
|
|
|
|
return COGL_TEXTURE (self->priv->buffer);
|
|
|
|
}
|