[gtk: 2/4] wayland: Commit surface from cairo context




commit 1abcd6f3043fc272d8fd30437fc0969c73fc6eb5
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Thu Sep 17 17:35:35 2020 +0200

    wayland: Commit surface from cairo context
    
    In order to make the cairo renderer/context behave more similar to how
    the OpenGL and Vulkan renderer/context behaves, request a frame callback
    and commit in the end frame vfunc.
    
    This means the end frame vfunc in cairo does
    
     * attach buffer
     * request frame callback
     * sync surface state
     * commit
    
    Where as e.g. the OpenGL version of the same flow does
    
     * attach buffer
     * request frame callback
     * sync surface state
     * eglSwapBuffers()
    
    where eglSwapBuffers() indirectly calls wl_surface_commit().

 gdk/wayland/gdkcairocontext-wayland.c |  5 +++++
 gdk/wayland/gdkprivate-wayland.h      |  1 +
 gdk/wayland/gdksurface-wayland.c      | 29 ++++++++---------------------
 3 files changed, 14 insertions(+), 21 deletions(-)
---
diff --git a/gdk/wayland/gdkcairocontext-wayland.c b/gdk/wayland/gdkcairocontext-wayland.c
index bb28ada46f..d0fc54d0b0 100644
--- a/gdk/wayland/gdkcairocontext-wayland.c
+++ b/gdk/wayland/gdkcairocontext-wayland.c
@@ -23,6 +23,7 @@
 #include "gdkprivate-wayland.h"
 
 #include "gdkinternals.h"
+#include "gdkprofilerprivate.h"
 
 static const cairo_user_data_key_t gdk_wayland_cairo_context_key;
 static const cairo_user_data_key_t gdk_wayland_cairo_region_key;
@@ -180,6 +181,10 @@ gdk_wayland_cairo_context_end_frame (GdkDrawContext *draw_context,
 
   gdk_wayland_surface_attach_image (surface, self->paint_surface, painted);
   gdk_wayland_surface_sync (surface);
+  gdk_wayland_surface_request_frame (surface);
+
+  gdk_profiler_add_mark (GDK_PROFILER_CURRENT_TIME, 0, "wayland", "surface commit");
+  gdk_wayland_surface_commit (surface);
 
   gdk_wayland_cairo_context_surface_clear_region (self->paint_surface);
   self->paint_surface = NULL;
diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h
index dc7c4848a2..db45a07c08 100644
--- a/gdk/wayland/gdkprivate-wayland.h
+++ b/gdk/wayland/gdkprivate-wayland.h
@@ -94,6 +94,7 @@ guint      _gdk_wayland_cursor_get_next_image_index (GdkWaylandDisplay *display,
                                                      guint             *next_image_delay);
 
 void       gdk_wayland_surface_sync (GdkSurface *surface);
+void       gdk_wayland_surface_commit (GdkSurface *surface);
 void       gdk_wayland_surface_request_frame (GdkSurface *surface);
 void            gdk_wayland_surface_attach_image           (GdkSurface           *surface,
                                                             cairo_surface_t      *cairo_surface,
diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c
index 7ac0a78263..bda30ae39c 100644
--- a/gdk/wayland/gdksurface-wayland.c
+++ b/gdk/wayland/gdksurface-wayland.c
@@ -95,7 +95,6 @@ struct _GdkWaylandSurface
 
   unsigned int initial_configure_received : 1;
   unsigned int mapped : 1;
-  unsigned int pending_commit : 1;
   unsigned int awaiting_frame : 1;
   unsigned int awaiting_frame_frozen : 1;
   unsigned int is_drag_surface : 1;
@@ -615,30 +614,20 @@ gdk_wayland_surface_request_frame (GdkSurface *surface)
   impl->awaiting_frame = TRUE;
 }
 
+void
+gdk_wayland_surface_commit (GdkSurface *surface)
+{
+  GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
+
+  wl_surface_commit (impl->display_server.wl_surface);
+}
+
 static void
 on_frame_clock_after_paint (GdkFrameClock *clock,
                             GdkSurface    *surface)
 {
   GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
 
-  if (impl->pending_commit && surface->update_freeze_count == 0)
-    {
-      gdk_wayland_surface_request_frame (surface);
-
-      /* From this commit forward, we can't write to the buffer,
-       * it's "live".  In the future, if we need to stage more changes
-       * we have to allocate a new staging buffer and draw to it instead.
-       *
-       * Our one saving grace is if the compositor releases the buffer
-       * before we need to stage any changes, then we can take it back and
-       * use it again.
-       */
-      gdk_profiler_add_mark (GDK_PROFILER_CURRENT_TIME, 0, "wayland", "surface commit");
-      wl_surface_commit (impl->display_server.wl_surface);
-
-      impl->pending_commit = FALSE;
-    }
-
   if (impl->awaiting_frame &&
       impl->pending_frame_counter == gdk_frame_clock_get_frame_counter (clock))
     {
@@ -804,7 +793,6 @@ gdk_wayland_surface_attach_image (GdkSurface           *surface,
       cairo_region_get_rectangle (damage, i, &rect);
       wl_surface_damage (impl->display_server.wl_surface, rect.x, rect.y, rect.width, rect.height);
     }
-  impl->pending_commit = TRUE;
 }
 
 void
@@ -2789,7 +2777,6 @@ gdk_wayland_surface_hide_surface (GdkSurface *surface)
   unset_transient_for_exported (surface);
 
   _gdk_wayland_surface_clear_saved_size (surface);
-  impl->pending_commit = FALSE;
   impl->mapped = FALSE;
 }
 


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