Class FlutterRenderer
- All Implemented Interfaces:
TextureRegistry
FlutterEngine.
FlutterRenderer works in tandem with a provided RenderSurface to paint Flutter
pixels to an Android View hierarchy.
FlutterRenderer manages textures for rendering, and forwards some Java calls to native
Flutter code via JNI. The corresponding RenderSurface provides the Android Surface that this renderer paints.
FlutterSurfaceView and FlutterTextureView are implementations of RenderSurface.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDescription of a physical feature on the display.static enumState of the display feature.static enumTypes of display features that can appear on the viewport.static final classMutable data structure that holds all viewport metrics properties that Flutter cares about.Nested classes/interfaces inherited from interface io.flutter.view.TextureRegistry
TextureRegistry.GLTextureConsumer, TextureRegistry.ImageConsumer, TextureRegistry.ImageTextureEntry, TextureRegistry.OnFrameConsumedListener, TextureRegistry.OnTrimMemoryListener, TextureRegistry.SurfaceLifecycle, TextureRegistry.SurfaceProducer, TextureRegistry.SurfaceTextureEntry, TextureRegistry.TextureEntry -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanWhether to disable clearing of the Surface used to render platform views.static booleanWhether to always use GL textures forTextureRegistry.createSurfaceProducer(). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a listener that is invoked whenever thisFlutterRendererstarts and stops painting pixels to an AndroidViewhierarchy.Creates and registers a texture managed by the Flutter engine.Creates and returns a new external textureTextureRegistry.SurfaceProducermanaged by the Flutter engine that is also made available to Flutter code.Creates and returns a newSurfaceTexturemanaged by the Flutter engine that is also made available to Flutter code.voiddispatchPointerDataPacket(ByteBuffer buffer, int position) voiddispatchSemanticsAction(int nodeId, int action, ByteBuffer args, int argsPosition) booleanReturns true if thisFlutterRendereris painting pixels to an AndroidViewhierarchy, false otherwise.booleanvoidonTrimMemory(int level) Callback invoked when memory is low.registerSurfaceTexture(SurfaceTexture surfaceTexture) Registers and returns aSurfaceTexturemanaged by the Flutter engine that is also made available to Flutter code.voidRemoves a listener added viaaddIsDisplayingFlutterUiListener(FlutterUiDisplayListener).voidRestoresImageReaderSurfaceProducers that were previously notified to be destroyed due to a call toonTrimMemoryas part of anonResumeapp lifecycle event.voidsetAccessibilityFeatures(int flags) voidsetSemanticsEnabled(boolean enabled) voidsetViewportMetrics(FlutterRenderer.ViewportMetrics viewportMetrics) Notifies Flutter that the viewport metrics, e.g.voidstartRenderingToSurface(Surface surface, boolean onlySwap) Notifies Flutter that the givensurfacewas created and is available for Flutter rendering.voidNotifies Flutter that asurfacepreviously registered withstartRenderingToSurface(Surface, boolean)has been destroyed and needs to be released and cleaned up on the Flutter side.voidsurfaceChanged(int width, int height) Notifies Flutter that asurfacepreviously registered withstartRenderingToSurface(Surface, boolean)has changed size to the givenwidthandheight.voidswapSurface(Surface surface) Swaps theSurfaceused to render the current frame.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.flutter.view.TextureRegistry
createSurfaceProducer
-
Field Details
-
debugForceSurfaceProducerGlTextures
@VisibleForTesting public static boolean debugForceSurfaceProducerGlTexturesWhether to always use GL textures forTextureRegistry.createSurfaceProducer().This is a debug-only API intended for local development. For example, when using a newer Android device (that normally would use
FlutterRenderer.ImageReaderSurfaceProducer, but wanting to test the OpenGLES/SurfaceTextureSurfaceProducercode branch. This flag has undefined behavior if set to true while running in a Vulkan (Impeller) context. -
debugDisableSurfaceClear
@VisibleForTesting public static boolean debugDisableSurfaceClearWhether to disable clearing of the Surface used to render platform views.
-
-
Constructor Details
-
FlutterRenderer
-
-
Method Details
-
restoreSurfaceProducers
public void restoreSurfaceProducers()RestoresImageReaderSurfaceProducers that were previously notified to be destroyed due to a call toonTrimMemoryas part of anonResumeapp lifecycle event.All
FlutterActivitys andFlutterFragments are expected to call thisonResumeto ensure surface producers are restored when the app returns to the foreground. -
isDisplayingFlutterUi
public boolean isDisplayingFlutterUi()Returns true if thisFlutterRendereris painting pixels to an AndroidViewhierarchy, false otherwise. -
addIsDisplayingFlutterUiListener
Adds a listener that is invoked whenever thisFlutterRendererstarts and stops painting pixels to an AndroidViewhierarchy. -
removeIsDisplayingFlutterUiListener
Removes a listener added viaaddIsDisplayingFlutterUiListener(FlutterUiDisplayListener). -
createSurfaceProducer
@NonNull public TextureRegistry.SurfaceProducer createSurfaceProducer(TextureRegistry.SurfaceLifecycle lifecycle) Creates and returns a new external textureTextureRegistry.SurfaceProducermanaged by the Flutter engine that is also made available to Flutter code.- Specified by:
createSurfaceProducerin interfaceTextureRegistry- Parameters:
lifecycle- Whether to automatically reset the last image and release the surface.- Returns:
- A SurfaceProducer.
-
createSurfaceTexture
Creates and returns a newSurfaceTexturemanaged by the Flutter engine that is also made available to Flutter code.- Specified by:
createSurfaceTexturein interfaceTextureRegistry- Returns:
- A SurfaceTextureEntry.
-
registerSurfaceTexture
@NonNull public TextureRegistry.SurfaceTextureEntry registerSurfaceTexture(@NonNull SurfaceTexture surfaceTexture) Registers and returns aSurfaceTexturemanaged by the Flutter engine that is also made available to Flutter code.- Specified by:
registerSurfaceTexturein interfaceTextureRegistry- Returns:
- A SurfaceTextureEntry.
-
createImageTexture
Description copied from interface:TextureRegistryCreates and registers a texture managed by the Flutter engine.- Specified by:
createImageTexturein interfaceTextureRegistry- Returns:
- a ImageTextureEntry.
-
onTrimMemory
public void onTrimMemory(int level) Description copied from interface:TextureRegistryCallback invoked when memory is low.Invoke this from
Activity.onTrimMemory(int).- Specified by:
onTrimMemoryin interfaceTextureRegistry
-
startRenderingToSurface
Notifies Flutter that the givensurfacewas created and is available for Flutter rendering.If called more than once, the current native resources are released. This can be undesired if the Engine expects to reuse this surface later. For example, this is true when platform views are displayed in a frame, and then removed in the next frame.
To avoid releasing the current surface resources, set
keepCurrentSurfaceto true.See
SurfaceHolder.CallbackandTextureView.SurfaceTextureListener- Parameters:
surface- The render surface.onlySwap- True if the current active surface should not be detached.
-
swapSurface
Swaps theSurfaceused to render the current frame.In hybrid composition, the root surfaces changes from
SurfaceHolder.getSurface()toImageReader.getSurface()when a platform view is in the current frame. -
surfaceChanged
public void surfaceChanged(int width, int height) Notifies Flutter that asurfacepreviously registered withstartRenderingToSurface(Surface, boolean)has changed size to the givenwidthandheight.See
SurfaceHolder.CallbackandTextureView.SurfaceTextureListener -
stopRenderingToSurface
public void stopRenderingToSurface()Notifies Flutter that asurfacepreviously registered withstartRenderingToSurface(Surface, boolean)has been destroyed and needs to be released and cleaned up on the Flutter side.See
SurfaceHolder.CallbackandTextureView.SurfaceTextureListener -
setViewportMetrics
Notifies Flutter that the viewport metrics, e.g. window height and width, have changed.If the width, height, or devicePixelRatio are less than or equal to 0, this update is ignored.
- Parameters:
viewportMetrics- The metrics to send to the Dart application.
-
getBitmap
-
dispatchPointerDataPacket
-
isSoftwareRenderingEnabled
public boolean isSoftwareRenderingEnabled() -
setAccessibilityFeatures
public void setAccessibilityFeatures(int flags) -
setSemanticsEnabled
public void setSemanticsEnabled(boolean enabled) -
dispatchSemanticsAction
public void dispatchSemanticsAction(int nodeId, int action, @Nullable ByteBuffer args, int argsPosition)
-