[gtk/wip/otte/gleanup: 52/53] x11: Move code from GdkGLContextX11




commit ae1a362ede43db4bfc445c910bc1d07c4e8f255d
Author: Benjamin Otte <otte redhat com>
Date:   Tue Jul 13 05:04:45 2021 +0200

    x11: Move code from GdkGLContextX11
    
    It's not used there, but both backends have independent
    immplementationgs for it.
    
    I want to get rid of GdkGLContextX11 and moving code from it is the
    first step.

 gdk/x11/gdkglcontext-egl.c | 16 +++++++++-------
 gdk/x11/gdkglcontext-glx.c | 31 ++++++++++++++++---------------
 gdk/x11/gdkglcontext-x11.c |  1 -
 gdk/x11/gdkglcontext-x11.h |  4 ----
 4 files changed, 25 insertions(+), 27 deletions(-)
---
diff --git a/gdk/x11/gdkglcontext-egl.c b/gdk/x11/gdkglcontext-egl.c
index 40c458b2d4..8b69919e14 100644
--- a/gdk/x11/gdkglcontext-egl.c
+++ b/gdk/x11/gdkglcontext-egl.c
@@ -35,6 +35,8 @@ struct _GdkX11GLContextEGL
   GdkX11GLContext parent_instance;
 
   EGLContext egl_context;
+
+  guint do_frame_sync : 1;
 };
 
 typedef struct _GdkX11GLContextClass    GdkX11GLContextEGLClass;
@@ -385,8 +387,7 @@ static gboolean
 gdk_x11_gl_context_egl_make_current (GdkGLContext *context,
                                      gboolean      surfaceless)
 {
-  GdkX11GLContextEGL *context_egl = GDK_X11_GL_CONTEXT_EGL (context);
-  GdkX11GLContext *context_x11 = GDK_X11_GL_CONTEXT (context);
+  GdkX11GLContextEGL *self = GDK_X11_GL_CONTEXT_EGL (context);
   GdkDisplay *display = gdk_gl_context_get_display (context);
   GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
   GdkSurface *surface;
@@ -398,7 +399,7 @@ gdk_x11_gl_context_egl_make_current (GdkGLContext *context,
       return eglMakeCurrent (display_x11->egl_display,
                              EGL_NO_SURFACE,
                              EGL_NO_SURFACE,
-                             context_egl->egl_context);
+                             self->egl_context);
     }
 
   surface = gdk_gl_context_get_surface (context);
@@ -406,12 +407,12 @@ gdk_x11_gl_context_egl_make_current (GdkGLContext *context,
 
   GDK_DISPLAY_NOTE (display, OPENGL,
                     g_message ("Making EGL context %p current to surface %p",
-                               context_egl->egl_context, egl_surface));
+                               self->egl_context, egl_surface));
 
   if (!eglMakeCurrent (display_x11->egl_display,
                        egl_surface,
                        egl_surface,
-                       context_egl->egl_context))
+                       self->egl_context))
     return FALSE;
 
   /* If the WM is compositing there is no particular need to delay
@@ -420,9 +421,9 @@ gdk_x11_gl_context_egl_make_current (GdkGLContext *context,
    * to the vblank. */
   do_frame_sync = ! gdk_display_is_composited (display);
 
-  if (do_frame_sync != context_x11->do_frame_sync)
+  if (do_frame_sync != self->do_frame_sync)
     {
-      context_x11->do_frame_sync = do_frame_sync;
+      self->do_frame_sync = do_frame_sync;
 
       if (do_frame_sync)
         eglSwapInterval (display_x11->egl_display, 1);
@@ -655,6 +656,7 @@ gdk_x11_gl_context_egl_class_init (GdkX11GLContextEGLClass *klass)
 static void
 gdk_x11_gl_context_egl_init (GdkX11GLContextEGL *self)
 {
+  self->do_frame_sync = TRUE;
 }
 
 gboolean
diff --git a/gdk/x11/gdkglcontext-glx.c b/gdk/x11/gdkglcontext-glx.c
index 1c2338e392..fea5746ffe 100644
--- a/gdk/x11/gdkglcontext-glx.c
+++ b/gdk/x11/gdkglcontext-glx.c
@@ -40,6 +40,8 @@ struct _GdkX11GLContextGLX
   GLsync frame_fence;
   Damage xdamage;
 #endif
+
+  guint do_frame_sync : 1;
 };
 
 typedef struct _GdkX11GLContextClass    GdkX11GLContextGLXClass;
