[gtk/wip/otte/paintable: 52/62] texture: Implement GdkPaintable



commit 42e98f7347112d07c4cc872a0fa3ddc9341b042e
Author: Benjamin Otte <otte redhat com>
Date:   Fri Feb 16 08:41:48 2018 +0100

    texture: Implement GdkPaintable
    
    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 | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 gdk/meson.build  |  1 +
 2 files changed, 65 insertions(+), 2 deletions(-)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index dd3d0d7b60..0f456c222e 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -36,8 +36,12 @@
 
 #include "gdktextureprivate.h"
 
-#include "gdkinternals.h"
 #include "gdkcairo.h"
+#include "gdkinternals.h"
+#include "gdkpaintable.h"
+
+#define GTK_COMPILATION
+#include "gtk/gtksnapshot.h"
 
 #include <epoxy/gl.h>
 
@@ -73,7 +77,65 @@ 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 double gdk_texture_paintable_get_intrinsic_aspect_ratio (GdkPaintable *paintable)
+{
+  GdkTexture *self = GDK_TEXTURE (paintable);
+
+  return (double) self->width / 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;
+  iface->get_intrinsic_aspect_ratio = gdk_texture_paintable_get_intrinsic_aspect_ratio;
+}
+
+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))
diff --git a/gdk/meson.build b/gdk/meson.build
index 5fb00513fb..a3487c80b9 100644
--- a/gdk/meson.build
+++ b/gdk/meson.build
@@ -163,6 +163,7 @@ gdk_deps = [
   cairogobj_dep,
   glib_dep,
   gobject_dep,
+  graphene_dep,
   epoxy_dep,
   fontconfig_dep,
   platform_gio_dep,


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