Package io.flutter.embedding.engine.renderer

# Class FlutterRenderer

java.lang.Object
io.flutter.embedding.engine.renderer.FlutterRenderer

All Implemented Interfaces:
  `TextureRegistry`

public class FlutterRenderer extends Object implements TextureRegistry
Represents the rendering responsibilities of a `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 Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `FlutterRenderer.DisplayFeature`
  Description of a physical feature on the display.
  `static enum`
  `FlutterRenderer.DisplayFeatureState`
  State of the display feature.
  `static enum`
  `FlutterRenderer.DisplayFeatureType`
  Types of display features that can appear on the viewport.
  `static final class`
  `FlutterRenderer.ViewportMetrics`
  Mutable 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

  Fields
  Modifier and Type
  Field
  Description
  `static boolean`
  `debugDisableSurfaceClear`
  Whether to disable clearing of the Surface used to render platform views.
  `static boolean`
  `debugForceSurfaceProducerGlTextures`
  Whether to always use GL textures for `TextureRegistry.createSurfaceProducer()`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FlutterRenderer(FlutterJNI flutterJNI)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addIsDisplayingFlutterUiListener(FlutterUiDisplayListener listener)`
  Adds a listener that is invoked whenever this `FlutterRenderer` starts and stops painting pixels to an Android `View` hierarchy.
  `TextureRegistry.ImageTextureEntry`
  `createImageTexture()`
  Creates and registers a texture managed by the Flutter engine.
  `TextureRegistry.SurfaceProducer`
  `createSurfaceProducer(TextureRegistry.SurfaceLifecycle lifecycle)`
  Creates and returns a new external texture `TextureRegistry.SurfaceProducer` managed by the Flutter engine that is also made available to Flutter code.
  `TextureRegistry.SurfaceTextureEntry`
  `createSurfaceTexture()`
  Creates and returns a new `SurfaceTexture` managed by the Flutter engine that is also made available to Flutter code.
  `void`
  `dispatchPointerDataPacket(ByteBuffer buffer, int position)`
  `void`
  `dispatchSemanticsAction(int nodeId, int action, ByteBuffer args, int argsPosition)`
  `Bitmap`
  `getBitmap()`
  `boolean`
  `isDisplayingFlutterUi()`
  Returns true if this `FlutterRenderer` is painting pixels to an Android `View` hierarchy, false otherwise.
  `boolean`
  `isSoftwareRenderingEnabled()`
  `void`
  `onTrimMemory(int level)`
  Callback invoked when memory is low.
  `TextureRegistry.SurfaceTextureEntry`
  `registerSurfaceTexture(SurfaceTexture surfaceTexture)`
  Registers and returns a `SurfaceTexture` managed by the Flutter engine that is also made available to Flutter code.
  `void`
  `removeIsDisplayingFlutterUiListener(FlutterUiDisplayListener listener)`
  Removes a listener added via `addIsDisplayingFlutterUiListener(FlutterUiDisplayListener)`.
  `void`
  `restoreSurfaceProducers()`
  Restores `ImageReaderSurfaceProducer`s that were previously notified to be destroyed due to a call to `onTrimMemory` as part of an `onResume` app lifecycle event.
  `void`
  `setAccessibilityFeatures(int flags)`
  `void`
  `setSemanticsEnabled(boolean enabled)`
  `void`
  `setViewportMetrics(FlutterRenderer.ViewportMetrics viewportMetrics)`
  Notifies Flutter that the viewport metrics, e.g.
  `void`
  `startRenderingToSurface(Surface surface, boolean onlySwap)`
  Notifies Flutter that the given `surface` was created and is available for Flutter rendering.
  `void`
  `stopRenderingToSurface()`
  Notifies Flutter that a `surface` previously registered with `startRenderingToSurface(Surface, boolean)` has been destroyed and needs to be released and cleaned up on the Flutter side.
  `void`
  `surfaceChanged(int width, int height)`
  Notifies Flutter that a `surface` previously registered with `startRenderingToSurface(Surface, boolean)` has changed size to the given `width` and `height`.
  `void`
  `swapSurface(Surface surface)`
  Swaps the `Surface` used to render the current frame.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface io.flutter.view.TextureRegistry

  `createSurfaceProducer`

