Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Attributes | Package Functions | List of all members
io.flutter.embedding.engine.renderer.FlutterRenderer Class Reference
Inheritance diagram for io.flutter.embedding.engine.renderer.FlutterRenderer:
io.flutter.view.TextureRegistry

Classes

class  DisplayFeature
 
enum  DisplayFeatureState
 
enum  DisplayFeatureType
 
class  ImageReaderSurfaceProducer
 
class  ImageTextureRegistryEntry
 
class  SurfaceTextureRegistryEntry
 
class  TextureFinalizerRunnable
 
class  ViewportMetrics
 

Public Member Functions

 FlutterRenderer (@NonNull FlutterJNI flutterJNI)
 
boolean isDisplayingFlutterUi ()
 
void addIsDisplayingFlutterUiListener (@NonNull FlutterUiDisplayListener listener)
 
void removeIsDisplayingFlutterUiListener (@NonNull FlutterUiDisplayListener listener)
 
SurfaceProducer createSurfaceProducer ()
 
SurfaceTextureEntry createSurfaceTexture ()
 
SurfaceTextureEntry registerSurfaceTexture (@NonNull SurfaceTexture surfaceTexture)
 
SurfaceProducer createSurfaceProducer ()
 
SurfaceTextureEntry createSurfaceTexture ()
 
SurfaceTextureEntry registerSurfaceTexture (@NonNull SurfaceTexture surfaceTexture)
 
ImageTextureEntry createImageTexture ()
 
default void onTrimMemory (int level)
 

Static Public Attributes

static boolean debugForceSurfaceProducerGlTextures = false
 
static boolean debugDisableSurfaceClear = false
 

Package Functions

void addOnTrimMemoryListener (@NonNull OnTrimMemoryListener listener)
 
void removeOnTrimMemoryListener (@NonNull OnTrimMemoryListener listener)
 
ImageTextureEntry createImageTexture ()
 
void onTrimMemory (int level)
 
void startRenderingToSurface (@NonNull Surface surface, boolean onlySwap)
 
void swapSurface (@NonNull Surface surface)
 
void surfaceChanged (int width, int height)
 
void stopRenderingToSurface ()
 
void setViewportMetrics (@NonNull ViewportMetrics viewportMetrics)
 
Bitmap getBitmap ()
 
void dispatchPointerDataPacket (@NonNull ByteBuffer buffer, int position)
 
boolean isSoftwareRenderingEnabled ()
 
void setAccessibilityFeatures (int flags)
 
void setSemanticsEnabled (boolean enabled)
 
void dispatchSemanticsAction (int nodeId, int action, @Nullable ByteBuffer args, int argsPosition)
 

Detailed Description

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.

io.flutter.embedding.android.FlutterSurfaceView and io.flutter.embedding.android.FlutterTextureView are implementations of RenderSurface.

Definition at line 55 of file FlutterRenderer.java.

Constructor & Destructor Documentation

◆ FlutterRenderer()

io.flutter.embedding.engine.renderer.FlutterRenderer.FlutterRenderer ( @NonNull FlutterJNI  flutterJNI)
inline

Definition at line 95 of file FlutterRenderer.java.

95 {
96 this.flutterJNI = flutterJNI;
97 this.flutterJNI.addIsDisplayingFlutterUiListener(flutterUiDisplayListener);
98 }
void addIsDisplayingFlutterUiListener(@NonNull FlutterUiDisplayListener listener)

Member Function Documentation

◆ addIsDisplayingFlutterUiListener()

void io.flutter.embedding.engine.renderer.FlutterRenderer.addIsDisplayingFlutterUiListener ( @NonNull FlutterUiDisplayListener  listener)
inline

Adds a listener that is invoked whenever this FlutterRenderer starts and stops painting pixels to an Android View hierarchy.

Definition at line 112 of file FlutterRenderer.java.

112 {
113 flutterJNI.addIsDisplayingFlutterUiListener(listener);
114
115 if (isDisplayingFlutterUi) {
116 listener.onFlutterUiDisplayed();
117 }
118 }

◆ addOnTrimMemoryListener()

void io.flutter.embedding.engine.renderer.FlutterRenderer.addOnTrimMemoryListener ( @NonNull OnTrimMemoryListener  listener)
inlinepackage

Adds a listener that is invoked when a memory pressure warning was forward.

Definition at line 141 of file FlutterRenderer.java.

141 {
142 // Purge dead listener to avoid accumulating.
143 clearDeadListeners();
144 onTrimMemoryListeners.add(new WeakReference<>(listener));
145 }

