[gtk/wip/otte/cairo-context] cairocontext: Remove fallback implementations



commit 5b4a6e7a859a0277c5387e42db6b2ee8bf03d517
Author: Benjamin Otte <otte redhat com>
Date:   Mon Apr 23 18:42:36 2018 +0200

    cairocontext: Remove fallback implementations
    
    Now that all Cairo contexts are ported to managing cairo surfaces
    themselves, the old fallback code that didi the managing is no longer
    needed.
    
    Also clarify the behavior of gdk_cairo_context_cairo_create() wrt the
    vfunc by doing the early exit and the clipping outside of it.

 gdk/broadway/gdksurface-broadway.c    |   9 --
 gdk/gdkcairocontext.c                 | 201 +++-------------------------------
 gdk/gdkinternals.h                    |  15 ---
 gdk/gdksurface.c                      |  61 -----------
 gdk/gdksurfaceimpl.h                  |   2 -
 gdk/wayland/gdkcairocontext-wayland.c |  10 +-
 gdk/x11/gdkcairocontext-x11.c         |   3 -
 7 files changed, 17 insertions(+), 284 deletions(-)
---
diff --git a/gdk/broadway/gdksurface-broadway.c b/gdk/broadway/gdksurface-broadway.c
index 29c449d7f1..f835f0e795 100644
--- a/gdk/broadway/gdksurface-broadway.c
+++ b/gdk/broadway/gdksurface-broadway.c
@@ -871,14 +871,6 @@ gdk_broadway_surface_set_functions (GdkSurface    *surface,
     return;
 }
 
-static void
-gdk_broadway_surface_end_paint (GdkSurface *surface)
-{
-  GdkSurfaceImplBroadway *impl;
-  impl = GDK_SURFACE_IMPL_BROADWAY (surface->impl);
-  impl->dirty = TRUE;
-}
-
 typedef struct _MoveResizeData MoveResizeData;
 
 struct _MoveResizeData
@@ -1375,7 +1367,6 @@ gdk_surface_impl_broadway_class_init (GdkSurfaceImplBroadwayClass *klass)
   impl_class->get_device_state = gdk_surface_broadway_get_device_state;
   impl_class->input_shape_combine_region = gdk_surface_broadway_input_shape_combine_region;
   impl_class->destroy = _gdk_broadway_surface_destroy;
-  impl_class->end_paint = gdk_broadway_surface_end_paint;
   impl_class->beep = gdk_broadway_surface_beep;
 
   impl_class->focus = gdk_broadway_surface_focus;
diff --git a/gdk/gdkcairocontext.c b/gdk/gdkcairocontext.c
index 3e4a31274e..5b6deef1f9 100644
--- a/gdk/gdkcairocontext.c
+++ b/gdk/gdkcairocontext.c
@@ -56,193 +56,9 @@ struct _GdkCairoContextPrivate {
 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkCairoContext, gdk_cairo_context, GDK_TYPE_DRAW_CONTEXT,
                                   G_ADD_PRIVATE (GdkCairoContext))
 
