Flutter Engine
The Flutter Engine
|
Classes | |
interface | AccessibilityDelegate |
interface | AsyncWaitForVsyncDelegate |
class | Factory |
Public Member Functions | |
FlutterJNI () | |
void | loadLibrary () |
void | prefetchDefaultFontManager () |
void | init ( @NonNull Context context, @NonNull String[] args, @Nullable String bundlePath, @NonNull String appStoragePath, @NonNull String engineCachesPath, long initTimeMillis) |
boolean | getIsSoftwareRenderingEnabled () |
void | setRefreshRateFPS (float refreshRateFPS) |
void | updateDisplayMetrics (int displayId, float width, float height, float density) |
void | updateRefreshRate () |
void | setAsyncWaitForVsyncDelegate (@Nullable AsyncWaitForVsyncDelegate delegate) |
void | onVsync (long frameDelayNanos, long refreshPeriodNanos, long cookie) |
boolean | isCodePointEmoji (int codePoint) |
boolean | isCodePointEmojiModifier (int codePoint) |
boolean | isCodePointEmojiModifierBase (int codePoint) |
boolean | isCodePointVariantSelector (int codePoint) |
boolean | isCodePointRegionalIndicator (int codePoint) |
boolean | isAttached () |
void | attachToNative () |
long | performNativeAttach (@NonNull FlutterJNI flutterJNI) |
FlutterJNI | spawn ( @Nullable String entrypointFunctionName, @Nullable String pathToEntrypointFunction, @Nullable String initialRoute, @Nullable List< String > entrypointArgs) |
void | detachFromNativeAndReleaseResources () |
void | addIsDisplayingFlutterUiListener (@NonNull FlutterUiDisplayListener listener) |
void | removeIsDisplayingFlutterUiListener (@NonNull FlutterUiDisplayListener listener) |
void | onFirstFrame () |
void | onSurfaceCreated (@NonNull Surface surface) |
void | onSurfaceWindowChanged (@NonNull Surface surface) |
void | onSurfaceChanged (int width, int height) |
void | onSurfaceDestroyed () |
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) |
void | dispatchPointerDataPacket (@NonNull ByteBuffer buffer, int position) |
void | setPlatformViewsController (@NonNull PlatformViewsController platformViewsController) |
void | setAccessibilityDelegate (@Nullable AccessibilityDelegate accessibilityDelegate) |
void | dispatchSemanticsAction (int nodeId, @NonNull AccessibilityBridge.Action action) |
void | dispatchSemanticsAction (int nodeId, @NonNull AccessibilityBridge.Action action, @Nullable Object args) |
void | dispatchSemanticsAction (int nodeId, int action, @Nullable ByteBuffer args, int argsPosition) |
void | setSemanticsEnabled (boolean enabled) |
void | setAccessibilityFeatures (int flags) |
void | registerTexture (long textureId, @NonNull SurfaceTextureWrapper textureWrapper) |
void | registerImageTexture (long textureId, @NonNull TextureRegistry.ImageConsumer imageTexture) |
void | markTextureFrameAvailable (long textureId) |
void | scheduleFrame () |
void | unregisterTexture (long textureId) |
void | runBundleAndSnapshotFromLibrary ( @NonNull String bundlePath, @Nullable String entrypointFunctionName, @Nullable String pathToEntrypointFunction, @NonNull AssetManager assetManager, @Nullable List< String > entrypointArgs) |
void | setPlatformMessageHandler (@Nullable PlatformMessageHandler platformMessageHandler) |
void | cleanupMessageData (long messageData) |
void | handlePlatformMessage ( @NonNull final String channel, ByteBuffer message, final int replyId, final long messageData) |
void | dispatchEmptyPlatformMessage (@NonNull String channel, int responseId) |
void | dispatchPlatformMessage ( @NonNull String channel, @Nullable ByteBuffer message, int position, int responseId) |
void | invokePlatformMessageEmptyResponseCallback (int responseId) |
void | invokePlatformMessageResponseCallback (int responseId, @NonNull ByteBuffer message, int position) |
void | addEngineLifecycleListener (@NonNull EngineLifecycleListener engineLifecycleListener) |
void | removeEngineLifecycleListener ( @NonNull EngineLifecycleListener engineLifecycleListener) |
void | onDisplayOverlaySurface (int id, int x, int y, int width, int height) |
void | onBeginFrame () |
void | onEndFrame () |
FlutterOverlaySurface | createOverlaySurface () |
void | destroyOverlaySurfaces () |
void | setLocalizationPlugin (@Nullable LocalizationPlugin localizationPlugin) |
String[] | computePlatformResolvedLocale (@NonNull String[] strings) |
float | getScaledFontSize (float fontSize, int configurationId) |
void | setDeferredComponentManager ( @Nullable DeferredComponentManager deferredComponentManager) |
void | requestDartDeferredLibrary (int loadingUnitId) |
void | loadDartDeferredLibrary (int loadingUnitId, @NonNull String[] searchPaths) |
void | updateJavaAssetManager ( @NonNull AssetManager assetManager, @NonNull String assetBundlePath) |
void | deferredComponentInstallFailure (int loadingUnitId, @NonNull String error, boolean isTransient) |
void | onDisplayPlatformView (int viewId, int x, int y, int width, int height, int viewWidth, int viewHeight, FlutterMutatorsStack mutatorsStack) |
Bitmap | getBitmap () |
void | notifyLowMemoryWarning () |
Static Public Member Functions | |
static String | getVMServiceUri () |
static String | getObservatoryUri () |
static native FlutterCallbackInformation | nativeLookupCallbackInformation (long handle) |
static native void | nativeImageHeaderCallback (long imageGeneratorPointer, int width, int height) |
static Bitmap | decodeImage (@NonNull ByteBuffer buffer, long imageGeneratorAddress) |
Package Functions | |
void | onRenderingStopped () |
Interface between Flutter embedding's Java code and Flutter engine's C/C++ code.
Flutter's engine is built with C/C++. The Android Flutter embedding is responsible for coordinating Android OS events and app user interactions with the C/C++ engine. Such coordination requires messaging from an Android app in Java code to the C/C++ engine code. This communication requires a JNI (Java Native Interface) API to cross the Java/native boundary.
The entirety of Flutter's JNI API is codified in FlutterJNI
. There are multiple reasons that all such calls are centralized in one class. First, JNI calls are inherently static and contain no Java implementation, therefore there is little reason to associate calls with different classes. Second, every JNI call must be registered in C/C++ code and this registration becomes more complicated with every additional Java class that contains JNI calls. Third, most Android developers are not familiar with native development or JNI intricacies, therefore it is in the interest of future maintenance to reduce the API surface that includes JNI declarations. Thus, all Flutter JNI calls are centralized in FlutterJNI
.
Despite the fact that individual JNI calls are inherently static, there is state that exists within FlutterJNI
. Most calls within FlutterJNI
correspond to a specific "platform view", of which there may be many. Therefore, each FlutterJNI
instance holds onto a "native platform view ID" after attachToNative()
, which is shared with the native C/C++ engine code. That ID is passed to every platform-view-specific native method. ID management is handled within FlutterJNI
so that developers don't have to hold onto that ID.
To connect part of an Android app to Flutter's C/C++ engine, instantiate a FlutterJNI
and then attach it to the native side:
// Instantiate FlutterJNI and attach to the native side.
FlutterJNI flutterJNI = new FlutterJNI();
flutterJNI.attachToNative();
// Use FlutterJNI as desired. flutterJNI.dispatchPointerDataPacket(...);
// Destroy the connection to the native side and cleanup.
flutterJNI.detachFromNativeAndReleaseResources();
To receive callbacks for certain events that occur on the native side, register listeners:
addEngineLifecycleListener(FlutterEngine.EngineLifecycleListener)
addIsDisplayingFlutterUiListener(FlutterUiDisplayListener)
To facilitate platform messages between Java and Dart running in Flutter, register a handler:
setPlatformMessageHandler(PlatformMessageHandler)
To invoke a native method that is not associated with a platform view, invoke it statically:
bool enabled = FlutterJNI.getIsSoftwareRenderingEnabled();
Definition at line 106 of file FlutterJNI.java.
|
inline |
Definition at line 116 of file FlutterJNI.java.
|
inline |
Adds the given engineLifecycleListener
to be notified of Flutter engine lifecycle events, e.g., EngineLifecycleListener#onPreEngineRestart()
.
Definition at line 1186 of file FlutterJNI.java.
|
inline |
Adds a FlutterUiDisplayListener
, which receives a callback when Flutter's engine notifies FlutterJNI
that Flutter is painting pixels to the Surface
that was provided to Flutter.
Definition at line 529 of file FlutterJNI.java.
|
inline |
Attaches this FlutterJNI
instance to Flutter's native engine, which allows for communication between Android code and Flutter's platform agnostic engine.
This method must not be invoked if FlutterJNI
is already attached to native.
Definition at line 419 of file FlutterJNI.java.
|
inline |
Destroys the resources provided sent to handlePlatformMessage
.
This can be called on any thread.
messageData | the argument sent to handlePlatformMessage. |
Definition at line 1048 of file FlutterJNI.java.
|
inline |
Invoked by native to obtain the results of Android's locale resolution algorithm.
Definition at line 1278 of file FlutterJNI.java.
|
inline |
Definition at line 1245 of file FlutterJNI.java.
|
inlinestatic |
Called by native as a fallback method of image decoding. There are other ways to decode images on lower API levels, they involve copying the native data and do not support any additional formats, whereas ImageDecoder supports HEIF images. Unlike most other methods called from native, this method is expected to be called on a worker thread, since it only uses thread safe methods and may take multiple frames to complete.
Definition at line 557 of file FlutterJNI.java.
|
inline |
Indicates that a failure was encountered during the Android portion of downloading a dynamic feature module and loading a dart deferred library, which is typically done by DeferredComponentManager.
This will inform dart that the future returned by loadLibrary() should complete with an error.
loadingUnitId | The loadingUnitId that corresponds to the dart deferred library that failed to install. |
error | The error message to display. |
isTransient | When isTransient is false, new attempts to install will automatically result in same error in Dart before the request is passed to Android. |
Definition at line 1431 of file FlutterJNI.java.
|
inline |
Definition at line 1256 of file FlutterJNI.java.
|
inline |
Detaches this FlutterJNI
instance from Flutter's native engine, which precludes any further communication between Android code and Flutter's platform agnostic engine.
This method must not be invoked if FlutterJNI
is not already attached to native.
Invoking this method will result in the release of all native-side resources that were set up during attachToNative()
or spawn(String, String, String, List)
, or accumulated thereafter.
It is permissible to re-attach this instance to native after detaching it from native.
Definition at line 493 of file FlutterJNI.java.
|
inline |
Sends an empty reply (identified by responseId
) from Android to Flutter over the given channel
.
Definition at line 1087 of file FlutterJNI.java.
|
inline |
Sends a reply message
from Android to Flutter over the given channel
.
Definition at line 1107 of file FlutterJNI.java.
|
inline |
Sends a packet of pointer data to Flutter's engine.
Definition at line 752 of file FlutterJNI.java.
|
inline |
Sends a semantics action to Flutter's engine, without any additional arguments.
Definition at line 828 of file FlutterJNI.java.
|
inline |
Sends a semantics action to Flutter's engine, with additional arguments.
Definition at line 833 of file FlutterJNI.java.
|
inline |
Sends a semantics action to Flutter's engine, given arguments that are already encoded for the engine.
To send a semantics action that has not already been encoded, see dispatchSemanticsAction(int, AccessibilityBridge.Action)
and dispatchSemanticsAction(int, AccessibilityBridge.Action, Object)
.
Definition at line 855 of file FlutterJNI.java.
|
inline |
Definition at line 1464 of file FlutterJNI.java.
|
inline |
Checks launch settings for whether software rendering is requested.
The value is the same per program.
Definition at line 239 of file FlutterJNI.java.
|
inlinestatic |
VM Service URI for the VM instance.
Its value is set by the native engine once init(Context, String[], String, String,
String, long)
is run.
getVMServiceUri()
. Definition at line 264 of file FlutterJNI.java.
|
inline |
Definition at line 1316 of file FlutterJNI.java.
|
inlinestatic |
VM Service URI for the VM instance.
Its value is set by the native engine once init(Context, String[], String, String,
String, long)
is run.
Definition at line 250 of file FlutterJNI.java.
|
inline |
Definition at line 1057 of file FlutterJNI.java.
|
inline |
Perform one time initialization of the Dart VM and Flutter engine.
This method must be called only once. Calling more than once will cause an exception.
context | The application context. |
args | Arguments to the Dart VM/Flutter engine. |
bundlePath | For JIT runtimes, the path to the Dart kernel file for the application. |
appStoragePath | The path to the application data directory. |
engineCachesPath | The path to the application cache directory. |
initTimeMillis | The time, in milliseconds, taken for initialization. |
Definition at line 194 of file FlutterJNI.java.
|
inline |
Definition at line 1131 of file FlutterJNI.java.
|
inline |
Definition at line 1153 of file FlutterJNI.java.
|
inline |
Returns true if this instance of FlutterJNI
is connected to Flutter's native engine via a Java Native Interface (JNI).
Definition at line 408 of file FlutterJNI.java.
|
inline |
Definition at line 353 of file FlutterJNI.java.
|
inline |
Definition at line 359 of file FlutterJNI.java.
|
inline |
Definition at line 365 of file FlutterJNI.java.
|
inline |
Definition at line 377 of file FlutterJNI.java.
|
inline |
Definition at line 371 of file FlutterJNI.java.
|
inline |
Searches each of the provided paths for a valid Dart shared library .so file and resolves symbols to load into the dart VM.
Successful loading of the dart library completes the future returned by loadLibrary() that triggered the install/load process.
loadingUnitId | The loadingUnitId is assigned during compile time by gen_snapshot and is automatically retrieved when loadLibrary() is called on a dart deferred library. This is used to identify which Dart deferred library the resolved correspond to. |
searchPaths | An array of paths in which to look for valid dart shared libraries. This supports paths within zipped apks as long as the apks are not compressed using the path/to/apk.apk!path/inside/apk/lib.so format. Paths will be tried first to last and ends when a library is successfully found. When the found library is invalid, no additional paths will be attempted. |
Definition at line 1383 of file FlutterJNI.java.
|
inline |
Loads the libflutter.so C++ library.
This must be called before any other native methods, and can be overridden by tests to avoid loading native libraries.
This method should only be called once across all FlutterJNI instances.
Definition at line 142 of file FlutterJNI.java.
|
inline |
Call this method to inform Flutter that a texture previously registered with registerTexture(long, SurfaceTextureWrapper)
has a new frame available.
Invoking this method instructs Flutter to update its presentation of the given texture so that the new frame is displayed.
Definition at line 941 of file FlutterJNI.java.
|
static |
|
static |
|
inline |
Notifies the Dart VM of a low memory event, or that the application is in a state such that now is an appropriate time to free resources, such as going to the background.
This is distinct from sending a SystemChannel message about low memory, which only notifies the running Flutter application.
Definition at line 1481 of file FlutterJNI.java.
|
inline |
Definition at line 1223 of file FlutterJNI.java.
|
inline |
Definition at line 1212 of file FlutterJNI.java.
|
inline |
Definition at line 1444 of file FlutterJNI.java.
|
inline |
Definition at line 1234 of file FlutterJNI.java.
|
inline |
Definition at line 587 of file FlutterJNI.java.
|
inlinepackage |
Definition at line 598 of file FlutterJNI.java.
Call this method when the Surface
changes that was previously registered with onSurfaceCreated(Surface)
.
See android.view.SurfaceHolder.Callback#surfaceChanged(SurfaceHolder, int, int, int)
for an example of where this call might originate.
Definition at line 647 of file FlutterJNI.java.
|
inline |
Call this method when a Surface
has been created onto which you would like Flutter to paint.
See android.view.SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)
for an example of where this call might originate.
Definition at line 614 of file FlutterJNI.java.
|
inline |
Call this method when the Surface
is destroyed that was previously registered with onSurfaceCreated(Surface)
.
See android.view.SurfaceHolder.Callback#surfaceDestroyed(SurfaceHolder)
for an example of where this call might originate.
Definition at line 663 of file FlutterJNI.java.
|
inline |
In hybrid composition, call this method when the Surface
has changed.
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 630 of file FlutterJNI.java.
|
inline |
Notifies the engine that the Choreographer has signaled a vsync.
frameDelayNanos | The time in nanoseconds when the frame started being rendered, subtracted from the System#nanoTime timebase. |
refreshPeriodNanos | The display refresh period in nanoseconds. |
cookie | An opaque handle to the C++ VSyncWaiter object. |
Definition at line 342 of file FlutterJNI.java.
|
inline |
Definition at line 431 of file FlutterJNI.java.
|
inline |
Prefetch the default font manager provided by txt::GetDefaultFontManager() which is a process-wide singleton owned by Skia. Note that, the first call to txt::GetDefaultFontManager() will take noticeable time, but later calls will return a reference to the preexisting font manager.
This method should only be called once across all FlutterJNI instances.
Definition at line 163 of file FlutterJNI.java.
|
inline |
Registers a ImageTexture with the given id.
REQUIRED: Callers should eventually unregisterTexture with the same id.
Definition at line 918 of file FlutterJNI.java.
|
inline |
Gives control of a SurfaceTexture
to Flutter so that Flutter can display that texture within Flutter's UI.
Definition at line 900 of file FlutterJNI.java.
|
inline |
Removes the given engineLifecycleListener
, which was previously added using addIsDisplayingFlutterUiListener(FlutterUiDisplayListener)
.
Definition at line 1196 of file FlutterJNI.java.
|
inline |
Removes a FlutterUiDisplayListener
that was added with addIsDisplayingFlutterUiListener(FlutterUiDisplayListener)
.
Definition at line 539 of file FlutterJNI.java.
|
inline |
Called by dart to request that a Dart deferred library corresponding to loadingUnitId be downloaded (if necessary) and loaded into the dart vm.
This method delegates the task to DeferredComponentManager, which handles the download and loading of the dart library and any assets.
loadingUnitId | The loadingUnitId is assigned during compile time by gen_snapshot and is automatically retrieved when loadLibrary() is called on a dart deferred library. |
Definition at line 1355 of file FlutterJNI.java.
|
inline |
Executes a Dart entrypoint.
This can only be done once per JNI attachment because a Dart isolate can only be entered once.
Definition at line 981 of file FlutterJNI.java.
|
inline |
Schedule the engine to draw a frame but does not invalidate the layout tree.
Definition at line 951 of file FlutterJNI.java.
|
inline |
Sets the AccessibilityDelegate
for the attached Flutter context.
The AccessibilityDelegate
is responsible for maintaining an Android-side cache of Flutter's semantics tree and custom accessibility actions. This cache should be hooked up to Android's accessibility system.
See AccessibilityBridge
for an example of an AccessibilityDelegate
and the surrounding responsibilities.
Definition at line 780 of file FlutterJNI.java.
|
inline |
Definition at line 885 of file FlutterJNI.java.
|
inline |
The Android vsync waiter implementation in C++ needs to know when a vsync signal arrives, which is obtained via Java API. The delegate set here is called on the C++ side when the engine is ready to wait for the next vsync signal. The delegate is expected to add a postFrameCallback to the android.view.Choreographer
, and call onVsync
to notify the engine.
delegate | The delegate that will call the engine back on the next vsync signal. |
Definition at line 317 of file FlutterJNI.java.
|
inline |
Sets the deferred component manager that is used to download and install split features.
Definition at line 1334 of file FlutterJNI.java.
|
inline |
Sets the localization plugin that is used in various localization methods.
Definition at line 1270 of file FlutterJNI.java.
|
inline |
Sets the handler for all platform messages that come from the attached platform view to Java.
Communication between a specific Flutter context (Dart) and the host platform (Java) is accomplished by passing messages. Messages can be sent from Java to Dart with the corresponding FlutterJNI
methods:
FlutterJNI
is also the recipient of all platform messages sent from its attached Flutter context. FlutterJNI
does not know what to do with these messages, so a handler is exposed to allow these messages to be processed in whatever manner is desired:
setPlatformMessageHandler(PlatformMessageHandler)
If a message is received but no PlatformMessageHandler
is registered, that message will be dropped (ignored). Therefore, when using FlutterJNI
to integrate a Flutter context in an app, a PlatformMessageHandler
must be registered for 2-way Java/Dart communication to operate correctly. Moreover, the handler must be implemented such that fundamental platform messages are handled as expected. See io.flutter.view.FlutterNativeView
for an example implementation.
Definition at line 1034 of file FlutterJNI.java.
|
inline |
Definition at line 763 of file FlutterJNI.java.
|
inline |
Notifies the engine about the refresh rate of the display when the API level is below 30.
For API 30 and above, this value is ignored.
Calling this method multiple times will update the refresh rate for the next vsync period. However, callers should avoid calling android.view.Display#getRefreshRate
frequently, since it is expensive on some vendor implementations.
refreshRateFPS | The refresh rate in nanoseconds. |
Definition at line 279 of file FlutterJNI.java.
|
inline |
Instructs Flutter to enable/disable its semantics tree, which is used by Flutter to support accessibility and related behaviors.
Definition at line 874 of file FlutterJNI.java.
|
inline |
Call this method to notify Flutter of the current device viewport metrics that are applies to the Flutter UI that is being rendered.
This method should be invoked with initial values upon attaching to native. Then, it should be invoked any time those metrics change while FlutterJNI
is attached to native.
Definition at line 680 of file FlutterJNI.java.
|
inline |
Spawns a new FlutterJNI instance from the current instance.
This creates another native shell from the current shell. This causes the 2 shells to re-use some of the shared resources, reducing the total memory consumption versus creating a new FlutterJNI by calling its standard constructor.
This can only be called once the current FlutterJNI instance is attached by calling attachToNative()
.
Static methods that should be only called once such as init(Context, String[],
String, String, String, long)
shouldn't be called again on the spawned FlutterJNI instance.
Definition at line 452 of file FlutterJNI.java.
|
inline |
Unregisters a texture that was registered with registerTexture(long,
SurfaceTextureWrapper)
.
Definition at line 964 of file FlutterJNI.java.
|
inline |
Definition at line 288 of file FlutterJNI.java.
|
inline |
Adds the specified AssetManager as an APKAssetResolver in the Flutter Engine's AssetManager.
This may be used to update the engine AssetManager when a new deferred component is installed and a new Android AssetManager is created with access to new assets.
assetManager | An android AssetManager that is able to access the newly downloaded assets. |
assetBundlePath | The subdirectory that the flutter assets are stored in. The typical value is flutter_assets . |
Definition at line 1403 of file FlutterJNI.java.
|
inline |
Definition at line 300 of file FlutterJNI.java.