pub struct WebGpuChartBackend { /* private fields */ }Expand description
The WebGPU rendering backend for the chart.
This is the backend the chart prefers: vector geometry is tessellated into triangles once, uploaded to the GPU once, and replayed with a handful of draw calls. The display list is retained between frames, so a chart that has not changed does not re-tessellate and does not re-upload anything — the backend keeps the GPU buffers alive and reuses them as long as the list is unchanged.
The backend is created asynchronously, because acquiring a GPU adapter
and a GPU device returns JavaScript promises. When the host cannot
provide WebGPU, WebGpuChartBackend::create returns None and the
factory falls back to WebGL2 and then to Canvas2D.
Implementations§
Source§impl WebGpuChartBackend
Inherent implementation of WebGpuChartBackend.
impl WebGpuChartBackend
Inherent implementation of WebGpuChartBackend.
Sourcepub fn is_supported() -> bool
pub fn is_supported() -> bool
Returns true when the host browser exposes WebGPU.
The check is synchronous and cheap: it only looks for
navigator.gpu. It says nothing about whether an adapter can
actually be acquired — headless browsers, GPU-blacklisted devices,
and sandboxed frames all expose the entry point while failing to
hand out a device. For the definitive answer, create the backend:
WebGpuChartBackend::create asks for an adapter and a device for
real, and returns None when either fails.
§Returns
bool- A boolean.
Sourcepub async fn create(canvas: &HtmlCanvasElement) -> Option<Self>
pub async fn create(canvas: &HtmlCanvasElement) -> Option<Self>
Creates a backend around the given canvas.
The whole acquisition is asynchronous: requestAdapter and
requestDevice return JavaScript promises. Every failure mode —
no navigator.gpu, no adapter, no device, a canvas that already
has a context of another kind — returns None, so the backend
factory can fall back to WebGL2 and then to Canvas2D.
The GPU buffers are not allocated here. They are created on the first render, once the size of the glyph atlas is known, and then kept until the display list changes.
§Arguments
&HtmlCanvasElement- The&HtmlCanvasElementvalue.
§Returns
Option<Self>- TheOption<Self>value.
Sourcepub fn canvas(&self) -> &HtmlCanvasElement
pub fn canvas(&self) -> &HtmlCanvasElement
Sourcepub fn batch_count(&self) -> usize
pub fn batch_count(&self) -> usize
Returns the number of draw calls the last frame used.
One batch is one draw call, so this is the number the chart pays per frame. A chart that has not changed keeps the same number.
§Returns
usize- A non-negative integer.
Sourcepub fn invalidate(&mut self)
pub fn invalidate(&mut self)
Forces the backend to rebuild its geometry on the next render.
The backend notices a changed display list on its own, by fingerprinting it. This is for the cases the fingerprint cannot see — a web font that finished loading, for instance, changes the metrics of the text without changing the display list.
Trait Implementations§
Source§impl ChartBackend for WebGpuChartBackend
Implements ChartBackend for WebGpuChartBackend.
impl ChartBackend for WebGpuChartBackend
Implements ChartBackend for WebGpuChartBackend.
Source§fn kind(&self) -> BackendKind
fn kind(&self) -> BackendKind
Source§fn render(&mut self, list: &DisplayList, shaper: &mut TextShaper)
fn render(&mut self, list: &DisplayList, shaper: &mut TextShaper)
Implements the render operation on WebGpuChartBackend.
§Arguments
&DisplayList- Shared reference to aDisplayList.&mut TextShaper- Mutable reference to aTextShaper(mutated in place).
Source§fn dispose(&mut self)
fn dispose(&mut self)
Implements the dispose operation on WebGpuChartBackend.
Source§impl Drop for WebGpuChartBackend
Implements Drop for WebGpuChartBackend.
impl Drop for WebGpuChartBackend
Implements Drop for WebGpuChartBackend.