Android: migrate external texture to SurfaceProducer (fix transparency under Impeller)#173
Open
frenradar wants to merge 1 commit into
Open
Android: migrate external texture to SurfaceProducer (fix transparency under Impeller)#173frenradar wants to merge 1 commit into
frenradar wants to merge 1 commit into
Conversation
…t transparency) The legacy TextureRegistry.createSurfaceTexture() external-texture path composites transparent Filament output with broken premultiplied alpha under Impeller (default on Android since Flutter 3.22), so a transparent background reads as a grey veil over bright content composited beneath it. iOS/Metal is unaffected. Migrate to the modern createSurfaceProducer() API (TextureRegistry.SurfaceProducer: setSize/getSurface/id/release), which composites premultiplied alpha correctly with Impeller on. FREN fork patch for GH#61 (3D nav puck). Minimal change; the SurfaceProducer.Callback (surface recreate on background) is a follow-up.
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.
Problem
On Android, the plugin creates the Filament external texture via the legacy
TextureRegistry.createSurfaceTexture(). Under Impeller (now the defaultAndroid renderer), that legacy
SurfaceTextureexternal-texture path compositesa transparent Filament view (
View.BlendMode.TRANSLUCENTover aCONFIG_TRANSPARENTswapchain, whichcreateViewalready sets up) withincorrect premultiplied alpha — so the transparent regions of the render read as
a grey/dark veil over whatever is composited beneath the
Texturewidget.iOS/Metal is unaffected.
Minimal repro: a
ViewerWidgetwithbackground: Color(0x00000000)layered overother content. The transparent area veils grey on Android with Impeller on;
correct with Impeller off (confirms it's the external-texture composite path,
not the Filament view config).
Fix
Migrate the Android texture from
createSurfaceTexture()to the modernTextureRegistry.createSurfaceProducer()(setSize/getSurface/id/release), which composites premultiplied alpha correctly with Impeller on. Thenative-window handoff (
getNativeWindowFromSurface) and everything else areunchanged; this is Android-only.
Compatibility
SurfaceProducerlanded in Flutter 3.22.thermion_flutter's min Flutter is>=3.23.0-0.1.pre, socreateSurfaceProducer()is always available in thesupported range — no version guard needed.
Testing
Device-verified on a Samsung Galaxy A15 (Android 14) rendering a transparent
Filament model over a map basemap: the grey veil is gone with Impeller on and the
model renders correctly; survives a brief app background/resume.
Follow-up (not in this PR)
A
SurfaceProducer.Callback(onSurfaceAvailable/onSurfaceCleanup) torecreate the swapchain when Android destroys/recreates the surface under memory
pressure or long backgrounding. The common case (brief background) survives
without it in my testing; the callback would harden the worst case. Happy to add
it here or in a follow-up — let me know your preference.