Skip to content

Write document about canvas (contexts) #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

sagudev
Copy link
Member

@sagudev sagudev commented Apr 20, 2025

No description provided.

@sagudev sagudev force-pushed the canvas-ctx branch 2 times, most recently from a4a1e01 to b6d695b Compare June 24, 2025 15:48
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
@sagudev
Copy link
Member Author

sagudev commented Jun 24, 2025

I think it's enough baking for first round.

@sagudev sagudev marked this pull request as ready for review June 24, 2025 17:45
@sagudev sagudev requested review from delan, jdm and mrobinson as code owners June 24, 2025 17:45
@delan
Copy link
Member

delan commented Jun 25, 2025

Reviewing now :)

@delan
Copy link
Member

delan commented Jun 25, 2025

Thanks for writing this new chapter, it’s very useful!

For new content I think it makes sense to edit and polish before landing, so I’ve done some copyediting. Let me know if I’ve made any mistakes, since script and canvas are not my areas of expertise.

sagudev and others added 2 commits June 25, 2025 06:59
Co-authored-by: shuppy <delan@azabani.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
sagudev and others added 3 commits June 25, 2025 07:12
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Comment on lines 52 to 59
As part of HTML event loop, script thread runs a task (parsing, script evaluating, callbacks, events, ...) and after that it [performs a microtask checkpoint](https://html.spec.whatwg.org/multipage/#perform-a-microtask-checkpoint) that drains microtasks queue.
In [window event loop](https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-processing-model:window-event-loop-3) we queue a global task to [updates the rendering](https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering) if there is an [rendering opportunity](https://html.spec.whatwg.org/multipage/webappapis.html#rendering-opportunity) (usually driven by compositor based on hardware refresh rate).
In servo we do not actually queue a task, but instead we [run updates the rendering on any IPC messages in the ScriptThread](https://github.com/servo/servo/blob/d970584332a3761009f672f975bfffa917513b85/components/script/script_thread.rs#L1418) and [then perform a microtask checkpoint to as event loop would done after a task is completed](https://github.com/servo/servo/blob/d970584332a3761009f672f975bfffa917513b85/components/script/script_thread.rs#L1371).
[Updates the rendering](https://github.com/servo/servo/blob/d970584332a3761009f672f975bfffa917513b85/components/script/script_thread.rs#L1201) does various resize, scroll and animations steps (which also includes performing a microtask checkpoint; to resolve promises) and then [run the animation frame callbacks](https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#run-the-animation-frame-callbacks) (callbacks added with [`requestAnimationFrame`](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame)).
Here draw commands are issued to painters to create new frame of animation.
Then we update the rendering of those that do not require a reflow (animated images and WebGPU).
Finally we triggers reflow (layout), which takes the DOM and its styles, builds a `DisplayList`, and sends that to WebRender for rendering.
Dirty WebGL and 2D canvases are flushed as part of a reflow.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gterzian could you check if my understanding is correct.

Also driving force of rendering opportunities is not just compositor (via any script msg), but also script itself, at least for now.

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
@sagudev sagudev force-pushed the canvas-ctx branch 2 times, most recently from 807ba53 to dc25c23 Compare June 27, 2025 09:51
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants