[gtk+/wip/renderops: 1/6] renderops: Add a simple functionality to track rendering operations
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/renderops: 1/6] renderops: Add a simple functionality to track rendering operations
- Date: Tue, 30 Jun 2015 04:07:51 +0000 (UTC)
commit fc9b67a7396821d6fae107a631f1557f9f365448
Author: Benjamin Otte <otte redhat com>
Date: Sat Jun 27 05:25:36 2015 +0200
renderops: Add a simple functionality to track rendering operations
gtk/Makefile.am | 2 +
gtk/gtkrenderops.c | 107 +++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkrenderopsprivate.h | 72 ++++++++++++++++++++++++++++++
gtk/gtktypes.h | 2 +
gtk/gtkwidget.c | 8 +++-
5 files changed, 190 insertions(+), 1 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 50e8efb..5a27f7b 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -482,6 +482,7 @@ gtk_private_h_sources = \
gtkpixelcacheprivate.h \
gtkquery.h \
gtkrangeprivate.h \
+ gtkrenderopsprivate.h \
gtkrbtree.h \
gtkrecentchooserdefault.h \
gtkrecentchooserprivate.h \
@@ -782,6 +783,7 @@ gtk_base_c_sources = \
gtkrenderbackground.c \
gtkrenderborder.c \
gtkrendericon.c \
+ gtkrenderops.c \
gtkresources.c \
gtkrevealer.c \
gtkroundedbox.c \
diff --git a/gtk/gtkrenderops.c b/gtk/gtkrenderops.c
new file mode 100644
index 0000000..8515bdf
--- /dev/null
+++ b/gtk/gtkrenderops.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright © 2011 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#include "config.h"
+
+#include "gtkrenderopsprivate.h"
+
+G_DEFINE_TYPE (GtkRenderOps, gtk_render_ops, G_TYPE_OBJECT)
+
+static cairo_t *
+gtk_render_ops_real_begin_draw_widget (GtkRenderOps *ops,
+ GtkWidget *widget,
+ cairo_t *cr)
+{
+ return cairo_reference (cr);
+}
+
+static void
+gtk_render_ops_real_end_draw_widget (GtkRenderOps *ops,
+ GtkWidget *widget,
+ cairo_t *draw_cr,
+ cairo_t *original_cr)
+{
+ cairo_destroy (draw_cr);
+}
+
+static void
+gtk_render_ops_class_init (GtkRenderOpsClass *klass)
+{
+ klass->begin_draw_widget = gtk_render_ops_real_begin_draw_widget;
+ klass->end_draw_widget = gtk_render_ops_real_end_draw_widget;
+}
+
+static void
+gtk_render_ops_init (GtkRenderOps *image)
+{
+}
+
+static const cairo_user_data_key_t render_ops_key;
+
+static GtkRenderOps *
+gtk_cairo_get_render_ops (cairo_t *cr)
+{
+ return cairo_get_user_data (cr, &render_ops_key);
+}
+
+/* public API */
+void
+gtk_cairo_set_render_ops (cairo_t *cr,
+ GtkRenderOps *ops)
+{
+ if (ops)
+ {
+ g_object_ref (ops);
+ cairo_set_user_data (cr, &render_ops_key, ops, g_object_unref);
+ }
+ else
+ {
+ cairo_set_user_data (cr, &render_ops_key, NULL, NULL);
+ }
+}
+
+cairo_t *
+gtk_render_ops_begin_draw_widget (GtkWidget *widget,
+ cairo_t *cr)
+{
+ GtkRenderOps *ops;
+
+ ops = gtk_cairo_get_render_ops (cr);
+ if (ops == NULL)
+ return gtk_render_ops_real_begin_draw_widget (NULL, widget, cr);
+
+ return GTK_RENDER_OPS_GET_CLASS (ops)->begin_draw_widget (ops, widget, cr);
+}
+
+void
+gtk_render_ops_end_draw_widget (GtkWidget *widget,
+ cairo_t *draw_cr,
+ cairo_t *original_cr)
+{
+ GtkRenderOps *ops;
+
+ ops = gtk_cairo_get_render_ops (original_cr);
+ if (ops == NULL)
+ {
+ gtk_render_ops_real_end_draw_widget (NULL, widget, draw_cr, original_cr);
+ return;
+ }
+
+ GTK_RENDER_OPS_GET_CLASS (ops)->end_draw_widget (ops, widget, draw_cr, original_cr);
+}
diff --git a/gtk/gtkrenderopsprivate.h b/gtk/gtkrenderopsprivate.h
new file mode 100644
index 0000000..f149d00
--- /dev/null
+++ b/gtk/gtkrenderopsprivate.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright © 2014 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#ifndef __GTK_RENDER_OPS_PRIVATE_H__
+#define __GTK_RENDER_OPS_PRIVATE_H__
+
+#include <cairo.h>
+
+#include <gtk/gtktypes.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_RENDER_OPS (gtk_render_ops_get_type ())
+#define GTK_RENDER_OPS(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_RENDER_OPS, GtkRenderOps))
+#define GTK_RENDER_OPS_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_RENDER_OPS, GtkRenderOpsClass))
+#define GTK_IS_RENDER_OPS(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_RENDER_OPS))
+#define GTK_IS_RENDER_OPS_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_RENDER_OPS))
+#define GTK_RENDER_OPS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RENDER_OPS,
GtkRenderOpsClass))
+
+typedef struct _GtkRenderOps GtkRenderOps;
+typedef struct _GtkRenderOpsClass GtkRenderOpsClass;
+
+struct _GtkRenderOps
+{
+ GObject parent;
+};
+
+struct _GtkRenderOpsClass
+{
+ GObjectClass parent_class;
+
+ cairo_t * (* begin_draw_widget) (GtkRenderOps *ops,
+ GtkWidget *widget,
+ cairo_t *cr);
+ void (* end_draw_widget) (GtkRenderOps *ops,
+ GtkWidget *widget,
+ cairo_t *draw_cr,
+ cairo_t *original_cr);
+};
+
+GType gtk_render_ops_get_type (void) G_GNUC_CONST;
+
+/* public API */
+void gtk_cairo_set_render_ops (cairo_t *cr,
+ GtkRenderOps *ops);
+
+/* calls from inside GTK */
+cairo_t * gtk_render_ops_begin_draw_widget (GtkWidget *widget,
+ cairo_t *cr);
+void gtk_render_ops_end_draw_widget (GtkWidget *widget,
+ cairo_t *draw_cr,
+ cairo_t *original_cr);
+
+G_END_DECLS
+
+#endif /* __GTK_RENDER_OPS_PRIVATE_H__ */
diff --git a/gtk/gtktypes.h b/gtk/gtktypes.h
index f1b645a..95e4506 100644
--- a/gtk/gtktypes.h
+++ b/gtk/gtktypes.h
@@ -29,6 +29,8 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
+#include <glib-object.h>
+
G_BEGIN_DECLS
typedef struct _GtkAdjustment GtkAdjustment;
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index d9230f5..465ce21 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -42,6 +42,7 @@
#include "gtkcssshadowsvalueprivate.h"
#include "gtkintl.h"
#include "gtkmarshalers.h"
+#include "gtkrenderopsprivate.h"
#include "gtkselectionprivate.h"
#include "gtksettingsprivate.h"
#include "gtksizegroup-private.h"
@@ -6984,13 +6985,18 @@ _gtk_widget_draw_internal (GtkWidget *widget,
if (gdk_cairo_get_clip_rectangle (cr, NULL))
{
gboolean result;
+ cairo_t *draw_cr;
gdk_window_mark_paint_from_clip (window, cr);
+ draw_cr = gtk_render_ops_begin_draw_widget (widget, cr);
+
g_signal_emit (widget, widget_signals[DRAW],
- 0, cr,
+ 0, draw_cr,
&result);
+ gtk_render_ops_end_draw_widget (widget, draw_cr, cr);
+
#ifdef G_ENABLE_DEBUG
if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_BASELINES))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]