[gtk+/wip/ebassi/gsk-renderer: 1/3] gtk: Add a GskRenderer to GtkWindow



commit 45e354f8c91caf829d3a0bbeb1baaacfa834b88b
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Jun 23 17:34:38 2016 +0100

    gtk: Add a GskRenderer to GtkWindow
    
    Each top-level should have its own GskRenderer, to be used when drawing
    the render node tree.

 gtk/gtkwindow.c        |   49 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkwindowprivate.h |    2 +
 2 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 95beb5d..d987434 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <limits.h>
+#include <graphene.h>
 
 #include "gtkprivate.h"
 #include "gtkwindowprivate.h"
@@ -271,6 +272,8 @@ struct _GtkWindowPrivate
   GdkWindow *hardcoded_window;
 
   GtkCssNode *decoration_node;
+
+  GskRenderer *renderer;
 };
 
 static const GtkTargetEntry dnd_dest_targets [] = {
@@ -7141,6 +7144,16 @@ gtk_window_realize (GtkWidget *widget)
 
   _gtk_widget_get_allocation (widget, &allocation);
 
+  if (priv->renderer == NULL)
+    {
+      graphene_rect_t viewport;
+
+      priv->renderer = gsk_renderer_get_for_display (gtk_widget_get_display (widget));
+
+      graphene_rect_init (&viewport, 0, 0, allocation.width, allocation.height);
+      gsk_renderer_set_viewport (priv->renderer, &viewport);
+    }
+
   if (gtk_widget_get_parent_window (widget))
     {
       gtk_container_set_default_resize_mode (GTK_CONTAINER (widget), GTK_RESIZE_PARENT);
@@ -7164,6 +7177,9 @@ gtk_window_realize (GtkWidget *widget)
       gtk_widget_register_window (widget, gdk_window);
       gtk_widget_set_realized (widget, TRUE);
 
+      gsk_renderer_set_window (priv->renderer, gdk_window);
+      gsk_renderer_realize (priv->renderer);
+
       return;
     }
 
@@ -7257,6 +7273,10 @@ gtk_window_realize (GtkWidget *widget)
   gtk_widget_register_window (widget, gdk_window);
   gtk_widget_set_realized (widget, TRUE);
 
+  gsk_renderer_set_window (priv->renderer, gdk_window);
+  gsk_renderer_set_use_alpha (priv->renderer, TRUE);
+  gsk_renderer_realize (priv->renderer);
+
   attributes.x = allocation.x;
   attributes.y = allocation.y;
   attributes.width = allocation.width;
@@ -7377,6 +7397,9 @@ gtk_window_realize (GtkWidget *widget)
     }
 
   check_scale_changed (window);
+
+  /* Renderer */
+  gsk_renderer_realize (priv->renderer);
 }
 
 static void
@@ -7404,6 +7427,9 @@ gtk_window_unrealize (GtkWidget *widget)
   GList *link;
   gint i;
 
+  if (priv->renderer != NULL)
+    gsk_renderer_unrealize (priv->renderer);
+
   /* On unrealize, we reset the size of the window such
    * that we will re-apply the default sizing stuff
    * next time we show the window.
@@ -7551,6 +7577,21 @@ _gtk_window_set_allocation (GtkWindow           *window,
   child_allocation.width = allocation->width;
   child_allocation.height = allocation->height;
 
+  if (priv->renderer != NULL)
+    {
+      graphene_rect_t viewport;
+      graphene_matrix_t projection;
+
+      graphene_rect_init (&viewport, 0, 0, allocation->width, allocation->height);
+      gsk_renderer_set_viewport (priv->renderer, &viewport);
+
+      graphene_matrix_init_ortho (&projection,
+                                  0, allocation->width,
+                                  0, allocation->height,
+                                  -1, 1);
+      gsk_renderer_set_projection (priv->renderer, &projection);
+    }
+
   get_shadow_width (window, &window_border);
 
   if (_gtk_widget_get_realized (widget))
@@ -12613,3 +12654,11 @@ gtk_window_set_hardcoded_window (GtkWindow *window,
 
   g_set_object (&priv->hardcoded_window, gdk_window);
 }
+
+GskRenderer *
+gtk_window_get_renderer (GtkWindow *window)
+{
+  GtkWindowPrivate *priv = window->priv;
+
+  return priv->renderer;
+}
diff --git a/gtk/gtkwindowprivate.h b/gtk/gtkwindowprivate.h
index 80253bf..7d9d447 100644
--- a/gtk/gtkwindowprivate.h
+++ b/gtk/gtkwindowprivate.h
@@ -135,6 +135,8 @@ void       gtk_window_set_hardcoded_window (GtkWindow *window,
 
 GdkScreen *_gtk_window_get_screen (GtkWindow *window);
 
+GskRenderer *gtk_window_get_renderer (GtkWindow *window);
+
 G_END_DECLS
 
 #endif /* __GTK_WINDOW_PRIVATE_H__ */


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