feat(layers): rasterize layers outside a live editor session - #853
Merged
Conversation
Add `LayerRasterizer` and `LayerRasterizerHost`. `Layer.captureAsPng` returns `null` for an unmounted layer, so layers restored from an exported state history could not be baked into a render. The host mounts them behind its own child - painted, never visible - so `capture()` returns the same `ExportedLayer`s a live session would. Layers whose content loads asynchronously (network images, decoded assets, custom `WidgetLayer`s) are handled via `awaitContentReady`. Includes an example page that renders a persisted history without ever opening the editor.
Queued captures shared the host's `LayerWidget` element: the host never rebuilds with an empty request between two captures, and `LayerWidget` resolves its layer type only in `initState`. A follow-up capture of a different layer type therefore built the previous type and was dropped (`EmojiLayer is not a subtype of TextLayer`). Key the widgets by layer identity. Disposing the rasterizer mid-capture replaced a finished result with "used after being disposed", because `notifyListeners` throws once `dispose` ran. The host mounted layers without the `Theme` and `Material` the editor supplies, so layer content inherited MaterialApp's error text style and Material-based widget layers asserted. Both paths now share the editor's fallback theme. Also assert the one-host and not-mounted-elsewhere rules that duplicate layer GlobalKeys, throw instead of returning an empty list when the host stops rendering mid-capture, default `basePixelRatio` to `configs.imageGeneration.customPixelRatio`, keep captured layers out of the semantics tree, and document that `configs` must match the session that created the layers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
LayerRasterizerandLayerRasterizerHostso layers can be captured without a running editor.Layer.captureAsPngreturnsnullfor an unmounted layer, so layers restored from an exported state history could not be baked into a render — they deserialize fine, but they have never been laid out. The host mounts them behind its own child (painted, never visible) socapture()returns the sameExportedLayers a live session would.Concurrent
capturecalls are serialized so they cannot read each other's repaint boundaries, and layers whose content loads asynchronously (network images, decoded assets, customWidgetLayers) are held untilawaitContentReadyresolves.Example
New page under Layers → Rasterize Layers without Editor: parses a persisted state history, rasterizes its layers with no editor involved, and shows the result both composited over the background image and layer-by-layer on a transparency grid.
Testing
flutter test test/shared/services/layer_rasterizer/— 6 tests, all passingawaitContentReady)flutter analyzeclean for package and example