From: Benjamin Otte Date: Fri, 20 Apr 2018 22:47:35 +0000 (+0200) Subject: gdk: Add gdk_draw_context_get_frame_region() X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~22^2~391 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=dbe4f1d766f0c571ea0d778cd561929c19e63c94;p=gtk4.git gdk: Add gdk_draw_context_get_frame_region() This does the same as gdk_drawing_context_get_clip(). --- diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt index ebe7c37850..716d655ee1 100644 --- a/docs/reference/gdk/gdk4-sections.txt +++ b/docs/reference/gdk/gdk4-sections.txt @@ -1106,6 +1106,7 @@ gdk_frame_timings_get_type GdkDrawContext gdk_draw_context_get_display gdk_draw_context_get_surface +gdk_draw_context_get_frame_region GDK_DRAW_CONTEXT diff --git a/gdk/gdkdrawcontext.c b/gdk/gdkdrawcontext.c index 33324f44e3..45a353b086 100644 --- a/gdk/gdkdrawcontext.c +++ b/gdk/gdkdrawcontext.c @@ -303,3 +303,26 @@ gdk_draw_context_get_surface (GdkDrawContext *context) return priv->surface; } +/** + * gdk_draw_context_get_frame_region: + * @context: a #GdkDrawContext + * + * Retrieves the region that is currently in the process of being repainted. + * + * After a call to gdk_draw_context_begin_frame() this function will return + * a union of the region passed to that function and the area of the surface + * that the @context determined needs to be repainted. + * + * If @context is not inbetween calls to gdk_draw_context_begin_frame() and + * gdk_draw_context_end_frame(), %NULL will be returned. + * + * Returns: (transfer none) (nullable): a Cairo region or %NULL if not drawing + * a frame. + */ +const cairo_region_t * +gdk_draw_context_get_frame_region (GdkDrawContext *context) +{ + g_return_val_if_fail (GDK_IS_DRAW_CONTEXT (context), NULL); + + return context->frame_region; +} diff --git a/gdk/gdkdrawcontext.h b/gdk/gdkdrawcontext.h index 70bc802c4a..5b542667cd 100644 --- a/gdk/gdkdrawcontext.h +++ b/gdk/gdkdrawcontext.h @@ -40,7 +40,10 @@ GType gdk_draw_context_get_type (void) G_GNUC_CONST; GDK_AVAILABLE_IN_ALL GdkDisplay * gdk_draw_context_get_display (GdkDrawContext *context); GDK_AVAILABLE_IN_ALL -GdkSurface * gdk_draw_context_get_surface (GdkDrawContext *context); +GdkSurface * gdk_draw_context_get_surface (GdkDrawContext *context); + +GDK_AVAILABLE_IN_ALL +const cairo_region_t * gdk_draw_context_get_frame_region (GdkDrawContext *context); G_END_DECLS diff --git a/gdk/gdkdrawcontextprivate.h b/gdk/gdkdrawcontextprivate.h index 33c4b72546..242919698f 100644 --- a/gdk/gdkdrawcontextprivate.h +++ b/gdk/gdkdrawcontextprivate.h @@ -34,6 +34,8 @@ typedef struct _GdkDrawContextClass GdkDrawContextClass; struct _GdkDrawContext { GObject parent_instance; + + cairo_region_t *frame_region; }; struct _GdkDrawContextClass diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c index 6e7f125896..90486c4ed8 100644 --- a/gdk/gdksurface.c +++ b/gdk/gdksurface.c @@ -1586,7 +1586,6 @@ gdk_surface_begin_draw_frame (GdkSurface *surface, const cairo_region_t *region) { GdkDrawingContext *context; - cairo_region_t *real_region; g_return_val_if_fail (GDK_IS_SURFACE (surface), NULL); g_return_val_if_fail (gdk_surface_has_native (surface), NULL); @@ -1606,21 +1605,19 @@ gdk_surface_begin_draw_frame (GdkSurface *surface, return NULL; } - real_region = cairo_region_copy (region); + draw_context->frame_region = cairo_region_copy (region); - gdk_draw_context_begin_frame (draw_context, real_region); + gdk_draw_context_begin_frame (draw_context, draw_context->frame_region); context = g_object_new (GDK_TYPE_DRAWING_CONTEXT, "surface", surface, "paint-context", draw_context, - "clip", real_region, + "clip", draw_context->frame_region, NULL); /* Do not take a reference, to avoid creating cycles */ surface->drawing_context = context; - cairo_region_destroy (real_region); - return context; } @@ -1659,22 +1656,13 @@ gdk_surface_end_draw_frame (GdkSurface *surface, g_return_if_fail (surface->drawing_context == context); paint_context = gdk_drawing_context_get_paint_context (context); - if (paint_context) - { - cairo_region_t *clip = gdk_drawing_context_get_clip (context); - - gdk_draw_context_end_frame (paint_context, - clip, - surface->active_update_area); - - cairo_region_destroy (clip); - } - else - { - } + gdk_draw_context_end_frame (paint_context, + paint_context->frame_region, + surface->active_update_area); surface->drawing_context = NULL; + g_clear_pointer (&paint_context->frame_region, cairo_region_destroy); g_object_unref (context); }