[gtk+/wip/ebassi/frame-marker: 1/4] Associate the drawing context to the Cairo context
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/ebassi/frame-marker: 1/4] Associate the drawing context to the Cairo context
- Date: Tue, 7 Jun 2016 16:11:48 +0000 (UTC)
commit 77ad7e5b1f85a509fbd9c3d15b406092c94fdecb
Author: Emmanuele Bassi <ebassi gnome org>
Date: Tue Jun 7 16:34:50 2016 +0100
Associate the drawing context to the Cairo context
Instead of associating the GdkWindow that created the GdkDrawingContext
we can directly bind the Cairo context to the GDK drawing context.
Cairo contexts created via gdk_cairo_create() go back to not having a
GdkWindow associated to them, like they did before we introduced the
gdk_window_begin_draw_frame() API.
https://bugzilla.gnome.org/show_bug.cgi?id=766675
docs/reference/gdk/gdk3-sections.txt | 2 +-
gdk/gdkcairo.h | 6 ++++--
gdk/gdkdrawingcontext.c | 31 +++++++++++++++++++++++++++++++
gdk/gdkwindow.c | 29 -----------------------------
gtk/gtkwidget.c | 29 ++++++++++++++++++-----------
5 files changed, 54 insertions(+), 43 deletions(-)
---
diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt
index f3e005a..b0fa61f 100644
--- a/docs/reference/gdk/gdk3-sections.txt
+++ b/docs/reference/gdk/gdk3-sections.txt
@@ -625,7 +625,7 @@ gdk_window_create_similar_surface
gdk_window_create_similar_image_surface
gdk_cairo_create
gdk_cairo_get_clip_rectangle
-gdk_cairo_get_window
+gdk_cairo_get_drawing_context
gdk_cairo_set_source_color
gdk_cairo_set_source_rgba
gdk_cairo_set_source_pixbuf
diff --git a/gdk/gdkcairo.h b/gdk/gdkcairo.h
index 4d8d223..6cd50aa 100644
--- a/gdk/gdkcairo.h
+++ b/gdk/gdkcairo.h
@@ -25,6 +25,7 @@
#include <gdk/gdkversionmacros.h>
#include <gdk/deprecated/gdkcolor.h>
#include <gdk/gdkrgba.h>
+#include <gdk/gdkdrawingcontext.h>
#include <gdk/gdkpixbuf.h>
#include <pango/pangocairo.h>
@@ -32,8 +33,7 @@ G_BEGIN_DECLS
GDK_AVAILABLE_IN_ALL
cairo_t * gdk_cairo_create (GdkWindow *window);
-GDK_AVAILABLE_IN_3_22
-GdkWindow * gdk_cairo_get_window (cairo_t *cr);
+
GDK_AVAILABLE_IN_ALL
gboolean gdk_cairo_get_clip_rectangle (cairo_t *cr,
GdkRectangle *rect);
@@ -83,6 +83,8 @@ void gdk_cairo_draw_from_gl (cairo_t *cr,
int width,
int height);
+GDK_AVAILABLE_IN_3_22
+GdkDrawingContext * gdk_cairo_get_drawing_context (cairo_t *cr);
G_END_DECLS
diff --git a/gdk/gdkdrawingcontext.c b/gdk/gdkdrawingcontext.c
index caffa0c..6216bab 100644
--- a/gdk/gdkdrawingcontext.c
+++ b/gdk/gdkdrawingcontext.c
@@ -178,6 +178,34 @@ gdk_drawing_context_init (GdkDrawingContext *self)
{
}
+static const cairo_user_data_key_t draw_context_key;
+
+static void
+gdk_cairo_set_drawing_context (cairo_t *cr,
+ GdkDrawingContext *context)
+{
+ cairo_set_user_data (cr, &draw_context_key, context, NULL);
+}
+
+/**
+ * gdk_cairo_get_drawing_context:
+ * @cr: a Cairo context
+ *
+ * Retrieves the #GdkDrawingContext that created the Cairo
+ * context @cr.
+ *
+ * Returns: (transfer none) (nullable): a #GdkDrawingContext, if any is set
+ *
+ * Since: 3.22
+ */
+GdkDrawingContext *
+gdk_cairo_get_drawing_context (cairo_t *cr)
+{
+ g_return_val_if_fail (cr != NULL, NULL);
+
+ return cairo_get_user_data (cr, &draw_context_key);
+}
+
/**
* gdk_drawing_context_get_cairo_context:
* @context:
@@ -204,6 +232,9 @@ gdk_drawing_context_get_cairo_context (GdkDrawingContext *context)
if (context->cr == NULL)
{
context->cr = gdk_cairo_create (context->window);
+
+ gdk_cairo_set_drawing_context (context->cr, context);
+
gdk_cairo_region (context->cr, context->clip);
cairo_clip (context->cr);
}
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 4724f3f..0f3e222 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -3111,33 +3111,6 @@ gdk_window_begin_paint_region (GdkWindow *window,
gdk_window_begin_paint_internal (window, region);
}
-static const cairo_user_data_key_t draw_context_window_key;
-
-static void
-gdk_cairo_set_window (cairo_t *cr,
- GdkWindow *window)
-{
- cairo_set_user_data (cr, &draw_context_window_key, window, NULL);
-}
-
-/**
- * gdk_cairo_get_window:
- * @cr: a Cairo context created by gdk_window_begin_draw_frame()
- *
- * Retrieves the #GdkWindow that created the Cairo context @cr.
- *
- * Returns: (nullable) (transfer none): a #GdkWindow
- *
- * Since: 3.22
- */
-GdkWindow *
-gdk_cairo_get_window (cairo_t *cr)
-{
- g_return_val_if_fail (cr != NULL, NULL);
-
- return cairo_get_user_data (cr, &draw_context_window_key);
-}
-
/**
* gdk_window_begin_draw_frame:
* @window: a #GdkWindow
@@ -3541,8 +3514,6 @@ gdk_cairo_create (GdkWindow *window)
cr = cairo_create (surface);
- gdk_cairo_set_window (cr, window);
-
if (window->impl_window->current_paint.region != NULL)
{
region = cairo_region_copy (window->impl_window->current_paint.region);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 158e656..313a425 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -6925,6 +6925,7 @@ gboolean
gtk_cairo_should_draw_window (cairo_t *cr,
GdkWindow *window)
{
+ GdkDrawingContext *context;
GdkWindow *tmp;
g_return_val_if_fail (cr != NULL, FALSE);
@@ -6933,8 +6934,11 @@ gtk_cairo_should_draw_window (cairo_t *cr,
if (gtk_cairo_is_marked_for_draw (cr))
return TRUE;
- tmp = gdk_cairo_get_window (cr);
+ context = gdk_cairo_get_drawing_context (cr);
+ if (context == NULL)
+ return TRUE;
+ tmp = gdk_drawing_context_get_window (context);
if (tmp == NULL)
return TRUE;
@@ -6964,22 +6968,25 @@ gtk_widget_draw_internal (GtkWidget *widget,
if (gdk_cairo_get_clip_rectangle (cr, NULL))
{
- GdkWindow *event_window;
+ GdkWindow *event_window = NULL;
gboolean result;
gboolean push_group;
/* If this was a cairo_t passed via gtk_widget_draw() then we don't
- * require a window
+ * require a window; otherwise we check for the window associated
+ * to the drawing context and mark it using the clip region of the
+ * Cairo context.
*/
- if (gtk_cairo_is_marked_for_draw (cr))
- {
- event_window = NULL;
- }
- else
+ if (!gtk_cairo_is_marked_for_draw (cr))
{
- event_window = gdk_cairo_get_window (cr);
- if (event_window != NULL)
- gdk_window_mark_paint_from_clip (event_window, cr);
+ GdkDrawingContext *context = gdk_cairo_get_drawing_context (cr);
+
+ if (context != NULL)
+ {
+ event_window = gdk_drawing_context_get_window (context);
+ if (event_window != NULL)
+ gdk_window_mark_paint_from_clip (event_window, cr);
+ }
}
push_group =
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]