GraphicsOffload#

Added in version 4.14.

class GraphicsOffload(**properties: Any)#

Superclasses: Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, ConstraintTarget

A widget that allows to bypass gsk rendering for its child by passing the content directly to the compositor.

Graphics offload is an optimization to reduce overhead and battery use that is most useful for video content. It only works on some platforms and in certain situations. GTK will automatically fall back to normal rendering if it doesn’t.

Graphics offload is most efficient if there are no controls drawn on top of the video content.

You should consider using graphics offload for your main widget if it shows frequently changing content (such as a video, or a VM display) and you provide the content in the form of dmabuf textures (see DmabufTextureBuilder), in particular if it may be fullscreen.

Numerous factors can prohibit graphics offload:

  • Unsupported platforms. Currently, graphics offload only works on Linux with Wayland.

  • Clipping, such as rounded corners that cause the video content to not be rectangular

  • Unsupported dmabuf formats (see get_dmabuf_formats)

  • Translucent video content (content with an alpha channel, even if it isn’t used)

  • Transforms that are more complex than translations and scales

  • Filters such as opacity, grayscale or similar

To investigate problems related graphics offload, GTK offers debug flags to print out information about graphics offload and dmabuf use:

GDK_DEBUG=offload GDK_DEBUG=dmabuf

The GTK inspector provides a visual debugging tool for graphics offload.

Constructors#

class GraphicsOffload
classmethod new(child: Widget | None = None) Widget#

Creates a new GtkGraphicsOffload widget.

Added in version 4.14.

Parameters:

child – the child widget

Methods#

class GraphicsOffload
get_black_background() bool#

Returns whether the widget draws a black background.

See set_black_background.

Added in version 4.16.

get_child() Widget | None#

Gets the child of self.

Added in version 4.14.

get_enabled() GraphicsOffloadEnabled#

Returns whether offload is enabled for self.

Added in version 4.14.

set_black_background(value: bool) None#

Sets whether this GtkGraphicsOffload widget will draw a black background.

A main use case for this is *letterboxing* where black bars are visible next to the content if the aspect ratio of the content does not match the dimensions of the monitor.

Using this property for letterboxing instead of CSS allows compositors to show content with maximum efficiency, using direct scanout to avoid extra copies in the compositor.

On Wayland, this is implemented using the single-pixel buffer protocol.

Added in version 4.16.

Parameters:

value – whether to draw a black background behind the content

set_child(child: Widget | None = None) None#

Sets the child of self.

Added in version 4.14.

Parameters:

child – the child widget

set_enabled(enabled: GraphicsOffloadEnabled) None#

Sets whether this GtkGraphicsOffload widget will attempt to offload the content of its child widget.

Added in version 4.14.

Parameters:

enabled – whether to enable offload

Properties#

class GraphicsOffload
props.black_background: bool#

The type of the None singleton.

Added in version 4.16.

props.child: Widget#

The type of the None singleton.

Added in version 4.14.

props.enabled: GraphicsOffloadEnabled#

The type of the None singleton.

Added in version 4.14.