[gnome-shell/wip/nielsdg/remove-cogl-handle] Remove deprecated CoglHandle



commit 4c4d43d378846eb57e984698a26b9642f493c991
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sat Nov 24 12:37:19 2018 +0100

    Remove deprecated CoglHandle
    
    Prefer something a bit more type-safe instead and in the meantime use
    the newly available `cogl_clear_object` to simplify some code a bit.

 src/shell-invert-lightness-effect.c |   2 +-
 src/st/st-entry.c                   |  31 +++-----
 src/st/st-scroll-view-fade.c        |   4 +-
 src/st/st-theme-node-drawing.c      | 146 ++++++++++++++----------------------
 src/st/st-theme-node-transition.c   |  96 +++++++-----------------
 src/st/st-theme-node.c              |  56 +++-----------
 src/st/st-theme-node.h              |   2 +-
 7 files changed, 111 insertions(+), 226 deletions(-)
---
diff --git a/src/shell-invert-lightness-effect.c b/src/shell-invert-lightness-effect.c
index b3a2ca44f..1d4658d8a 100644
--- a/src/shell-invert-lightness-effect.c
+++ b/src/shell-invert-lightness-effect.c
@@ -102,7 +102,7 @@ shell_invert_lightness_effect_pre_paint (ClutterEffect *effect)
     {
       ClutterOffscreenEffect *offscreen_effect =
         CLUTTER_OFFSCREEN_EFFECT (effect);
-      CoglHandle texture;
+      CoglTexture *texture;
 
       texture = clutter_offscreen_effect_get_texture (offscreen_effect);
       self->tex_width = cogl_texture_get_width (texture);
diff --git a/src/st/st-entry.c b/src/st/st-entry.c
index a9c062937..1db8c652c 100644
--- a/src/st/st-entry.c
+++ b/src/st/st-entry.c
@@ -108,7 +108,7 @@ struct _StEntryPrivate
   gboolean      capslock_warning_shown;
   gboolean      has_ibeam;
 
-  CoglHandle    text_shadow_material;
+  CoglPipeline *text_shadow_material;
   gfloat        shadow_width;
   gfloat        shadow_height;
 };
@@ -261,11 +261,7 @@ st_entry_dispose (GObject *object)
   StEntryPrivate *priv = ST_ENTRY_PRIV (entry);
   GdkKeymap *keymap;
 
-  if (priv->text_shadow_material != COGL_INVALID_HANDLE)
-    {
-      cogl_handle_unref (priv->text_shadow_material);
-      priv->text_shadow_material = COGL_INVALID_HANDLE;
-    }
+  cogl_clear_object (&priv->text_shadow_material);
 
   keymap = gdk_keymap_get_for_display (gdk_display_get_default ());
   g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
@@ -301,11 +297,7 @@ st_entry_style_changed (StWidget *self)
   gchar *font_string, *font_name;
   gdouble size;
 
-  if (priv->text_shadow_material != COGL_INVALID_HANDLE)
-    {
-      cogl_handle_unref (priv->text_shadow_material);
-      priv->text_shadow_material = COGL_INVALID_HANDLE;
-    }
+  cogl_clear_object (&priv->text_shadow_material);
 
   theme_node = st_widget_get_theme_node (self);
 
@@ -623,11 +615,7 @@ clutter_text_changed_cb (GObject    *object,
   StEntryPrivate *priv = ST_ENTRY_PRIV (entry);
 
   /* Since the text changed, force a regen of the shadow texture */
-  if (priv->text_shadow_material != COGL_INVALID_HANDLE)
-    {
-      cogl_handle_unref (priv->text_shadow_material);
-      priv->text_shadow_material = COGL_INVALID_HANDLE;
-    }
+  cogl_clear_object (&priv->text_shadow_material);
 }
 
 static void
@@ -863,14 +851,13 @@ st_entry_paint (ClutterActor *actor)
       clutter_actor_get_allocation_box (priv->entry, &allocation);
       clutter_actor_box_get_size (&allocation, &width, &height);
 
