gdk: Add gdk_draw_context_get_frame_region()
authorBenjamin Otte <otte@redhat.com>
Fri, 20 Apr 2018 22:47:35 +0000 (00:47 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 24 Apr 2018 21:16:58 +0000 (23:16 +0200)
This does the same as gdk_drawing_context_get_clip().

docs/reference/gdk/gdk4-sections.txt
gdk/gdkdrawcontext.c
gdk/gdkdrawcontext.h
gdk/gdkdrawcontextprivate.h
gdk/gdksurface.c

index ebe7c37850fd3119f1758187d9f79362b538f0ed..716d655ee1ed7b9505d1868e95c14d4c722cba54 100644 (file)
@@ -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
 
 <SUBSECTION Standard>
 GDK_DRAW_CONTEXT
index 33324f44e35762aef4f7fd3c2daf23f73318efc8..45a353b08699c79c32c1f390385306192db1aada 100644 (file)
@@ -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;
+}
index 70bc802c4a2425ca211f8e09bd8b3fc688a29098..5b542667cdb570b2a57843be34dcc1f8d31a596c 100644 (file)
@@ -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
 
index 33c4b725460a82108decb0f741ca1578c208f98d..242919698f272ccee12a1704728df6f16991e4f9 100644 (file)
@@ -34,6 +34,8 @@ typedef struct _GdkDrawContextClass GdkDrawContextClass;
 struct _GdkDrawContext
 {
   GObject parent_instance;
+
+  cairo_region_t *frame_region;
 };
 
 struct _GdkDrawContextClass
index 6e7f125896167f6b4af39fa933e1c6d5b6fc88a5..90486c4ed8b974b748d482971b3637b86efbf40a 100644 (file)
@@ -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);
 }