[libshumate] tile: Change texture property to paintable



commit ebd5f21ab3561240b1ee43f908b6d6ecd026900a
Author: James Westman <james jwestman net>
Date:   Thu Jul 28 13:25:20 2022 -0500

    tile: Change texture property to paintable
    
    There's no reason to restrict it to a texture; any paintable should
    work, and this gives us more flexibility in the future.

 demos/shumate-test-tile-source.c  |  2 +-
 shumate/shumate-map-layer.c       |  2 +-
 shumate/shumate-memory-cache.c    | 12 +++----
 shumate/shumate-raster-renderer.c |  2 +-
 shumate/shumate-tile.c            | 69 +++++++++++++++++++--------------------
 shumate/shumate-tile.h            |  6 ++--
 shumate/shumate-vector-renderer.c |  2 +-
 tests/memory-cache.c              | 30 ++++++++---------
 8 files changed, 61 insertions(+), 64 deletions(-)
---
diff --git a/demos/shumate-test-tile-source.c b/demos/shumate-test-tile-source.c
index e364807..e7cee6e 100644
--- a/demos/shumate-test-tile-source.c
+++ b/demos/shumate-test-tile-source.c
@@ -101,7 +101,7 @@ shumate_test_tile_source_fill_tile_async (ShumateMapSource *map_source,
   cairo_surface_destroy (surface);
   cairo_destroy (cr);
 
-  shumate_tile_set_texture (tile, texture);
+  shumate_tile_set_paintable (tile, GDK_PAINTABLE (texture));
   shumate_tile_set_fade_in (tile, TRUE);
   shumate_tile_set_state (tile, SHUMATE_STATE_DONE);
 
diff --git a/shumate/shumate-map-layer.c b/shumate/shumate-map-layer.c
index 37d33f7..9a7ce98 100644
--- a/shumate/shumate-map-layer.c
+++ b/shumate/shumate-map-layer.c
@@ -216,7 +216,7 @@ add_tile (ShumateMapLayer  *self,
       data->source_id = g_strdup (source_id);
       data->pos = *pos;
 
-      shumate_tile_set_texture (tile, NULL);
+      shumate_tile_set_paintable (tile, NULL);
       shumate_map_source_fill_tile_async (self->map_source, tile, cancellable, on_tile_filled, data);
       g_hash_table_insert (self->tile_fill, g_object_ref (tile), cancellable);
     }
diff --git a/shumate/shumate-memory-cache.c b/shumate/shumate-memory-cache.c
index dbed17a..bfb6a02 100644
--- a/shumate/shumate-memory-cache.c
+++ b/shumate/shumate-memory-cache.c
@@ -54,7 +54,7 @@ G_DEFINE_TYPE (ShumateMemoryCache, shumate_memory_cache, G_TYPE_OBJECT);
 typedef struct
 {
   char *key;
-  GdkTexture *texture;
+  GdkPaintable *paintable;
   GPtrArray *symbols;
 } QueueMember;
 
@@ -214,7 +214,7 @@ delete_queue_member (QueueMember *member, gpointer user_data)
 {
   if (member)
     {
-      g_clear_object (&member->texture);
+      g_clear_object (&member->paintable);
       g_clear_pointer (&member->symbols, g_ptr_array_unref);
       g_clear_pointer (&member->key, g_free);
       g_free (member);
@@ -255,7 +255,7 @@ shumate_memory_cache_try_fill_tile (ShumateMemoryCache *self,
 
   move_queue_member_to_head (self->queue, link);
 
-  shumate_tile_set_texture (tile, member->texture);
+  shumate_tile_set_paintable (tile, member->paintable);
   shumate_tile_set_symbols (tile, member->symbols);
   shumate_tile_set_fade_in (tile, FALSE);
   shumate_tile_set_state (tile, SHUMATE_STATE_DONE);
@@ -283,7 +283,7 @@ shumate_memory_cache_store_tile (ShumateMemoryCache *self,
   else
     {
       QueueMember *member;
-      GdkTexture *texture;
+      GdkPaintable *paintable;
       GPtrArray *symbols;
 
       if (self->queue->length >= self->size_limit)
@@ -295,8 +295,8 @@ shumate_memory_cache_store_tile (ShumateMemoryCache *self,
 
       member = g_new0 (QueueMember, 1);
       member->key = key;
-      if ((texture = shumate_tile_get_texture (tile)))
-        member->texture = g_object_ref (texture);
+      if ((paintable = shumate_tile_get_paintable (tile)))
+        member->paintable = g_object_ref (paintable);
       if ((symbols = shumate_tile_get_symbols (tile)))
         member->symbols = g_ptr_array_ref (symbols);
 
diff --git a/shumate/shumate-raster-renderer.c b/shumate/shumate-raster-renderer.c
index 838c924..e7bf85e 100644
--- a/shumate/shumate-raster-renderer.c
+++ b/shumate/shumate-raster-renderer.c
@@ -213,7 +213,7 @@ on_data_source_received_data (ShumateRasterRenderer *self,
       if (shumate_tile_get_x (tile) == x
           && shumate_tile_get_y (tile) == y
           && shumate_tile_get_zoom_level (tile) == zoom_level)
-        shumate_tile_set_texture (tile, texture);
+        shumate_tile_set_paintable (tile, GDK_PAINTABLE (texture));
     }
 }
 
diff --git a/shumate/shumate-tile.c b/shumate/shumate-tile.c
index 109cb91..5cc99de 100644
--- a/shumate/shumate-tile.c
+++ b/shumate/shumate-tile.c
@@ -47,7 +47,7 @@ struct _ShumateTile
   ShumateState state; /* The tile state: loading, validation, done */
   gboolean fade_in;
 
-  GdkTexture *texture;
+  GdkPaintable *paintable;
   GPtrArray *symbols;
 };
 
@@ -61,7 +61,7 @@ enum
   PROP_SIZE,
   PROP_STATE,
   PROP_FADE_IN,
-  PROP_TEXTURE,
+  PROP_PAINTABLE,
   N_PROPERTIES
 };
 
@@ -72,17 +72,14 @@ shumate_tile_snapshot (GtkWidget   *widget,
                        GtkSnapshot *snapshot)
 {
   ShumateTile *self = SHUMATE_TILE (widget);
-  GdkTexture *texture = self->texture;
+  GdkPaintable *paintable = self->paintable;
 
-  if (texture)
+  if (paintable)
     {
-      gtk_snapshot_append_texture (snapshot,
-                                   texture,
-                                   &GRAPHENE_RECT_INIT(
-                                     0, 0,
-                                     gtk_widget_get_width (widget),
-                                     gtk_widget_get_height (widget)
-                                   ));
+      gdk_paintable_snapshot (paintable,
+                              snapshot,
+                              gtk_widget_get_width (widget),
+                              gtk_widget_get_height (widget));
     }
 }
 
@@ -144,8 +141,8 @@ shumate_tile_get_property (GObject    *object,
       g_value_set_boolean (value, shumate_tile_get_fade_in (self));
       break;
 
-    case PROP_TEXTURE:
-      g_value_set_object (value, shumate_tile_get_texture (self));
+    case PROP_PAINTABLE:
+      g_value_set_object (value, shumate_tile_get_paintable (self));
       break;
 
     default:
@@ -188,8 +185,8 @@ shumate_tile_set_property (GObject      *object,
       shumate_tile_set_fade_in (self, g_value_get_boolean (value));
       break;
 
-    case PROP_TEXTURE:
-      shumate_tile_set_texture (self, g_value_get_object (value));
+    case PROP_PAINTABLE:
+      shumate_tile_set_paintable (self, g_value_get_object (value));
       break;
 
     default:
@@ -203,7 +200,7 @@ shumate_tile_dispose (GObject *object)
 {
   ShumateTile *self = SHUMATE_TILE (object);
 
-  g_clear_object (&self->texture);
+  g_clear_object (&self->paintable);
   g_clear_pointer (&self->symbols, g_ptr_array_unref);
 
   G_OBJECT_CLASS (shumate_tile_parent_class)->dispose (object);
@@ -306,15 +303,15 @@ shumate_tile_class_init (ShumateTileClass *klass)
                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
   /**
-   * ShumateTile:texture:
+   * ShumateTile:paintable:
    *
-   * The #GdkTexture backing the tile
+   * The #GdkPaintable backing the tile
    */
-  obj_properties[PROP_TEXTURE] =
-    g_param_spec_object ("texture",
-                         "Texture",
-                         "Gdk Texture representation",
-                         GDK_TYPE_TEXTURE,
+  obj_properties[PROP_PAINTABLE] =
+    g_param_spec_object ("paintable",
+                         "Paintable",
+                         "Paintable",
+                         GDK_TYPE_PAINTABLE,
                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
   g_object_class_install_properties (object_class,
@@ -599,37 +596,37 @@ shumate_tile_set_fade_in (ShumateTile *self,
 }
 
 /**
- * shumate_tile_get_texture:
+ * shumate_tile_get_paintable:
  * @self: the #ShumateTile
  *
- * Get the #GdkTexture representing this tile.
+ * Get the #GdkPaintable representing this tile.
  *
- * Returns: (transfer none) (nullable): A #GdkTexture
+ * Returns: (transfer none) (nullable): A #GdkPaintable
  */
-GdkTexture *
-shumate_tile_get_texture (ShumateTile *self)
+GdkPaintable *
+shumate_tile_get_paintable (ShumateTile *self)
 {
   g_return_val_if_fail (SHUMATE_TILE (self), NULL);
 
-  return self->texture;
+  return self->paintable;
 }
 
 /**
- * shumate_tile_set_texture:
+ * shumate_tile_set_paintable:
  * @self: the #ShumateTile
- * @texture: a #GdkTexture
+ * @paintable: a #GdkPaintable
  *
- * Sets the #GdkTexture representing this tile.
+ * Sets the #GdkPaintable representing this tile.
  */
 void
-shumate_tile_set_texture (ShumateTile *self,
-                          GdkTexture  *texture)
+shumate_tile_set_paintable (ShumateTile  *self,
+                            GdkPaintable *paintable)
 {
   g_return_if_fail (SHUMATE_TILE (self));
 
-  if (g_set_object (&self->texture, texture))
+  if (g_set_object (&self->paintable, paintable))
     {
-      g_object_notify_by_pspec (G_OBJECT (self), obj_properties[PROP_TEXTURE]);
+      g_object_notify_by_pspec (G_OBJECT (self), obj_properties[PROP_PAINTABLE]);
       gtk_widget_queue_draw (GTK_WIDGET (self));
     }
 }
diff --git a/shumate/shumate-tile.h b/shumate/shumate-tile.h
index 1f718ed..4a31495 100644
--- a/shumate/shumate-tile.h
+++ b/shumate/shumate-tile.h
@@ -86,9 +86,9 @@ gboolean shumate_tile_get_fade_in (ShumateTile *self);
 void shumate_tile_set_fade_in (ShumateTile *self,
                                gboolean     fade_in);
 
-GdkTexture *shumate_tile_get_texture (ShumateTile *self);
-void shumate_tile_set_texture (ShumateTile *self,
-                               GdkTexture  *texture);
+GdkPaintable *shumate_tile_get_paintable (ShumateTile *self);
+void shumate_tile_set_paintable (ShumateTile  *self,
+                                 GdkPaintable *paintable);
 G_END_DECLS
 
 #endif /* SHUMATE_MAP_TILE_H */
diff --git a/shumate/shumate-vector-renderer.c b/shumate/shumate-vector-renderer.c
index 68b2ba8..ab1cd49 100644
--- a/shumate/shumate-vector-renderer.c
+++ b/shumate/shumate-vector-renderer.c
@@ -552,7 +552,7 @@ render (ShumateVectorRenderer *self,
       shumate_vector_layer_render ((ShumateVectorLayer *)self->layers->pdata[i], &scope);
 
   texture = texture_new_for_surface (surface);
-  shumate_tile_set_texture (tile, texture);
+  shumate_tile_set_paintable (tile, GDK_PAINTABLE (texture));
   shumate_tile_set_symbols (tile, symbols);
 
   cairo_destroy (scope.cr);
diff --git a/tests/memory-cache.c b/tests/memory-cache.c
index 1307dd0..02387cd 100644
--- a/tests/memory-cache.c
+++ b/tests/memory-cache.c
@@ -1,11 +1,11 @@
 #include <shumate/shumate.h>
 #include "shumate/shumate-memory-cache-private.h"
 
-static GdkTexture *
-create_texture ()
+static GdkPaintable *
+create_paintable ()
 {
   g_autoptr(GdkPixbuf) pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 256, 256);
-  return gdk_texture_new_for_pixbuf (pixbuf);
+  return GDK_PAINTABLE (gdk_texture_new_for_pixbuf (pixbuf));
 }
 
 
@@ -15,17 +15,17 @@ test_memory_cache_store_retrieve ()
 {
   g_autoptr(ShumateMemoryCache) cache = shumate_memory_cache_new_full (100);
   g_autoptr(ShumateTile) tile = shumate_tile_new_full (0, 0, 256, 0);
-  g_autoptr(GdkTexture) texture = create_texture ();
+  g_autoptr(GdkPaintable) paintable = create_paintable ();
 
   g_object_ref_sink (tile);
 
   /* Store the tile */
-  shumate_tile_set_texture (tile, texture);
+  shumate_tile_set_paintable (tile, paintable);
   shumate_memory_cache_store_tile (cache, tile, "A");
 
   /* Now retrieve it */
   g_assert_true (shumate_memory_cache_try_fill_tile (cache, tile, "A"));
-  g_assert_true (texture == shumate_tile_get_texture (tile));
+  g_assert_true (paintable == shumate_tile_get_paintable (tile));
 }
 
 
@@ -36,18 +36,18 @@ test_memory_cache_miss ()
   g_autoptr(ShumateMemoryCache) cache = shumate_memory_cache_new_full (100);
   g_autoptr(ShumateTile) tile1 = shumate_tile_new_full (0, 0, 256, 0);
   g_autoptr(ShumateTile) tile2 = shumate_tile_new_full (0, 0, 256, 1);
-  g_autoptr(GdkTexture) texture = create_texture ();
+  g_autoptr(GdkPaintable) paintable = create_paintable ();
 
   g_object_ref_sink (tile1);
   g_object_ref_sink (tile2);
 
   /* Store a tile */
-  shumate_tile_set_texture (tile1, texture);
+  shumate_tile_set_paintable (tile1, paintable);
   shumate_memory_cache_store_tile (cache, tile1, "A");
 
   /* Now retrieve a different one */
   g_assert_false (shumate_memory_cache_try_fill_tile (cache, tile2, "A"));
-  g_assert_null (shumate_tile_get_texture (tile2));
+  g_assert_null (shumate_tile_get_paintable (tile2));
 }
 
 
@@ -58,24 +58,24 @@ test_memory_cache_source_id ()
   g_autoptr(ShumateMemoryCache) cache = shumate_memory_cache_new_full (100);
   g_autoptr(ShumateTile) tile1 = shumate_tile_new_full (0, 0, 256, 0);
   g_autoptr(ShumateTile) tile2 = shumate_tile_new_full (0, 0, 256, 0);
-  g_autoptr(GdkTexture) texture1 = create_texture ();
-  g_autoptr(GdkTexture) texture2 = create_texture ();
+  g_autoptr(GdkPaintable) paintable1 = create_paintable ();
+  g_autoptr(GdkPaintable) paintable2 = create_paintable ();
 
   g_object_ref_sink (tile1);
   g_object_ref_sink (tile2);
 
   /* Store the tiles */
-  shumate_tile_set_texture (tile1, texture1);
-  shumate_tile_set_texture (tile2, texture2);
+  shumate_tile_set_paintable (tile1, paintable1);
+  shumate_tile_set_paintable (tile2, paintable2);
   shumate_memory_cache_store_tile (cache, tile1, "A");
   shumate_memory_cache_store_tile (cache, tile2, "B");
 
   /* Now retrieve them */
   g_assert_true (shumate_memory_cache_try_fill_tile (cache, tile1, "A"));
-  g_assert_true (texture1 == shumate_tile_get_texture (tile1));
+  g_assert_true (paintable1 == shumate_tile_get_paintable (tile1));
 
   g_assert_true (shumate_memory_cache_try_fill_tile (cache, tile2, "B"));
-  g_assert_true (texture2 == shumate_tile_get_texture (tile2));
+  g_assert_true (paintable2 == shumate_tile_get_paintable (tile2));
 }
 
 


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