- ## Field Details

  - ### debugForceSurfaceProducerGlTextures

    @VisibleForTesting public static boolean debugForceSurfaceProducerGlTextures
    Whether to always use GL textures for `TextureRegistry.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/`SurfaceTextureSurfaceProducer` code branch. This flag has undefined behavior if set to true while running in a Vulkan (Impeller) context.

  - ### debugDisableSurfaceClear

    @VisibleForTesting public static boolean debugDisableSurfaceClear
    Whether to disable clearing of the Surface used to render platform views.

- ## Constructor Details

  - ### FlutterRenderer

    public FlutterRenderer(@NonNull FlutterJNI flutterJNI)

- ## Method Details

  - ### restoreSurfaceProducers

    public void restoreSurfaceProducers()
    Restores `ImageReaderSurfaceProducer`s that were previously notified to be destroyed due to a call to `onTrimMemory` as part of an `onResume` app lifecycle event.

    All `FlutterActivity`s and `FlutterFragment`s are expected to call this `onResume` to ensure surface producers are restored when the app returns to the foreground.

  - ### isDisplayingFlutterUi

    public boolean isDisplayingFlutterUi()
    Returns true if this `FlutterRenderer` is painting pixels to an Android `View` hierarchy, false otherwise.

  - ### addIsDisplayingFlutterUiListener

    public void addIsDisplayingFlutterUiListener(@NonNull FlutterUiDisplayListener listener)
    Adds a listener that is invoked whenever this `FlutterRenderer` starts and stops painting pixels to an Android `View` hierarchy.

  - ### removeIsDisplayingFlutterUiListener

    public void removeIsDisplayingFlutterUiListener(@NonNull FlutterUiDisplayListener listener)
    Removes a listener added via `addIsDisplayingFlutterUiListener(FlutterUiDisplayListener)`.

  - ### createSurfaceProducer

    @NonNull public TextureRegistry.SurfaceProducer createSurfaceProducer(TextureRegistry.SurfaceLifecycle lifecycle)
    Creates and returns a new external texture `TextureRegistry.SurfaceProducer` managed by the Flutter engine that is also made available to Flutter code.
    Specified by:
      `createSurfaceProducer` in interface `TextureRegistry`
    Parameters:
      `lifecycle` - Whether to automatically reset the last image and release the surface.
    Returns:
      A SurfaceProducer.

  - ### createSurfaceTexture

    @NonNull public TextureRegistry.SurfaceTextureEntry createSurfaceTexture()
    Creates and returns a new `SurfaceTexture` managed by the Flutter engine that is also made available to Flutter code.
    Specified by:
      `createSurfaceTexture` in interface `TextureRegistry`
    Returns:
      A SurfaceTextureEntry.

  - ### registerSurfaceTexture

    @NonNull public TextureRegistry.SurfaceTextureEntry registerSurfaceTexture(@NonNull SurfaceTexture surfaceTexture)
    Registers and returns a `SurfaceTexture` managed by the Flutter engine that is also made available to Flutter code.
    Specified by:
      `registerSurfaceTexture` in interface `TextureRegistry`
    Returns:
      A SurfaceTextureEntry.

  - ### createImageTexture

    @NonNull public TextureRegistry.ImageTextureEntry createImageTexture()
    Description copied from interface: `TextureRegistry`
    Creates and registers a texture managed by the Flutter engine.
    Specified by:
      `createImageTexture` in interface `TextureRegistry`
    Returns:
      a ImageTextureEntry.

  - ### onTrimMemory

    public void onTrimMemory(int level)
    Description copied from interface: `TextureRegistry`
    Callback invoked when memory is low.

    Invoke this from `Activity.onTrimMemory(int)`.

    Specified by:
      `onTrimMemory` in interface `TextureRegistry`

  - ### startRenderingToSurface

    public void startRenderingToSurface(@NonNull Surface surface, boolean onlySwap)
    Notifies Flutter that the given `surface` was 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 `keepCurrentSurface` to true.

    See `SurfaceHolder.Callback` and `TextureView.SurfaceTextureListener`

    Parameters:
      `surface` - The render surface.
      `onlySwap` - True if the current active surface should not be detached.

  - ### swapSurface

    public void swapSurface(@NonNull Surface surface)
    Swaps the `Surface` used to render the current frame.

    In hybrid composition, the root surfaces changes from `SurfaceHolder.getSurface()` to `ImageReader.getSurface()` when a platform view is in the current frame.

  - ### surfaceChanged

    public void surfaceChanged(int width, int height)
    Notifies Flutter that a `surface` previously registered with `startRenderingToSurface(Surface, boolean)` has changed size to the given `width` and `height`.

    See `SurfaceHolder.Callback` and `TextureView.SurfaceTextureListener`

  - ### stopRenderingToSurface

    public void stopRenderingToSurface()
    Notifies Flutter that a `surface` previously registered with `startRenderingToSurface(Surface, boolean)` has been destroyed and needs to be released and cleaned up on the Flutter side.

    See `SurfaceHolder.Callback` and `TextureView.SurfaceTextureListener`

  - ### setViewportMetrics

    public void setViewportMetrics(@NonNull FlutterRenderer.ViewportMetrics viewportMetrics)
    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

    public Bitmap getBitmap()

  - ### dispatchPointerDataPacket

    public void dispatchPointerDataPacket(@NonNull ByteBuffer buffer, int position)

  - ### 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)