shaped-texture: Take a ClutterContext when constructing

This will be used to fetch the corresponding pipeline cache.

This also means some minor reshuffling in MetaSurfaceActor to create it
after constructing the object.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3433>
This commit is contained in:
Jonas Ådahl 2023-11-08 15:18:54 +08:00 committed by Sebastian Wick
parent 6c34055cae
commit b538f4b999
3 changed files with 94 additions and 22 deletions

View File

@ -27,7 +27,7 @@
#include "backends/meta-monitor-manager-private.h" #include "backends/meta-monitor-manager-private.h"
#include "meta/meta-shaped-texture.h" #include "meta/meta-shaped-texture.h"
MetaShapedTexture * meta_shaped_texture_new (void); MetaShapedTexture * meta_shaped_texture_new (ClutterContext *clutter_context);
void meta_shaped_texture_set_texture (MetaShapedTexture *stex, void meta_shaped_texture_set_texture (MetaShapedTexture *stex,
MetaMultiTexture *multi_texture); MetaMultiTexture *multi_texture);
void meta_shaped_texture_set_is_y_inverted (MetaShapedTexture *stex, void meta_shaped_texture_set_is_y_inverted (MetaShapedTexture *stex,

View File

@ -51,6 +51,17 @@ static void meta_shaped_texture_dispose (GObject *object);
static void clutter_content_iface_init (ClutterContentInterface *iface); static void clutter_content_iface_init (ClutterContentInterface *iface);
enum
{
PROP_0,
PROP_CLUTTER_CONTEXT,
N_PROPS
};
static GParamSpec *obj_props[N_PROPS];
enum enum
{ {
SIZE_CHANGED, SIZE_CHANGED,
@ -69,6 +80,8 @@ struct _MetaShapedTexture
{ {
GObject parent; GObject parent;
ClutterContext *clutter_context;
MetaMultiTexture *texture; MetaMultiTexture *texture;
CoglTexture *mask_texture; CoglTexture *mask_texture;
CoglSnippet *snippet; CoglSnippet *snippet;
@ -114,12 +127,50 @@ G_DEFINE_TYPE_WITH_CODE (MetaShapedTexture, meta_shaped_texture, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTENT, G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTENT,
clutter_content_iface_init)); clutter_content_iface_init));
static void
meta_shaped_texture_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MetaShapedTexture *stex = META_SHAPED_TEXTURE (object);
switch (prop_id)
{
case PROP_CLUTTER_CONTEXT:
stex->clutter_context = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
meta_shaped_texture_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MetaShapedTexture *stex = META_SHAPED_TEXTURE (object);
switch (prop_id)
{
case PROP_CLUTTER_CONTEXT:
g_value_set_object (value, stex->clutter_context);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void static void
meta_shaped_texture_class_init (MetaShapedTextureClass *klass) meta_shaped_texture_class_init (MetaShapedTextureClass *klass)
{ {
GObjectClass *object_class = (GObjectClass *) klass; GObjectClass *object_class = (GObjectClass *) klass;
object_class->dispose = meta_shaped_texture_dispose; object_class->dispose = meta_shaped_texture_dispose;
object_class->set_property = meta_shaped_texture_set_property;
object_class->get_property = meta_shaped_texture_get_property;
signals[SIZE_CHANGED] = g_signal_new ("size-changed", signals[SIZE_CHANGED] = g_signal_new ("size-changed",
G_TYPE_FROM_CLASS (klass), G_TYPE_FROM_CLASS (klass),
@ -127,6 +178,14 @@ meta_shaped_texture_class_init (MetaShapedTextureClass *klass)
0, 0,
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
obj_props[PROP_CLUTTER_CONTEXT] =
g_param_spec_object ("clutter-context", NULL, NULL,
CLUTTER_TYPE_CONTEXT,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, obj_props);
} }
static void static void
@ -1512,9 +1571,11 @@ meta_shaped_texture_set_fallback_size (MetaShapedTexture *stex,
} }
MetaShapedTexture * MetaShapedTexture *
meta_shaped_texture_new (void) meta_shaped_texture_new (ClutterContext *clutter_context)
{ {
return g_object_new (META_TYPE_SHAPED_TEXTURE, NULL); return g_object_new (META_TYPE_SHAPED_TEXTURE,
"clutter-context", clutter_context,
NULL);
} }
/** /**

View File

@ -250,6 +250,35 @@ meta_surface_actor_get_property (GObject *object,
} }
} }
static void
texture_size_changed (MetaShapedTexture *texture,
MetaSurfaceActor *surface_actor)
{
g_signal_emit (surface_actor, signals[SIZE_CHANGED], 0);
}
static void
meta_surface_actor_constructed (GObject *object)
{
MetaSurfaceActor *surface_actor = META_SURFACE_ACTOR (object);
MetaSurfaceActorPrivate *priv =
meta_surface_actor_get_instance_private (surface_actor);
ClutterContext *clutter_context =
clutter_actor_get_context (CLUTTER_ACTOR (surface_actor));
priv->is_obscured = TRUE;
priv->texture = meta_shaped_texture_new (clutter_context);
g_signal_connect_object (priv->texture, "size-changed",
G_CALLBACK (texture_size_changed), surface_actor,
G_CONNECT_DEFAULT);
clutter_actor_set_content (CLUTTER_ACTOR (surface_actor),
CLUTTER_CONTENT (priv->texture));
clutter_actor_set_request_mode (CLUTTER_ACTOR (surface_actor),
CLUTTER_REQUEST_CONTENT_SIZE);
G_OBJECT_CLASS (meta_surface_actor_parent_class)->constructed (object);
}
static void static void
meta_surface_actor_dispose (GObject *object) meta_surface_actor_dispose (GObject *object)
{ {
@ -271,6 +300,7 @@ meta_surface_actor_class_init (MetaSurfaceActorClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
object_class->constructed = meta_surface_actor_constructed;
object_class->dispose = meta_surface_actor_dispose; object_class->dispose = meta_surface_actor_dispose;
object_class->get_property = meta_surface_actor_get_property; object_class->get_property = meta_surface_actor_get_property;
@ -369,28 +399,9 @@ cullable_iface_init (MetaCullableInterface *iface)
iface->cull_unobscured = meta_surface_actor_cull_unobscured; iface->cull_unobscured = meta_surface_actor_cull_unobscured;
} }
static void
texture_size_changed (MetaShapedTexture *texture,
gpointer user_data)
{
MetaSurfaceActor *actor = META_SURFACE_ACTOR (user_data);
g_signal_emit (actor, signals[SIZE_CHANGED], 0);
}
static void static void
meta_surface_actor_init (MetaSurfaceActor *self) meta_surface_actor_init (MetaSurfaceActor *self)
{ {
MetaSurfaceActorPrivate *priv =
meta_surface_actor_get_instance_private (self);
priv->is_obscured = TRUE;
priv->texture = meta_shaped_texture_new ();
g_signal_connect_object (priv->texture, "size-changed",
G_CALLBACK (texture_size_changed), self, 0);
clutter_actor_set_content (CLUTTER_ACTOR (self),
CLUTTER_CONTENT (priv->texture));
clutter_actor_set_request_mode (CLUTTER_ACTOR (self),
CLUTTER_REQUEST_CONTENT_SIZE);
} }
MetaShapedTexture * MetaShapedTexture *