-      if (priv->text_shadow_material == COGL_INVALID_HANDLE ||
+      if (priv->text_shadow_material == NULL ||
           width != priv->shadow_width ||
           height != priv->shadow_height)
         {
-          CoglHandle material;
+          CoglPipeline *material;
 
-          if (priv->text_shadow_material != COGL_INVALID_HANDLE)
-            cogl_handle_unref (priv->text_shadow_material);
+          cogl_clear_object (&priv->text_shadow_material);
 
           material = _st_create_shadow_pipeline_from_actor (shadow_spec,
                                                             priv->entry);
@@ -880,7 +867,7 @@ st_entry_paint (ClutterActor *actor)
           priv->text_shadow_material = material;
         }
 
-      if (priv->text_shadow_material != COGL_INVALID_HANDLE)
+      if (priv->text_shadow_material != NULL)
         _st_paint_shadow_with_opacity (shadow_spec,
                                        priv->text_shadow_material,
                                        &allocation,
@@ -1063,7 +1050,7 @@ st_entry_init (StEntry *entry)
 
   priv->spacing = 6.0f;
 
-  priv->text_shadow_material = COGL_INVALID_HANDLE;
+  priv->text_shadow_material = NULL;
   priv->shadow_width = -1.;
   priv->shadow_height = -1.;
 
diff --git a/src/st/st-scroll-view-fade.c b/src/st/st-scroll-view-fade.c
index 8282ddc5b..37f44c42c 100644
--- a/src/st/st-scroll-view-fade.c
+++ b/src/st/st-scroll-view-fade.c
@@ -61,7 +61,7 @@ enum {
   PROP_FADE_EDGES
 };
 
-static CoglHandle
+static CoglTexture *
 st_scroll_view_fade_create_texture (ClutterOffscreenEffect *effect,
                                     gfloat                  min_width,
                                     gfloat                  min_height)
@@ -69,7 +69,7 @@ st_scroll_view_fade_create_texture (ClutterOffscreenEffect *effect,
   CoglContext *ctx =
     clutter_backend_get_cogl_context (clutter_get_default_backend ());
 
-  return cogl_texture_2d_new_with_size (ctx, min_width, min_height);
+  return COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, min_width, min_height));
 }
 
 static char *
diff --git a/src/st/st-theme-node-drawing.c b/src/st/st-theme-node-drawing.c
index f59065aef..93496e7d4 100644
--- a/src/st/st-theme-node-drawing.c
+++ b/src/st/st-theme-node-drawing.c
@@ -66,13 +66,13 @@ elliptical_arc (cairo_t *cr,
   cairo_restore (cr);
 }
 
-static CoglHandle
+static CoglTexture *
 create_corner_material (StCornerSpec *corner)
 {
   ClutterBackend *backend = clutter_get_default_backend ();
   CoglContext *ctx = clutter_backend_get_cogl_context (backend);
   CoglError *error = NULL;
-  CoglHandle texture;
+  CoglTexture *texture;
   cairo_t *cr;
   cairo_surface_t *surface;
   guint rowstride;
@@ -198,7 +198,7 @@ corner_to_string (StCornerSpec *corner)
                           corner->border_width_2);
 }
 
-static CoglHandle
+static CoglTexture *
 load_corner (StTextureCache  *cache,
              const char      *key,
              void            *datap,
@@ -348,13 +348,14 @@ st_theme_node_get_corner_border_widths (StThemeNode *node,
     }
 }
 
