[gtk+/wip/otte/vulkan: 1/3] gsk: Change gsk_renderer_realize()



commit 60753454c527bc268f586f17b21044f44e7012e6
Author: Benjamin Otte <otte redhat com>
Date:   Tue Nov 29 03:36:33 2016 +0100

    gsk: Change gsk_renderer_realize()
    
    Instead of having a gsk_renderer_set_window() call, pass the window to
    realize(). This way, the realization can fail with the wrong window.

 docs/reference/gsk/gsk4-sections.txt |    1 -
 gsk/gskcairorenderer.c               |    3 +-
 gsk/gskglrenderer.c                  |    8 +----
 gsk/gskrenderer.c                    |   55 +++++++++++-----------------------
 gsk/gskrenderer.h                    |    3 +-
 gsk/gskrendererprivate.h             |    3 +-
 gtk/gtkwindow.c                      |    6 +--
 7 files changed, 28 insertions(+), 51 deletions(-)
---
diff --git a/docs/reference/gsk/gsk4-sections.txt b/docs/reference/gsk/gsk4-sections.txt
index 30adf19..1a1a18d 100644
--- a/docs/reference/gsk/gsk4-sections.txt
+++ b/docs/reference/gsk/gsk4-sections.txt
@@ -5,7 +5,6 @@ gsk_renderer_set_viewport
 gsk_renderer_get_viewport
 gsk_renderer_set_scale_factor
 gsk_renderer_get_scale_factor
-gsk_renderer_set_window
 gsk_renderer_get_window
 gsk_renderer_get_display
 gsk_renderer_realize
diff --git a/gsk/gskcairorenderer.c b/gsk/gskcairorenderer.c
index 71836c6..9c9929c 100644
--- a/gsk/gskcairorenderer.c
+++ b/gsk/gskcairorenderer.c
@@ -34,7 +34,8 @@ struct _GskCairoRendererClass
 G_DEFINE_TYPE (GskCairoRenderer, gsk_cairo_renderer, GSK_TYPE_RENDERER)
 
 static gboolean
-gsk_cairo_renderer_realize (GskRenderer *renderer)
+gsk_cairo_renderer_realize (GskRenderer *renderer,
+                            GdkWindow   *window)
 {
   return TRUE;
 }
diff --git a/gsk/gskglrenderer.c b/gsk/gskglrenderer.c
index 6834e32..1df501a 100644
--- a/gsk/gskglrenderer.c
+++ b/gsk/gskglrenderer.c
@@ -278,7 +278,8 @@ gsk_gl_renderer_destroy_programs (GskGLRenderer *self)
 }
 
 static gboolean
