Class Renderer

All Implemented Interfaces:
PointerInterface
Direct Known Subclasses:
BroadwayRenderer, CairoRenderer, GLRenderer, NglRenderer

public class Renderer extends Object
`GskRenderer` is a class that 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.

https://docs.gtk.org/gsk4/class.Renderer.html

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newForSurfaceRenderer

      public static Renderer newForSurfaceRenderer(@Nonnull Surface surface)
      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.
      Parameters:
      surface - a `GdkSurface`
      Returns:
      a `GskRenderer`
    • getSurface

      public Surface getSurface()
      Retrieves the `GdkSurface` set using gsk_enderer_realize().

      If the renderer has not been realized yet, %NULL will be returned.
      Returns:
      a `GdkSurface`
    • isRealized

      public boolean isRealized()
      Checks whether the @renderer is realized or not.
      Returns:
      %TRUE if the `GskRenderer` was realized, and %FALSE otherwise
    • realize

      public boolean realize(@Nullable Surface surface) throws AllocationError
      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.

      Note that it is mandatory to call [method@Gsk.Renderer.unrealize] before
      destroying the renderer.
      Parameters:
      surface - the `GdkSurface` renderer will be used on
      Returns:
      Whether the renderer was successfully realized
      Throws:
      AllocationError
    • render

      public void render(@Nonnull RenderNode root, @Nullable Region region)
      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.
      Parameters:
      root - a `GskRenderNode`
      region - the `cairo_region_t` that must be redrawn or %NULL for the whole window
    • renderTexture

      public Texture renderTexture(@Nonnull RenderNode root, @Nullable Rect viewport)
      Renders the scene graph, described by a tree of `GskRenderNode` instances,
      to a `GdkTexture`.

      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.
      Parameters:
      root - a `GskRenderNode`
      viewport - the section to draw or %NULL to use @root's bounds
      Returns:
      a `GdkTexture` with the rendered contents of @root.
    • unrealize

      public void unrealize()
      Releases all the resources created by gsk_renderer_realize().
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()