API: Add gsk_renderer_realize_for_display()

This makes realizing a renderer without a surface explicit.

And more importantly, it allows passing a different display than the
default one.
This commit is contained in:
Benjamin Otte 2024-01-07 10:00:38 +01:00
parent df09975753
commit d0bf33339e
2 changed files with 32 additions and 6 deletions

View File

@ -293,6 +293,8 @@ gsk_renderer_do_realize (GskRenderer *renderer,
*
* Since GTK 4.6, the surface may be `NULL`, which allows using
* renderers without having to create a surface.
* Since GTK 4.14, it is recommended to use [method@Gsk.Renderer.realize_for_display]
* instead.
*
* Note that it is mandatory to call [method@Gsk.Renderer.unrealize] before
* destroying the renderer.
@ -325,13 +327,33 @@ gsk_renderer_realize (GskRenderer *renderer,
}
}
priv->is_realized = TRUE;
/**
* 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);
g_object_notify (G_OBJECT (renderer), "realized");
if (surface)
g_object_notify (G_OBJECT (renderer), "surface");
return TRUE;
return gsk_renderer_do_realize (renderer, display, NULL, error);
}
/**

View File

@ -47,6 +47,10 @@ GDK_AVAILABLE_IN_ALL
gboolean gsk_renderer_realize (GskRenderer *renderer,
GdkSurface *surface,
GError **error);
GDK_AVAILABLE_IN_4_14
gboolean gsk_renderer_realize_for_display (GskRenderer *renderer,
GdkDisplay *display,
GError **error);
GDK_AVAILABLE_IN_ALL
void gsk_renderer_unrealize (GskRenderer *renderer);
GDK_AVAILABLE_IN_ALL