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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-02-25 11:59:41 +00:00
|
|
|
* GskRenderer:
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
2021-02-25 11:59:41 +00:00
|
|
|
* `GskRenderer` is a class that renders a scene graph defined via a
|
|
|
|
* tree of [class@Gsk.RenderNode] instances.
|
2016-07-03 23:23:19 +00:00
|
|
|
*
|
2021-02-25 11:59:41 +00:00
|
|
|
* Typically you will use a `GskRenderer` instance to repeatedly call
|
|
|
|
* [method@Gsk.Renderer.render] to update the contents of its associated
|
|
|
|
* [class@Gdk.Surface].
|
2016-07-03 23:23:19 +00:00
|
|
|
*
|
2021-02-25 11:59:41 +00:00
|
|
|
* It is necessary to realize a `GskRenderer` instance using
|
|
|
|
* [method@Gsk.Renderer.realize] before calling [method@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"
|
2016-08-03 15:51:21 +00:00
|
|
|
#include "gskprofilerprivate.h"
|
2016-03-17 13:48:19 +00:00
|
|
|
#include "gskrendernodeprivate.h"
|
2023-10-31 23:19:32 +00:00
|
|
|
#include "gskoffloadprivate.h"
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
#include "gskenumtypes.h"
|
|
|
|
|
2024-01-06 18:58:24 +00:00
|
|
|
#include "gl/gskglrenderer.h"
|
|
|
|
#include "gpu/gskvulkanrenderer.h"
|
2024-02-12 19:16:09 +00:00
|
|
|
#include "gdk/gdkvulkancontextprivate.h"
|
|
|
|
#include "gdk/gdkdisplayprivate.h"
|
2024-01-06 18:58:24 +00:00
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
#include <graphene-gobject.h>
|
|
|
|
#include <cairo-gobject.h>
|
|
|
|
#include <gdk/gdk.h>
|
2024-08-19 20:20:11 +00:00
|
|
|
#include "gdk/gdkdebugprivate.h"
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
#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
|
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
|
|
|
|
2016-08-03 15:51:21 +00:00
|
|
|
GskProfiler *profiler;
|
|
|
|
|
2018-01-14 14:52:52 +00:00
|
|
|
GskDebugFlags debug_flags;
|
|
|
|
|
2023-04-27 04:46:36 +00:00
|
|
|
unsigned int is_realized : 1;
|
2016-03-17 13:48:19 +00:00
|
|
|
} 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,
|
2024-01-07 09:00:04 +00:00
|
|
|
GdkDisplay *display,
|
2021-10-20 18:30:08 +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,
|
2023-11-14 20:45:47 +00:00
|
|
|
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;
|
|
|
|
|
2021-02-25 11:59:41 +00:00
|
|
|
/**
|
2024-06-03 11:04:05 +00:00
|
|
|
* GskRenderer:realized: (getter is_realized)
|
2021-02-25 11:59:41 +00:00
|
|
|
*
|
2021-10-20 18:30:08 +00:00
|
|
|
* Whether the renderer has been associated with a surface or draw context.
|
2021-02-25 11:59:41 +00:00
|
|
|
*/
|
2019-03-09 12:59:03 +00:00
|
|
|
gsk_renderer_properties[PROP_REALIZED] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("realized", NULL, NULL,
|
2019-03-09 12:59:03 +00:00
|
|
|
FALSE,
|
|
|
|
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
2021-02-25 11:59:41 +00:00
|
|
|
/**
|
2024-06-03 11:35:00 +00:00
|
|
|
* GskRenderer:surface:
|
2021-02-25 11:59:41 +00:00
|
|
|
*
|
|
|
|
* The surface associated with renderer.
|
|
|
|
*/
|
2018-03-21 10:49:14 +00:00
|
|
|
gsk_renderer_properties[PROP_SURFACE] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("surface", NULL, NULL,
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-03 11:36:59 +00:00
|
|
|
* gsk_renderer_get_surface:
|
2021-02-25 11:59:41 +00:00
|
|
|
* @renderer: a `GskRenderer`
|
|
|
|
*
|
|
|
|
* Retrieves the `GdkSurface` set using gsk_enderer_realize().
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
2021-02-25 11:59:41 +00:00
|
|
|
* If the renderer has not been realized yet, %NULL will be returned.
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
2021-02-25 11:59:41 +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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-03 11:04:05 +00:00
|
|
|
* gsk_renderer_is_realized: (get-property realized)
|
2021-02-25 11:59:41 +00:00
|
|
|
* @renderer: a `GskRenderer`
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
2016-06-22 16:30:36 +00:00
|
|
|
* Checks whether the @renderer is realized or not.
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
2021-02-25 11:59:41 +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
|
|
|
}
|
|
|
|
|
2024-01-07 09:00:04 +00:00
|
|
|
static gboolean
|
|
|
|
gsk_renderer_do_realize (GskRenderer *renderer,
|
|
|
|
GdkDisplay *display,
|
|
|
|
GdkSurface *surface,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
|
|
|
|
|
|
|
if (surface)
|
|
|
|
priv->surface = g_object_ref (surface);
|
|
|
|
|
|
|
|
if (!GSK_RENDERER_GET_CLASS (renderer)->realize (renderer, display, surface, error))
|
|
|
|
{
|
|
|
|
g_clear_object (&priv->surface);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->is_realized = TRUE;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (renderer), "realized");
|
|
|
|
if (surface)
|
|
|
|
g_object_notify (G_OBJECT (renderer), "surface");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
/**
|
|
|
|
* gsk_renderer_realize:
|
2021-02-25 11:59:41 +00:00
|
|
|
* @renderer: a `GskRenderer`
|
2021-10-20 18:30:08 +00:00
|
|
|
* @surface: (nullable): 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.
|
2021-10-20 18:30:08 +00:00
|
|
|
*
|
|
|
|
* Since GTK 4.6, the surface may be `NULL`, which allows using
|
|
|
|
* renderers without having to create a surface.
|
2024-01-07 09:00:38 +00:00
|
|
|
* Since GTK 4.14, it is recommended to use [method@Gsk.Renderer.realize_for_display]
|
|
|
|
* instead.
|
2022-01-11 09:04:16 +00:00
|
|
|
*
|
|
|
|
* Note that it is mandatory to call [method@Gsk.Renderer.unrealize] before
|
|
|
|
* destroying the renderer.
|
|
|
|
*
|
|
|
|
* Returns: Whether the renderer was successfully realized
|
2016-03-17 13:48:19 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2016-11-29 03:51:07 +00:00
|
|
|
gsk_renderer_realize (GskRenderer *renderer,
|
2022-01-11 09:04:16 +00:00
|
|
|
GdkSurface *surface,
|
2016-11-29 03:51:07 +00:00
|
|
|
GError **error)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
|
|
|
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);
|
2021-10-20 18:30:08 +00:00
|
|
|
g_return_val_if_fail (surface == NULL || 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
|
|
|
|
2024-01-07 09:00:04 +00:00
|
|
|
if (surface == NULL)
|
2016-11-29 02:36:33 +00:00
|
|
|
{
|
2024-01-07 09:00:04 +00:00
|
|
|
return gsk_renderer_do_realize (renderer,
|
|
|
|
gdk_display_get_default (),
|
|
|
|
NULL,
|
|
|
|
error);
|
2016-11-29 02:36:33 +00:00
|
|
|
}
|
2024-01-07 09:00:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return gsk_renderer_do_realize (renderer,
|
|
|
|
gdk_surface_get_display (surface),
|
|
|
|
surface,
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
}
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2024-01-07 09:00:38 +00:00
|
|
|
/**
|
|
|
|
* gsk_renderer_realize_for_display:
|
|
|
|
* @renderer: a `GskRenderer`
|
|
|
|
* @display: the `GdkDisplay` renderer will be used on
|
|
|
|
* @error: return location for an error
|
|
|
|
*
|
|
|
|
* Creates the resources needed by the @renderer to render the scene
|
|
|
|
* graph.
|
|
|
|
*
|
|
|
|
* Note that it is mandatory to call [method@Gsk.Renderer.unrealize] before
|
|
|
|
* destroying the renderer.
|
|
|
|
*
|
|
|
|
* Returns: Whether the renderer was successfully realized
|
|
|
|
*
|
|
|
|
* Since: 4.14
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gsk_renderer_realize_for_display (GskRenderer *renderer,
|
|
|
|
GdkDisplay *display,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
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 (display == NULL || GDK_IS_DISPLAY (display), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2023-05-10 20:55:16 +00:00
|
|
|
|
2024-01-07 09:00:38 +00:00
|
|
|
return gsk_renderer_do_realize (renderer, display, NULL, error);
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsk_renderer_unrealize:
|
2021-02-25 11:59:41 +00:00
|
|
|
* @renderer: a `GskRenderer`
|
2016-03-17 13:48:19 +00:00
|
|
|
*
|
|
|
|
* Releases all the resources created by gsk_renderer_realize().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gsk_renderer_unrealize (GskRenderer *renderer)
|
|
|
|
{
|
|
|
|
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
|
2023-05-10 20:55:16 +00:00
|
|
|
gboolean has_surface;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GSK_IS_RENDERER (renderer));
|
|
|
|
|
|
|
|
if (!priv->is_realized)
|
|
|
|
return;
|
|
|
|
|
2023-05-10 20:55:16 +00:00
|
|
|
has_surface = priv->surface != NULL;
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
GSK_RENDERER_GET_CLASS (renderer)->unrealize (renderer);
|
|
|
|
|
2023-05-10 20:55:16 +00:00
|
|
|
g_clear_object (&priv->surface);
|
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;
|
2023-05-10 20:55:16 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (renderer), "realized");
|
|
|
|
if (has_surface)
|
|
|
|
g_object_notify (G_OBJECT (renderer), "surface");
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 19:23:46 +00:00
|
|
|
/**
|
|
|
|
* gsk_renderer_render_texture:
|
2021-02-25 11:59:41 +00:00
|
|
|
* @renderer: a realized `GskRenderer`
|
|
|
|
* @root: a `GskRenderNode`
|
2021-05-19 11:24:34 +00:00
|
|
|
* @viewport: (nullable): the section to draw or %NULL to use @root's bounds
|
2016-12-21 19:23:46 +00:00
|
|
|
*
|
2021-02-25 11:59:41 +00:00
|
|
|
* Renders the scene graph, described by a tree of `GskRenderNode` instances,
|
|
|
|
* to a `GdkTexture`.
|
2016-12-21 19:23:46 +00:00
|
|
|
*
|
2021-02-25 11:59:41 +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
|
|
|
*
|
2021-02-25 11:59:41 +00:00
|
|
|
* If you want to apply any transformations to @root, you should put it into a
|
2016-12-21 19:23:46 +00:00
|
|
|
* transform node and pass that node instead.
|
|
|
|
*
|
2021-02-25 11:59:41 +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);
|
|
|
|
|
|
|
|
if (viewport == NULL)
|
|
|
|
{
|
|
|
|
gsk_render_node_get_bounds (root, &real_viewport);
|
|
|
|
viewport = &real_viewport;
|
|
|
|
}
|
2023-05-20 23:27:09 +00:00
|
|
|
g_return_val_if_fail (viewport->size.width > 0, NULL);
|
|
|
|
g_return_val_if_fail (viewport->size.height > 0, NULL);
|
2016-12-21 19:23:46 +00:00
|
|
|
|
|
|
|
texture = GSK_RENDERER_GET_CLASS (renderer)->render_texture (renderer, root, viewport);
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
/**
|
|
|
|
* gsk_renderer_render:
|
2021-10-20 18:30:08 +00:00
|
|
|
* @renderer: a realized `GskRenderer`
|
2021-02-25 11:59:41 +00:00
|
|
|
* @root: a `GskRenderNode`
|
|
|
|
* @region: (nullable): the `cairo_region_t` that must be redrawn or %NULL
|
2021-05-18 21:05:26 +00:00
|
|
|
* for the whole window
|
2016-06-22 16:30:36 +00:00
|
|
|
*
|
2021-10-20 18:30:08 +00:00
|
|
|
* Renders the scene graph, described by a tree of `GskRenderNode` instances
|
|
|
|
* to the renderer's surface, ensuring that the given @region gets redrawn.
|
|
|
|
*
|
|
|
|
* If the renderer has no associated surface, this function does nothing.
|
2018-03-27 23:29:39 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
2021-02-25 11:59:41 +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);
|
2023-11-14 11:50:12 +00:00
|
|
|
GskRendererClass *renderer_class;
|
2018-03-28 13:43:43 +00:00
|
|
|
cairo_region_t *clip;
|
2023-11-14 11:50:12 +00:00
|
|
|
GskOffload *offload;
|
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-03-17 13:48:19 +00:00
|
|
|
|
2021-10-20 18:30:08 +00:00
|
|
|
if (priv->surface == NULL)
|
|
|
|
return;
|
|
|
|
|
2023-11-14 11:50:12 +00:00
|
|
|
renderer_class = GSK_RENDERER_GET_CLASS (renderer);
|
2023-10-31 23:19:32 +00:00
|
|
|
|
2024-02-10 05:32:20 +00:00
|
|
|
clip = cairo_region_copy (region);
|
|
|
|
|
2024-08-19 20:20:11 +00:00
|
|
|
if (renderer_class->supports_offload && gdk_has_feature (GDK_FEATURE_OFFLOAD))
|
2024-02-10 05:32:20 +00:00
|
|
|
offload = gsk_offload_new (priv->surface, root, clip);
|
2023-11-14 11:50:12 +00:00
|
|
|
else
|
|
|
|
offload = NULL;
|
2023-10-31 23:19:32 +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
|
|
|
{
|
2024-02-10 05:32:20 +00:00
|
|
|
cairo_region_union_rectangle (clip,
|
|
|
|
&(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
|
|
|
{
|
2024-02-11 20:53:37 +00:00
|
|
|
gsk_render_node_diff (priv->prev_node, root, &(GskDiffData) { clip, priv->surface });
|
2018-03-28 13:01:34 +00:00
|
|
|
}
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2023-11-14 20:45:47 +00:00
|
|
|
renderer_class->render (renderer, root, clip);
|
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);
|
2023-11-14 11:49:35 +00:00
|
|
|
g_clear_pointer (&offload, gsk_offload_free);
|
2023-11-14 12:25:30 +00:00
|
|
|
priv->prev_node = gsk_render_node_ref (root);
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
2016-08-03 15:51:21 +00:00
|
|
|
/*< private >
|
|
|
|
* gsk_renderer_get_profiler:
|
2021-05-20 03:40:54 +00:00
|
|
|
* @renderer: a `GskRenderer`
|
2016-08-03 15:51:21 +00:00
|
|
|
*
|
2021-05-20 03:40:54 +00:00
|
|
|
* Retrieves a pointer to the `GskProfiler` instance of the renderer.
|
2016-08-03 15:51:21 +00:00
|
|
|
*
|
|
|
|
* 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;
|
2021-03-18 03:27:41 +00:00
|
|
|
else if (g_ascii_strcasecmp (renderer_name, "opengl") == 0 ||
|
2021-10-07 03:15:25 +00:00
|
|
|
g_ascii_strcasecmp (renderer_name, "gl") == 0)
|
|
|
|
return GSK_TYPE_GL_RENDERER;
|
2023-08-13 02:31:28 +00:00
|
|
|
else if (g_ascii_strcasecmp (renderer_name, "ngl") == 0)
|
|
|
|
return gsk_ngl_renderer_get_type ();
|
|
|
|
#ifdef GDK_RENDERING_VULKAN
|
|
|
|
else if (g_ascii_strcasecmp (renderer_name, "vulkan") == 0)
|
|
|
|
return GSK_TYPE_VULKAN_RENDERER;
|
|
|
|
#endif
|
2017-03-17 15:12:45 +00:00
|
|
|
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
|
2023-08-13 02:31:28 +00:00
|
|
|
g_print (" broadway - Use the Broadway specific renderer\n");
|
2018-05-07 14:45:32 +00:00
|
|
|
#else
|
2023-08-13 02:31:28 +00:00
|
|
|
g_print (" broadway - Disabled during GTK build\n");
|
2018-05-07 14:45:32 +00:00
|
|
|
#endif
|
2017-03-17 15:12:45 +00:00
|
|
|
g_print (" cairo - Use the Cairo fallback renderer\n");
|
2021-10-07 03:15:25 +00:00
|
|
|
g_print (" opengl - Use the OpenGL renderer\n");
|
|
|
|
g_print (" gl - Use the OpenGL renderer\n");
|
2023-08-13 02:31:28 +00:00
|
|
|
g_print (" ngl - Use the new OpenGL renderer\n");
|
|
|
|
#ifdef GDK_RENDERING_VULKAN
|
|
|
|
g_print (" vulkan - Use the Vulkan renderer\n");
|
|
|
|
#else
|
|
|
|
g_print (" vulkan - Disabled during GTK build\n");
|
|
|
|
#endif
|
2017-03-17 15:12:45 +00:00
|
|
|
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
|
|
|
{
|
2024-04-29 14:01:34 +00:00
|
|
|
static GType env_var_type = G_TYPE_INVALID;
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2024-04-29 14:01:34 +00:00
|
|
|
if (env_var_type == G_TYPE_INVALID)
|
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);
|
2024-04-29 14:01:34 +00:00
|
|
|
if (env_var_type != G_TYPE_INVALID)
|
|
|
|
GSK_DEBUG (RENDERER,
|
|
|
|
"Environment variable GSK_RENDERER=%s set, trying %s",
|
|
|
|
renderer_name,
|
|
|
|
g_type_name (env_var_type));
|
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
|
|
|
{
|
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
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-11-29 03:27:21 +00:00
|
|
|
return G_TYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
2024-02-12 19:16:09 +00:00
|
|
|
static gboolean
|
2024-04-29 14:01:34 +00:00
|
|
|
gl_supported_platform (GdkSurface *surface,
|
|
|
|
GType renderer_type,
|
|
|
|
gboolean as_fallback)
|
2024-02-12 19:16:09 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display = gdk_surface_get_display (surface);
|
|
|
|
GdkGLContext *context;
|
2024-04-29 14:01:34 +00:00
|
|
|
GError *error = NULL;
|
2024-02-12 19:16:09 +00:00
|
|
|
|
2024-04-29 14:01:34 +00:00
|
|
|
if (!gdk_display_prepare_gl (display, &error))
|
|
|
|
{
|
|
|
|
if (!as_fallback)
|
|
|
|
GSK_DEBUG (RENDERER, "Not using GL: %s", error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (as_fallback)
|
|
|
|
return TRUE;
|
2024-02-12 19:16:09 +00:00
|
|
|
|
|
|
|
context = gdk_display_get_gl_context (display);
|
|
|
|
gdk_gl_context_make_current (context);
|
|
|
|
|
2024-04-29 14:01:34 +00:00
|
|
|
if (strstr ((const char *) glGetString (GL_RENDERER), "llvmpipe") != NULL)
|
|
|
|
{
|
|
|
|
GSK_DEBUG (RENDERER, "Not using '%s': renderer is llvmpipe", g_type_name (renderer_type));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2024-02-12 19:16:09 +00:00
|
|
|
}
|
|
|
|
|
2023-12-21 13:24:11 +00:00
|
|
|
static GType
|
|
|
|
get_renderer_for_gl (GdkSurface *surface)
|
|
|
|
{
|
2024-04-29 14:01:34 +00:00
|
|
|
if (!gl_supported_platform (surface, gsk_ngl_renderer_get_type (), FALSE))
|
2024-02-12 19:16:09 +00:00
|
|
|
return G_TYPE_INVALID;
|
|
|
|
|
2024-01-25 15:09:04 +00:00
|
|
|
return gsk_ngl_renderer_get_type ();
|
2023-12-21 13:24:11 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 14:01:34 +00:00
|
|
|
static GType
|
|
|
|
get_renderer_for_gl_fallback (GdkSurface *surface)
|
|
|
|
{
|
|
|
|
if (!gl_supported_platform (surface, GSK_TYPE_GL_RENDERER, TRUE))
|
|
|
|
return G_TYPE_INVALID;
|
|
|
|
|
|
|
|
return GSK_TYPE_GL_RENDERER;
|
|
|
|
}
|
|
|
|
|
2024-02-12 19:16:09 +00:00
|
|
|
#ifdef GDK_RENDERING_VULKAN
|
|
|
|
static gboolean
|
2024-04-29 14:01:34 +00:00
|
|
|
vulkan_supported_platform (GdkSurface *surface,
|
|
|
|
GType renderer_type,
|
|
|
|
gboolean as_fallback)
|
2024-02-12 19:16:09 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display = gdk_surface_get_display (surface);
|
|
|
|
VkPhysicalDeviceProperties props;
|
2024-04-29 14:01:34 +00:00
|
|
|
GError *error = NULL;
|
2024-02-12 19:16:09 +00:00
|
|
|
|
2024-04-29 14:01:34 +00:00
|
|
|
if (!gdk_display_init_vulkan (display, &error))
|
|
|
|
{
|
|
|
|
if (!as_fallback)
|
|
|
|
GSK_DEBUG (RENDERER, "Not using Vulkan: %s", error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2024-02-12 19:16:09 +00:00
|
|
|
|
2024-02-12 19:41:14 +00:00
|
|
|
vkGetPhysicalDeviceProperties (display->vk_physical_device, &props);
|
2024-02-12 19:16:09 +00:00
|
|
|
|
2024-04-29 14:01:34 +00:00
|
|
|
if (props.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU)
|
|
|
|
{
|
|
|
|
if (!as_fallback)
|
2024-05-02 01:26:54 +00:00
|
|
|
GSK_DEBUG (RENDERER, "Not using '%s': device is CPU", g_type_name (renderer_type));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2024-09-16 07:54:19 +00:00
|
|
|
#ifdef HAVE_DMABUF
|
|
|
|
gdk_vulkan_init_dmabuf (display);
|
2024-05-02 01:26:54 +00:00
|
|
|
if (!display->vk_dmabuf_formats ||
|
|
|
|
gdk_dmabuf_formats_get_n_formats (display->vk_dmabuf_formats) == 0)
|
|
|
|
{
|
|
|
|
if (!as_fallback)
|
|
|
|
GSK_DEBUG (RENDERER, "Not using '%s': no dmabuf support", g_type_name (renderer_type));
|
2024-04-29 14:01:34 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2024-09-16 07:54:19 +00:00
|
|
|
#endif
|
2024-02-12 19:16:09 +00:00
|
|
|
|
2024-04-29 14:01:34 +00:00
|
|
|
if (as_fallback)
|
|
|
|
return TRUE;
|
2023-12-21 13:27:23 +00:00
|
|
|
|
2024-04-20 21:46:07 +00:00
|
|
|
#ifdef GDK_WINDOWING_WAYLAND
|
|
|
|
if (GDK_IS_WAYLAND_DISPLAY (gdk_surface_get_display (surface)))
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
|
|
|
|
2024-04-29 14:01:34 +00:00
|
|
|
GSK_DEBUG (RENDERER, "Not using '%s': platform is not Wayland", g_type_name (renderer_type));
|
|
|
|
|
2024-04-20 21:46:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GType
|
2024-04-29 14:01:34 +00:00
|
|
|
get_renderer_for_vulkan (GdkSurface *surface)
|
2024-04-20 21:46:07 +00:00
|
|
|
{
|
2024-04-29 14:01:34 +00:00
|
|
|
if (!vulkan_supported_platform (surface, GSK_TYPE_VULKAN_RENDERER, FALSE))
|
|
|
|
return G_TYPE_INVALID;
|
2024-04-20 21:46:07 +00:00
|
|
|
|
2024-04-29 14:01:34 +00:00
|
|
|
return GSK_TYPE_VULKAN_RENDERER;
|
2024-04-20 21:46:07 +00:00
|
|
|
}
|
|
|
|
|
2024-01-25 15:09:04 +00:00
|
|
|
static GType
|
2024-04-29 14:01:34 +00:00
|
|
|
get_renderer_for_vulkan_fallback (GdkSurface *surface)
|
2024-01-25 15:09:04 +00:00
|
|
|
{
|
2024-04-29 14:01:34 +00:00
|
|
|
if (!vulkan_supported_platform (surface, GSK_TYPE_VULKAN_RENDERER, TRUE))
|
|
|
|
return G_TYPE_INVALID;
|
|
|
|
|
|
|
|
return GSK_TYPE_VULKAN_RENDERER;
|
2024-01-25 15:09:04 +00:00
|
|
|
}
|
2024-04-29 14:01:34 +00:00
|
|
|
#endif
|
2024-01-25 15:09:04 +00:00
|
|
|
|
2016-11-29 03:27:21 +00:00
|
|
|
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[] = {
|
2024-04-29 14:01:34 +00:00
|
|
|
{ get_renderer_for_display },
|
|
|
|
{ get_renderer_for_env_var },
|
|
|
|
{ get_renderer_for_backend },
|
|
|
|
#ifdef GDK_RENDERING_VULKAN
|
|
|
|
{ get_renderer_for_vulkan },
|
|
|
|
#endif
|
|
|
|
{ get_renderer_for_gl },
|
|
|
|
#ifdef GDK_RENDERING_VULKAN
|
|
|
|
{ get_renderer_for_vulkan_fallback },
|
|
|
|
#endif
|
|
|
|
{ get_renderer_for_gl_fallback },
|
|
|
|
{ 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:
|
2021-02-25 11:59:41 +00:00
|
|
|
* @surface: a `GdkSurface`
|
2016-11-29 03:27:21 +00:00
|
|
|
*
|
2021-02-25 11:59:41 +00:00
|
|
|
* Creates an appropriate `GskRenderer` instance for the given @surface.
|
2016-11-29 03:27:21 +00:00
|
|
|
*
|
2020-10-29 18:58:12 +00:00
|
|
|
* If the `GSK_RENDERER` environment variable is set, GSK will
|
|
|
|
* try that renderer first, before trying the backend-specific
|
|
|
|
* default. The ultimate fallback is the cairo renderer.
|
|
|
|
*
|
|
|
|
* The renderer will be realized before it is returned.
|
2016-11-29 03:27:21 +00:00
|
|
|
*
|
2021-02-25 11:59:41 +00:00
|
|
|
* Returns: (transfer full) (nullable): a `GskRenderer`
|
2016-11-29 03:27:21 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
{
|
2024-04-29 14:01:34 +00:00
|
|
|
GSK_DEBUG (RENDERER,
|
|
|
|
"Using renderer '%s' for surface '%s'",
|
|
|
|
G_OBJECT_TYPE_NAME (renderer),
|
|
|
|
G_OBJECT_TYPE_NAME (surface));
|
2016-11-29 03:27:21 +00:00
|
|
|
return renderer;
|
|
|
|
}
|
|
|
|
|
2024-04-29 14:01:34 +00:00
|
|
|
GSK_DEBUG (RENDERER,
|
|
|
|
"Failed to realize renderer '%s' for surface '%s': %s",
|
2020-09-07 15:17:24 +00:00
|
|
|
G_OBJECT_TYPE_NAME (renderer),
|
|
|
|
G_OBJECT_TYPE_NAME (surface),
|
|
|
|
error->message);
|
2024-04-29 14:01:34 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2023-10-22 13:39:47 +00:00
|
|
|
|