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_idanswersPENDING_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
impl RenderWorker
Sourcepub fn start(
timer: Option<Arc<BrowserRenderTimer>>,
on_thread: Option<Box<dyn FnOnce() + Send>>,
) -> Result<bool>
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.
Sourcepub fn exists() -> bool
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.
Sourcepub fn thread_id() -> usize
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.
Sourcepub fn canvas_thread_id() -> i32
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.
Sourcepub fn post(work: impl FnOnce() + Send + 'static) -> bool
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.
Sourcepub fn on_render_target_registered(target_id: i32, kind: i32)
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.
Sourcepub fn page_thread() -> usize
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§
impl Freeze for RenderWorker
impl RefUnwindSafe for RenderWorker
impl Send for RenderWorker
impl Sync for RenderWorker
impl Unpin for RenderWorker
impl UnsafeUnpin for RenderWorker
impl UnwindSafe for RenderWorker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more