From 586c43d5a9882ed1ef6b8e3094702711006d9eb0 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 13 Sep 2023 10:12:01 +0200 Subject: [PATCH] clutter/cogl: Use more of memory management helpers Part-of: --- clutter/clutter/clutter-backend.c | 13 ++-------- clutter/clutter/clutter-blur-effect.c | 6 +---- clutter/clutter/clutter-blur.c | 6 ++--- .../clutter-brightness-contrast-effect.c | 6 +---- clutter/clutter/clutter-canvas.c | 17 +++--------- clutter/clutter/clutter-colorize-effect.c | 6 +---- clutter/clutter/clutter-deform-effect.c | 26 +++---------------- clutter/clutter/clutter-desaturate-effect.c | 6 +---- clutter/clutter/clutter-image.c | 9 ++----- clutter/clutter/clutter-path-constraint.c | 12 ++------- clutter/clutter/clutter-shader-effect.c | 15 ++--------- cogl/cogl/cogl-display.c | 13 ++-------- 12 files changed, 25 insertions(+), 110 deletions(-) diff --git a/clutter/clutter/clutter-backend.c b/clutter/clutter/clutter-backend.c index af98f4922..ca5bd8a7b 100644 --- a/clutter/clutter/clutter-backend.c +++ b/clutter/clutter/clutter-backend.c @@ -259,17 +259,8 @@ clutter_backend_do_real_create_context (ClutterBackend *backend, return TRUE; error: - if (backend->cogl_display != NULL) - { - g_object_unref (backend->cogl_display); - backend->cogl_display = NULL; - } - - if (backend->cogl_renderer != NULL) - { - g_object_unref (backend->cogl_renderer); - backend->cogl_renderer = NULL; - } + g_clear_object (&backend->cogl_display); + g_clear_object (&backend->cogl_renderer); if (swap_chain != NULL) g_object_unref (swap_chain); diff --git a/clutter/clutter/clutter-blur-effect.c b/clutter/clutter/clutter-blur-effect.c index 67f66d1f8..e624b0bce 100644 --- a/clutter/clutter/clutter-blur-effect.c +++ b/clutter/clutter/clutter-blur-effect.c @@ -147,11 +147,7 @@ clutter_blur_effect_dispose (GObject *gobject) { ClutterBlurEffect *self = CLUTTER_BLUR_EFFECT (gobject); - if (self->pipeline != NULL) - { - cogl_object_unref (self->pipeline); - self->pipeline = NULL; - } + cogl_clear_object (&self->pipeline); G_OBJECT_CLASS (clutter_blur_effect_parent_class)->dispose (gobject); } diff --git a/clutter/clutter/clutter-blur.c b/clutter/clutter/clutter-blur.c index 7f355c6a2..c630dc7e0 100644 --- a/clutter/clutter/clutter-blur.c +++ b/clutter/clutter/clutter-blur.c @@ -230,7 +230,7 @@ create_fbo (ClutterBlur *blur, float height; float width; - g_clear_pointer (&pass->texture, cogl_object_unref); + cogl_clear_object (&pass->texture); g_clear_object (&pass->framebuffer); width = cogl_texture_get_width (blur->source_texture); @@ -326,8 +326,8 @@ apply_blur_pass (BlurPass *pass) static void clear_blur_pass (BlurPass *pass) { - g_clear_pointer (&pass->pipeline, cogl_object_unref); - g_clear_pointer (&pass->texture, cogl_object_unref); + cogl_clear_object (&pass->pipeline); + cogl_clear_object (&pass->texture); g_clear_object (&pass->framebuffer); } diff --git a/clutter/clutter/clutter-brightness-contrast-effect.c b/clutter/clutter/clutter-brightness-contrast-effect.c index 61c2f9182..28838919b 100644 --- a/clutter/clutter/clutter-brightness-contrast-effect.c +++ b/clutter/clutter/clutter-brightness-contrast-effect.c @@ -155,11 +155,7 @@ clutter_brightness_contrast_effect_dispose (GObject *gobject) { ClutterBrightnessContrastEffect *self = CLUTTER_BRIGHTNESS_CONTRAST_EFFECT (gobject); - if (self->pipeline != NULL) - { - cogl_object_unref (self->pipeline); - self->pipeline = NULL; - } + cogl_clear_object (&self->pipeline); G_OBJECT_CLASS (clutter_brightness_contrast_effect_parent_class)->dispose (gobject); } diff --git a/clutter/clutter/clutter-canvas.c b/clutter/clutter/clutter-canvas.c index 8c6f7bc8d..13a26c149 100644 --- a/clutter/clutter/clutter-canvas.c +++ b/clutter/clutter/clutter-canvas.c @@ -127,13 +127,8 @@ clutter_canvas_finalize (GObject *gobject) { ClutterCanvasPrivate *priv = CLUTTER_CANVAS (gobject)->priv; - if (priv->buffer != NULL) - { - g_object_unref (priv->buffer); - priv->buffer = NULL; - } - - g_clear_pointer (&priv->texture, cogl_object_unref); + g_clear_object (&priv->buffer); + cogl_clear_object (&priv->texture); G_OBJECT_CLASS (clutter_canvas_parent_class)->finalize (gobject); } @@ -322,7 +317,7 @@ clutter_canvas_paint_content (ClutterContent *content, return; if (priv->dirty) - g_clear_pointer (&priv->texture, cogl_object_unref); + cogl_clear_object (&priv->texture); if (priv->texture == NULL) priv->texture = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (priv->buffer)); @@ -443,11 +438,7 @@ clutter_canvas_invalidate (ClutterContent *content) ClutterCanvas *self = CLUTTER_CANVAS (content); ClutterCanvasPrivate *priv = self->priv; - if (priv->buffer != NULL) - { - g_object_unref (priv->buffer); - priv->buffer = NULL; - } + g_clear_object (&priv->buffer); if (priv->width <= 0 || priv->height <= 0) return; diff --git a/clutter/clutter/clutter-colorize-effect.c b/clutter/clutter/clutter-colorize-effect.c index 810903ebe..0242351c9 100644 --- a/clutter/clutter/clutter-colorize-effect.c +++ b/clutter/clutter/clutter-colorize-effect.c @@ -113,11 +113,7 @@ clutter_colorize_effect_dispose (GObject *gobject) { ClutterColorizeEffect *self = CLUTTER_COLORIZE_EFFECT (gobject); - if (self->pipeline != NULL) - { - cogl_object_unref (self->pipeline); - self->pipeline = NULL; - } + cogl_clear_object (&self->pipeline); G_OBJECT_CLASS (clutter_colorize_effect_parent_class)->dispose (gobject); } diff --git a/clutter/clutter/clutter-deform-effect.c b/clutter/clutter/clutter-deform-effect.c index 3faea81b6..40d7969bb 100644 --- a/clutter/clutter/clutter-deform-effect.c +++ b/clutter/clutter/clutter-deform-effect.c @@ -337,23 +337,9 @@ clutter_deform_effect_free_arrays (ClutterDeformEffect *self) { ClutterDeformEffectPrivate *priv = self->priv; - if (priv->buffer) - { - cogl_object_unref (priv->buffer); - priv->buffer = NULL; - } - - if (priv->primitive) - { - cogl_object_unref (priv->primitive); - priv->primitive = NULL; - } - - if (priv->lines_primitive) - { - cogl_object_unref (priv->lines_primitive); - priv->lines_primitive = NULL; - } + cogl_clear_object (&priv->buffer); + cogl_clear_object (&priv->primitive); + cogl_clear_object (&priv->lines_primitive); } static void @@ -501,11 +487,7 @@ clutter_deform_effect_free_back_pipeline (ClutterDeformEffect *self) { ClutterDeformEffectPrivate *priv = self->priv; - if (priv->back_pipeline != NULL) - { - cogl_object_unref (priv->back_pipeline); - priv->back_pipeline = NULL; - } + cogl_clear_object (&priv->back_pipeline); } static void diff --git a/clutter/clutter/clutter-desaturate-effect.c b/clutter/clutter/clutter-desaturate-effect.c index 61319f2d5..87b4312e2 100644 --- a/clutter/clutter/clutter-desaturate-effect.c +++ b/clutter/clutter/clutter-desaturate-effect.c @@ -124,11 +124,7 @@ clutter_desaturate_effect_dispose (GObject *gobject) { ClutterDesaturateEffect *self = CLUTTER_DESATURATE_EFFECT (gobject); - if (self->pipeline != NULL) - { - cogl_object_unref (self->pipeline); - self->pipeline = NULL; - } + cogl_clear_object (&self->pipeline); G_OBJECT_CLASS (clutter_desaturate_effect_parent_class)->dispose (gobject); } diff --git a/clutter/clutter/clutter-image.c b/clutter/clutter/clutter-image.c index 8bd4f729b..3b0a8f2b4 100644 --- a/clutter/clutter/clutter-image.c +++ b/clutter/clutter/clutter-image.c @@ -111,11 +111,7 @@ clutter_image_finalize (GObject *gobject) ClutterImage *image = CLUTTER_IMAGE (gobject); ClutterImagePrivate *priv = clutter_image_get_instance_private (image); - if (priv->texture != NULL) - { - cogl_object_unref (priv->texture); - priv->texture = NULL; - } + cogl_clear_object (&priv->texture); G_OBJECT_CLASS (clutter_image_parent_class)->finalize (gobject); } @@ -395,8 +391,7 @@ clutter_image_set_area (ClutterImage *image, if (!res) { - cogl_object_unref (priv->texture); - priv->texture = NULL; + cogl_clear_object (&priv->texture); } } diff --git a/clutter/clutter/clutter-path-constraint.c b/clutter/clutter/clutter-path-constraint.c index 14136355b..b39d4d8bb 100644 --- a/clutter/clutter/clutter-path-constraint.c +++ b/clutter/clutter/clutter-path-constraint.c @@ -134,11 +134,7 @@ clutter_path_constraint_dispose (GObject *gobject) { ClutterPathConstraint *self = CLUTTER_PATH_CONSTRAINT (gobject); - if (self->path != NULL) - { - g_object_unref (self->path); - self->path = NULL; - } + g_clear_object (&self->path); G_OBJECT_CLASS (clutter_path_constraint_parent_class)->dispose (gobject); } @@ -298,11 +294,7 @@ clutter_path_constraint_set_path (ClutterPathConstraint *constraint, if (constraint->path == path) return; - if (constraint->path != NULL) - { - g_object_unref (constraint->path); - constraint->path = NULL; - } + g_clear_object (&constraint->path); if (path != NULL) constraint->path = g_object_ref_sink (path); diff --git a/clutter/clutter/clutter-shader-effect.c b/clutter/clutter/clutter-shader-effect.c index 237af97b0..1740d0d6b 100644 --- a/clutter/clutter/clutter-shader-effect.c +++ b/clutter/clutter/clutter-shader-effect.c @@ -175,19 +175,8 @@ clutter_shader_effect_clear (ClutterShaderEffect *self, { ClutterShaderEffectPrivate *priv = self->priv; - if (priv->shader != NULL) - { - g_object_unref (priv->shader); - - priv->shader = NULL; - } - - if (priv->program != NULL) - { - g_object_unref (priv->program); - - priv->program = NULL; - } + g_clear_object (&priv->shader); + g_clear_object (&priv->program); if (reset_uniforms && priv->uniforms != NULL) { diff --git a/cogl/cogl/cogl-display.c b/cogl/cogl/cogl-display.c index ededc264a..ffacf6155 100644 --- a/cogl/cogl/cogl-display.c +++ b/cogl/cogl/cogl-display.c @@ -62,17 +62,8 @@ cogl_display_dispose (GObject *object) display->setup = FALSE; } - if (display->renderer) - { - g_object_unref (display->renderer); - display->renderer = NULL; - } - - if (display->onscreen_template) - { - g_object_unref (display->onscreen_template); - display->onscreen_template = NULL; - } + g_clear_object (&display->renderer); + g_clear_object (&display->onscreen_template); G_OBJECT_CLASS (cogl_display_parent_class)->dispose (object); }