Skip to main content

WebGl2ChartBackend

Struct WebGl2ChartBackend 

Source
pub struct WebGl2ChartBackend { /* private fields */ }
Expand description

The WebGL2 rendering backend for the chart.

This is the GPU fallback for browsers that do not expose WebGPU. It replays the same display list as the WebGPU backend and the Canvas2D backend, so the picture it produces is the same; only the plumbing differs.

§Performance

The display list is retained between frames, and the backend takes advantage of that in two ways.

The first is caching: the backend fingerprints the display list and only re-tessellates and re-uploads when the fingerprint changes. An unchanged chart therefore costs no vertex work at all — the GPU buffers are simply drawn again.

The second is batching: every shape in the display list ends up in one vertex buffer, in paint order, and is drawn with a handful of draw calls. A steady-state frame of an ordinary chart issues two or three draw calls, and none of them crosses the JavaScript boundary more than a handful of times, because the vertex data is uploaded in one go rather than one vertex at a time.

Implementations§

Source§

impl WebGl2ChartBackend

Inherent implementation of WebGl2ChartBackend.

Source

pub fn is_supported() -> bool

Returns true when the host can give out a WebGL2 context.

The check opens a throw-away canvas and asks it for a context, so it costs one context creation. It is cheap enough to run while the backend is being picked, and it never throws.

§Returns
  • bool - A boolean.
Source

pub fn create(canvas: &HtmlCanvasElement) -> Option<Self>

Creates a backend around the given canvas.

Returns None when the canvas cannot give out a WebGL2 context — in practice, when the canvas already has a WebGPU context, or when the browser has no WebGL2 at all — and when the shaders cannot be built. The factory then falls back to the Canvas2D backend.

§Arguments
  • &HtmlCanvasElement - Shared reference to a HtmlCanvasElement.
§Returns
  • Option<Self> - Some(...) on success, None otherwise.
Source

pub fn canvas(&self) -> &HtmlCanvasElement

Returns the canvas the backend draws into.

§Returns
  • &HtmlCanvasElement - A HtmlCanvasElement value.
Source

pub fn draw_call_count(&self) -> usize

Returns the number of draw calls the last frame used.

The number is a debugging aid: it is the number of batches the last frame was split into, which is what a chart with no images and no clip paths reports as one.

§Returns
  • usize - A non-negative integer.

Trait Implementations§

Source§

impl ChartBackend for WebGl2ChartBackend

Source§

fn kind(&self) -> BackendKind

Implements the kind operation on WebGl2ChartBackend.

§Returns
  • BackendKind - A BackendKind value.
Source§

fn resize(&mut self, width: f64, height: f64, dpr: f64)

Implements the resize operation on WebGl2ChartBackend.

§Arguments
  • f64 - A 64-bit float (f64).
Source§

fn render(&mut self, list: &DisplayList, shaper: &mut TextShaper)

Implements the render operation on WebGl2ChartBackend.

§Arguments
  • &DisplayList - Shared reference to a DisplayList.
  • &mut TextShaper - Mutable reference to a TextShaper (mutated in place).
Source§

fn dispose(&mut self)

Implements the dispose operation on WebGl2ChartBackend.

Source§

impl Drop for WebGl2ChartBackend

Implements Drop for WebGl2ChartBackend.

Source§

fn drop(&mut self)

Releases the GPU resources when the backend is dropped.

A chart that is dropped without being disposed would hold on to its buffers until the browser collects them, and a chart over a million points holds on to a lot of memory.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more