Gsk.Renderer

g GObject.Object GObject.Object Gsk.Renderer Gsk.Renderer GObject.Object->Gsk.Renderer

Subclasses:

Gsk.BroadwayRenderer, Gsk.CairoRenderer, Gsk.GLRenderer, Gsk.NglRenderer, Gsk.VulkanRenderer

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new_for_surface (surface)

get_surface ()

is_realized ()

realize (surface)

realize_for_display (display)

render (root, region)

render_texture (root, viewport)

unrealize ()

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

realized

bool

r/en

surface

Gdk.Surface

r/en

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Gsk.Renderer(**kwargs)
Bases:

GObject.Object

Abstract:

Yes

Structure:

Gsk.RendererClass

Renders a scene graph defined via a tree of [class`Gsk`.RenderNode] instances.

Typically you will use a GskRenderer instance to repeatedly call [method`Gsk`.Renderer.render] to update the contents of its associated [class`Gdk`.Surface].

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.

classmethod new_for_surface(surface)
Parameters:

surface (Gdk.Surface) – a surface

Returns:

the realized renderer

Return type:

Gsk.Renderer or None

Creates an appropriate GskRenderer instance for the given surface.

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.

get_surface()
Returns:

the surface

Return type:

Gdk.Surface or None

Retrieves the surface that the renderer is associated with.

If the renderer has not been realized yet, NULL will be returned.

is_realized()
Returns:

true if the renderer was realized, false otherwise

Return type:

bool

Checks whether the renderer is realized or not.

realize(surface)
Parameters:

surface (Gdk.Surface or None) – the surface that renderer will be used on

Raises:

GLib.Error

Returns:

whether the renderer was successfully realized

Return type:

bool

Creates the resources needed by the 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] for this case.

Note that it is mandatory to call [method`Gsk`.Renderer.unrealize] before destroying the renderer.

realize_for_display(display)
Parameters:

display (Gdk.Display) – the display that the renderer will be used on

Raises:

GLib.Error

Returns:

whether the renderer was successfully realized

Return type:

bool

Creates the resources needed by the renderer.

Note that it is mandatory to call [method`Gsk`.Renderer.unrealize] before destroying the renderer.

New in version 4.14.

render(root, region)
Parameters:
  • root (Gsk.RenderNode) – the render node to render

  • region (cairo.Region or None) – the cairo_region_t that must be redrawn or NULL for the whole surface

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.

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.

The renderer will acquire a reference on the GskRenderNode tree while the rendering is in progress.

render_texture(root, viewport)
Parameters:
Returns:

a texture with the rendered contents of root

Return type:

Gdk.Texture

Renders a scene graph, described by a tree of GskRenderNode instances, to a texture.

The renderer will acquire a reference on the GskRenderNode tree while the rendering is in progress.

If you want to apply any transformations to root, you should put it into a transform node and pass that node instead.

unrealize()

Releases all the resources created by [method`Gsk`.Renderer.realize].

Property Details

Gsk.Renderer.props.realized
Name:

realized

Type:

bool

Default Value:

False

Flags:

READABLE, EXPLICIT_NOTIFY

Whether the renderer has been associated with a surface or draw context.

Gsk.Renderer.props.surface
Name:

surface

Type:

Gdk.Surface

Default Value:

None

Flags:

READABLE, EXPLICIT_NOTIFY

The surface associated with renderer.