2016-03-17 13:48:19 +00:00
|
|
|
/* GSK - The GTK Scene Kit
|
|
|
|
*
|
|
|
|
* Copyright 2016 Endless
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:GskRenderer
|
2016-08-07 03:08:04 +00:00
|
|
|
* @Title: GskRenderer
|
|
|
|
* @Short_description: Renders a scene
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
2016-07-03 23:23:19 +00:00
|
|
|
* #GskRenderer is a class that renders a scene graph defined via a
|
|
|
|
* tree of #GskRenderNode instances.
|
|
|
|
*
|
2018-03-27 23:29:39 +00:00
|
|
|
* Typically you will use a #GskRenderer instance to repeatedly call
|
|
|
|
* gsk_renderer_render() to update the contents of its associated #GdkSurface.
|
2016-07-03 23:23:19 +00:00
|
|
|
*
|
|
|
|
* It is necessary to realize a #GskRenderer instance using gsk_renderer_realize()
|
|
|
|
* before calling gsk_renderer_render(), in order to create the appropriate
|
|
|
|
* windowing system resources needed to render the scene.
|
2016-03-17 13:48:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskrendererprivate.h"
|
|
|
|
|
2019-05-01 21:58:57 +00:00
|
|
|
#include "gskcairorenderer.h"
|
2016-03-17 13:48:19 +00:00
|
|
|
#include "gskdebugprivate.h"
|
2019-05-02 00:13:16 +00:00
|
|
|
#include "gl/gskglrenderer.h"
|
2016-08-03 15:51:21 +00:00
|
|
|
#include "gskprofilerprivate.h"
|
2016-03-17 13:48:19 +00:00
|
|
|
#include "gskrendernodeprivate.h"
|
|
|
|
|
|
|
|
#include "gskenumtypes.h"
|
|
|
|
|
|
|
|
#include <graphene-gobject.h>
|
|
|
|
#include <cairo-gobject.h>
|
|
|
|
#include <gdk/gdk.h>
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_X11
|
|
|
|
#include <gdk/x11/gdkx.h>
|
|
|
|
#endif
|
|
|
|
#ifdef GDK_WINDOWING_WAYLAND
|
|
|
|
#include <gdk/wayland/gdkwayland.h>
|
|
|
|
#endif
|
2017-11-17 11:04:02 +00:00
|
|
|
#ifdef GDK_WINDOWING_BROADWAY
|
2019-05-02 00:46:23 +00:00
|
|
|
#include "broadway/gskbroadwayrenderer.h"
|
2017-11-17 11:04:02 +00:00
|
|
|
#endif
|
2016-12-09 20:51:25 +00:00
|
|
|
#ifdef GDK_RENDERING_VULKAN
|
2019-05-02 00:57:23 +00:00
|
|
|
#include "vulkan/gskvulkanrenderer.h"
|
2016-11-29 15:33:14 +00:00
|
|
|
#endif
|
2020-04-23 23:36:46 +00:00
|
|
|
#ifdef GDK_WINDOWING_MACOS
|
|
|
|
#include <gdk/macos/gdkmacos.h>
|
|
|
|
#endif
|
2020-07-31 10:44:10 +00:00
|
|
|
#ifdef GDK_WINDOWING_WIN32
|
|
|
|
#include <gdk/win32/gdkwin32.h>
|
|
|
|
|
|
|
|
/* Remove these lines when OpenGL/ES 2.0 shader is ready */
|
|
|
|
#include "win32/gdkprivate-win32.h"
|
|
|
|
#include "win32/gdkdisplay-win32.h"
|
|
|
|
#endif
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GObject parent_instance;
|
|
|
|
|
2018-03-21 10:49:14 +00:00
|
|
|
GdkSurface *surface;
|
2018-03-28 13:43:43 +00:00
|
|
|
GskRenderNode *prev_node;
|
2016-03-17 13:48:19 +00:00
|
|
|
GskRenderNode *root_node;
|
|
|
|
|
2016-08-03 15:51:21 +00:00
|
|
|
GskProfiler *profiler;
|
|
|
|
|
2018-01-14 14:52:52 +00:00
|
|
|
GskDebugFlags debug_flags;
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
gboolean is_realized : 1;
|
|
|
|
} GskRendererPrivate;
|
|
|
|
|
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GskRenderer, gsk_renderer, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
enum {
|
2019-03-09 12:59:03 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_REALIZED,
|
|
|
|
PROP_SURFACE,
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *gsk_renderer_properties[N_PROPS];
|
|
|
|
|
|
|
|
#define GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD(obj,method) \
|
|
|
|
g_critical ("Renderer of type '%s' does not implement GskRenderer::" # method, G_OBJECT_TYPE_NAME (obj))
|
|
|
|
|
|
|
|
static gboolean
|
2016-11-29 03:51:07 +00:00
|
|
|
gsk_renderer_real_realize (GskRenderer *self,
|
2018-03-21 10:49:14 +00:00
|
|
|
GdkSurface *surface,
|
2016-11-29 03:51:07 +00:00
|
|
|
GError **error)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
|
|
|
GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD (self, realize);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_renderer_real_unrealize (GskRenderer *self)
|
|
|
|
{
|
|
|
|
GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD (self, unrealize);
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
static GdkTexture *
|
2016-12-21 19:23:46 +00:00
|
|
|
gsk_renderer_real_render_texture (GskRenderer *self,
|
|
|
|
GskRenderNode *root,
|
|
|
|
const graphene_rect_t *viewport)
|
|
|
|
{
|
|
|
|
GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD (self, render_texture);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
static void
|
2018-03-28 13:01:34 +00:00
|
|
|
gsk_renderer_real_render (GskRenderer *self,
|
|
|
|
GskRenderNode *root,
|
|
|
|
const cairo_region_t *region)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
|
|
|
GSK_RENDERER_WARN_NOT_IMPLEMENTED_METHOD (self, render);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_renderer_dispose (GObject *gobject)
|
|
|
|
{
|
|
|
|
GskRenderer *self = GSK_RENDERER (gobject);
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (self);
|
|
|
|
|
2017-11-04 14:09:43 +00:00
|
|
|
/* We can't just unrealize here because superclasses have already run dispose.
|
|
|
|
* So we insist that unrealize must be called before unreffing. */
|
|
|
|
g_assert (!priv->is_realized);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-10-18 15:49:21 +00:00
|
|
|
g_clear_object (&priv->profiler);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gsk_renderer_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_renderer_get_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GskRenderer *self = GSK_RENDERER (gobject);
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (self);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2019-03-09 12:59:03 +00:00
|
|
|
case PROP_REALIZED:
|
|
|
|
g_value_set_boolean (value, priv->is_realized);
|
|
|
|
break;
|
|
|
|
|
2018-03-21 10:49:14 +00:00
|
|
|
case PROP_SURFACE:
|
|
|
|
g_value_set_object (value, priv->surface);
|
2016-03-17 13:48:19 +00:00
|
|
|
break;
|
|
|
|
|
2017-10-06 19:19:42 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_renderer_class_init (GskRendererClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
klass->realize = gsk_renderer_real_realize;
|
|
|
|
klass->unrealize = gsk_renderer_real_unrealize;
|
|
|
|
klass->render = gsk_renderer_real_render;
|
2016-12-21 19:23:46 +00:00
|
|
|
klass->render_texture = gsk_renderer_real_render_texture;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
gobject_class->get_property = gsk_renderer_get_property;
|
|
|
|
gobject_class->dispose = gsk_renderer_dispose;
|
|
|
|
|
2019-03-09 12:59:03 +00:00
|
|
|
gsk_renderer_properties[PROP_REALIZED] =
|
|
|
|
g_param_spec_boolean ("realized",
|
|
|
|
"Realized",
|
|
|
|
"The renderer has been associated with a surface",
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
2018-03-21 10:49:14 +00:00
|
|
|
gsk_renderer_properties[PROP_SURFACE] =
|
|
|
|
g_param_spec_object ("surface",
|
|
|
|
"Surface",
|
|
|
|
"The surface associated to the renderer",
|
2018-03-20 10:40:08 +00:00
|
|
|
GDK_TYPE_SURFACE,
|
2019-03-09 12:59:03 +00:00
|
|
|
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
2016-06-22 16:30:36 +00:00
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
g_object_class_install_properties (gobject_class, N_PROPS, gsk_renderer_properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_renderer_init (GskRenderer *self)
|
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (self);
|
|
|
|
|
2016-08-03 15:51:21 +00:00
|
|
|
priv->profiler = gsk_profiler_new ();
|
2018-01-14 14:52:52 +00:00
|
|
|
priv->debug_flags = gsk_get_debug_flags ();
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-20 11:05:26 +00:00
|
|
|
* gsk_renderer_get_surface:
|
2016-03-17 13:48:19 +00:00
|
|
|
* @renderer: a #GskRenderer
|
|
|
|
*
|
2018-03-20 10:40:08 +00:00
|
|
|
* Retrieves the #GdkSurface set using gsk_renderer_realize(). If the renderer
|
2016-11-29 02:36:33 +00:00
|
|
|
* has not been realized yet, %NULL will be returned.
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
2018-03-20 10:40:08 +00:00
|
|
|
* Returns: (transfer none) (nullable): a #GdkSurface
|
2016-03-17 13:48:19 +00:00
|
|
|
*/
|
2018-03-20 10:40:08 +00:00
|
|
|
GdkSurface *
|
2018-03-20 11:05:26 +00:00
|
|
|
gsk_renderer_get_surface (GskRenderer *renderer)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDERER (renderer), NULL);
|
|
|
|
|
2018-03-21 10:49:14 +00:00
|
|
|
return priv->surface;
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2016-06-22 16:30:36 +00:00
|
|
|
/*< private >
|
2016-03-17 13:48:19 +00:00
|
|
|
* gsk_renderer_get_root_node:
|
|
|
|
* @renderer: a #GskRenderer
|
|
|
|
*
|
2016-06-22 16:30:36 +00:00
|
|
|
* Retrieves the #GskRenderNode used by @renderer.
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer none) (nullable): a #GskRenderNode
|
|
|
|
*/
|
|
|
|
GskRenderNode *
|
|
|
|
gsk_renderer_get_root_node (GskRenderer *renderer)
|
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDERER (renderer), NULL);
|
|
|
|
|
|
|
|
return priv->root_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-22 16:30:36 +00:00
|
|
|
* gsk_renderer_is_realized:
|
2016-03-17 13:48:19 +00:00
|
|
|
* @renderer: a #GskRenderer
|
|
|
|
*
|
2016-06-22 16:30:36 +00:00
|
|
|
* Checks whether the @renderer is realized or not.
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
2016-06-22 16:30:36 +00:00
|
|
|
* Returns: %TRUE if the #GskRenderer was realized, and %FALSE otherwise
|
2016-03-17 13:48:19 +00:00
|
|
|
*/
|
2016-06-22 16:30:36 +00:00
|
|
|
gboolean
|
|
|
|
gsk_renderer_is_realized (GskRenderer *renderer)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
|
|
|
|
2016-06-22 16:30:36 +00:00
|
|
|
g_return_val_if_fail (GSK_IS_RENDERER (renderer), FALSE);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-06-22 16:30:36 +00:00
|
|
|
return priv->is_realized;
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_renderer_realize:
|
|
|
|
* @renderer: a #GskRenderer
|
2018-03-21 10:49:14 +00:00
|
|
|
* @surface: the #GdkSurface renderer will be used on
|
2016-11-29 03:51:07 +00:00
|
|
|
* @error: return location for an error
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
|
|
|
* Creates the resources needed by the @renderer to render the scene
|
|
|
|
* graph.
|
|
|
|
*/
|
|
|
|
gboolean
|
2016-11-29 03:51:07 +00:00
|
|
|
gsk_renderer_realize (GskRenderer *renderer,
|
2018-03-21 10:49:14 +00:00
|
|
|
GdkSurface *surface,
|
2016-11-29 03:51:07 +00:00
|
|
|
GError **error)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDERER (renderer), FALSE);
|
2016-11-29 02:36:33 +00:00
|
|
|
g_return_val_if_fail (!gsk_renderer_is_realized (renderer), FALSE);
|
2018-03-21 10:49:14 +00:00
|
|
|
g_return_val_if_fail (GDK_IS_SURFACE (surface), FALSE);
|
2016-11-29 03:51:07 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2018-03-21 10:49:14 +00:00
|
|
|
priv->surface = g_object_ref (surface);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2018-03-21 10:49:14 +00:00
|
|
|
if (!GSK_RENDERER_GET_CLASS (renderer)->realize (renderer, surface, error))
|
2016-11-29 02:36:33 +00:00
|
|
|
{
|
2018-03-21 10:49:14 +00:00
|
|
|
g_clear_object (&priv->surface);
|
2016-11-29 02:36:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-11-29 02:36:33 +00:00
|
|
|
priv->is_realized = TRUE;
|
|
|
|
return TRUE;
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_renderer_unrealize:
|
|
|
|
* @renderer: a #GskRenderer
|
|
|
|
*
|
|
|
|
* Releases all the resources created by gsk_renderer_realize().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gsk_renderer_unrealize (GskRenderer *renderer)
|
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
|
|
|
|
|
|
|
g_return_if_fail (GSK_IS_RENDERER (renderer));
|
|
|
|
|
|
|
|
if (!priv->is_realized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GSK_RENDERER_GET_CLASS (renderer)->unrealize (renderer);
|
|
|
|
|
2018-03-28 13:43:43 +00:00
|
|
|
g_clear_pointer (&priv->prev_node, gsk_render_node_unref);
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
priv->is_realized = FALSE;
|
|
|
|
}
|
|
|
|
|
2016-12-21 19:23:46 +00:00
|
|
|
/**
|
|
|
|
* gsk_renderer_render_texture:
|
2020-05-11 16:47:20 +00:00
|
|
|
* @renderer: a realized #GskRenderer
|
2016-12-21 19:23:46 +00:00
|
|
|
* @root: a #GskRenderNode
|
|
|
|
* @viewport: (allow-none): the section to draw or %NULL to use @root's bounds
|
|
|
|
*
|
|
|
|
* Renders the scene graph, described by a tree of #GskRenderNode instances,
|
2017-11-02 20:39:00 +00:00
|
|
|
* to a #GdkTexture.
|
2016-12-21 19:23:46 +00:00
|
|
|
*
|
|
|
|
* The @renderer will acquire a reference on the #GskRenderNode tree while
|
2018-03-31 11:52:19 +00:00
|
|
|
* the rendering is in progress.
|
2016-12-21 19:23:46 +00:00
|
|
|
*
|
|
|
|
* If you want to apply any transformations to @root, you should put it into a
|
|
|
|
* transform node and pass that node instead.
|
|
|
|
*
|
2017-11-02 20:39:00 +00:00
|
|
|
* Returns: (transfer full): a #GdkTexture with the rendered contents of @root.
|
2016-12-21 19:23:46 +00:00
|
|
|
*/
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *
|
2016-12-21 19:23:46 +00:00
|
|
|
gsk_renderer_render_texture (GskRenderer *renderer,
|
|
|
|
GskRenderNode *root,
|
|
|
|
const graphene_rect_t *viewport)
|
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
|
|
|
graphene_rect_t real_viewport;
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *texture;
|
2016-12-21 19:23:46 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDERER (renderer), NULL);
|
|
|
|
g_return_val_if_fail (priv->is_realized, NULL);
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDER_NODE (root), NULL);
|
|
|
|
g_return_val_if_fail (priv->root_node == NULL, NULL);
|
|
|
|
|
|
|
|
priv->root_node = gsk_render_node_ref (root);
|
|
|
|
|
|
|
|
if (viewport == NULL)
|
|
|
|
{
|
|
|
|
gsk_render_node_get_bounds (root, &real_viewport);
|
|
|
|
viewport = &real_viewport;
|
|
|
|
}
|
|
|
|
|
|
|
|
texture = GSK_RENDERER_GET_CLASS (renderer)->render_texture (renderer, root, viewport);
|
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
2018-01-14 14:52:52 +00:00
|
|
|
if (GSK_RENDERER_DEBUG_CHECK (renderer, RENDERER))
|
2016-12-21 19:23:46 +00:00
|
|
|
{
|
|
|
|
GString *buf = g_string_new ("*** Texture stats ***\n\n");
|
|
|
|
|
|
|
|
gsk_profiler_append_counters (priv->profiler, buf);
|
|
|
|
g_string_append_c (buf, '\n');
|
|
|
|
|
|
|
|
gsk_profiler_append_timers (priv->profiler, buf);
|
|
|
|
g_string_append_c (buf, '\n');
|
|
|
|
|
|
|
|
g_print ("%s\n***\n\n", buf->str);
|
|
|
|
|
|
|
|
g_string_free (buf, TRUE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
g_clear_pointer (&priv->root_node, gsk_render_node_unref);
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
/**
|
|
|
|
* gsk_renderer_render:
|
2016-06-22 16:30:36 +00:00
|
|
|
* @renderer: a #GskRenderer
|
|
|
|
* @root: a #GskRenderNode
|
2018-07-08 10:39:06 +00:00
|
|
|
* @region: (nullable): the #cairo_region_t that must be redrawn or %NULL
|
|
|
|
* for the whole window
|
2016-06-22 16:30:36 +00:00
|
|
|
*
|
|
|
|
* Renders the scene graph, described by a tree of #GskRenderNode instances,
|
2018-03-27 23:29:39 +00:00
|
|
|
* ensuring that the given @region gets redrawn.
|
|
|
|
*
|
|
|
|
* Renderers must ensure that changes of the contents given by the @root
|
|
|
|
* node as well as the area given by @region are redrawn. They are however
|
|
|
|
* free to not redraw any pixel outside of @region if they can guarantee that
|
|
|
|
* it didn't change.
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
2016-06-22 16:30:36 +00:00
|
|
|
* The @renderer will acquire a reference on the #GskRenderNode tree while
|
2016-12-21 10:00:18 +00:00
|
|
|
* the rendering is in progress.
|
2016-03-17 13:48:19 +00:00
|
|
|
*/
|
|
|
|
void
|
2018-03-27 23:29:39 +00:00
|
|
|
gsk_renderer_render (GskRenderer *renderer,
|
|
|
|
GskRenderNode *root,
|
|
|
|
const cairo_region_t *region)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
2018-03-28 13:43:43 +00:00
|
|
|
cairo_region_t *clip;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GSK_IS_RENDERER (renderer));
|
|
|
|
g_return_if_fail (priv->is_realized);
|
2016-06-22 16:30:36 +00:00
|
|
|
g_return_if_fail (GSK_IS_RENDER_NODE (root));
|
2016-06-29 18:05:33 +00:00
|
|
|
g_return_if_fail (priv->root_node == NULL);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2018-03-28 13:43:43 +00:00
|
|
|
if (region == NULL || priv->prev_node == NULL || GSK_RENDERER_DEBUG_CHECK (renderer, FULL_REDRAW))
|
2018-03-27 23:29:39 +00:00
|
|
|
{
|
2018-03-28 13:43:43 +00:00
|
|
|
clip = cairo_region_create_rectangle (&(GdkRectangle) {
|
|
|
|
0, 0,
|
|
|
|
gdk_surface_get_width (priv->surface),
|
|
|
|
gdk_surface_get_height (priv->surface)
|
|
|
|
});
|
2018-03-27 23:29:39 +00:00
|
|
|
}
|
|
|
|
else
|
2018-03-28 13:01:34 +00:00
|
|
|
{
|
2018-03-28 13:43:43 +00:00
|
|
|
clip = cairo_region_copy (region);
|
|
|
|
gsk_render_node_diff (priv->prev_node, root, clip);
|
|
|
|
|
|
|
|
if (cairo_region_is_empty (clip))
|
|
|
|
{
|
|
|
|
cairo_region_destroy (clip);
|
|
|
|
return;
|
|
|
|
}
|
2018-03-28 13:01:34 +00:00
|
|
|
}
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2018-03-28 13:43:43 +00:00
|
|
|
priv->root_node = gsk_render_node_ref (root);
|
|
|
|
|
|
|
|
GSK_RENDERER_GET_CLASS (renderer)->render (renderer, root, clip);
|
|
|
|
|
2016-08-03 15:51:21 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2018-01-14 14:52:52 +00:00
|
|
|
if (GSK_RENDERER_DEBUG_CHECK (renderer, RENDERER))
|
2016-08-03 15:51:21 +00:00
|
|
|
{
|
|
|
|
GString *buf = g_string_new ("*** Frame stats ***\n\n");
|
|
|
|
|
|
|
|
gsk_profiler_append_counters (priv->profiler, buf);
|
|
|
|
g_string_append_c (buf, '\n');
|
|
|
|
|
|
|
|
gsk_profiler_append_timers (priv->profiler, buf);
|
|
|
|
g_string_append_c (buf, '\n');
|
|
|
|
|
|
|
|
g_print ("%s\n***\n\n", buf->str);
|
|
|
|
|
|
|
|
g_string_free (buf, TRUE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-28 13:43:43 +00:00
|
|
|
g_clear_pointer (&priv->prev_node, gsk_render_node_unref);
|
2018-04-14 10:37:19 +00:00
|
|
|
cairo_region_destroy (clip);
|
2018-03-28 13:43:43 +00:00
|
|
|
priv->prev_node = priv->root_node;
|
|
|
|
priv->root_node = NULL;
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2016-08-03 15:51:21 +00:00
|
|
|
/*< private >
|
|
|
|
* gsk_renderer_get_profiler:
|
|
|
|
* @renderer: a #GskRenderer
|
|
|
|
*
|
|
|
|
* Retrieves a pointer to the GskProfiler instance of the renderer.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the profiler
|
|
|
|
*/
|
|
|
|
GskProfiler *
|
|
|
|
gsk_renderer_get_profiler (GskRenderer *renderer)
|
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDERER (renderer), NULL);
|
|
|
|
|
|
|
|
return priv->profiler;
|
|
|
|
}
|
|
|
|
|
2017-03-17 15:12:45 +00:00
|
|
|
static GType
|
|
|
|
get_renderer_for_name (const char *renderer_name)
|
|
|
|
{
|
|
|
|
if (renderer_name == NULL)
|
|
|
|
return G_TYPE_INVALID;
|
2018-05-07 14:45:32 +00:00
|
|
|
#ifdef GDK_WINDOWING_BROADWAY
|
|
|
|
else if (g_ascii_strcasecmp (renderer_name, "broadway") == 0)
|
|
|
|
return GSK_TYPE_BROADWAY_RENDERER;
|
|
|
|
#endif
|
2017-03-17 15:12:45 +00:00
|
|
|
else if (g_ascii_strcasecmp (renderer_name, "cairo") == 0)
|
|
|
|
return GSK_TYPE_CAIRO_RENDERER;
|
|
|
|
else if (g_ascii_strcasecmp (renderer_name, "opengl") == 0
|
|
|
|
|| g_ascii_strcasecmp (renderer_name, "gl") == 0)
|
|
|
|
return GSK_TYPE_GL_RENDERER;
|
|
|
|
#ifdef GDK_RENDERING_VULKAN
|
|
|
|
else if (g_ascii_strcasecmp (renderer_name, "vulkan") == 0)
|
2017-03-18 12:17:44 +00:00
|
|
|
return GSK_TYPE_VULKAN_RENDERER;
|
2017-03-17 15:12:45 +00:00
|
|
|
#endif
|
|
|
|
else if (g_ascii_strcasecmp (renderer_name, "help") == 0)
|
|
|
|
{
|
|
|
|
g_print ("Supported arguments for GSK_RENDERER environment variable:\n");
|
2018-05-07 14:45:32 +00:00
|
|
|
#ifdef GDK_WINDOWING_BROADWAY
|
|
|
|
g_print ("broadway - Use the Broadway specific renderer\n");
|
|
|
|
#else
|
|
|
|
g_print ("broadway - disabled during GTK build\n");
|
|
|
|
#endif
|
2017-03-17 15:12:45 +00:00
|
|
|
g_print (" cairo - Use the Cairo fallback renderer\n");
|
|
|
|
g_print (" opengl - Use the default OpenGL renderer\n");
|
2020-09-07 15:16:52 +00:00
|
|
|
g_print (" gl - Same as opengl\n");
|
2017-03-17 15:12:45 +00:00
|
|
|
#ifdef GDK_RENDERING_VULKAN
|
|
|
|
g_print (" vulkan - Use the Vulkan renderer\n");
|
2018-05-07 14:45:32 +00:00
|
|
|
#else
|
|
|
|
g_print (" vulkan - Disabled during GTK build\n");
|
2017-03-17 15:12:45 +00:00
|
|
|
#endif
|
|
|
|
g_print (" help - Print this help\n\n");
|
|
|
|
g_print ("Other arguments will cause a warning and be ignored.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("Unrecognized renderer \"%s\". Try GSK_RENDERER=help", renderer_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return G_TYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GType
|
2018-03-21 10:49:14 +00:00
|
|
|
get_renderer_for_display (GdkSurface *surface)
|
2017-03-17 15:12:45 +00:00
|
|
|
{
|
2018-03-21 10:49:14 +00:00
|
|
|
GdkDisplay *display = gdk_surface_get_display (surface);
|
2017-03-17 15:12:45 +00:00
|
|
|
const char *renderer_name;
|
|
|
|
|
2017-03-19 13:26:02 +00:00
|
|
|
renderer_name = g_object_get_data (G_OBJECT (display), "gsk-renderer");
|
2017-03-17 15:12:45 +00:00
|
|
|
return get_renderer_for_name (renderer_name);
|
|
|
|
}
|
|
|
|
|
2016-11-29 03:27:21 +00:00
|
|
|
static GType
|
2018-03-21 10:49:14 +00:00
|
|
|
get_renderer_for_env_var (GdkSurface *surface)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
2016-11-29 12:36:31 +00:00
|
|
|
static GType env_var_type = G_TYPE_NONE;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-11-29 12:36:31 +00:00
|
|
|
if (env_var_type == G_TYPE_NONE)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
2016-11-29 12:36:31 +00:00
|
|
|
const char *renderer_name = g_getenv ("GSK_RENDERER");
|
2017-03-17 15:12:45 +00:00
|
|
|
env_var_type = get_renderer_for_name (renderer_name);
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 12:36:31 +00:00
|
|
|
return env_var_type;
|
2016-11-29 03:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GType
|
2018-03-21 10:49:14 +00:00
|
|
|
get_renderer_for_backend (GdkSurface *surface)
|
2016-11-29 03:27:21 +00:00
|
|
|
{
|
2016-03-17 13:48:19 +00:00
|
|
|
#ifdef GDK_WINDOWING_X11
|
2018-03-21 10:49:14 +00:00
|
|
|
if (GDK_IS_X11_SURFACE (surface))
|
2016-11-29 03:27:21 +00:00
|
|
|
return GSK_TYPE_GL_RENDERER;
|
2016-03-17 13:48:19 +00:00
|
|
|
#endif
|
|
|
|
#ifdef GDK_WINDOWING_WAYLAND
|
2018-03-21 10:49:14 +00:00
|
|
|
if (GDK_IS_WAYLAND_SURFACE (surface))
|
2016-11-29 03:27:21 +00:00
|
|
|
return GSK_TYPE_GL_RENDERER;
|
2016-07-25 16:36:33 +00:00
|
|
|
#endif
|
2017-11-17 11:04:02 +00:00
|
|
|
#ifdef GDK_WINDOWING_BROADWAY
|
2018-03-21 10:49:14 +00:00
|
|
|
if (GDK_IS_BROADWAY_SURFACE (surface))
|
2017-11-17 11:04:02 +00:00
|
|
|
return GSK_TYPE_BROADWAY_RENDERER;
|
|
|
|
#endif
|
2020-04-23 23:36:46 +00:00
|
|
|
#ifdef GDK_WINDOWING_MACOS
|
|
|
|
if (GDK_IS_MACOS_SURFACE (surface))
|
|
|
|
return GSK_TYPE_GL_RENDERER;
|
|
|
|
#endif
|
2020-07-31 10:44:10 +00:00
|
|
|
#ifdef GDK_WINDOWING_WIN32
|
|
|
|
if (GDK_IS_WIN32_SURFACE (surface))
|
|
|
|
/* remove check for OpenGL/ES when OpenGL/ES 2.0 shader is ready */
|
|
|
|
{
|
|
|
|
GdkDisplay *display = gdk_surface_get_display (surface);
|
|
|
|
|
|
|
|
if (!(GDK_DISPLAY_DEBUG_CHECK (display, GL_GLES) ||
|
|
|
|
GDK_WIN32_DISPLAY (display)->running_on_arm64))
|
|
|
|
return GSK_TYPE_GL_RENDERER;
|
|
|
|
}
|
|
|
|
#endif
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-11-29 03:27:21 +00:00
|
|
|
return G_TYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GType
|
2018-03-21 10:49:14 +00:00
|
|
|
get_renderer_fallback (GdkSurface *surface)
|
2016-11-29 03:27:21 +00:00
|
|
|
{
|
|
|
|
return GSK_TYPE_CAIRO_RENDERER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct {
|
2018-03-21 10:49:14 +00:00
|
|
|
GType (* get_renderer) (GdkSurface *surface);
|
2016-11-29 03:27:21 +00:00
|
|
|
} renderer_possibilities[] = {
|
2020-03-20 14:25:14 +00:00
|
|
|
{ get_renderer_for_display },
|
|
|
|
{ get_renderer_for_env_var },
|
|
|
|
{ get_renderer_for_backend },
|
|
|
|
{ get_renderer_fallback },
|
2016-11-29 03:27:21 +00:00
|
|
|
};
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-11-29 03:27:21 +00:00
|
|
|
/**
|
2018-03-20 11:05:26 +00:00
|
|
|
* gsk_renderer_new_for_surface:
|
2018-03-21 10:49:14 +00:00
|
|
|
* @surface: a #GdkSurface
|
2016-11-29 03:27:21 +00:00
|
|
|
*
|
2018-03-21 10:49:14 +00:00
|
|
|
* Creates an appropriate #GskRenderer instance for the given @surface.
|
2016-11-29 03:27:21 +00:00
|
|
|
*
|
|
|
|
* The renderer will be realized when it is returned.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (nullable): a #GskRenderer
|
|
|
|
*/
|
|
|
|
GskRenderer *
|
2018-03-21 10:49:14 +00:00
|
|
|
gsk_renderer_new_for_surface (GdkSurface *surface)
|
2016-11-29 03:27:21 +00:00
|
|
|
{
|
|
|
|
GType renderer_type;
|
|
|
|
GskRenderer *renderer;
|
2016-11-29 03:51:07 +00:00
|
|
|
GError *error = NULL;
|
2016-11-29 03:27:21 +00:00
|
|
|
guint i;
|
|
|
|
|
2018-03-21 10:49:14 +00:00
|
|
|
g_return_val_if_fail (GDK_IS_SURFACE (surface), NULL);
|
2016-11-29 03:27:21 +00:00
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (renderer_possibilities); i++)
|
|
|
|
{
|
2018-03-21 10:49:14 +00:00
|
|
|
renderer_type = renderer_possibilities[i].get_renderer (surface);
|
2016-11-29 03:27:21 +00:00
|
|
|
if (renderer_type == G_TYPE_INVALID)
|
|
|
|
continue;
|
|
|
|
|
2019-03-09 12:36:14 +00:00
|
|
|
renderer = g_object_new (renderer_type, NULL);
|
2016-11-29 03:27:21 +00:00
|
|
|
|
2018-03-21 10:49:14 +00:00
|
|
|
if (gsk_renderer_realize (renderer, surface, &error))
|
2016-11-29 03:27:21 +00:00
|
|
|
{
|
2020-03-20 14:25:14 +00:00
|
|
|
GSK_RENDERER_NOTE (renderer, RENDERER,
|
|
|
|
g_message ("Using renderer of type '%s' for surface '%s'\n",
|
|
|
|
G_OBJECT_TYPE_NAME (renderer),
|
|
|
|
G_OBJECT_TYPE_NAME (surface)));
|
2016-11-29 03:27:21 +00:00
|
|
|
return renderer;
|
|
|
|
}
|
|
|
|
|
2020-09-07 15:17:24 +00:00
|
|
|
g_message ("Failed to realize renderer of type '%s' for surface '%s': %s\n",
|
|
|
|
G_OBJECT_TYPE_NAME (renderer),
|
|
|
|
G_OBJECT_TYPE_NAME (surface),
|
|
|
|
error->message);
|
2016-11-29 03:27:21 +00:00
|
|
|
g_object_unref (renderer);
|
2016-11-29 03:51:07 +00:00
|
|
|
g_clear_error (&error);
|
2016-11-29 03:27:21 +00:00
|
|
|
}
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-11-29 03:27:21 +00:00
|
|
|
g_assert_not_reached ();
|
|
|
|
return NULL;
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
2016-08-25 10:31:56 +00:00
|
|
|
|
2018-01-14 14:52:52 +00:00
|
|
|
GskDebugFlags
|
|
|
|
gsk_renderer_get_debug_flags (GskRenderer *renderer)
|
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GSK_IS_RENDERER (renderer), 0);
|
|
|
|
|
|
|
|
return priv->debug_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_renderer_set_debug_flags (GskRenderer *renderer,
|
|
|
|
GskDebugFlags flags)
|
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
|
|
|
|
|
|
|
g_return_if_fail (GSK_IS_RENDERER (renderer));
|
|
|
|
|
|
|
|
priv->debug_flags = flags;
|
|
|
|
}
|