[gtk+] gsk: Make GskRenderer.render() drawing context-agnostic



commit 6b3c0052fcc0d837ce31a8a14d097cfa0c7a0385
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Aug 24 16:21:50 2016 +0100

    gsk: Make GskRenderer.render() drawing context-agnostic
    
    We're going to need to allow rendering on a specific cairo_t in order to
    implement fallback code paths inside GTK; this means that there will be
    times when we have a transient GskRenderer instance that does not have a
    GdkDrawingContext to draw on.
    
    Instead of adding a new render() implementation for those cases and then
    decide which one to use, we can remove the drawing context argument from
    the virtual function itself, and allow using a NULL GdkDrawingContext
    when calling gsk_renderer_render(). A later commit will add a generic
    function to create a transient GskRenderer with a cairo_t attached to
    it.
    
    Renderers inside GSK will have to check whether we have access to a
    GdkDrawingContext, in which case we're going to use it; or if we have
    access to a cairo_t and a window.

 gsk/gskcairorenderer.c   |    6 +++---
 gsk/gskglrenderer.c      |   35 +++++++++++++++++++++++------------
 gsk/gskrenderer.c        |   11 ++++++-----
 gsk/gskrendererprivate.h |    3 +--
 4 files changed, 33 insertions(+), 22 deletions(-)
---
diff --git a/gsk/gskcairorenderer.c b/gsk/gskcairorenderer.c
index d0766c7..282bb0f 100644
--- a/gsk/gskcairorenderer.c
+++ b/gsk/gskcairorenderer.c
@@ -123,11 +123,11 @@ gsk_cairo_renderer_render_node (GskCairoRenderer *self,
 }
 
 static void
-gsk_cairo_renderer_render (GskRenderer *renderer,
-                           GskRenderNode *root,
-                           GdkDrawingContext *context)
+gsk_cairo_renderer_render (GskRenderer   *renderer,
+                           GskRenderNode *root)
 {
   GskCairoRenderer *self = GSK_CAIRO_RENDERER (renderer);
+  GdkDrawingContext *context = gsk_renderer_get_drawing_context (renderer);
   cairo_t *cr = gdk_drawing_context_get_cairo_context (context); 
 
   gsk_renderer_get_viewport (renderer, &self->viewport);
diff --git a/gsk/gskglrenderer.c b/gsk/gskglrenderer.c
index 7384d04..373f389 100644
--- a/gsk/gskglrenderer.c
+++ b/gsk/gskglrenderer.c
@@ -828,15 +828,15 @@ gsk_gl_renderer_clear (GskGLRenderer *self)
 #define ORTHO_FAR_PLANE          10000
 
 static void
-gsk_gl_renderer_render (GskRenderer       *renderer,
-                        GskRenderNode     *root,
-                        GdkDrawingContext *context)
+gsk_gl_renderer_render (GskRenderer   *renderer,
+                        GskRenderNode *root)
 {
   GskGLRenderer *self = GSK_GL_RENDERER (renderer);
   graphene_matrix_t modelview, projection;
   graphene_rect_t viewport;
   guint i;
   int scale_factor;
+  GdkDrawingContext *context;
 #ifdef G_ENABLE_DEBUG
   GskProfiler *profiler;
   gint64 gpu_time, cpu_time;
@@ -845,7 +845,11 @@ gsk_gl_renderer_render (GskRenderer       *renderer,
   if (self->gl_context == NULL)
     return;
 
+  context = gsk_renderer_get_drawing_context (renderer);
+
+#ifdef G_ENABLE_DEBUG
   profiler = gsk_renderer_get_profiler (renderer);
+#endif
 
   gdk_gl_context_make_current (self->gl_context);
 
@@ -912,15 +916,22 @@ gsk_gl_renderer_render (GskRenderer       *renderer,
 #endif
 
 out:
-  /* XXX: Add GdkDrawingContext API */
-  gdk_cairo_draw_from_gl (gdk_drawing_context_get_cairo_context (context),
-                          gdk_drawing_context_get_window (context),
-                          self->texture_id,
-                          GL_TEXTURE,
-                          scale_factor,
-                          0, 0,
-                          viewport.size.width * scale_factor,
-                          viewport.size.height * scale_factor);
+  {
+    GdkWindow *window;
+    cairo_t *cr;
+
+    /* XXX: Add GdkDrawingContext API */
+    cr = gdk_drawing_context_get_cairo_context (context);
+    window = gdk_drawing_context_get_window (context);
+
+    gdk_cairo_draw_from_gl (cr, window,
+                            self->texture_id,
+                            GL_TEXTURE,
+                            scale_factor,
+                            0, 0,
+                            viewport.size.width * scale_factor,
+                            viewport.size.height * scale_factor);
+  }
 
   gdk_gl_context_make_current (self->gl_context);
   gsk_gl_renderer_clear_tree (self);
diff --git a/gsk/gskrenderer.c b/gsk/gskrenderer.c
index 323f2c1..ebdb1a4 100644
--- a/gsk/gskrenderer.c
+++ b/gsk/gskrenderer.c
@@ -108,8 +108,7 @@ gsk_renderer_real_unrealize (GskRenderer *self)
 
 static void
 gsk_renderer_real_render (GskRenderer *self,
-                          GskRenderNode *root,
-                          GdkDrawingContext *context)
+                          GskRenderNode *root)
 {
   GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD (self, render);
 }
@@ -597,12 +596,14 @@ gsk_renderer_render (GskRenderer       *renderer,
   g_return_if_fail (GSK_IS_RENDERER (renderer));
   g_return_if_fail (priv->is_realized);
   g_return_if_fail (GSK_IS_RENDER_NODE (root));
-  g_return_if_fail (GDK_IS_DRAWING_CONTEXT (context));
+  g_return_if_fail (context == NULL || GDK_IS_DRAWING_CONTEXT (context));
   g_return_if_fail (priv->drawing_context == NULL);
   g_return_if_fail (priv->root_node == NULL);
   g_return_if_fail (root->renderer == renderer);
 
-  priv->drawing_context = g_object_ref (context);
+  if (context != NULL)
+    priv->drawing_context = g_object_ref (context);
+
   priv->root_node = gsk_render_node_ref (root);
   gsk_render_node_make_immutable (priv->root_node);
 
@@ -610,7 +611,7 @@ gsk_renderer_render (GskRenderer       *renderer,
   gsk_profiler_reset (priv->profiler);
 #endif
 
-  GSK_RENDERER_GET_CLASS (renderer)->render (renderer, root, context);
+  GSK_RENDERER_GET_CLASS (renderer)->render (renderer, root);
 
 #ifdef G_ENABLE_DEBUG
   if (GSK_DEBUG_CHECK (RENDERER))
diff --git a/gsk/gskrendererprivate.h b/gsk/gskrendererprivate.h
index d560d01..1267188 100644
--- a/gsk/gskrendererprivate.h
+++ b/gsk/gskrendererprivate.h
@@ -41,8 +41,7 @@ struct _GskRendererClass
   void (* unrealize) (GskRenderer *renderer);
 
   void (* render) (GskRenderer *renderer,
-                   GskRenderNode *root,
-                   GdkDrawingContext *context);
+                   GskRenderNode *root);
 };
 
 gboolean gsk_renderer_is_realized (GskRenderer *renderer);


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