-static cairo_surface_t *
-gdk_surface_ref_impl_surface (GdkSurface *surface)
-{
-  return GDK_SURFACE_IMPL_GET_CLASS (surface->impl)->ref_cairo_surface (surface);
-}
-
-static cairo_content_t
-gdk_surface_get_content (GdkSurface *surface)
-{
-  cairo_surface_t *cairo_surface;
-  cairo_content_t content;
-
-  g_return_val_if_fail (GDK_IS_SURFACE (surface), 0);
-
-  cairo_surface = gdk_surface_ref_impl_surface (surface);
-  content = cairo_surface_get_content (cairo_surface);
-  cairo_surface_destroy (cairo_surface);
-
-  return content;
-}
-
-static cairo_t *
-gdk_cairo_context_default_cairo_create (GdkCairoContext *self)
-{
-  GdkDrawContext *context;
-  GdkSurface *surface;
-  cairo_surface_t *cairo_surface;
-  cairo_t *cr;
-
-  g_return_val_if_fail (GDK_IS_CAIRO_CONTEXT (self), NULL);
-
-  context = GDK_DRAW_CONTEXT (self);
-  if (!gdk_draw_context_is_in_frame (context))
-    return NULL;
-
-  surface = gdk_draw_context_get_surface (context);
-  cairo_surface = _gdk_surface_ref_cairo_surface (surface);
-  cr = cairo_create (cairo_surface);
-
-  gdk_cairo_region (cr, gdk_draw_context_get_frame_region (context));
-  cairo_clip (cr);
-
-  cairo_surface_destroy (cairo_surface);
-
-  return cr;
-}
-
-static void
-gdk_surface_clear_backing_region (GdkSurface *surface)
-{
-  cairo_t *cr;
-
-  if (GDK_SURFACE_DESTROYED (surface))
-    return;
-
-  cr = cairo_create (surface->current_paint.surface);
-
-  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
-  gdk_cairo_region (cr, surface->current_paint.region);
-  cairo_fill (cr);
-
-  cairo_destroy (cr);
-}
-
-static void
-gdk_surface_free_current_paint (GdkSurface *surface)
-{
-  cairo_surface_destroy (surface->current_paint.surface);
-  surface->current_paint.surface = NULL;
-
-  cairo_region_destroy (surface->current_paint.region);
-  surface->current_paint.region = NULL;
-
-  surface->current_paint.surface_needs_composite = FALSE;
-}
-
-static void
-gdk_cairo_context_begin_frame (GdkDrawContext *draw_context,
-                               cairo_region_t *region)
-{
-  GdkRectangle clip_box;
-  GdkSurface *surface;
-  GdkSurfaceImplClass *impl_class;
-  double sx, sy;
-  gboolean needs_surface;
-  cairo_content_t surface_content;
-
-  surface = gdk_draw_context_get_surface (draw_context);
-  if (surface->current_paint.surface != NULL)
-    {
-      g_warning ("A paint operation on the surface is alredy in progress. "
-                 "This is not allowed.");
-      return;
-    }
-
-  impl_class = GDK_SURFACE_IMPL_GET_CLASS (surface->impl);
-
-  needs_surface = TRUE;
-  if (impl_class->begin_paint)
-    needs_surface = impl_class->begin_paint (surface);
-
-  surface->current_paint.region = cairo_region_copy (region);
-  cairo_region_get_extents (surface->current_paint.region, &clip_box);
-
-  surface_content = gdk_surface_get_content (surface);
-
-  if (needs_surface)
-    {
-      surface->current_paint.surface = gdk_surface_create_similar_surface (surface,
-                                                                           surface_content,
-                                                                           MAX (clip_box.width, 1),
-                                                                           MAX (clip_box.height, 1));
-      sx = sy = 1;
-      cairo_surface_get_device_scale (surface->current_paint.surface, &sx, &sy);
-      cairo_surface_set_device_offset (surface->current_paint.surface, -clip_box.x*sx, -clip_box.y*sy);
-
-      surface->current_paint.surface_needs_composite = TRUE;
-    }
-  else
-    {
-      surface->current_paint.surface = gdk_surface_ref_impl_surface (surface);
-      surface->current_paint.surface_needs_composite = FALSE;
-    }
-
-  if (!cairo_region_is_empty (surface->current_paint.region))
-    gdk_surface_clear_backing_region (surface);
-}
-
-static void
-gdk_cairo_context_end_frame (GdkDrawContext *draw_context,
-                             cairo_region_t *painted,
-                             cairo_region_t *damage)
-{
-  GdkSurfaceImplClass *impl_class;
-  GdkSurface *surface;
-  cairo_t *cr;
-
-  surface = gdk_draw_context_get_surface (draw_context);
-  if (surface->current_paint.surface == NULL)
-    {
-      g_warning (G_STRLOC": no preceding call to gdk_draw_context_end_frame(), see documentation");
-      return;
-    }
-
-  impl_class = GDK_SURFACE_IMPL_GET_CLASS (surface->impl);
-
-  if (impl_class->end_paint)
-    impl_class->end_paint (surface);
-
-  if (surface->current_paint.surface_needs_composite)
-    {
-      cairo_surface_t *cairo_surface;
-
-      cairo_surface = gdk_surface_ref_impl_surface (surface);
-      cr = cairo_create (cairo_surface);
-
-      cairo_set_source_surface (cr, surface->current_paint.surface, 0, 0);
-      gdk_cairo_region (cr, surface->current_paint.region);
-      cairo_clip (cr);
-
-      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
-      cairo_paint (cr);
-
-      cairo_destroy (cr);
-
-      cairo_surface_flush (cairo_surface);
-      cairo_surface_destroy (cairo_surface);
-    }
-
-  gdk_surface_free_current_paint (surface);
-}
-
-static void
-gdk_cairo_context_surface_resized (GdkDrawContext *draw_context)
-{
-}
-
 static void
 gdk_cairo_context_class_init (GdkCairoContextClass *klass)
 {
-  GdkDrawContextClass *draw_context_class = GDK_DRAW_CONTEXT_CLASS (klass);
-
-  draw_context_class->begin_frame = gdk_cairo_context_begin_frame;
-  draw_context_class->end_frame = gdk_cairo_context_end_frame;
-  draw_context_class->surface_resized = gdk_cairo_context_surface_resized;
-
-  klass->cairo_create = gdk_cairo_context_default_cairo_create;
 }
 
 static void