-static CoglHandle
+static CoglPipeline
 st_theme_node_lookup_corner (StThemeNode    *node,
                              float           width,
                              float           height,
                              StCorner        corner_id)
 {
-  CoglHandle texture, material = COGL_INVALID_HANDLE;
+  CoglTexture *texture = NULL;
+  CoglPipeline *material = NULL;
   char *key;
   StTextureCache *cache;
   StCornerSpec corner;
@@ -365,7 +366,7 @@ st_theme_node_lookup_corner (StThemeNode    *node,
   st_theme_node_reduce_border_radius (node, width, height, radius);
 
   if (radius[corner_id] == 0)
-    return COGL_INVALID_HANDLE;
+    return NULL;
 
   corner.radius = radius[corner_id];
   corner.color = node->background_color;
@@ -399,7 +400,7 @@ st_theme_node_lookup_corner (StThemeNode    *node,
   if (corner.color.alpha == 0 &&
       corner.border_color_1.alpha == 0 &&
       corner.border_color_2.alpha == 0)
-    return COGL_INVALID_HANDLE;
+    return NULL;
 
   key = corner_to_string (&corner);
   texture = st_texture_cache_load (cache, key, ST_TEXTURE_CACHE_POLICY_FOREVER, load_corner, &corner, NULL);
@@ -407,7 +408,7 @@ st_theme_node_lookup_corner (StThemeNode    *node,
   if (texture)
     {
       material = _st_create_texture_pipeline (texture);
-      cogl_handle_unref (texture);
+      cogl_object_unref (texture);
     }
 
   g_free (key);
@@ -962,7 +963,7 @@ paint_inset_box_shadow_to_cairo_context (StThemeNode     *node,
  * we need to use cairo.  This function is a slow fallback path for those
  * cases (gradients, background images, etc).
  */
-static CoglHandle
+static CoglTexture *
 st_theme_node_prerender_background (StThemeNode *node,
                                     float        actor_width,
                                     float        actor_height)
@@ -971,7 +972,7 @@ st_theme_node_prerender_background (StThemeNode *node,
   CoglContext *ctx = clutter_backend_get_cogl_context (backend);
   CoglError *error = NULL;
   StBorderImage *border_image;
-  CoglHandle texture;
+  CoglTexture *texture;
   guint radius[4];
   int i;
   cairo_t *cr;
@@ -1312,23 +1313,14 @@ static void st_theme_node_paint_borders (StThemeNodePaintState *state,
 void
 st_theme_node_invalidate_border_image (StThemeNode *node)
 {
-  if (node->border_slices_texture != COGL_INVALID_HANDLE)
-    {
-      cogl_handle_unref (node->border_slices_texture);
-      node->border_slices_texture = COGL_INVALID_HANDLE;
-    }
-
-  if (node->border_slices_pipeline != COGL_INVALID_HANDLE)
-    {
-      cogl_handle_unref (node->border_slices_pipeline);
-      node->border_slices_pipeline = COGL_INVALID_HANDLE;
-    }
+  cogl_clear_object (&node->border_slices_texture);
+  cogl_clear_object (&node->border_slices_pipeline);
 }
 
 static gboolean
 st_theme_node_load_border_image (StThemeNode *node)
 {
-  if (node->border_slices_texture == COGL_INVALID_HANDLE)
+  if (node->border_slices_texture == NULL)
     {
       StBorderImage *border_image;
       GFile *file;
@@ -1344,42 +1336,28 @@ st_theme_node_load_border_image (StThemeNode *node)
 
       node->border_slices_texture = st_texture_cache_load_file_to_cogl_texture (st_texture_cache_get_default 
(),
                                                                                 file, scale_factor);
-      if (node->border_slices_texture == COGL_INVALID_HANDLE)
+      if (node->border_slices_texture == NULL)
         goto out;
 
       node->border_slices_pipeline = _st_create_texture_pipeline (node->border_slices_texture);
     }
 
  out:
-  return node->border_slices_texture != COGL_INVALID_HANDLE;
+  return node->border_slices_texture != NULL;
 }
 
 void
 st_theme_node_invalidate_background_image (StThemeNode *node)
 {
-  if (node->background_texture != COGL_INVALID_HANDLE)
-    {
-      cogl_handle_unref (node->background_texture);
-      node->background_texture = COGL_INVALID_HANDLE;
-    }
-
-  if (node->background_pipeline != COGL_INVALID_HANDLE)
-    {
-      cogl_handle_unref (node->background_pipeline);
-      node->background_pipeline = COGL_INVALID_HANDLE;
-    }
-
-  if (node->background_shadow_pipeline != COGL_INVALID_HANDLE)
-    {
-      cogl_handle_unref (node->background_shadow_pipeline);
-      node->background_shadow_pipeline = COGL_INVALID_HANDLE;
-    }
+  cogl_clear_object (&node->background_texture);
+  cogl_clear_object (&node->background_pipeline);
+  cogl_clear_object (&node->background_shadow_pipeline);
 }
 
 static gboolean
 st_theme_node_load_background_image (StThemeNode *node)
 {
-  if (node->background_texture == COGL_INVALID_HANDLE)
+  if (node->background_texture == NULL)
     {
       GFile *background_image;
       StShadow *background_image_shadow_spec;
@@ -1394,7 +1372,7 @@ st_theme_node_load_background_image (StThemeNode *node)
       background_image_shadow_spec = st_theme_node_get_background_image_shadow (node);
       node->background_texture = st_texture_cache_load_file_to_cogl_texture (st_texture_cache_get_default (),
                                                                              background_image, scale_factor);
-      if (node->background_texture == COGL_INVALID_HANDLE)
+      if (node->background_texture == NULL)
         goto out;
 
       node->background_pipeline = _st_create_texture_pipeline (node->background_texture);
@@ -1411,7 +1389,7 @@ st_theme_node_load_background_image (StThemeNode *node)
     }
 
  out:
-  return node->background_texture != COGL_INVALID_HANDLE;
+  return node->background_texture != NULL;
 }
 
 static void st_theme_node_prerender_shadow (StThemeNodePaintState *state);
@@ -1510,14 +1488,14 @@ st_theme_node_render_resources (StThemeNodePaintState *state,
   if (state->prerendered_texture)
     state->prerendered_pipeline = _st_create_texture_pipeline (state->prerendered_texture);
   else
-    state->prerendered_pipeline = COGL_INVALID_HANDLE;
+    state->prerendered_pipeline = NULL;
 
   if (box_shadow_spec && !has_inset_box_shadow)
     {
       if (st_theme_node_load_border_image (node))
         state->box_shadow_pipeline = _st_create_shadow_pipeline (box_shadow_spec,
                                                                  node->border_slices_texture);
-      else if (state->prerendered_texture != COGL_INVALID_HANDLE)
+      else if (state->prerendered_texture != NULL)
         state->box_shadow_pipeline = _st_create_shadow_pipeline (box_shadow_spec,
                                                                  state->prerendered_texture);
       else if (node->background_color.alpha > 0 || has_border)
@@ -1528,7 +1506,7 @@ st_theme_node_render_resources (StThemeNodePaintState *state,
      them. */
   if (!node->cached_textures)
     {
-      if (state->prerendered_pipeline == COGL_INVALID_HANDLE &&
+      if (state->prerendered_pipeline == NULL &&
           width >= node->box_shadow_min_width &&
           height >= node->box_shadow_min_height)
         {
@@ -1551,22 +1529,17 @@ st_theme_node_update_resources (StThemeNodePaintState *state,
   g_return_if_fail (width > 0 && height > 0);
 
   /* Free handles we can't reuse */
-  if (state->prerendered_texture != COGL_INVALID_HANDLE)
-    {
-      cogl_handle_unref (state->prerendered_texture);
-      state->prerendered_texture = COGL_INVALID_HANDLE;
-      had_prerendered_texture = TRUE;
-    }
-  if (state->prerendered_pipeline != COGL_INVALID_HANDLE)
+  had_prerendered_texture = (state->prerendered_texture != NULL);
+  cogl_clear_object (&state->prerendered_texture);
+
+  if (state->prerendered_pipeline != NULL)
     {
-      cogl_handle_unref (state->prerendered_pipeline);
-      state->prerendered_pipeline = COGL_INVALID_HANDLE;
+      cogl_clear_object (&state->prerendered_pipeline);
 
-      if (node->border_slices_texture == COGL_INVALID_HANDLE &&
-          state->box_shadow_pipeline != COGL_INVALID_HANDLE)
+      if (node->border_slices_texture == NULL &&
+          state->box_shadow_pipeline != NULL)
         {
-          cogl_handle_unref (state->box_shadow_pipeline);
-          state->box_shadow_pipeline = COGL_INVALID_HANDLE;
+          cogl_clear_object (&state->box_shadow_pipeline);
           had_box_shadow = TRUE;
         }
     }
@@ -1587,7 +1560,7 @@ st_theme_node_update_resources (StThemeNodePaintState *state,
       int corner_id;
 
       for (corner_id = 0; corner_id < 4; corner_id++)
-        if (state->corner_material[corner_id] == COGL_INVALID_HANDLE)
+        if (state->corner_material[corner_id] == NULL)
           state->corner_material[corner_id] =
             st_theme_node_lookup_corner (node, width, height, corner_id);
     }
@@ -1598,7 +1571,7 @@ st_theme_node_update_resources (StThemeNodePaintState *state,
 }
 
 static void
-paint_material_with_opacity (CoglHandle       material,
+paint_material_with_opacity (CoglPipeline    *material,
                              CoglFramebuffer *framebuffer,
                              ClutterActorBox *box,
                              ClutterActorBox *coords,
@@ -1621,7 +1594,7 @@ st_theme_node_ensure_color_pipeline (StThemeNode *node)
 {
   static CoglPipeline *color_pipeline_template = NULL;
 
-  if (node->color_pipeline != COGL_INVALID_HANDLE)
+  if (node->color_pipeline != NULL)
     return;
 
   if (G_UNLIKELY (color_pipeline_template == NULL))
@@ -1749,7 +1722,7 @@ st_theme_node_paint_borders (StThemeNodePaintState *state,
     {
       for (corner_id = 0; corner_id < 4; corner_id++)
         {
-          if (state->corner_material[corner_id] == COGL_INVALID_HANDLE)
+          if (state->corner_material[corner_id] == NULL)
             continue;
 
           cogl_pipeline_set_color4ub (state->corner_material[corner_id],
@@ -2224,7 +2197,8 @@ st_theme_node_prerender_shadow (StThemeNodePaintState *state)
   guint border_radius[4];
   int max_borders[4];
   int center_radius, corner_id;
-  CoglHandle buffer, offscreen = COGL_INVALID_HANDLE;
+  CoglTexture *buffer;
+  CoglFramebuffer *offscreen = NULL;
   CoglError *error = NULL;
 
   ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
@@ -2264,9 +2238,9 @@ st_theme_node_prerender_shadow (StThemeNodePaintState *state)
     }
 
   /* Render offscreen */
-  buffer = cogl_texture_2d_new_with_size (ctx,
-                                          state->box_shadow_width,
-                                          state->box_shadow_height);
+  buffer = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
+                                                        state->box_shadow_width,
+                                                        state->box_shadow_height));
   if (buffer == NULL)
     return;
 
@@ -2291,8 +2265,8 @@ st_theme_node_prerender_shadow (StThemeNodePaintState *state)
       cogl_error_free (error);
     }
 
-  cogl_handle_unref (offscreen);
-  cogl_handle_unref (buffer);
+  cogl_clear_object (&offscreen);
+  cogl_clear_object (&buffer);
 }
 
 static void
@@ -2307,7 +2281,7 @@ st_theme_node_paint_sliced_border_image (StThemeNode           *node,
   gint border_left, border_right, border_top, border_bottom;
   float img_width, img_height;
   StBorderImage *border_image;
-  CoglHandle pipeline;
+  CoglPipeline *pipeline;
 
   border_image = st_theme_node_get_border_image (node);
   g_assert (border_image != NULL);
@@ -2574,10 +2548,10 @@ st_theme_node_paint (StThemeNode           *node,
                                            paint_opacity);
     }
 
-  if (state->prerendered_pipeline != COGL_INVALID_HANDLE ||
+  if (state->prerendered_pipeline != NULL ||
       st_theme_node_load_border_image (node))
     {
-      if (state->prerendered_pipeline != COGL_INVALID_HANDLE)
+      if (state->prerendered_pipeline != NULL)
         {
           ClutterActorBox paint_box;
 
@@ -2592,7 +2566,7 @@ st_theme_node_paint (StThemeNode           *node,
                                        paint_opacity);
         }
 
-      if (node->border_slices_pipeline != COGL_INVALID_HANDLE)
+      if (node->border_slices_pipeline != NULL)
         st_theme_node_paint_sliced_border_image (node, framebuffer, width, height, paint_opacity);
     }
   else
@@ -2602,7 +2576,7 @@ st_theme_node_paint (StThemeNode           *node,
 
   st_theme_node_paint_outline (node, framebuffer, box, paint_opacity);
 
-  if (state->prerendered_pipeline == COGL_INVALID_HANDLE &&
+  if (state->prerendered_pipeline == NULL &&
       st_theme_node_load_background_image (node))
     {
       ClutterActorBox background_box;
@@ -2635,7 +2609,7 @@ st_theme_node_paint (StThemeNode           *node,
        * there is nothing (like a border, or the edge of the background color)
        * to logically confine it.
        */
-      if (node->background_shadow_pipeline != COGL_INVALID_HANDLE)
+      if (node->background_shadow_pipeline != NULL)
         _st_paint_shadow_with_opacity (node->background_image_shadow,
                                        node->background_shadow_pipeline,
                                        &background_box,
@@ -2658,16 +2632,12 @@ st_theme_node_paint_state_node_free_internal (StThemeNodePaintState *state,
 {
   int corner_id;
 
-  if (state->prerendered_texture != COGL_INVALID_HANDLE)
-    cogl_handle_unref (state->prerendered_texture);
-  if (state->prerendered_pipeline != COGL_INVALID_HANDLE)
-    cogl_handle_unref (state->prerendered_pipeline);
-  if (state->box_shadow_pipeline != COGL_INVALID_HANDLE)
-    cogl_handle_unref (state->box_shadow_pipeline);
+  cogl_clear_object (&state->prerendered_texture);
+  cogl_clear_object (&state->prerendered_pipeline);
+  cogl_clear_object (&state->box_shadow_pipeline);
 
   for (corner_id = 0; corner_id < 4; corner_id++)
-    if (state->corner_material[corner_id] != COGL_INVALID_HANDLE)
-      cogl_handle_unref (state->corner_material[corner_id]);
+    cogl_clear_object (&state->corner_material[corner_id]);
 
   if (unref_node)
     st_theme_node_paint_state_set_node (state, NULL);
@@ -2710,12 +2680,12 @@ st_theme_node_paint_state_init (StThemeNodePaintState *state)
   state->alloc_width = 0;
   state->alloc_height = 0;
   state->node = NULL;
-  state->box_shadow_pipeline = COGL_INVALID_HANDLE;
-  state->prerendered_texture = COGL_INVALID_HANDLE;
-  state->prerendered_pipeline = COGL_INVALID_HANDLE;
+  state->box_shadow_pipeline = NULL;
+  state->prerendered_texture = NULL;
+  state->prerendered_pipeline = NULL;
 
   for (corner_id = 0; corner_id < 4; corner_id++)
-    state->corner_material[corner_id] = COGL_INVALID_HANDLE;
+    state->corner_material[corner_id] = NULL;
 }
 
 void
diff --git a/src/st/st-theme-node-transition.c b/src/st/st-theme-node-transition.c
index 608c49cab..f2620ec29 100644
--- a/src/st/st-theme-node-transition.c
+++ b/src/st/st-theme-node-transition.c
@@ -42,13 +42,13 @@ struct _StThemeNodeTransitionPrivate {
   StThemeNodePaintState old_paint_state;
   StThemeNodePaintState new_paint_state;
 
-  CoglHandle old_texture;
-  CoglHandle new_texture;
+  CoglTexture *old_texture;
+  CoglTexture *new_texture;
 
-  CoglHandle old_offscreen;
-  CoglHandle new_offscreen;
+  CoglFramebuffer *old_offscreen;
+  CoglFramebuffer *new_offscreen;
 
-  CoglHandle material;
+  CoglPipeline *material;
 
   ClutterTimeline *timeline;
 
@@ -245,7 +245,7 @@ setup_framebuffers (StThemeNodeTransition *transition,
   CoglError *catch_error = NULL;
 
   /* template material to avoid unnecessary shader compilation */
-  static CoglHandle material_template = COGL_INVALID_HANDLE;
+  static CoglPipeline *material_template = NULL;
 
   ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
   width  = priv->offscreen_box.x2 - priv->offscreen_box.x1;
@@ -254,45 +254,39 @@ setup_framebuffers (StThemeNodeTransition *transition,
   g_return_val_if_fail (width  > 0, FALSE);
   g_return_val_if_fail (height > 0, FALSE);
 
-  if (priv->old_texture)
-    cogl_handle_unref (priv->old_texture);
-  priv->old_texture = cogl_texture_2d_new_with_size (ctx, width, height);
+  cogl_clear_object (&priv->old_texture);
+  priv->old_texture = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, width, height));
 
-  if (priv->new_texture)
-    cogl_handle_unref (priv->new_texture);
-  priv->new_texture = cogl_texture_2d_new_with_size (ctx, width, height);
+  cogl_clear_object (&priv->new_texture);
+  priv->new_texture = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, width, height));
 
-  if (priv->old_texture == COGL_INVALID_HANDLE)
+  if (priv->old_texture == NULL)
     return FALSE;
 
-  if (priv->new_texture == COGL_INVALID_HANDLE)
+  if (priv->new_texture == NULL)
     return FALSE;
 
-  if (priv->old_offscreen)
-    cogl_handle_unref (priv->old_offscreen);
-  priv->old_offscreen = cogl_offscreen_new_with_texture (priv->old_texture);
-  if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (priv->old_offscreen), &catch_error))
+  cogl_clear_object (&priv->old_offscreen);
+  priv->old_offscreen = COGL_FRAMEBUFFER (cogl_offscreen_new_with_texture (priv->old_texture));
+  if (!cogl_framebuffer_allocate (priv->old_offscreen, &catch_error))
     {
-      cogl_object_unref (priv->old_offscreen);
       cogl_error_free (catch_error);
-      priv->old_offscreen = COGL_INVALID_HANDLE;
+      cogl_clear_object (&priv->old_offscreen);
       return FALSE;
     }
 
-  if (priv->new_offscreen)
-    cogl_handle_unref (priv->new_offscreen);
-  priv->new_offscreen = cogl_offscreen_new_with_texture (priv->new_texture);
-  if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (priv->new_offscreen), &catch_error))
+  cogl_clear_object (&priv->new_offscreen);
+  priv->new_offscreen = COGL_FRAMEBUFFER (cogl_offscreen_new_with_texture (priv->new_texture));
+  if (!cogl_framebuffer_allocate (priv->new_offscreen, &catch_error))
     {
-      cogl_object_unref (priv->new_offscreen);
       cogl_error_free (catch_error);
-      priv->new_offscreen = COGL_INVALID_HANDLE;
+      cogl_clear_object (&priv->new_offscreen);
       return FALSE;
     }
 
   if (priv->material == NULL)
     {
-      if (G_UNLIKELY (material_template == COGL_INVALID_HANDLE))
+      if (G_UNLIKELY (material_template == NULL))
         {
           CoglContext *ctx =
             clutter_backend_get_cogl_context (clutter_get_default_backend ());
@@ -393,47 +387,16 @@ st_theme_node_transition_dispose (GObject *object)
 {
   StThemeNodeTransitionPrivate *priv = ST_THEME_NODE_TRANSITION (object)->priv;
 
-  if (priv->old_theme_node)
-    {
-      g_object_unref (priv->old_theme_node);
-      priv->old_theme_node = NULL;
-    }
+  cogl_clear_object (&priv->old_theme_node);
+  cogl_clear_object (&priv->new_theme_node);
 
-  if (priv->new_theme_node)
-    {
-      g_object_unref (priv->new_theme_node);
-      priv->new_theme_node = NULL;
-    }
+  cogl_clear_object (&priv->old_texture);
+  cogl_clear_object (&priv->new_texture);
 
-  if (priv->old_texture)
-    {
-      cogl_handle_unref (priv->old_texture);
-      priv->old_texture = NULL;
-    }
-
-  if (priv->new_texture)
-    {
-      cogl_handle_unref (priv->new_texture);
-      priv->new_texture = NULL;
-    }
+  cogl_clear_object (&priv->old_offscreen);
+  cogl_clear_object (&priv->new_offscreen);
 
-  if (priv->old_offscreen)
-    {
-      cogl_handle_unref (priv->old_offscreen);
-      priv->old_offscreen = NULL;
-    }
-
-  if (priv->new_offscreen)
-    {
-      cogl_handle_unref (priv->new_offscreen);
-      priv->new_offscreen = NULL;
-    }
-
-  if (priv->material)
-    {
-      cogl_handle_unref (priv->material);
-      priv->material = NULL;
-    }
+  cogl_clear_object (&priv->material);
 
   if (priv->timeline)
     {
@@ -444,8 +407,7 @@ st_theme_node_transition_dispose (GObject *object)
         g_signal_handler_disconnect (priv->timeline,
                                      priv->timeline_new_frame_id);
 
-      g_object_unref (priv->timeline);
-      priv->timeline = NULL;
+      cogl_clear_object (&priv->timeline);
     }
 
   priv->timeline_completed_id = 0;
diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c
index 69a0848af..ee2d0a1b3 100644
--- a/src/st/st-theme-node.c
+++ b/src/st/st-theme-node.c
@@ -47,12 +47,6 @@ static void
 st_theme_node_init (StThemeNode *node)
 {
   node->transition_duration = -1;
-  node->background_texture = COGL_INVALID_HANDLE;
-  node->background_pipeline = COGL_INVALID_HANDLE;
-  node->background_shadow_pipeline = COGL_INVALID_HANDLE;
-  node->border_slices_texture = COGL_INVALID_HANDLE;
-  node->border_slices_pipeline = COGL_INVALID_HANDLE;
-  node->color_pipeline = COGL_INVALID_HANDLE;
 
   st_theme_node_paint_state_init (&node->cached_state);
 }
@@ -140,48 +134,20 @@ st_theme_node_finalize (GObject *object)
 
   maybe_free_properties (node);
 
-  if (node->font_desc)
-    {
-      pango_font_description_free (node->font_desc);
-      node->font_desc = NULL;
-    }
+  g_clear_pointer (&node->font_desc, pango_font_description_free)
 
-  if (node->box_shadow)
-    {
-      st_shadow_unref (node->box_shadow);
-      node->box_shadow = NULL;
-    }
+  g_clear_pointer (&node->box_shadow, st_shadow_unref)
+  g_clear_pointer (&node->background_image_shadow, st_shadow_unref)
+  g_clear_pointer (&node->text_shadow, st_shadow_unref)
 
-  if (node->background_image_shadow)
-    {
-      st_shadow_unref (node->background_image_shadow);
-      node->background_image_shadow = NULL;
-    }
-
-  if (node->text_shadow)
-    {
-      st_shadow_unref (node->text_shadow);
-      node->text_shadow = NULL;
-    }
-
-  if (node->background_image)
-    {
-      g_object_unref (node->background_image);
-      node->background_image = NULL;
-    }
+  g_clear_object (&node->background_image);
 
-  if (node->background_texture != COGL_INVALID_HANDLE)
-    cogl_handle_unref (node->background_texture);
-  if (node->background_pipeline != COGL_INVALID_HANDLE)
-    cogl_handle_unref (node->background_pipeline);
-  if (node->background_shadow_pipeline != COGL_INVALID_HANDLE)
-    cogl_handle_unref (node->background_shadow_pipeline);
-  if (node->border_slices_texture != COGL_INVALID_HANDLE)
-    cogl_handle_unref (node->border_slices_texture);
-  if (node->border_slices_pipeline != COGL_INVALID_HANDLE)
-    cogl_handle_unref (node->border_slices_pipeline);
-  if (node->color_pipeline != COGL_INVALID_HANDLE)
-    cogl_handle_unref (node->color_pipeline);
+  cogl_clear_object (&node->background_texture);
+  cogl_clear_object (&node->background_pipeline);
+  cogl_clear_object (&node->background_shadow_pipeline);
+  cogl_clear_object (&node->border_slices_texture);
+  cogl_clear_object (&node->border_slices_pipeline);
+  cogl_clear_object (&node->color_pipeline);
 
   G_OBJECT_CLASS (st_theme_node_parent_class)->finalize (object);
 }
diff --git a/src/st/st-theme-node.h b/src/st/st-theme-node.h
index e71c1d522..4da0d48e3 100644
--- a/src/st/st-theme-node.h
+++ b/src/st/st-theme-node.h
@@ -107,7 +107,7 @@ struct _StThemeNodePaintState {
   CoglPipeline *box_shadow_pipeline;
   CoglPipeline *prerendered_texture;
   CoglPipeline *prerendered_pipeline;
-  CoglHandle corner_material[4];
+  CoglObject *corner_material[4];
 };
 
 StThemeNode *st_theme_node_new (StThemeContext *context,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]