Renderer#
Superclasses: Object
Subclasses: BroadwayRenderer
, CairoRenderer
, GLRenderer
, NglRenderer
, VulkanRenderer
GskRenderer
is a class that renders a scene graph defined via a
tree of RenderNode
instances.
Typically you will use a GskRenderer
instance to repeatedly call
render
to update the contents of its associated
Surface
.
It is necessary to realize a GskRenderer
instance using
realize
before calling render
,
in order to create the appropriate windowing system resources needed
to render the scene.
Constructors#
- class Renderer
- classmethod new_for_surface(surface: Surface) Renderer | None #
Creates an appropriate
GskRenderer
instance for the givensurface
.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.
- Parameters:
surface – a
GdkSurface
Methods#
- class Renderer
- get_surface() Surface | None #
Retrieves the
GdkSurface
set using gsk_enderer_realize().If the renderer has not been realized yet,
None
will be returned.
- realize(surface: Surface | None = None) bool #
Creates the resources needed by the
renderer
to render the scene graph.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 userealize_for_display
instead.Note that it is mandatory to call
unrealize
before destroying the renderer.- Parameters:
surface – the
GdkSurface
renderer will be used on
- realize_for_display(display: Display) bool #
Creates the resources needed by the
renderer
to render the scene graph.Note that it is mandatory to call
unrealize
before destroying the renderer.Added in version 4.14.
- Parameters:
display – the
GdkDisplay
renderer will be used on
- render(root: RenderNode, region: Region | None = None) None #
Renders the scene graph, described by a tree of
GskRenderNode
instances to the renderer’s surface, ensuring that the givenregion
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 byregion
are redrawn. They are however free to not redraw any pixel outside ofregion
if they can guarantee that it didn’t change.The
renderer
will acquire a reference on theGskRenderNode
tree while the rendering is in progress.- Parameters:
root – a
GskRenderNode
region – the
cairo_region_t
that must be redrawn orNone
for the whole window
- render_texture(root: RenderNode, viewport: Rect | None = None) Texture #
Renders the scene graph, described by a tree of
GskRenderNode
instances, to aGdkTexture
.The
renderer
will acquire a reference on theGskRenderNode
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.- Parameters:
root – a
GskRenderNode
viewport – the section to draw or
None
to useroot
's bounds