[gtk+/wip/gdk-gl] gl: Drop the async viewport update



commit 06d48d0e9acfa974c75456eed6e83ff66823070c
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Fri Aug 15 12:44:53 2014 +0100

    gl: Drop the async viewport update
    
    It is not the cause of the flickering, and after checking with the
    current implementation of GL widgets like GtkClutterEmbed, it's not
    necessary to update the viewport in response to a ConfigureNotify
    for child windows.

 gdk/gdkglcontext.c         |   42 +----------------------------------
 gdk/gdkglcontextprivate.h  |   11 +-------
 gdk/x11/gdkdisplay-x11.c   |   27 +---------------------
 gdk/x11/gdkglcontext-x11.c |   51 ++++++++++++++++++++++++++++++++++++-------
 4 files changed, 48 insertions(+), 83 deletions(-)
---
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index cff8c79..4e12d70 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -140,8 +140,6 @@ typedef struct {
   GdkVisual *visual;
 
   gboolean swap_interval;
-
-  gboolean needs_update;
 } GdkGLContextPrivate;
 
 enum {
@@ -547,46 +545,10 @@ gdk_gl_context_update (GdkGLContext *context)
 
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
 
-  if (priv->needs_update)
+  if (priv->window == NULL)
     return;
 
-  priv->needs_update = TRUE;
-}
-
-/*< private >
- * gdk_gl_context_needs_update:
- * @context: a #GdkGLContext
- *
- * Checks whether gdk_gl_context_update() was called on @context.
- *
- * Platform-specific code may need to be executed to update the
- * viewport in case the context requested an update.
- */
-gboolean
-gdk_gl_context_needs_update (GdkGLContext *context)
-{
-  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
-
-  return priv->needs_update;
-}
-
-/*< private >*
- * gdk_gl_context_update_viewport:
- * @context: a #GdkGLContext
- * @window: a #GdkWindow
- * @width: width of the viewport
- * @height: height of the viewport
- *
- * Updates the viewport of @context in response to a size change
- * of the given @window.
- */
-void
-gdk_gl_context_update_viewport (GdkGLContext *context,
-                                GdkWindow    *window,
-                                int           width,
-                                int           height)
-{
-  GDK_GL_CONTEXT_GET_CLASS (context)->update_viewport (context, window, width, height);
+  GDK_GL_CONTEXT_GET_CLASS (context)->update (context, priv->window);
 }
 
 /**
diff --git a/gdk/gdkglcontextprivate.h b/gdk/gdkglcontextprivate.h
index 412c5f9..f7965d8 100644
--- a/gdk/gdkglcontextprivate.h
+++ b/gdk/gdkglcontextprivate.h
@@ -42,19 +42,12 @@ struct _GdkGLContextClass
 
   void (* set_window)      (GdkGLContext *context,
                             GdkWindow    *window);
-  void (* update_viewport) (GdkGLContext *context,
-                            GdkWindow    *window,
-                            int           width,
-                            int           height);
+  void (* update)          (GdkGLContext *context,
+                            GdkWindow    *window);
   void (* flush_buffer)    (GdkGLContext *context);
 };
 
 gboolean        gdk_gl_context_get_swap_interval        (GdkGLContext *context);
-gboolean        gdk_gl_context_needs_update             (GdkGLContext *context);
-void            gdk_gl_context_update_viewport          (GdkGLContext *context,
-                                                         GdkWindow    *window,
-                                                         int           width,
-                                                         int           height);
 
 G_END_DECLS
 
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index 29cd960..bcf2681 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -784,34 +784,11 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
 
       if (!window ||
           xevent->xconfigure.event != xevent->xconfigure.window ||
-          GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
+          GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT ||
+          GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
         {
           return_val = FALSE;
         }
-      else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
-        {
-          /* on X11 we need to wait until a ConfigureNotify before
-           * updating the GL viewport, otherwise the GLX drawable
-           * and the X drawable will go out of sync.
-           */
-          if (gdk_window_has_gl_context (window))
-            {
-              GdkGLContext *context = gdk_window_get_gl_context (window);
-
-              /* only update the viewport if the context asked for it */
-              if (gdk_gl_context_needs_update (context))
-                {
-                  GDK_NOTE (OPENGL,
-                            g_print ("Updating viewport after a ConfigureNotify on window %lu\n",
-                                     (unsigned long) xevent->xconfigure.window));
-                  gdk_gl_context_update_viewport (context, window,
-                                                  xevent->xconfigure.width,
-                                                  xevent->xconfigure.height);
-                }
-            }
-
-          return_val = FALSE;
-        }
       else
        {
          event->configure.type = GDK_CONFIGURE;
diff --git a/gdk/x11/gdkglcontext-x11.c b/gdk/x11/gdkglcontext-x11.c
index 1c60ee8..676d661 100644
--- a/gdk/x11/gdkglcontext-x11.c
+++ b/gdk/x11/gdkglcontext-x11.c
@@ -120,12 +120,22 @@ gdk_x11_gl_context_set_window (GdkGLContext *context,
 }
 
 static void
-gdk_x11_gl_context_update_viewport (GdkGLContext *context,
-                                    GdkWindow    *window,
-                                    int           width,
-                                    int           height)
+gdk_x11_gl_context_update (GdkGLContext *context,
+                           GdkWindow    *window)
 {
-  GDK_NOTE (OPENGL, g_print ("Updating viewport to { 0, 0, %d, %d }\n", width, height));
+  GdkDisplay *display = gdk_gl_context_get_display (context);
+  int width, height;
+
+  if (!gdk_x11_display_make_gl_context_current (display, context, window))
+    return;
+
+  width = gdk_window_get_width (window);
+  height = gdk_window_get_height (window);
+
+  GDK_NOTE (OPENGL, g_print ("Updating GL viewport size to { %d, %d } for window %lu (context: %p)\n",
+                             width, height,
+                             (unsigned long) gdk_x11_window_get_xid (window),
+                             context));
 
   glViewport (0, 0, width, height);
 }
@@ -168,6 +178,8 @@ gdk_x11_gl_context_flush_buffer (GdkGLContext *context)
   if (window == NULL)
     return;
 
+  gdk_x11_display_make_gl_context_current (display, context, window);
+
   info = get_glx_drawable_info (window);
   if (info != NULL && info->drawable != None)
     drawable = info->drawable;
@@ -225,7 +237,7 @@ gdk_x11_gl_context_class_init (GdkX11GLContextClass *klass)
   GdkGLContextClass *context_class = GDK_GL_CONTEXT_CLASS (klass);
 
   context_class->set_window = gdk_x11_gl_context_set_window;
-  context_class->update_viewport = gdk_x11_gl_context_update_viewport;
+  context_class->update = gdk_x11_gl_context_update;
   context_class->flush_buffer = gdk_x11_gl_context_flush_buffer;
 }
 
