mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 13:41:07 +00:00
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
This commit is contained in:
parent
01b4bf1920
commit
dda6a0d385
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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))
|
||||
if (!gtk_cairo_is_marked_for_draw (cr))
|
||||
{
|
||||
event_window = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
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 =
|
||||
|
Loading…
Reference in New Issue
Block a user