-gsk_gl_renderer_realize (GskRenderer *renderer)
+gsk_gl_renderer_realize (GskRenderer *renderer,
+                         GdkWindow   *window)
 {
   GskGLRenderer *self = GSK_GL_RENDERER (renderer);
   GError *error = NULL;
@@ -288,11 +289,6 @@ gsk_gl_renderer_realize (GskRenderer *renderer)
    */
   if (self->gl_context == NULL)
     {
-      GdkWindow *window = gsk_renderer_get_window (renderer);
-
-      if (window == NULL)
-        return FALSE;
-
       self->gl_context = gdk_window_create_gl_context (window, &error);
       if (error != NULL)
         {
diff --git a/gsk/gskrenderer.c b/gsk/gskrenderer.c
index edf4633..7d0d842 100644
--- a/gsk/gskrenderer.c
+++ b/gsk/gskrenderer.c
@@ -97,7 +97,8 @@ static GParamSpec *gsk_renderer_properties[N_PROPS];
   g_critical ("Renderer of type '%s' does not implement GskRenderer::" # method, G_OBJECT_TYPE_NAME (obj))
 
 static gboolean
-gsk_renderer_real_realize (GskRenderer *self)
+gsk_renderer_real_realize (GskRenderer *self,
+                           GdkWindow   *window)
 {
   GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD (self, realize);
   return FALSE;
@@ -145,7 +146,6 @@ gsk_renderer_dispose (GObject *gobject)
   g_clear_pointer (&priv->cairo_context, cairo_destroy);
 
   g_clear_object (&priv->profiler);
-  g_clear_object (&priv->window);
   g_clear_object (&priv->display);
 
   G_OBJECT_CLASS (gsk_renderer_parent_class)->dispose (gobject);
@@ -170,10 +170,6 @@ gsk_renderer_set_property (GObject      *gobject,
       gsk_renderer_set_scale_factor (self, g_value_get_int (value));
       break;
 
-    case PROP_WINDOW:
-      gsk_renderer_set_window (self, g_value_get_object (value));
-      break;
-
     case PROP_DISPLAY:
       /* Construct-only */
       priv->display = g_value_dup_object (value);
@@ -432,33 +428,11 @@ gsk_renderer_get_scale_factor (GskRenderer *renderer)
 }
 
 /**
- * gsk_renderer_set_window:
- * @renderer: a #GskRenderer
- * @window: the window to set
- *
- * Sets the window on which the @renderer is rendering.
- *
- * Since: 3.90
- */
-void
-gsk_renderer_set_window (GskRenderer *renderer,
-                         GdkWindow   *window)
-{
-  GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
-
-  g_return_if_fail (GSK_IS_RENDERER (renderer));
-  g_return_if_fail (!priv->is_realized);
-  g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
-
-  if (g_set_object (&priv->window, window))
-    g_object_notify_by_pspec (G_OBJECT (renderer), gsk_renderer_properties[PROP_WINDOW]);
-}
-
-/**
  * gsk_renderer_get_window:
  * @renderer: a #GskRenderer
  *
- * Retrieves the #GdkWindow set using gsk_renderer_set_window().
+ * Retrieves the #GdkWindow set using gsk_renderer_realize(). If the renderer
+ * has not been realized yet, %NULL will be returned.
  *
  * Returns: (transfer none) (nullable): a #GdkWindow
  *
@@ -553,6 +527,7 @@ gsk_renderer_is_realized (GskRenderer *renderer)
 /**
  * gsk_renderer_realize:
  * @renderer: a #GskRenderer
+ * @window: the #GdkWindow renderer will be used on
  *
  * Creates the resources needed by the @renderer to render the scene
  * graph.
@@ -560,18 +535,25 @@ gsk_renderer_is_realized (GskRenderer *renderer)
  * Since: 3.90
  */
 gboolean
-gsk_renderer_realize (GskRenderer *renderer)
+gsk_renderer_realize (GskRenderer *renderer,
+                      GdkWindow   *window)
 {
   GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
 
   g_return_val_if_fail (GSK_IS_RENDERER (renderer), FALSE);
+  g_return_val_if_fail (!gsk_renderer_is_realized (renderer), FALSE);
+  g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
 
-  if (priv->is_realized)
-    return TRUE;
+  priv->window = g_object_ref (window);
 
-  priv->is_realized = GSK_RENDERER_GET_CLASS (renderer)->realize (renderer);
+  if (!GSK_RENDERER_GET_CLASS (renderer)->realize (renderer, window))
+    {
+      g_clear_object (&priv->window);
+      return FALSE;
+    }
 
-  return priv->is_realized;
+  priv->is_realized = TRUE;
+  return TRUE;
 }
 
 /**
@@ -815,13 +797,12 @@ gsk_renderer_create_fallback (GskRenderer           *renderer,
 
   res = g_object_new (GSK_TYPE_CAIRO_RENDERER,
                       "display", priv->display,
-                      "window", priv->window,
                       "scale-factor", priv->scale_factor,
                       "viewport", viewport,
                       NULL);
 
   gsk_renderer_set_cairo_context (res, cr);
-  gsk_renderer_realize (res);
+  gsk_renderer_realize (res, priv->window);
 
   return res;
 }
diff --git a/gsk/gskrenderer.h b/gsk/gskrenderer.h
index d3e1b3e..031de8e 100644
--- a/gsk/gskrenderer.h
+++ b/gsk/gskrenderer.h
@@ -62,7 +62,8 @@ GDK_AVAILABLE_IN_3_90
 GdkDisplay *            gsk_renderer_get_display                (GskRenderer             *renderer);
 
 GDK_AVAILABLE_IN_3_90
-gboolean                gsk_renderer_realize                    (GskRenderer             *renderer);
+gboolean                gsk_renderer_realize                    (GskRenderer             *renderer,
+                                                                 GdkWindow               *window);
 GDK_AVAILABLE_IN_3_90
 void                    gsk_renderer_unrealize                  (GskRenderer             *renderer);
 
diff --git a/gsk/gskrendererprivate.h b/gsk/gskrendererprivate.h
index 57f7e86..41064fb 100644
--- a/gsk/gskrendererprivate.h
+++ b/gsk/gskrendererprivate.h
@@ -37,7 +37,8 @@ struct _GskRendererClass
 {
   GObjectClass parent_class;
 
-  gboolean (* realize) (GskRenderer *renderer);
+  gboolean (* realize) (GskRenderer *renderer,
+                        GdkWindow *window);
   void (* unrealize) (GskRenderer *renderer);
 
   void (* render) (GskRenderer *renderer,
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 2715d0c..89a43e8 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -6910,8 +6910,7 @@ gtk_window_realize (GtkWidget *widget)
           popover_realize (popover->widget, popover, window);
         }
 
-      gsk_renderer_set_window (priv->renderer, gdk_window);
-      gsk_renderer_realize (priv->renderer);
+      gsk_renderer_realize (priv->renderer, gdk_window);
 
       return;
     }
@@ -7109,8 +7108,7 @@ gtk_window_realize (GtkWidget *widget)
   check_scale_changed (window);
 
   /* Renderer */
-  gsk_renderer_set_window (priv->renderer, gdk_window);
-  gsk_renderer_realize (priv->renderer);
+  gsk_renderer_realize (priv->renderer, gdk_window);
 }
 
 static void


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