@@ -268,6 +84,21 @@ gdk_cairo_context_init (GdkCairoContext *self)
 cairo_t *
 gdk_cairo_context_cairo_create (GdkCairoContext *self)
 {
-  return GDK_CAIRO_CONTEXT_GET_CLASS (self)->cairo_create (self);
+  GdkDrawContext *draw_context;
+  cairo_t *cr;
+
+  g_return_val_if_fail (GDK_IS_CAIRO_CONTEXT (self), NULL);
+
+  draw_context = GDK_DRAW_CONTEXT (self);
+
+  if (!gdk_draw_context_is_in_frame (draw_context))
+    return NULL;
+
+  cr = GDK_CAIRO_CONTEXT_GET_CLASS (self)->cairo_create (self);
+
+  gdk_cairo_region (cr, gdk_draw_context_get_frame_region (draw_context));
+  cairo_clip (cr);
+
+  return cr;
 }
 
diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h
index f7ccf740a6..ab985288b4 100644
--- a/gdk/gdkinternals.h
+++ b/gdk/gdkinternals.h
@@ -158,16 +158,6 @@ struct _GdkSurface
   GList *children;
   GList children_list_node;
 
-  struct {
-    /* The temporary surface that we're painting to. This will be composited
-     * back into the surface when we call end_paint. This is our poor-man's
-     * way of doing double buffering. */
-    cairo_surface_t *surface;
-
-    cairo_region_t *region;
-
-    gboolean surface_needs_composite;
-  } current_paint;
   GdkGLContext *gl_paint_context;
 
   cairo_region_t *update_area;
@@ -290,9 +280,6 @@ cairo_region_t *gdk_cairo_region_from_clip       (cairo_t         *cr);
  * Interfaces used by windowing code *
  *************************************/
 
-cairo_surface_t *
-           _gdk_surface_ref_cairo_surface (GdkSurface *surface);
-
 GdkSurface* gdk_surface_new               (GdkDisplay     *display,
                                            GdkSurface      *parent,
                                            GdkSurfaceAttr  *attributes);
@@ -307,8 +294,6 @@ void gdk_surface_get_unscaled_size (GdkSurface *surface,
                                     int *unscaled_width,
                                     int *unscaled_height);
 
-cairo_region_t *gdk_surface_get_current_paint_region (GdkSurface *surface);
-
 /*****************************************
  * Interfaces provided by windowing code *
  *****************************************/
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index f5234bcc33..c5c176df2d 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -1541,67 +1541,6 @@ gdk_surface_create_vulkan_context (GdkSurface  *surface,
                          NULL);
 }
 
