Class FlutterRenderer

All Implemented Interfaces:

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.

  • Field Details

    • debugForceSurfaceProducerGlTextures

      public static boolean debugForceSurfaceProducerGlTextures
      Whether to always use GL textures for 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.

  • Constructor Details

    • FlutterRenderer

      public FlutterRenderer(@NonNull FlutterJNI flutterJNI)
  • Method Details

    • 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)
    • createSurfaceProducer

      @NonNull public TextureRegistry.SurfaceProducer createSurfaceProducer()
      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
      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
      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
      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
      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

      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.

      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)