Question about materializing active saveLayer() results into reusable textures/images

39 views
Skip to first unread message

Leoardo Lubary

unread,
May 12, 2026, 9:44:28 AMMay 12
to skia-discuss
Hi Skia team,

I am working on a 2D layer/effects engine on top of Skia, and I have run into a problem involving nested saveLayer() usage, backdrop-dependent effects, and group masking.

What I need conceptually is the ability to materialize the current result of an active saveLayer() into a stable image/texture that can be sampled by later rendering steps, while still remaining inside nested saveLayer() scopes.

In other words, I am looking for something like an “active layer snapshot” with the following properties:

- it captures the current result of a saveLayer()
- it can be sampled by later rendering passes
- it remains valid even if that same layer continues to receive more draws afterwards
- ideally it can refer to the current layer, or possibly an ancestor active layer

The motivation is supporting design-tool-style effects such as:

- group opacity masks
- backdrop blur / background-dependent filters
- non-SrcOver blending inside masked groups
- arbitrarily nested layer/effect trees

A simplified form of the composition I need is:

A = parent/backdrop content  
B = rendered group content  
C = mask result, where the mask itself may depend on A

Final result:

final = C * B + (1 - C) * A

The difficult case is when the mask itself depends on the backdrop, for example because it contains backdrop blur or other effects that require previous content.

I found that some public API approaches are not sufficient:

- Converting an SkPicture to an SkShader / clipShader() only works when the mask is self-contained. If the picture depends on the outer canvas content, that information is lost.
- Re-implementing the whole thing externally with multiple SkSurfaces is possible, but becomes very heavy in practice in terms of clip stack handling, coordinate alignment, nested saveLayer semantics, caching, invalidation, and performance.

So my questions are:

1. Is there any existing public or internal mechanism in Skia for safely snapshotting/materializing the result of an active saveLayer() while still inside nested layer scopes?
2. Is there any recommended way to model this kind of dependency in Skia when effects need access to backdrop content from ancestor layers?
3. Would extending saveLayer()/SkCanvas with some form of internal layer materialization be a reasonable direction, or would that go against Skia’s intended architecture?
4. Is this something Graphite may model better than Ganesh, or is the limitation fundamentally the same at the SkCanvas API level?

Any guidance would be greatly appreciated.
Reply all
Reply to author
Forward
0 new messages