WgpuCanvasInterface

class wgpu.gui.WgpuCanvasInterface(*args, **kwargs)

Bases: object

The minimal interface to be a valid canvas.

Any object that implements these methods is a canvas that wgpu can work with. The object does not even have to derive from this class.

In most cases it’s more convenient to subclass WgpuCanvasBase.

get_context(kind='webgpu')

Get the GPUCanvasContext object corresponding to this canvas.

The context is used to obtain a texture to render to, and to present that texture to the canvas. This class provides a default implementation to get the appropriate context.

The kind argument is a remnant from the WebGPU spec and must always be “webgpu”.

get_physical_size()

Get the physical size of the canvas in integer pixels.

get_surface_info()

Get information about the native window / surface.

This is used to obtain a surface id, so that wgpu can render to the region of the screen occupied by the canvas. Should return None for offscreen canvases. Otherwise, this should return a dict with a “window” field. On Linux the dict should contain more fields, see the existing implementations for reference.