Skip to content
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

beginLayer vs beginFilter #32

Open
ianstormtaylor opened this issue Nov 30, 2022 · 2 comments
Open

beginLayer vs beginFilter #32

ianstormtaylor opened this issue Nov 30, 2022 · 2 comments

Comments

@ianstormtaylor
Copy link

I'm curious about why the naming uses "layers" as a concept with beginLayer/endLayer, instead of calling them simply beginFilter/endFilter if their sole purpose is to be able to apply filters to groups of commands. Because I excepted "layers" to be something else, more analogous to layers in a graphics editor that can be shown/hidden/reordered/etc.

@graveljp
Copy link
Collaborator

graveljp commented Dec 5, 2022

Layers are not only useful for filtering operations. They can also be used to apply blending to the result of a group of draw calls, or more generally apply composite operations to such group.

The canvas API is procedural, not declarative. It would be wasteful to have the JavaScript build a whole layer, just for it to be marked as hidden later. If a layer is to be hidden, it's better to simply not render it in the first place. Perhaps what you have in mind aligns with the Recorded Picture proposal (also called Display List). Display Lists would allow a group of draw calls to be replayed multiple times. Layers and Display Lists would be very different in terms of implementation, and in terms for their performance characteristics. We think that Layers and Display Lists provide solutions for two different problems and are both complementary. It would be a shame to impose the cost of building optimizing and caching display list if it's to be rasterized only once. We would rather have a high-performance code-path for single-use draw call group rasterizing, and another API focused on making draw calls rasterizable multiple times.

Does that make sense?

@ianstormtaylor
Copy link
Author

Hey @graveljp thanks for taking the time to write that up. That makes total sense on the reasoning for why it's designed the way it is. For actual layering I'd probably use multiple canvases stacked on top of each other.

I think my point is mostly about naming. Using the "layer" in the name is likely going to require every explanation of the concept to be prefaced by something like:

Note that the beginLayer / endLayer methods don't deal with layers in the traditional graphics editor sense, but are instead used to compose blending modes and filters.

(If you search "html canvas layers" you'll see lots of results all trying to solve the familiar problem of layering with canvas.)

So I'd suggest using a different naming scheme that avoids that confusion. Something like beginComposition, beginCompose, beginBlend, beginFilter, or some other name I'm not knowledgeable enough to know of.

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

No branches or pull requests

2 participants