texture: Implement GdkPaintable
authorBenjamin Otte <otte@redhat.com>
Fri, 16 Feb 2018 07:41:48 +0000 (08:41 +0100)
committerBenjamin Otte <otte@redhat.com>
Fri, 16 Mar 2018 05:04:44 +0000 (06:04 +0100)
This is kind of evil because we need to link to GTK to be able to
snapshot, but I hope nobody notices.

gdk/gdktexture.c
gdk/meson.build

index 6e42f0a952ced8440a871ac902667638a827b004..663f53c283abe1915b8357373c941664610654e5 100644 (file)
 
 #include "gdkinternals.h"
 #include "gdkmemorytextureprivate.h"
+#include "gdkpaintable.h"
+
+#define GTK_COMPILATION
+#include "gtk/gtksnapshot.h"
 
 /**
  * SECTION:gdktexture
@@ -71,7 +75,57 @@ enum {
 
 static GParamSpec *properties[N_PROPS];
 
-G_DEFINE_ABSTRACT_TYPE (GdkTexture, gdk_texture, G_TYPE_OBJECT)
+static void
+gdk_texture_paintable_snapshot (GdkPaintable *paintable,
+                                GdkSnapshot  *snapshot,
+                                double        width,
+                                double        height)
+{
+  GdkTexture *self = GDK_TEXTURE (paintable);
+
+  gtk_snapshot_append_texture (snapshot,
+                               self,
+                               &GRAPHENE_RECT_INIT (0, 0, width, height),
+                               "%s as paintable %dx%d",
+                               G_OBJECT_TYPE_NAME (paintable),
+                               self->width, self->height);
+}
+
+static GdkPaintableFlags
+gdk_texture_paintable_get_flags (GdkPaintable *paintable)
+{
+  return GDK_PAINTABLE_STATIC_SIZE
+       | GDK_PAINTABLE_STATIC_CONTENTS;
+}
+
+static int
+gdk_texture_paintable_get_intrinsic_width (GdkPaintable *paintable)
+{
+  GdkTexture *self = GDK_TEXTURE (paintable);
+
+  return self->width;
+}
+
+static int
+gdk_texture_paintable_get_intrinsic_height (GdkPaintable *paintable)
+{
+  GdkTexture *self = GDK_TEXTURE (paintable);
+
+  return self->height;
+}
+
+static void
+gdk_texture_paintable_init (GdkPaintableInterface *iface)
+{
+  iface->snapshot = gdk_texture_paintable_snapshot;
+  iface->get_flags = gdk_texture_paintable_get_flags;
+  iface->get_intrinsic_width = gdk_texture_paintable_get_intrinsic_width;
+  iface->get_intrinsic_height = gdk_texture_paintable_get_intrinsic_height;
+}
+
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkTexture, gdk_texture, G_TYPE_OBJECT,
+                                  G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
+                                                         gdk_texture_paintable_init))
 
 #define GDK_TEXTURE_WARN_NOT_IMPLEMENTED_METHOD(obj,method) \
   g_critical ("Texture of type '%s' does not implement GdkTexture::" # method, G_OBJECT_TYPE_NAME (obj))
index 1254ec1393b4335663fd2245b37fe94eaad415ae..7808ab20eac88d5cfa89628f56af76b393ccebb9 100644 (file)
@@ -167,6 +167,7 @@ gdk_deps = [
   cairogobj_dep,
   glib_dep,
   gobject_dep,
+  graphene_dep,
   epoxy_dep,
   fontconfig_dep,
   platform_gio_dep,