thorvg_python.canvas.wg

Classes

WgCanvas

WgCanvas API

Module Contents

class thorvg_python.canvas.wg.WgCanvas(engine: thorvg_python.engine.Engine, op: thorvg_python.base.EngineOption, canvas: thorvg_python.base.CanvasPointer | None = None)

Bases: thorvg_python.canvas.Canvas

WgCanvas API

A module for rendering the graphical elements using the webgpu engine.

Warning

The thorvg library bundled with precompiled wheel was not compiled with Wg support You will have to load your own thorvg library compiled with Wg support with Engine(thorvg_lib_path=”…”)

engine
thorvg_lib
_create(op: thorvg_python.base.EngineOption) thorvg_python.base.CanvasPointer

Creates a new WebGPU Canvas object with optional rendering engine settings.

This method generates a WebGPU canvas instance that can be used for drawing vector graphics. It accepts an optional parameter op to choose between different rendering engine behaviors.

Parameters:
op : thorvg_python.engine.EngineOption

The rendering engine option.

Returns:

A new CanvasPointer object.

Return type:

thorvg_python.base.CanvasPointer

Note

Currently, it does not support EngineOption.SMART_RENDER. The request will be ignored.

See also

EngineOption

Added in version 1.0.

set_target(device: Any, instance: Any, target: Any, _type: int, w: int, h: int, cs: thorvg_python.base.Colorspace = Colorspace.ABGR8888) tuple[thorvg_python.base.Result]

Sets the drawing target for the rasterization.

Parameters:
device : Any

WGPUDevice, a desired handle for the wgpu device. If it is None, ThorVG will assign an appropriate device internally.

instance : Any

WGPUInstance, context for all other wgpu objects.

target : Any

Either WGPUSurface or WGPUTexture, serving as handles to a presentable surface or texture.

_type : int

0: surface, 1: texture are used as pesentable target.

w : int

The width of the target.

h : int

The height of the target.

cs : int

Specifies how the pixel values should be interpreted. Currently, it only allows Colorspace.ABGR8888S as WGPUTextureFormat_RGBA8Unorm.

TVG_RESULT_INSUFFICIENT_CONDITION if the canvas is performing rendering. Please ensure the canvas is synced. TVG_RESULT_NOT_SUPPORTED In case the wg engine is not supported.

Added in version 1.0.