offscreen-effect: Use macros for subclassing boilerplate

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3387>
This commit is contained in:
Bilal Elmoussaoui 2023-11-10 17:23:13 +01:00
parent 0760e90b0d
commit 99501482df
3 changed files with 53 additions and 45 deletions

View File

@ -43,7 +43,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterFlowLayout, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterGridLayout, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterInputDevice, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterInterval, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterOffscreenEffect, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPageTurnEffect, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterScrollActor, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterShaderEffect, g_object_unref)

View File

@ -103,7 +103,7 @@
#include "clutter/clutter-paint-volume-private.h"
#include "clutter/clutter-actor-box-private.h"
struct _ClutterOffscreenEffectPrivate
typedef struct _ClutterOffscreenEffectPrivate
{
CoglOffscreen *offscreen;
CoglPipeline *pipeline;
@ -123,7 +123,7 @@ struct _ClutterOffscreenEffectPrivate
int target_height;
gulong purge_handler_id;
};
} ClutterOffscreenEffectPrivate;
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ClutterOffscreenEffect,
clutter_offscreen_effect,
@ -134,7 +134,8 @@ clutter_offscreen_effect_set_actor (ClutterActorMeta *meta,
ClutterActor *actor)
{
ClutterOffscreenEffect *self = CLUTTER_OFFSCREEN_EFFECT (meta);
ClutterOffscreenEffectPrivate *priv = self->priv;
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (self);
ClutterActorMetaClass *meta_class;
meta_class = CLUTTER_ACTOR_META_CLASS (clutter_offscreen_effect_parent_class);
@ -162,9 +163,11 @@ static void
ensure_pipeline_filter_for_scale (ClutterOffscreenEffect *self,
float resource_scale)
{
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (self);
CoglPipelineFilter filter;
if (!self->priv->pipeline)
if (!priv->pipeline)
return;
/* If no fractional scaling is set, we're always going to render the texture
@ -178,7 +181,7 @@ ensure_pipeline_filter_for_scale (ClutterOffscreenEffect *self,
else
filter = COGL_PIPELINE_FILTER_LINEAR;
cogl_pipeline_set_layer_filters (self->priv->pipeline, 0 /* layer_index */,
cogl_pipeline_set_layer_filters (priv->pipeline, 0 /* layer_index */,
filter, filter);
}
@ -186,7 +189,8 @@ static CoglPipeline *
clutter_offscreen_effect_real_create_pipeline (ClutterOffscreenEffect *effect,
CoglTexture *texture)
{
ClutterOffscreenEffectPrivate *priv = effect->priv;
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (effect);
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
CoglPipeline *pipeline;
@ -204,7 +208,10 @@ clutter_offscreen_effect_real_create_pipeline (ClutterOffscreenEffect *effect,
static void
video_memory_purged (ClutterOffscreenEffect *self)
{
g_clear_object (&self->priv->offscreen);
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (self);
g_clear_object (&priv->offscreen);
}
static gboolean
@ -216,7 +223,8 @@ update_fbo (ClutterEffect *effect,
ClutterOffscreenEffect *self = CLUTTER_OFFSCREEN_EFFECT (effect);
ClutterOffscreenEffectClass *offscreen_class =
CLUTTER_OFFSCREEN_EFFECT_GET_CLASS (self);
ClutterOffscreenEffectPrivate *priv = self->priv;
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (self);
ClutterActor *stage_actor;
CoglOffscreen *offscreen;
g_autoptr (GError) error = NULL;
@ -251,10 +259,10 @@ update_fbo (ClutterEffect *effect,
if (priv->target_width == target_width &&
priv->target_height == target_height &&
priv->offscreen != NULL)
{
ensure_pipeline_filter_for_scale (self, resource_scale);
return TRUE;
}
{
ensure_pipeline_filter_for_scale (self, resource_scale);
return TRUE;
}
g_clear_object (&priv->texture);
g_clear_object (&priv->offscreen);
@ -296,7 +304,8 @@ clutter_offscreen_effect_pre_paint (ClutterEffect *effect,
ClutterPaintContext *paint_context)
{
ClutterOffscreenEffect *self = CLUTTER_OFFSCREEN_EFFECT (effect);
ClutterOffscreenEffectPrivate *priv = self->priv;
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (self);
CoglFramebuffer *offscreen;
ClutterActorBox raw_box, box;
ClutterActor *stage;
@ -412,7 +421,8 @@ clutter_offscreen_effect_real_paint_target (ClutterOffscreenEffect *effect,
ClutterPaintNode *node,
ClutterPaintContext *paint_context)
{
ClutterOffscreenEffectPrivate *priv = effect->priv;
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (effect);
ClutterPaintNode *pipeline_node;
guint8 paint_opacity;
@ -449,7 +459,8 @@ clutter_offscreen_effect_paint_texture (ClutterOffscreenEffect *effect,
ClutterPaintNode *node,
ClutterPaintContext *paint_context)
{
ClutterOffscreenEffectPrivate *priv = effect->priv;
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (effect);
graphene_matrix_t transform;
float unscale;
@ -485,7 +496,8 @@ clutter_offscreen_effect_post_paint (ClutterEffect *effect,
ClutterPaintContext *paint_context)
{
ClutterOffscreenEffect *self = CLUTTER_OFFSCREEN_EFFECT (effect);
ClutterOffscreenEffectPrivate *priv = self->priv;
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (self);
g_warn_if_fail (priv->offscreen);
g_warn_if_fail (priv->pipeline);
@ -499,7 +511,8 @@ add_actor_node (ClutterOffscreenEffect *offscreen_effect,
ClutterPaintNode *node,
int paint_opacity)
{
ClutterOffscreenEffectPrivate *priv = offscreen_effect->priv;
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (offscreen_effect);
ClutterPaintNode *actor_node;
actor_node = clutter_actor_node_new (priv->actor, paint_opacity);
@ -514,7 +527,8 @@ clutter_offscreen_effect_paint_node (ClutterEffect *effect,
ClutterEffectPaintFlags flags)
{
ClutterOffscreenEffect *offscreen_effect = CLUTTER_OFFSCREEN_EFFECT (effect);
ClutterOffscreenEffectPrivate *priv = offscreen_effect->priv;
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (offscreen_effect);
ClutterPaintNode *layer_node;
CoglFramebuffer *fb;
@ -535,7 +549,8 @@ clutter_offscreen_effect_paint (ClutterEffect *effect,
ClutterEffectPaintFlags flags)
{
ClutterOffscreenEffect *self = CLUTTER_OFFSCREEN_EFFECT (effect);
ClutterOffscreenEffectPrivate *priv = self->priv;
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (self);
ClutterEffectClass *parent_class =
CLUTTER_EFFECT_CLASS (clutter_offscreen_effect_parent_class);
@ -562,7 +577,8 @@ clutter_offscreen_effect_set_enabled (ClutterActorMeta *meta,
ClutterActorMetaClass *parent_class =
CLUTTER_ACTOR_META_CLASS (clutter_offscreen_effect_parent_class);
ClutterOffscreenEffect *offscreen_effect = CLUTTER_OFFSCREEN_EFFECT (meta);
ClutterOffscreenEffectPrivate *priv = offscreen_effect->priv;
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (offscreen_effect);
g_clear_object (&priv->offscreen);
@ -573,7 +589,8 @@ static void
clutter_offscreen_effect_finalize (GObject *gobject)
{
ClutterOffscreenEffect *self = CLUTTER_OFFSCREEN_EFFECT (gobject);
ClutterOffscreenEffectPrivate *priv = self->priv;
ClutterOffscreenEffectPrivate *priv =
clutter_offscreen_effect_get_instance_private (self);
g_clear_object (&priv->offscreen);
g_clear_object (&priv->texture);
@ -607,7 +624,6 @@ clutter_offscreen_effect_class_init (ClutterOffscreenEffectClass *klass)
static void
clutter_offscreen_effect_init (ClutterOffscreenEffect *self)
{
self->priv = clutter_offscreen_effect_get_instance_private (self);
}
/**
@ -631,10 +647,13 @@ clutter_offscreen_effect_init (ClutterOffscreenEffect *self)
CoglTexture*
clutter_offscreen_effect_get_texture (ClutterOffscreenEffect *effect)
{
ClutterOffscreenEffectPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_OFFSCREEN_EFFECT (effect),
NULL);
return effect->priv->texture;
priv = clutter_offscreen_effect_get_instance_private (effect);
return priv->texture;
}
/**
@ -654,10 +673,13 @@ clutter_offscreen_effect_get_texture (ClutterOffscreenEffect *effect)
CoglPipeline *
clutter_offscreen_effect_get_pipeline (ClutterOffscreenEffect *effect)
{
ClutterOffscreenEffectPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_OFFSCREEN_EFFECT (effect),
NULL);
return effect->priv->pipeline;
priv = clutter_offscreen_effect_get_instance_private (effect);
return priv->pipeline;
}
/**
@ -730,7 +752,7 @@ clutter_offscreen_effect_get_target_size (ClutterOffscreenEffect *effect,
g_return_val_if_fail (CLUTTER_IS_OFFSCREEN_EFFECT (effect), FALSE);
priv = effect->priv;
priv = clutter_offscreen_effect_get_instance_private (effect);
if (priv->texture == NULL)
return FALSE;

View File

@ -34,23 +34,13 @@
G_BEGIN_DECLS
#define CLUTTER_TYPE_OFFSCREEN_EFFECT (clutter_offscreen_effect_get_type ())
#define CLUTTER_OFFSCREEN_EFFECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CLUTTER_TYPE_OFFSCREEN_EFFECT, ClutterOffscreenEffect))
#define CLUTTER_IS_OFFSCREEN_EFFECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CLUTTER_TYPE_OFFSCREEN_EFFECT))
#define CLUTTER_OFFSCREEN_EFFECT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), CLUTTER_TYPE_OFFSCREEN_EFFECT, ClutterOffscreenEffectClass))
#define CLUTTER_IS_OFFSCREEN_EFFECT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CLUTTER_TYPE_OFFSCREEN_EFFECT))
#define CLUTTER_OFFSCREEN_EFFECT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CLUTTER_TYPE_OFFSCREEN_EFFECT, ClutterOffscreenEffectClass))
typedef struct _ClutterOffscreenEffect ClutterOffscreenEffect;
typedef struct _ClutterOffscreenEffectPrivate ClutterOffscreenEffectPrivate;
typedef struct _ClutterOffscreenEffectClass ClutterOffscreenEffectClass;
struct _ClutterOffscreenEffect
{
/*< private >*/
ClutterEffect parent_instance;
ClutterOffscreenEffectPrivate *priv;
};
CLUTTER_EXPORT
G_DECLARE_DERIVABLE_TYPE (ClutterOffscreenEffect,
clutter_offscreen_effect,
CLUTTER,
OFFSCREEN_EFFECT,
ClutterEffect)
/**
* ClutterOffscreenEffectClass:
@ -75,9 +65,6 @@ struct _ClutterOffscreenEffectClass
ClutterPaintContext *paint_context);
};
CLUTTER_EXPORT
GType clutter_offscreen_effect_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT
CoglPipeline * clutter_offscreen_effect_get_pipeline (ClutterOffscreenEffect *effect);