@@ -766,14 +778,14 @@ gdk_x11_display_make_gl_context_current (GdkDisplay   *display,
   if (G_UNLIKELY (drawable == None))
     return FALSE;
 
+  if (drawable == context_x11->current_drawable)
+    return TRUE;
+
   GDK_NOTE (OPENGL,
             g_print ("Making GLX context current to drawable %lu (dummy: %s)\n",
                      (unsigned long) drawable,
                      drawable == context_x11->dummy_drawable ? "yes" : "no"));
 
-  if (drawable == context_x11->current_drawable)
-    return TRUE;
-
   gdk_x11_display_error_trap_push (display);
 
   glXMakeContextCurrent (gdk_x11_display_get_xdisplay (display),
@@ -833,6 +845,27 @@ gdk_x11_display_validate_gl_pixel_format (GdkDisplay        *display,
   if (!find_fbconfig_for_pixel_format (display, format, &config, NULL, error))
     return FALSE;
 
+  GDK_NOTE (OPENGL,
+            g_print ("Found GLX config for requested pixel format:\n"
+                     " - double-buffer: %s\n"
+                     " - multi-sample: %s\n"
+                     " - stereo: %s\n"
+                     " - color-size: %d, alpha-size: %d\n"
+                     " - depth-size: %d\n"
+                     " - stencil-size: %d\n"
+                     " - aux-buffers: %d\n"
+                     " - accum-size: %d\n"
+                     " - sample-buffers: %d, samples: %d\n",
+                     format->double_buffer ? "yes" : "no",
+                     format->multi_sample ? "yes" : "no",
+                     format->stereo ? "yes" : "no",
+                     format->color_size, format->alpha_size,
+                     format->depth_size,
+                     format->stencil_size,
+                     format->aux_buffers,
+                     format->accum_size,
+                     format->sample_buffers, format->samples));
+
   if (validated_format != NULL)
     {
       GdkGLPixelFormat *valid = g_object_new (GDK_TYPE_GL_PIXEL_FORMAT, NULL);


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