@@ -146,9 +148,8 @@ static void
 gdk_x11_gl_context_glx_end_frame (GdkDrawContext *draw_context,
                                   cairo_region_t *painted)
 {
+  GdkX11GLContextGLX *self = GDK_X11_GL_CONTEXT_GLX (draw_context);
   GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
-  GdkX11GLContext *context_x11 = GDK_X11_GL_CONTEXT (context);
-  GdkX11GLContextGLX *context_glx = GDK_X11_GL_CONTEXT_GLX (context);
   GdkSurface *surface = gdk_gl_context_get_surface (context);
   GdkDisplay *display = gdk_gl_context_get_display (context);
   Display *dpy = gdk_x11_display_get_xdisplay (display);
@@ -168,7 +169,7 @@ gdk_x11_gl_context_glx_end_frame (GdkDrawContext *draw_context,
             g_message ("Flushing GLX buffers for drawable %lu (window: %lu), frame sync: %s",
                        (unsigned long) drawable,
                        (unsigned long) gdk_x11_surface_get_xid (surface),
-                       context_x11->do_frame_sync ? "yes" : "no"));
+                       self->do_frame_sync ? "yes" : "no"));
 
   gdk_profiler_add_mark (GDK_PROFILER_CURRENT_TIME, 0, "x11", "swap buffers");
 