-/*< private >
- * gdk_surface_get_current_paint_region:
- * @surface: a #GdkSurface
- *
- * Retrieves a copy of the current paint region.
- *
- * Returns: (transfer full): a Cairo region
- */
-cairo_region_t *
-gdk_surface_get_current_paint_region (GdkSurface *surface)
-{
-  cairo_region_t *region;
-
-  if (surface->impl_surface->current_paint.region != NULL)
-    {
-      region = cairo_region_copy (surface->impl_surface->current_paint.region);
-      cairo_region_translate (region, -surface->abs_x, -surface->abs_y);
-    }
-  else
-    {
-      region = cairo_region_create_rectangle (&(cairo_rectangle_int_t) { 0, 0, surface->width, 
surface->height });
-    }
-
-  return region;
-}
-
-/* This is used in places like gdk_cairo_set_source_surface and
- * other places to take "screenshots" of surfaces. Thus, we allow
- * it to be used outside of a begin_paint / end_paint. */
-cairo_surface_t *
-_gdk_surface_ref_cairo_surface (GdkSurface *surface)
-{
-  cairo_surface_t *cairo_surface;
-
-  g_return_val_if_fail (GDK_IS_SURFACE (surface), NULL);
-
-  /* This returns either the current working surface on the paint stack
-   * or the actual impl surface of the surface. This should not be used
-   * from very many places: be careful! */
-  if (surface->impl_surface->current_paint.surface)
-    cairo_surface = cairo_surface_reference (surface->impl_surface->current_paint.surface);
-  else
-    cairo_surface = GDK_SURFACE_IMPL_GET_CLASS (surface->impl)->ref_cairo_surface 
(gdk_surface_get_impl_surface (surface));
-
-  if (gdk_surface_has_impl (surface))
-    {
-      return cairo_surface;
-    }
-  else
-    {
-      cairo_surface_t *subsurface;
-      subsurface = cairo_surface_create_for_rectangle (cairo_surface,
-                                                       surface->abs_x,
-                                                       surface->abs_y,
-                                                       surface->width,
-                                                       surface->height);
-      cairo_surface_destroy (cairo_surface);
-      return subsurface;
-    }
-}
-
 /* Code for dirty-region queueing
  */
 static GSList *update_surfaces = NULL;
diff --git a/gdk/gdksurfaceimpl.h b/gdk/gdksurfaceimpl.h
index 0e33f254a4..26290193a9 100644
--- a/gdk/gdksurfaceimpl.h
+++ b/gdk/gdksurfaceimpl.h
@@ -95,8 +95,6 @@ struct _GdkSurfaceImplClass
                                          gdouble         *x,
                                          gdouble         *y,
                                          GdkModifierType *mask);
-  gboolean    (* begin_paint)           (GdkSurface       *surface);
-  void        (* end_paint)             (GdkSurface       *surface);
 
   void         (* input_shape_combine_region) (GdkSurface       *surface,
                                                const cairo_region_t *shape_region,
diff --git a/gdk/wayland/gdkcairocontext-wayland.c b/gdk/wayland/gdkcairocontext-wayland.c
index fe4237f63d..9a8b456c7e 100644
--- a/gdk/wayland/gdkcairocontext-wayland.c
+++ b/gdk/wayland/gdkcairocontext-wayland.c
@@ -206,16 +206,8 @@ static cairo_t *
 gdk_wayland_cairo_context_cairo_create (GdkCairoContext *context)
 {
   GdkWaylandCairoContext *self = GDK_WAYLAND_CAIRO_CONTEXT (context);
-  cairo_t *cr;
-
-  if (self->paint_surface == NULL)
-    return NULL;
-
-  cr = cairo_create (self->paint_surface);
-  gdk_cairo_region (cr, gdk_wayland_cairo_context_surface_get_region (self->paint_surface));
-  cairo_clip (cr);
 
-  return cr;
+  return cairo_create (self->paint_surface);
 }
 
 static void
diff --git a/gdk/x11/gdkcairocontext-x11.c b/gdk/x11/gdkcairocontext-x11.c
index 41fb43ee0c..aee8a1228f 100644
--- a/gdk/x11/gdkcairocontext-x11.c
+++ b/gdk/x11/gdkcairocontext-x11.c
@@ -106,9 +106,6 @@ gdk_x11_cairo_context_cairo_create (GdkCairoContext *context)
 {
   GdkX11CairoContext *self = GDK_X11_CAIRO_CONTEXT (context);
 
-  if (self->paint_surface == NULL)
-    return NULL;
-
   return cairo_create (self->paint_surface);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]