From: Benjamin Otte Date: Fri, 16 Feb 2018 07:41:48 +0000 (+0100) Subject: texture: Implement GdkPaintable X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~22^2~956 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a4e16ce3cc41ee50a6b8d5eb895f27f5c178bac0;p=gtk4.git 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. --- diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c index 6e42f0a952..663f53c283 100644 --- a/gdk/gdktexture.c +++ b/gdk/gdktexture.c @@ -38,6 +38,10 @@ #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)) diff --git a/gdk/meson.build b/gdk/meson.build index 1254ec1393..7808ab20ea 100644 --- a/gdk/meson.build +++ b/gdk/meson.build @@ -167,6 +167,7 @@ gdk_deps = [ cairogobj_dep, glib_dep, gobject_dep, + graphene_dep, epoxy_dep, fontconfig_dep, platform_gio_dep,