@@ -180,7 +181,7 @@ gdk_x11_gl_context_glx_end_frame (GdkDrawContext *draw_context,
    * GLX_SGI_swap_control, and we ask the driver to do the right
    * thing.
    */
-  if (context_x11->do_frame_sync)
+  if (self->do_frame_sync)
     {
       guint32 end_frame_counter = 0;
       gboolean has_counter = display_x11->has_glx_video_sync;
@@ -189,7 +190,7 @@ gdk_x11_gl_context_glx_end_frame (GdkDrawContext *draw_context,
       if (display_x11->has_glx_video_sync)
         glXGetVideoSyncSGI (&end_frame_counter);
 
-      if (context_x11->do_frame_sync && !display_x11->has_glx_swap_interval)
+      if (self->do_frame_sync && !display_x11->has_glx_swap_interval)
         {
           glFinish ();
 
@@ -208,11 +209,11 @@ gdk_x11_gl_context_glx_end_frame (GdkDrawContext *draw_context,
   gdk_x11_surface_pre_damage (surface);
 
 #ifdef HAVE_XDAMAGE
-  if (context_glx->xdamage != 0 && _gdk_x11_surface_syncs_frames (surface))
+  if (self->xdamage != 0 && _gdk_x11_surface_syncs_frames (surface))
     {
-      g_assert (context_glx->frame_fence == 0);
+      g_assert (self->frame_fence == 0);
 
-      context_glx->frame_fence = glFenceSync (GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
+      self->frame_fence = glFenceSync (GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
 
       /* We consider the frame still getting painted until the GL operation is
        * finished, and the window gets damage reported from the X server.
@@ -225,7 +226,7 @@ gdk_x11_gl_context_glx_end_frame (GdkDrawContext *draw_context,
 
   glXSwapBuffers (dpy, drawable);
 
-  if (context_x11->do_frame_sync && info != NULL && display_x11->has_glx_video_sync)
+  if (self->do_frame_sync && info != NULL && display_x11->has_glx_video_sync)
     glXGetVideoSyncSGI (&info->last_frame_counter);
 }
 
@@ -244,15 +245,14 @@ gdk_x11_gl_context_glx_make_current (GdkGLContext *context,
                                      gboolean      surfaceless)
                                      
 {
-  GdkX11GLContext *context_x11 = GDK_X11_GL_CONTEXT (context);
-  GdkX11GLContextGLX *context_glx = GDK_X11_GL_CONTEXT_GLX (context);
+  GdkX11GLContextGLX *self = GDK_X11_GL_CONTEXT_GLX (context);
   GdkDisplay *display = gdk_gl_context_get_display (context);
   Display *dpy = gdk_x11_display_get_xdisplay (display);
   gboolean do_frame_sync = FALSE;
   GdkSurface *surface;
   GLXWindow drawable;
 
-  drawable = gdk_x11_gl_context_glx_get_drawable (context_glx);
+  drawable = gdk_x11_gl_context_glx_get_drawable (self);
 
   if (!surfaceless)
     surface = gdk_gl_context_get_surface (context);
@@ -264,7 +264,7 @@ gdk_x11_gl_context_glx_make_current (GdkGLContext *context,
                     g_message ("Making GLX context %p current to drawable %lu",
                                context, (unsigned long) drawable));
 
-  if (!glXMakeContextCurrent (dpy, drawable, drawable, context_glx->glx_context))
+  if (!glXMakeContextCurrent (dpy, drawable, drawable, self->glx_context))
     return FALSE;
 
   if (!surfaceless && GDK_X11_DISPLAY (display)->has_glx_swap_interval)
@@ -275,9 +275,9 @@ gdk_x11_gl_context_glx_make_current (GdkGLContext *context,
        * to the vblank. */
       do_frame_sync = ! gdk_display_is_composited (display);
 
-      if (do_frame_sync != context_x11->do_frame_sync)
+      if (do_frame_sync != self->do_frame_sync)
         {
-          context_x11->do_frame_sync = do_frame_sync;
+          self->do_frame_sync = do_frame_sync;
 
           if (do_frame_sync)
             glXSwapIntervalSGI (1);
@@ -747,6 +747,7 @@ gdk_x11_gl_context_glx_class_init (GdkX11GLContextGLXClass *klass)
 static void
 gdk_x11_gl_context_glx_init (GdkX11GLContextGLX *self)
 {
+  self->do_frame_sync = TRUE;
 }
 
 static gboolean
diff --git a/gdk/x11/gdkglcontext-x11.c b/gdk/x11/gdkglcontext-x11.c
index 98210b5ef1..9fa70c96af 100644
--- a/gdk/x11/gdkglcontext-x11.c
+++ b/gdk/x11/gdkglcontext-x11.c
@@ -50,7 +50,6 @@ gdk_x11_gl_context_class_init (GdkX11GLContextClass *klass)
 static void
 gdk_x11_gl_context_init (GdkX11GLContext *self)
 {
-  self->do_frame_sync = TRUE;
 }
 
 gboolean
diff --git a/gdk/x11/gdkglcontext-x11.h b/gdk/x11/gdkglcontext-x11.h
index d1b6c8e106..a12d39e5eb 100644
--- a/gdk/x11/gdkglcontext-x11.h
+++ b/gdk/x11/gdkglcontext-x11.h
@@ -47,15 +47,11 @@ G_BEGIN_DECLS
 struct _GdkX11GLContext
 {
   GdkGLContext parent_instance;
-
-  guint do_frame_sync : 1;
 };
 
 struct _GdkX11GLContextClass
 {
   GdkGLContextClass parent_class;
-
-  void (* bind_for_frame_fence) (GdkX11GLContext *self);
 };
 
 gboolean                gdk_x11_display_init_gl_backend         (GdkX11Display *self,


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