Skip to main content

RenderWorker

Struct RenderWorker 

Source
pub struct RenderWorker;
Expand description

The render thread of the page: a thread of the module whose worker takes the canvases of the views and draws to them.

Upstream starts a worker of its runtime, waits for it and only then goes on with the start of the application. A start function of this port cannot wait (the thread of the page may not block on a thread that needs the page to start), so start returns at once and the thread reports itself when it runs:

  • the thread installs the handler of the registry of its script (initialize_worker), follows the reports of that registry (on_render_target_registered), keeps itself alive past the return of its start function, starts the frame loop it was given, and publishes its id;
  • a canvas that is created before that (canvas_thread_id answers PENDING_RENDER_THREAD) is transferred by the script at once and posted to the worker when the thread of the page hears of the thread; its surface is simply not ready until the worker has reported the target.

There is one render thread for the life of the page; it never ends.

A panic of the thread does not end it either. A frame that panics is caught by the render loop (DefaultRenderLoop, as upstream’s loop catches the exception of a frame and logs it), and the loop goes on with its next tick. The panic is reported to the thread of the page, which logs it on the console of the page (on_panic): what the thread itself logs stays in its worker.

The platform starts it when it is registered, for the frame loop of the page (BrowserSharedRenderLoop::start_render_thread). A module built without threads cannot start it at all.

Implementations§

Source§

impl RenderWorker

Source

pub fn start( timer: Option<Arc<BrowserRenderTimer>>, on_thread: Option<Box<dyn FnOnce() + Send>>, ) -> Result<bool>

Starts the render thread and returns at once; Ok(false) when it was started before. Called by the thread that creates the canvases (the thread of the page).

timer is the render timer whose frame loop the thread runs: it is started on the thread (BrowserRenderTimer::start_on_this_thread). on_thread runs on the thread before that, when its worker already takes canvases; a caller subscribes there to what arrives on that thread.

§Errors

An error when the thread could not be created; in a module built without threads always.

Source

pub fn exists() -> bool

Whether a render thread exists: it was started, though it may not have reported itself yet. Upstream’s condition for where the frame loop runs (IsThreadingEnabled) is a property of the build; here it is whether the thread was started, so that a module built with threads can still run on one.

Source

pub fn thread_id() -> usize

The id of the render thread, as thread_proxy::current_thread names it there (what pthread_self returns); 0 until the thread has reported itself, and always without one.

Source

pub fn canvas_thread_id() -> i32

The thread a canvas is created for (create_render_target_surface): 0 without a render thread, the id of the render thread once it has reported itself, and PENDING_RENDER_THREAD in between. Called by the thread that creates the canvases.

Source

pub fn post(work: impl FnOnce() + Send + 'static) -> bool

Queues work for the render thread, which runs it from the event loop of its worker. Returns whether it was queued: false while the thread has not reported itself, and without one.

Source

pub fn on_render_target_registered(target_id: i32, kind: i32)

The worker of the calling thread created the render target target_id of a canvas that was transferred to it, and the target is of kind: publishes the kind in the canvas registered under the id (BrowserSurfaceShared::report_target), from where both threads read that the surface is ready. The render thread subscribes this to the reports of its registry (add_render_target_registered).

The render loop is not asked for a frame: its timer ticks with every animation frame of the worker, and a composition target without a render target asks its surface again on each.

Source

pub fn page_thread() -> usize

The thread that started the render thread and creates the canvases, as thread_proxy::current_thread names it there; 0 without a render thread.

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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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