[gtk+] widget: Add GtkWidgetClass.snapshot() vfunc
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] widget: Add GtkWidgetClass.snapshot() vfunc
- Date: Tue, 15 Nov 2016 16:55:31 +0000 (UTC)
commit b1154be1c4210c095760555af9f4f3f0058f4903
Author: Benjamin Otte <otte redhat com>
Date: Mon Nov 7 19:28:42 2016 +0100
widget: Add GtkWidgetClass.snapshot() vfunc
Does the same thing as the render vfunc, only that it uses a different
prototype.
gtk/gtkwidget.c | 35 ++++++++++++++++++++++++++++++++---
gtk/gtkwidget.h | 3 +++
2 files changed, 35 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index f051175..562c5ee 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -6375,7 +6375,32 @@ gtk_widget_draw_internal (GtkWidget *widget,
* render on the Cairo context; otherwise we just go through the old
* GtkWidget::draw path
*/
- if (widget_class->get_render_node != NULL)
+ if (widget_class->snapshot != NULL)
+ {
+ GskRenderer *renderer = gtk_widget_get_renderer (widget);
+ GtkSnapshot snapshot;
+ GskRenderer *fallback;
+ graphene_rect_t viewport;
+ GskRenderNode *node;
+
+ graphene_rect_init (&viewport,
+ widget->priv->allocation.x - widget->priv->clip.x,
+ widget->priv->allocation.y - widget->priv->clip.y,
+ widget->priv->clip.width,
+ widget->priv->clip.height);
+ fallback = gsk_renderer_create_fallback (renderer, &viewport, cr);
+ gtk_snapshot_init_root (&snapshot, renderer);
+ node = gtk_widget_snapshot (widget, &snapshot);
+ if (node != NULL)
+ {
+ gsk_renderer_render (fallback, node, NULL);
+ gsk_render_node_unref (node);
+ }
+ gtk_snapshot_finish (&snapshot);
+
+ g_object_unref (fallback);
+ }
+ else if (widget_class->get_render_node != NULL)
{
GskRenderer *renderer = gtk_widget_get_renderer (widget);
GskRenderer *fallback;
@@ -15664,7 +15689,8 @@ gtk_widget_snapshot (GtkWidget *widget,
/* Compatibility mode: if the widget does not have a render node, we draw
* using gtk_widget_draw() on a temporary node
*/
- if (klass->get_render_node == NULL)
+ if (klass->get_render_node == NULL &&
+ klass->snapshot == NULL)
{
GskRenderNode *tmp;
cairo_t *cr;
@@ -15682,7 +15708,10 @@ gtk_widget_snapshot (GtkWidget *widget,
}
else
{
- node = klass->get_render_node (widget, gtk_snapshot_get_renderer (snapshot));
+ if (klass->snapshot)
+ node = klass->snapshot (widget, snapshot);
+ else
+ node = klass->get_render_node (widget, gtk_snapshot_get_renderer (snapshot));
/* Compatibility mode: if there's a ::draw signal handler, we add a
* child node with the contents of the handler
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index d229183..ccf875f 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -33,6 +33,7 @@
#include <gsk/gsk.h>
#include <gtk/gtkaccelgroup.h>
#include <gtk/gtkborder.h>
+#include <gtk/gtksnapshot.h>
#include <gtk/gtktypes.h>
#include <atk/atk.h>
@@ -528,6 +529,8 @@ struct _GtkWidgetClass
GskRenderNode *(* get_render_node) (GtkWidget *widget,
GskRenderer *renderer);
+ GskRenderNode *(* snapshot) (GtkWidget *widget,
+ const GtkSnapshot *snapshot);
/*< private >*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]