◆ createImageTexture()

ImageTextureEntry io.flutter.embedding.engine.renderer.FlutterRenderer.createImageTexture ( )
inline

Creates and registers a texture managed by the Flutter engine.

Returns
a ImageTextureEntry.

Implements io.flutter.view.TextureRegistry.

Definition at line 260 of file FlutterRenderer.java.

260 {
261 final ImageTextureRegistryEntry entry =
262 new ImageTextureRegistryEntry(nextTextureId.getAndIncrement());
263 Log.v(TAG, "New ImageTextureEntry ID: " + entry.id());
264 registerImageTexture(entry.id(), entry);
265 return entry;
266 }
void Log(const char *format,...) SK_PRINTF_LIKE(1
Definition: TestRunner.cpp:137

◆ createSurfaceProducer()

SurfaceProducer io.flutter.embedding.engine.renderer.FlutterRenderer.createSurfaceProducer ( )
inline

Creates and returns a new external texture SurfaceProducer managed by the Flutter engine that is also made available to Flutter code.

Implements io.flutter.view.TextureRegistry.

Definition at line 169 of file FlutterRenderer.java.

169 {
170 // Prior to Impeller, Flutter on Android *only* ran on OpenGLES (via Skia). That
171 // meant that
172 // plugins (i.e. end-users) either explicitly created a SurfaceTexture (via
173 // createX/registerX) or an ImageTexture (via createX/registerX).
174 //
175 // In an Impeller world, which for the first time uses (if available) a Vulkan
176 // rendering
177 // backend, it is no longer possible (at least not trivially) to render an
178 // OpenGLES-provided
179 // texture (SurfaceTexture) in a Vulkan context.
180 //
181 // This function picks the "best" rendering surface based on the Android
182 // runtime, and
183 // provides a consumer-agnostic SurfaceProducer (which in turn vends a Surface),
184 // and has
185 // plugins (i.e. end-users) use the Surface instead, letting us "hide" the
186 // consumer-side
187 // of the implementation.
188 //
189 // tl;dr: If ImageTexture is available, we use it, otherwise we use a
190 // SurfaceTexture.
191 // Coincidentally, if ImageTexture is available, we are also on an Android
192 // version that is
193 // running Vulkan, so we don't have to worry about it not being supported.
194 final SurfaceProducer entry;
195 if (!debugForceSurfaceProducerGlTextures && Build.VERSION.SDK_INT >= API_LEVELS.API_29) {
196 final long id = nextTextureId.getAndIncrement();
197 final ImageReaderSurfaceProducer producer = new ImageReaderSurfaceProducer(id);
198 registerImageTexture(id, producer);
199 addOnTrimMemoryListener(producer);
200 Log.v(TAG, "New ImageReaderSurfaceProducer ID: " + id);
201 entry = producer;
202 } else {
203 // TODO(matanlurey): Actually have the class named "*Producer" to well, produce
204 // something. This is a code smell, but does guarantee the paths for both
205 // createSurfaceTexture and createSurfaceProducer doesn't diverge. As we get more
206 // confident in this API and any possible bugs (and have tests to check we don't
207 // regress), reconsider this pattern.
208 final SurfaceTextureEntry texture = createSurfaceTexture();
209 final SurfaceTextureSurfaceProducer producer =
210 new SurfaceTextureSurfaceProducer(texture.id(), handler, flutterJNI, texture);
211 Log.v(TAG, "New SurfaceTextureSurfaceProducer ID: " + texture.id());
212 entry = producer;
213 }
214 return entry;
215 }
void addOnTrimMemoryListener(@NonNull OnTrimMemoryListener listener)
FlTexture * texture
def Build(configs, env, options)
Definition: build.py:232

◆ createSurfaceTexture()

SurfaceTextureEntry io.flutter.embedding.engine.renderer.FlutterRenderer.createSurfaceTexture ( )
inline

Creates and returns a new SurfaceTexture managed by the Flutter engine that is also made available to Flutter code.

Implements io.flutter.view.TextureRegistry.

Definition at line 223 of file FlutterRenderer.java.

223 {
224 Log.v(TAG, "Creating a SurfaceTexture.");
225 final SurfaceTexture surfaceTexture = new SurfaceTexture(0);
226 return registerSurfaceTexture(surfaceTexture);
227 }
SurfaceTextureEntry registerSurfaceTexture(@NonNull SurfaceTexture surfaceTexture)

◆ dispatchPointerDataPacket()

void io.flutter.embedding.engine.renderer.FlutterRenderer.dispatchPointerDataPacket ( @NonNull ByteBuffer  buffer,
int  position 
)
inline

Definition at line 1199 of file FlutterRenderer.java.

1199 {
1200 flutterJNI.dispatchPointerDataPacket(buffer, position);
1201 }
void dispatchPointerDataPacket(@NonNull ByteBuffer buffer, int position)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ dispatchSemanticsAction()

void io.flutter.embedding.engine.renderer.FlutterRenderer.dispatchSemanticsAction ( int  nodeId,
int  action,
@Nullable ByteBuffer  args,
int  argsPosition 
)
inline

Definition at line 1243 of file FlutterRenderer.java.

1244 {
1245 flutterJNI.dispatchSemanticsAction(nodeId, action, args, argsPosition);
1246 }
void dispatchSemanticsAction(int nodeId, @NonNull AccessibilityBridge.Action action)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args

◆ getBitmap()

Bitmap io.flutter.embedding.engine.renderer.FlutterRenderer.getBitmap ( )
inline

Definition at line 1194 of file FlutterRenderer.java.

1194 {
1195 return flutterJNI.getBitmap();
1196 }

◆ isDisplayingFlutterUi()

boolean io.flutter.embedding.engine.renderer.FlutterRenderer.isDisplayingFlutterUi ( )
inline

Returns true if this FlutterRenderer is painting pixels to an Android View hierarchy, false otherwise.

Definition at line 104 of file FlutterRenderer.java.

104 {
105 return isDisplayingFlutterUi;
106 }

◆ isSoftwareRenderingEnabled()

boolean io.flutter.embedding.engine.renderer.FlutterRenderer.isSoftwareRenderingEnabled ( )
inline

Definition at line 1228 of file FlutterRenderer.java.

1228 {
1229 return flutterJNI.getIsSoftwareRenderingEnabled();
1230 }

◆ onTrimMemory()

void io.flutter.embedding.engine.renderer.FlutterRenderer.onTrimMemory ( int  level)
inline

Callback invoked when memory is low.

Invoke this from android.app.Activity#onTrimMemory(int).

Implements io.flutter.view.TextureRegistry.

Definition at line 269 of file FlutterRenderer.java.

269 {
270 final Iterator<WeakReference<OnTrimMemoryListener>> iterator = onTrimMemoryListeners.iterator();
271 while (iterator.hasNext()) {
272 WeakReference<OnTrimMemoryListener> listenerRef = iterator.next();
273 final OnTrimMemoryListener listener = listenerRef.get();
274 if (listener != null) {
275 listener.onTrimMemory(level);
276 } else {
277 // Purge cleared refs to avoid accumulating a lot of dead listener
278 iterator.remove();
279 }
280 }
281 }

◆ registerSurfaceTexture()

SurfaceTextureEntry io.flutter.embedding.engine.renderer.FlutterRenderer.registerSurfaceTexture ( @NonNull SurfaceTexture  surfaceTexture)
inline

Registers and returns a SurfaceTexture managed by the Flutter engine that is also made available to Flutter code.

Implements io.flutter.view.TextureRegistry.

Definition at line 235 of file FlutterRenderer.java.

235 {
236 return registerSurfaceTexture(nextTextureId.getAndIncrement(), surfaceTexture);
237 }

◆ removeIsDisplayingFlutterUiListener()

void io.flutter.embedding.engine.renderer.FlutterRenderer.removeIsDisplayingFlutterUiListener ( @NonNull FlutterUiDisplayListener  listener)
inline

Removes a listener added via addIsDisplayingFlutterUiListener(FlutterUiDisplayListener).

Definition at line 124 of file FlutterRenderer.java.

124 {
125 flutterJNI.removeIsDisplayingFlutterUiListener(listener);
126 }
void removeIsDisplayingFlutterUiListener(@NonNull FlutterUiDisplayListener listener)

◆ removeOnTrimMemoryListener()

void io.flutter.embedding.engine.renderer.FlutterRenderer.removeOnTrimMemoryListener ( @NonNull OnTrimMemoryListener  listener)
inlinepackage

Removes a OnTrimMemoryListener that was added with addOnTrimMemoryListener(OnTrimMemoryListener).

Definition at line 152 of file FlutterRenderer.java.

152 {
153 for (WeakReference<OnTrimMemoryListener> listenerRef : onTrimMemoryListeners) {
154 if (listenerRef.get() == listener) {
155 onTrimMemoryListeners.remove(listenerRef);
156 break;
157 }
158 }
159 }

◆ setAccessibilityFeatures()

void io.flutter.embedding.engine.renderer.FlutterRenderer.setAccessibilityFeatures ( int  flags)
inline

Definition at line 1233 of file FlutterRenderer.java.

1233 {
1234 flutterJNI.setAccessibilityFeatures(flags);
1235 }
FlutterSemanticsFlag flags

◆ setSemanticsEnabled()

void io.flutter.embedding.engine.renderer.FlutterRenderer.setSemanticsEnabled ( boolean  enabled)
inline

Definition at line 1238 of file FlutterRenderer.java.

1238 {
1239 flutterJNI.setSemanticsEnabled(enabled);
1240 }
void setSemanticsEnabled(boolean enabled)

◆ setViewportMetrics()

void io.flutter.embedding.engine.renderer.FlutterRenderer.setViewportMetrics ( @NonNull ViewportMetrics  viewportMetrics)
inline

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
viewportMetricsThe metrics to send to the Dart application.

Definition at line 1113 of file FlutterRenderer.java.

1113 {
1114 // We might get called with just the DPR if width/height aren't available yet.
1115 // Just ignore, as it will get called again when width/height are set.
1116 if (!viewportMetrics.validate()) {
1117 return;
1118 }
1119 Log.v(
1120 TAG,
1121 "Setting viewport metrics\n"
1122 + "Size: "
1123 + viewportMetrics.width
1124 + " x "
1125 + viewportMetrics.height
1126 + "\n"
1127 + "Padding - L: "
1128 + viewportMetrics.viewPaddingLeft
1129 + ", T: "
1130 + viewportMetrics.viewPaddingTop
1131 + ", R: "
1132 + viewportMetrics.viewPaddingRight
1133 + ", B: "
1134 + viewportMetrics.viewPaddingBottom
1135 + "\n"
1136 + "Insets - L: "
1137 + viewportMetrics.viewInsetLeft
1138 + ", T: "
1139 + viewportMetrics.viewInsetTop
1140 + ", R: "
1141 + viewportMetrics.viewInsetRight
1142 + ", B: "
1143 + viewportMetrics.viewInsetBottom
1144 + "\n"
1145 + "System Gesture Insets - L: "
1146 + viewportMetrics.systemGestureInsetLeft
1147 + ", T: "
1148 + viewportMetrics.systemGestureInsetTop
1149 + ", R: "
1150 + viewportMetrics.systemGestureInsetRight
1151 + ", B: "
1152 + viewportMetrics.systemGestureInsetRight
1153 + "\n"
1154 + "Display Features: "
1155 + viewportMetrics.displayFeatures.size());
1156
1157 int[] displayFeaturesBounds = new int[viewportMetrics.displayFeatures.size() * 4];
1158 int[] displayFeaturesType = new int[viewportMetrics.displayFeatures.size()];
1159 int[] displayFeaturesState = new int[viewportMetrics.displayFeatures.size()];
1160 for (int i = 0; i < viewportMetrics.displayFeatures.size(); i++) {
1161 DisplayFeature displayFeature = viewportMetrics.displayFeatures.get(i);
1162 displayFeaturesBounds[4 * i] = displayFeature.bounds.left;
1163 displayFeaturesBounds[4 * i + 1] = displayFeature.bounds.top;
1164 displayFeaturesBounds[4 * i + 2] = displayFeature.bounds.right;
1165 displayFeaturesBounds[4 * i + 3] = displayFeature.bounds.bottom;
1166 displayFeaturesType[i] = displayFeature.type.encodedValue;
1167 displayFeaturesState[i] = displayFeature.state.encodedValue;
1168 }
1169
1170 flutterJNI.setViewportMetrics(
1171 viewportMetrics.devicePixelRatio,
1172 viewportMetrics.width,
1173 viewportMetrics.height,
1174 viewportMetrics.viewPaddingTop,
1175 viewportMetrics.viewPaddingRight,
1176 viewportMetrics.viewPaddingBottom,
1177 viewportMetrics.viewPaddingLeft,
1178 viewportMetrics.viewInsetTop,
1179 viewportMetrics.viewInsetRight,
1180 viewportMetrics.viewInsetBottom,
1181 viewportMetrics.viewInsetLeft,
1182 viewportMetrics.systemGestureInsetTop,
1183 viewportMetrics.systemGestureInsetRight,
1184 viewportMetrics.systemGestureInsetBottom,
1185 viewportMetrics.systemGestureInsetLeft,
1186 viewportMetrics.physicalTouchSlop,
1187 displayFeaturesBounds,
1188 displayFeaturesType,
1189 displayFeaturesState);
1190 }
void setViewportMetrics(float devicePixelRatio, int physicalWidth, int physicalHeight, int physicalPaddingTop, int physicalPaddingRight, int physicalPaddingBottom, int physicalPaddingLeft, int physicalViewInsetTop, int physicalViewInsetRight, int physicalViewInsetBottom, int physicalViewInsetLeft, int systemGestureInsetTop, int systemGestureInsetRight, int systemGestureInsetBottom, int systemGestureInsetLeft, int physicalTouchSlop, int[] displayFeaturesBounds, int[] displayFeaturesType, int[] displayFeaturesState)

◆ startRenderingToSurface()

void io.flutter.embedding.engine.renderer.FlutterRenderer.startRenderingToSurface ( @NonNull Surface  surface,
boolean  onlySwap 
)
inline

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 android.view.SurfaceHolder.Callback and android.view.TextureView.SurfaceTextureListener

Parameters
surfaceThe render surface.
onlySwapTrue if the current active surface should not be detached.

Definition at line 1036 of file FlutterRenderer.java.

1036 {
1037 if (!onlySwap) {
1038 // Stop rendering to the surface releases the associated native resources, which causes
1039 // a glitch when toggling between rendering to an image view (hybrid composition) and
1040 // rendering directly to a Surface or Texture view. For more,
1041 // https://github.com/flutter/flutter/issues/95343
1043 }
1044
1045 this.surface = surface;
1046
1047 if (onlySwap) {
1048 // In the swap case we are just swapping the surface that we render to.
1049 flutterJNI.onSurfaceWindowChanged(surface);
1050 } else {
1051 // In the non-swap case we are creating a new surface to render to.
1052 flutterJNI.onSurfaceCreated(surface);
1053 }
1054 }
void onSurfaceCreated(@NonNull Surface surface)
void onSurfaceWindowChanged(@NonNull Surface surface)

◆ stopRenderingToSurface()

void io.flutter.embedding.engine.renderer.FlutterRenderer.stopRenderingToSurface ( )
inline

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 android.view.SurfaceHolder.Callback and android.view.TextureView.SurfaceTextureListener

Definition at line 1088 of file FlutterRenderer.java.

1088 {
1089 if (surface != null) {
1090 flutterJNI.onSurfaceDestroyed();
1091
1092 // TODO(mattcarroll): the source of truth for this call should be FlutterJNI, which is
1093 // where the call to onFlutterUiDisplayed() comes from. However, no such native callback
1094 // exists yet, so until the engine and FlutterJNI are configured to call us back when
1095 // rendering stops, we will manually monitor that change here.
1096 if (isDisplayingFlutterUi) {
1097 flutterUiDisplayListener.onFlutterUiNoLongerDisplayed();
1098 }
1099
1100 isDisplayingFlutterUi = false;
1101 surface = null;
1102 }
1103 }

◆ surfaceChanged()

void io.flutter.embedding.engine.renderer.FlutterRenderer.surfaceChanged ( int  width,
int  height 
)
inline

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

See android.view.SurfaceHolder.Callback and android.view.TextureView.SurfaceTextureListener

Definition at line 1076 of file FlutterRenderer.java.

1076 {
1077 flutterJNI.onSurfaceChanged(width, height);
1078 }
void onSurfaceChanged(int width, int height)
int32_t height
int32_t width

◆ swapSurface()

void io.flutter.embedding.engine.renderer.FlutterRenderer.swapSurface ( @NonNull Surface  surface)
inline

Swaps the Surface used to render the current frame.

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

Definition at line 1063 of file FlutterRenderer.java.

1063 {
1064 this.surface = surface;
1065 flutterJNI.onSurfaceWindowChanged(surface);
1066 }

Member Data Documentation

◆ debugDisableSurfaceClear

boolean io.flutter.embedding.engine.renderer.FlutterRenderer.debugDisableSurfaceClear = false
static

Whether to disable clearing of the Surface used to render platform views.

Definition at line 67 of file FlutterRenderer.java.

◆ debugForceSurfaceProducerGlTextures

boolean io.flutter.embedding.engine.renderer.FlutterRenderer.debugForceSurfaceProducerGlTextures = false
static

Whether to always use GL textures for FlutterRenderer#createSurfaceProducer().

This is a debug-only API intended for local development. For example, when using a newer Android device (that normally would use 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.

Definition at line 64 of file FlutterRenderer.java.


The documentation for this class was generated from the following file: