Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
flutter::PlatformViewAndroid Class Referencefinal

#include <platform_view_android.h>

Inheritance diagram for flutter::PlatformViewAndroid:
flutter::PlatformView

Public Member Functions

 PlatformViewAndroid (PlatformView::Delegate &delegate, const flutter::TaskRunners &task_runners, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade, AndroidRenderingAPI rendering_api)
 
 PlatformViewAndroid (PlatformView::Delegate &delegate, const flutter::TaskRunners &task_runners, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade, const std::shared_ptr< flutter::AndroidContext > &android_context)
 Creates a new PlatformViewAndroid but using an existing Android GPU context to create new surfaces. This maximizes resource sharing between 2 PlatformViewAndroids of 2 Shells.
 
 ~PlatformViewAndroid () override
 
void NotifyCreated (fml::RefPtr< AndroidNativeWindow > native_window)
 
void NotifySurfaceWindowChanged (fml::RefPtr< AndroidNativeWindow > native_window)
 
void NotifyChanged (const DlISize &size)
 
void NotifyDestroyed () override
 Used by embedders to notify the shell that the platform view has been destroyed. This notification used to collect the rendering surface and all associated resources. Frame scheduling is also suspended.
 
void DispatchPlatformMessage (JNIEnv *env, std::string name, jobject message_data, jint message_position, jint response_id)
 
void DispatchEmptyPlatformMessage (JNIEnv *env, std::string name, jint response_id)
 
void DispatchSemanticsAction (JNIEnv *env, jint id, jint action, jobject args, jint args_position)
 
void RegisterExternalTexture (int64_t texture_id, const fml::jni::ScopedJavaGlobalRef< jobject > &surface_texture)
 
void RegisterImageTexture (int64_t texture_id, const fml::jni::ScopedJavaGlobalRef< jobject > &image_texture_entry, ImageExternalTexture::ImageLifecycle lifecycle)
 
void LoadDartDeferredLibrary (intptr_t loading_unit_id, std::unique_ptr< const fml::Mapping > snapshot_data, std::unique_ptr< const fml::Mapping > snapshot_instructions) override
 Loads the Dart shared library into the Dart VM. When the Dart library is loaded successfully, the Dart future returned by the originating loadLibrary() call completes.
 
void LoadDartDeferredLibraryError (intptr_t loading_unit_id, const std::string error_message, bool transient) override
 Indicates to the dart VM that the request to load a deferred library with the specified loading unit id has failed.
 
void UpdateAssetResolverByType (std::unique_ptr< AssetResolver > updated_asset_resolver, AssetResolver::AssetResolverType type) override
 Replaces the asset resolver handled by the engine's AssetManager of the specified type with updated_asset_resolver. The matching AssetResolver is removed and replaced with updated_asset_resolvers.
 
const std::shared_ptr< AndroidContext > & GetAndroidContext ()
 
std::shared_ptr< PlatformMessageHandlerGetPlatformMessageHandler () const override
 Specifies a delegate that will receive PlatformMessages from Flutter to the host platform.
 
bool IsSurfaceControlEnabled () const
 Whether the SurfaceControl based swapchain is enabled and active.
 
void SetupImpellerContext () override
 Performs any deferred setup of the Impeller context.
 
- Public Member Functions inherited from flutter::PlatformView
 PlatformView (Delegate &delegate, const TaskRunners &task_runners)
 Creates a platform view with the specified delegate and task runner. The base class by itself does not do much but is suitable for use in test environments where full platform integration may not be necessary. The platform view may only be created, accessed and destroyed on the platform task runner.
 
virtual ~PlatformView ()
 Destroys the platform view. The platform view is owned by the shell and will be destroyed by the same on the platform tasks runner.
 
void DispatchPlatformMessage (std::unique_ptr< PlatformMessage > message)
 Used by embedders to dispatch a platform message to a running root isolate hosted by the engine. If an isolate is not running, the message is dropped. If there is no one on the other side listening on the channel, the message is dropped. When a platform message is dropped, any response handles associated with that message will be dropped as well. All users of platform messages must assume that message may not be delivered and/or their response handles may not be invoked. Platform messages are not buffered.
 
virtual void HandlePlatformMessage (std::unique_ptr< PlatformMessage > message)
 Overridden by embedders to perform actions in response to platform messages sent from the framework to the embedder. Default implementation of this method simply returns an empty response.
 
void DispatchSemanticsAction (int64_t view_id, int32_t node_id, SemanticsAction action, fml::MallocMapping args)
 Used by embedders to dispatch an accessibility action to a running isolate hosted by the engine.
 
virtual void SetSemanticsEnabled (bool enabled)
 Used by embedder to notify the running isolate hosted by the engine on the UI thread that the accessibility tree needs to be generated.
 
virtual void SetAccessibilityFeatures (int32_t flags)
 Used by the embedder to specify the features to enable in the accessibility tree generated by the isolate. This information is forwarded to the root isolate hosted by the engine on the UI thread.
 
virtual void SendChannelUpdate (const std::string &name, bool listening)
 Used by the framework to tell the embedder that it has registered a listener on a given channel.
 
void SetViewportMetrics (int64_t view_id, const ViewportMetrics &metrics)
 Used by embedders to specify the updated viewport metrics for a view. In response to this call, on the raster thread, the rasterizer may need to be reconfigured to the updated viewport dimensions. On the UI thread, the framework may need to start generating a new frame for the updated viewport metrics as well.
 
void NotifyCreated ()
 Used by embedders to notify the shell that a platform view has been created. This notification is used to create a rendering surface and pick the client rendering API to use to render into this surface. No frames will be scheduled or rendered before this call. The surface must remain valid till the corresponding call to NotifyDestroyed.
 
void ScheduleFrame ()
 Used by embedders to schedule a frame. In response to this call, the framework may need to start generating a new frame.
 
void AddView (int64_t view_id, const ViewportMetrics &viewport_metrics, AddViewCallback callback)
 Used by embedders to notify the shell of a new non-implicit view.
 
void RemoveView (int64_t view_id, RemoveViewCallback callback)
 Used by embedders to notify the shell of a removed non-implicit view.
 
void SendViewFocusEvent (const ViewFocusEvent &event)
 
virtual PointerDataDispatcherMaker GetDispatcherMaker ()
 Returns a platform-specific PointerDataDispatcherMaker so the Engine can construct the PointerDataPacketDispatcher based on platforms.
 
fml::WeakPtr< PlatformViewGetWeakPtr () const
 Returns a weak pointer to the platform view. Since the platform view may only be created, accessed and destroyed on the platform thread, any access to the platform view from a non-platform task runner needs a weak pointer to the platform view along with a reference to the platform task runner. A task must be posted to the platform task runner with the weak pointer captured in the same. The platform view method may only be called in the posted task once the weak pointer validity has been checked. This method is used by callers to obtain that weak pointer.
 
void SetNextFrameCallback (const fml::closure &closure)
 Sets a callback that gets executed when the rasterizer renders the next frame. Due to the asynchronous nature of rendering in Flutter, embedders usually add a placeholder over the contents in which Flutter is going to render when Flutter is first initialized. This callback may be used as a signal to remove that placeholder. The callback is executed on the render task runner and not the platform task runner. It is the embedder's responsibility to re-thread as necessary.
 
void DispatchPointerDataPacket (std::unique_ptr< PointerDataPacket > packet)
 Dispatches pointer events from the embedder to the framework. Each pointer data packet may contain multiple pointer input events. Each call to this method wakes up the UI thread.
 
HitTestResponse HitTest (int64_t view_id, const flutter::PointData offset)
 Requests to perform framework hit test from the engine.
 
void RegisterTexture (std::shared_ptr< flutter::Texture > texture)
 Used by the embedder to specify a texture that it wants the rasterizer to composite within the Flutter layer tree. All textures must have a unique identifier. When the rasterizer encounters an external texture within its hierarchy, it gives the embedder a chance to update that texture on the raster thread before it composites the same on-screen.
 
void UnregisterTexture (int64_t texture_id)
 Used by the embedder to notify the rasterizer that it will no longer attempt to composite the specified texture within the layer tree. This allows the rasterizer to collect associated resources.
 
void MarkTextureFrameAvailable (int64_t texture_id)
 Used by the embedder to notify the rasterizer that the context of the previously registered texture have been updated. Typically, Flutter will only render a frame if there is an updated layer tree. However, in cases where the layer tree is static but one of the externally composited textures has been updated by the embedder, the embedder needs to notify the rasterizer to render a new frame. In such cases, the existing layer tree may be reused with the frame re-composited with all updated external textures. Unlike the calls to register and unregister the texture, this call must be made each time a new texture frame is available.
 
const SettingsGetSettings () const
 Get the settings for this platform view instance.
 
virtual void RequestViewFocusChange (const ViewFocusChangeRequest &request)
 Notifies the client that the Flutter view focus state has changed and the platform view should be updated.
 

Static Public Member Functions

static bool Register (JNIEnv *env)
 

Additional Inherited Members

- Public Types inherited from flutter::PlatformView
using AddViewCallback = std::function< void(bool added)>
 
using RemoveViewCallback = std::function< void(bool removed)>
 
- Protected Attributes inherited from flutter::PlatformView
PlatformView::Delegatedelegate_
 
const TaskRunners task_runners_
 
fml::WeakPtrFactory< PlatformViewweak_factory_
 

Detailed Description

Definition at line 43 of file platform_view_android.h.

Constructor & Destructor Documentation

◆ PlatformViewAndroid() [1/2]

flutter::PlatformViewAndroid::PlatformViewAndroid ( PlatformView::Delegate delegate,
const flutter::TaskRunners task_runners,
const std::shared_ptr< PlatformViewAndroidJNI > &  jni_facade,
AndroidRenderingAPI  rendering_api 
)

Definition at line 135 of file platform_view_android.cc.

141 delegate,
142 task_runners,
143 jni_facade,
145 task_runners,
146 rendering_api,
147 delegate.OnPlatformViewGetSettings().enable_opengl_gpu_tracing,
148 CreateContextSettings(delegate.OnPlatformViewGetSettings()),
149 delegate.OnPlatformViewGetShutdownSafeIOTaskRunner())) {}
PlatformViewAndroid(PlatformView::Delegate &delegate, const flutter::TaskRunners &task_runners, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade, AndroidRenderingAPI rendering_api)
static std::shared_ptr< flutter::AndroidContext > CreateAndroidContext(const flutter::TaskRunners &task_runners, AndroidRenderingAPI android_rendering_api, bool enable_opengl_gpu_tracing, const AndroidContext::ContextSettings &settings, std::shared_ptr< fml::BasicTaskRunner > io_task_runner)

◆ PlatformViewAndroid() [2/2]

flutter::PlatformViewAndroid::PlatformViewAndroid ( PlatformView::Delegate delegate,
const flutter::TaskRunners task_runners,
const std::shared_ptr< PlatformViewAndroidJNI > &  jni_facade,
const std::shared_ptr< flutter::AndroidContext > &  android_context 
)

Creates a new PlatformViewAndroid but using an existing Android GPU context to create new surfaces. This maximizes resource sharing between 2 PlatformViewAndroids of 2 Shells.

Definition at line 151 of file platform_view_android.cc.

156 : PlatformView(delegate, task_runners),
157 jni_facade_(jni_facade),
158 android_context_(android_context),
159 platform_view_android_delegate_(jni_facade),
160 platform_message_handler_(new PlatformMessageHandlerAndroid(jni_facade)) {
161 if (android_context_) {
162 FML_CHECK(android_context_->IsValid())
163 << "Could not create surface from invalid Android context.";
164 surface_factory_ = std::make_shared<AndroidSurfaceFactoryImpl>(
165 android_context_, //
166 delegate.OnPlatformViewGetSettings().enable_impeller, //
167 delegate.OnPlatformViewGetSettings()
168 .impeller_enable_lazy_shader_mode //
169 );
170 android_surface_ = surface_factory_->CreateSurface();
171 android_meets_hcpp_criteria_ =
172 delegate.OnPlatformViewGetSettings().enable_surface_control &&
173 android_get_device_api_level() >= kMinAPILevelHCPP &&
174 delegate.OnPlatformViewGetSettings().enable_impeller;
175 FML_CHECK(android_surface_ && android_surface_->IsValid())
176 << "Could not create an OpenGL, Vulkan or Software surface to set "
177 "up "
178 "rendering.";
179 }
180}
PlatformView(Delegate &delegate, const TaskRunners &task_runners)
Creates a platform view with the specified delegate and task runner. The base class by itself does no...
#define FML_CHECK(condition)
Definition logging.h:104

References flutter::Settings::enable_impeller, flutter::Settings::enable_surface_control, FML_CHECK, flutter::Settings::impeller_enable_lazy_shader_mode, and flutter::PlatformView::Delegate::OnPlatformViewGetSettings().

◆ ~PlatformViewAndroid()

flutter::PlatformViewAndroid::~PlatformViewAndroid ( )
overridedefault

Member Function Documentation

◆ DispatchEmptyPlatformMessage()

void flutter::PlatformViewAndroid::DispatchEmptyPlatformMessage ( JNIEnv *  env,
std::string  name,
jint  response_id 
)

Definition at line 271 of file platform_view_android.cc.

273 {
275 if (response_id) {
276 response = fml::MakeRefCounted<PlatformMessageResponseAndroid>(
277 response_id, jni_facade_, task_runners_.GetPlatformTaskRunner());
278 }
279
281 std::make_unique<flutter::PlatformMessage>(std::move(name),
282 std::move(response)));
283}
void DispatchPlatformMessage(std::unique_ptr< PlatformMessage > message)
Used by embedders to dispatch a platform message to a running root isolate hosted by the engine....
const TaskRunners task_runners_
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27

References flutter::PlatformView::DispatchPlatformMessage(), flutter::TaskRunners::GetPlatformTaskRunner(), flutter::name, and flutter::PlatformView::task_runners_.

◆ DispatchPlatformMessage()

void flutter::PlatformViewAndroid::DispatchPlatformMessage ( JNIEnv *  env,
std::string  name,
jobject  message_data,
jint  message_position,
jint  response_id 
)

Definition at line 250 of file platform_view_android.cc.

254 {
255 uint8_t* message_data =
256 static_cast<uint8_t*>(env->GetDirectBufferAddress(java_message_data));
258 fml::MallocMapping::Copy(message_data, java_message_position);
259
261 if (response_id) {
262 response = fml::MakeRefCounted<PlatformMessageResponseAndroid>(
263 response_id, jni_facade_, task_runners_.GetPlatformTaskRunner());
264 }
265
267 std::make_unique<flutter::PlatformMessage>(
268 std::move(name), std::move(message), std::move(response)));
269}
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition mapping.h:144
static MallocMapping Copy(const T *begin, const T *end)
Definition mapping.h:162
const char * message

References fml::MallocMapping::Copy(), flutter::PlatformView::DispatchPlatformMessage(), flutter::TaskRunners::GetPlatformTaskRunner(), message, flutter::name, and flutter::PlatformView::task_runners_.

◆ DispatchSemanticsAction()

void flutter::PlatformViewAndroid::DispatchSemanticsAction ( JNIEnv *  env,
jint  id,
jint  action,
jobject  args,
jint  args_position 
)

Definition at line 297 of file platform_view_android.cc.

301 {
302 // TODO(team-android): Remove implicit view assumption.
303 // https://github.com/flutter/flutter/issues/142845
304 if (env->IsSameObject(args, NULL)) {
306 kImplicitViewId, node_id, static_cast<flutter::SemanticsAction>(action),
308 return;
309 }
310
311 uint8_t* args_data = static_cast<uint8_t*>(env->GetDirectBufferAddress(args));
312 auto args_vector = fml::MallocMapping::Copy(args_data, args_position);
313
315 kImplicitViewId, node_id, static_cast<flutter::SemanticsAction>(action),
316 std::move(args_vector));
317}
void DispatchSemanticsAction(int64_t view_id, int32_t node_id, SemanticsAction action, fml::MallocMapping args)
Used by embedders to dispatch an accessibility action to a running isolate hosted by the engine.
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
constexpr FlutterViewId kImplicitViewId

References action, args, fml::MallocMapping::Copy(), flutter::PlatformView::DispatchSemanticsAction(), and flutter::kImplicitViewId.

◆ GetAndroidContext()

const std::shared_ptr< AndroidContext > & flutter::PlatformViewAndroid::GetAndroidContext ( )
inline

Definition at line 115 of file platform_view_android.h.

115 {
116 return android_context_;
117 }

Referenced by flutter::AndroidShellHolder::Spawn().

◆ GetPlatformMessageHandler()

std::shared_ptr< PlatformMessageHandler > flutter::PlatformViewAndroid::GetPlatformMessageHandler ( ) const
inlineoverridevirtual

Specifies a delegate that will receive PlatformMessages from Flutter to the host platform.

If this returns null that means PlatformMessages should be sent to the PlatformView. That is to protect legacy behavior, any embedder that wants to support executing Platform Channel handlers on background threads should be returning a thread-safe PlatformMessageHandler instead.

Reimplemented from flutter::PlatformView.

Definition at line 119 of file platform_view_android.h.

120 {
121 return platform_message_handler_;
122 }

◆ IsSurfaceControlEnabled()

bool flutter::PlatformViewAndroid::IsSurfaceControlEnabled ( ) const

Whether the SurfaceControl based swapchain is enabled and active.

Definition at line 558 of file platform_view_android.cc.

558 {
559 // This needs to know if we're actually using HCPP.
560 return android_meets_hcpp_criteria_ &&
561 android_context_->RenderingApi() ==
563 impeller::ContextVK::Cast(*android_context_->GetImpellerContext())
565}
static ContextVK & Cast(Context &base)
bool GetShouldEnableSurfaceControlSwapchain() const
Whether the Android Surface control based swapchain should be enabled.

References impeller::BackendCast< ContextVK, Context >::Cast(), and impeller::ContextVK::GetShouldEnableSurfaceControlSwapchain().

◆ LoadDartDeferredLibrary()

void flutter::PlatformViewAndroid::LoadDartDeferredLibrary ( intptr_t  loading_unit_id,
std::unique_ptr< const fml::Mapping snapshot_data,
std::unique_ptr< const fml::Mapping snapshot_instructions 
)
overridevirtual

Loads the Dart shared library into the Dart VM. When the Dart library is loaded successfully, the Dart future returned by the originating loadLibrary() call completes.

The Dart compiler may generate separate shared libraries files called 'loading units' when libraries are imported as deferred. Each of these shared libraries are identified by a unique loading unit id. Callers should open and resolve a SymbolMapping from the shared library. The Mappings should be moved into this method, as ownership will be assumed by the dart isolate after successful loading and released after shutdown of the dart isolate. If loading fails, the mappings will naturally go out of scope.

This method is paired with a RequestDartDeferredLibrary invocation that provides the embedder with the loading unit id of the deferred library to load.

Parameters
[in]loading_unit_idThe unique id of the deferred library's loading unit, as passed in by RequestDartDeferredLibrary.
[in]snapshot_dataDart snapshot data of the loading unit's shared library.
[in]snapshot_dataDart snapshot instructions of the loading unit's shared library.

Reimplemented from flutter::PlatformView.

Definition at line 508 of file platform_view_android.cc.

511 {
512 delegate_.LoadDartDeferredLibrary(loading_unit_id, std::move(snapshot_data),
513 std::move(snapshot_instructions));
514}
virtual void LoadDartDeferredLibrary(intptr_t loading_unit_id, std::unique_ptr< const fml::Mapping > snapshot_data, std::unique_ptr< const fml::Mapping > snapshot_instructions)=0
Loads the dart shared library into the dart VM. When the dart library is loaded successfully,...
PlatformView::Delegate & delegate_

References flutter::PlatformView::delegate_, and flutter::PlatformView::Delegate::LoadDartDeferredLibrary().

◆ LoadDartDeferredLibraryError()

void flutter::PlatformViewAndroid::LoadDartDeferredLibraryError ( intptr_t  loading_unit_id,
const std::string  error_message,
bool  transient 
)
overridevirtual

Indicates to the dart VM that the request to load a deferred library with the specified loading unit id has failed.

The dart future returned by the initiating loadLibrary() call will complete with an error.

Parameters
[in]loading_unit_idThe unique id of the deferred library's loading unit, as passed in by RequestDartDeferredLibrary.
[in]error_messageThe error message that will appear in the dart Future.
[in]transientA transient error is a failure due to temporary conditions such as no network. Transient errors allow the dart VM to re-request the same deferred library and loading_unit_id again. Non-transient errors are permanent and attempts to re-request the library will instantly complete with an error.

Reimplemented from flutter::PlatformView.

Definition at line 517 of file platform_view_android.cc.

520 {
521 delegate_.LoadDartDeferredLibraryError(loading_unit_id, error_message,
522 transient);
523}
virtual void LoadDartDeferredLibraryError(intptr_t loading_unit_id, const std::string error_message, bool transient)=0
Indicates to the dart VM that the request to load a deferred library with the specified loading unit ...

References flutter::PlatformView::delegate_, and flutter::PlatformView::Delegate::LoadDartDeferredLibraryError().

◆ NotifyChanged()

void flutter::PlatformViewAndroid::NotifyChanged ( const DlISize size)

Definition at line 236 of file platform_view_android.cc.

236 {
237 if (!android_surface_) {
238 return;
239 }
243 [&latch, surface = android_surface_.get(), size]() {
244 surface->OnScreenSurfaceResize(size);
245 latch.Signal();
246 });
247 latch.Wait();
248}
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size

References flutter::TaskRunners::GetRasterTaskRunner(), fml::TaskRunner::RunNowOrPostTask(), flutter::size, surface, flutter::PlatformView::task_runners_, and fml::AutoResetWaitableEvent::Wait().

◆ NotifyCreated()

void flutter::PlatformViewAndroid::NotifyCreated ( fml::RefPtr< AndroidNativeWindow native_window)

Definition at line 184 of file platform_view_android.cc.

185 {
186 if (android_surface_) {
187 InstallFirstFrameCallback();
188
192 [&latch, surface = android_surface_.get(),
193 native_window = std::move(native_window), jni_facade = jni_facade_]() {
194 surface->SetNativeWindow(native_window, jni_facade);
195 latch.Signal();
196 });
197 latch.Wait();
198 }
199
201}
void NotifyCreated()
Used by embedders to notify the shell that a platform view has been created. This notification is use...

References flutter::TaskRunners::GetRasterTaskRunner(), flutter::PlatformView::NotifyCreated(), fml::TaskRunner::RunNowOrPostTask(), surface, flutter::PlatformView::task_runners_, and fml::AutoResetWaitableEvent::Wait().

◆ NotifyDestroyed()

void flutter::PlatformViewAndroid::NotifyDestroyed ( )
overridevirtual

Used by embedders to notify the shell that the platform view has been destroyed. This notification used to collect the rendering surface and all associated resources. Frame scheduling is also suspended.

Attention
Subclasses may choose to override this method to perform platform specific functions. However, they must call the base class method at some point in their implementation.

Reimplemented from flutter::PlatformView.

Definition at line 221 of file platform_view_android.cc.

221 {
223
224 if (android_surface_) {
228 [&latch, surface = android_surface_.get()]() {
229 surface->TeardownOnScreenContext();
230 latch.Signal();
231 });
232 latch.Wait();
233 }
234}
virtual void NotifyDestroyed()
Used by embedders to notify the shell that the platform view has been destroyed. This notification us...

References flutter::TaskRunners::GetRasterTaskRunner(), flutter::PlatformView::NotifyDestroyed(), fml::TaskRunner::RunNowOrPostTask(), surface, flutter::PlatformView::task_runners_, and fml::AutoResetWaitableEvent::Wait().

◆ NotifySurfaceWindowChanged()

void flutter::PlatformViewAndroid::NotifySurfaceWindowChanged ( fml::RefPtr< AndroidNativeWindow native_window)

Definition at line 203 of file platform_view_android.cc.

204 {
205 if (android_surface_) {
209 [&latch, surface = android_surface_.get(),
210 native_window = std::move(native_window), jni_facade = jni_facade_]() {
211 surface->TeardownOnScreenContext();
212 surface->SetNativeWindow(native_window, jni_facade);
213 latch.Signal();
214 });
215 latch.Wait();
216 }
217
219}
void ScheduleFrame()
Used by embedders to schedule a frame. In response to this call, the framework may need to start gene...

References flutter::TaskRunners::GetRasterTaskRunner(), fml::TaskRunner::RunNowOrPostTask(), flutter::PlatformView::ScheduleFrame(), surface, flutter::PlatformView::task_runners_, and fml::AutoResetWaitableEvent::Wait().

◆ Register()

bool flutter::PlatformViewAndroid::Register ( JNIEnv *  env)
static

Definition at line 1034 of file platform_view_android_jni_impl.cc.

1034 {
1035 if (env == nullptr) {
1036 FML_LOG(ERROR) << "No JNIEnv provided";
1037 return false;
1038 }
1039
1041 env, env->FindClass("io/flutter/view/FlutterCallbackInformation"));
1042 if (g_flutter_callback_info_class->is_null()) {
1043 FML_LOG(ERROR) << "Could not locate FlutterCallbackInformation class";
1044 return false;
1045 }
1046
1047 g_flutter_callback_info_constructor = env->GetMethodID(
1048 g_flutter_callback_info_class->obj(), "<init>",
1049 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
1050 if (g_flutter_callback_info_constructor == nullptr) {
1051 FML_LOG(ERROR) << "Could not locate FlutterCallbackInformation constructor";
1052 return false;
1053 }
1054
1056 env, env->FindClass("io/flutter/embedding/engine/FlutterJNI"));
1057 if (g_flutter_jni_class->is_null()) {
1058 FML_LOG(ERROR) << "Failed to find FlutterJNI Class.";
1059 return false;
1060 }
1061
1063 env,
1064 env->FindClass(
1065 "io/flutter/embedding/engine/mutatorsstack/FlutterMutatorsStack"));
1066 if (g_mutators_stack_class == nullptr) {
1067 FML_LOG(ERROR) << "Could not locate FlutterMutatorsStack";
1068 return false;
1069 }
1070
1072 env->GetMethodID(g_mutators_stack_class->obj(), "<init>", "()V");
1073 if (g_mutators_stack_init_method == nullptr) {
1074 FML_LOG(ERROR) << "Could not locate FlutterMutatorsStack.init method";
1075 return false;
1076 }
1077
1079 env->GetMethodID(g_mutators_stack_class->obj(), "pushTransform", "([F)V");
1081 FML_LOG(ERROR)
1082 << "Could not locate FlutterMutatorsStack.pushTransform method";
1083 return false;
1084 }
1085
1086 g_mutators_stack_push_cliprect_method = env->GetMethodID(
1087 g_mutators_stack_class->obj(), "pushClipRect", "(IIII)V");
1089 FML_LOG(ERROR)
1090 << "Could not locate FlutterMutatorsStack.pushClipRect method";
1091 return false;
1092 }
1093
1094 g_mutators_stack_push_cliprrect_method = env->GetMethodID(
1095 g_mutators_stack_class->obj(), "pushClipRRect", "(IIII[F)V");
1097 FML_LOG(ERROR)
1098 << "Could not locate FlutterMutatorsStack.pushClipRRect method";
1099 return false;
1100 }
1101
1103 env->GetMethodID(g_mutators_stack_class->obj(), "pushOpacity", "(F)V");
1104 if (g_mutators_stack_push_opacity_method == nullptr) {
1105 FML_LOG(ERROR)
1106 << "Could not locate FlutterMutatorsStack.pushOpacity method";
1107 return false;
1108 }
1109
1111 env->GetMethodID(g_mutators_stack_class->obj(), "pushClipPath",
1112 "(Landroid/graphics/Path;)V");
1114 FML_LOG(ERROR)
1115 << "Could not locate FlutterMutatorsStack.pushClipPath method";
1116 return false;
1117 }
1118
1120 env, env->FindClass("java/lang/ref/WeakReference"));
1121 if (g_java_weak_reference_class->is_null()) {
1122 FML_LOG(ERROR) << "Could not locate WeakReference class";
1123 return false;
1124 }
1125
1126 g_java_weak_reference_get_method = env->GetMethodID(
1127 g_java_weak_reference_class->obj(), "get", "()Ljava/lang/Object;");
1128 if (g_java_weak_reference_get_method == nullptr) {
1129 FML_LOG(ERROR) << "Could not locate WeakReference.get method";
1130 return false;
1131 }
1132
1134 env, env->FindClass(
1135 "io/flutter/embedding/engine/renderer/SurfaceTextureWrapper"));
1136 if (g_texture_wrapper_class->is_null()) {
1137 FML_LOG(ERROR) << "Could not locate SurfaceTextureWrapper class";
1138 return false;
1139 }
1140
1141 g_attach_to_gl_context_method = env->GetMethodID(
1142 g_texture_wrapper_class->obj(), "attachToGLContext", "(I)V");
1143
1144 if (g_attach_to_gl_context_method == nullptr) {
1145 FML_LOG(ERROR) << "Could not locate attachToGlContext method";
1146 return false;
1147 }
1148
1150 env->GetMethodID(g_texture_wrapper_class->obj(), "shouldUpdate", "()Z");
1151
1153 FML_LOG(ERROR)
1154 << "Could not locate SurfaceTextureWrapper.shouldUpdate method";
1155 return false;
1156 }
1157
1159 env->GetMethodID(g_texture_wrapper_class->obj(), "updateTexImage", "()V");
1160
1161 if (g_update_tex_image_method == nullptr) {
1162 FML_LOG(ERROR) << "Could not locate updateTexImage method";
1163 return false;
1164 }
1165
1166 g_get_transform_matrix_method = env->GetMethodID(
1167 g_texture_wrapper_class->obj(), "getTransformMatrix", "([F)V");
1168
1169 if (g_get_transform_matrix_method == nullptr) {
1170 FML_LOG(ERROR) << "Could not locate getTransformMatrix method";
1171 return false;
1172 }
1173
1174 g_detach_from_gl_context_method = env->GetMethodID(
1175 g_texture_wrapper_class->obj(), "detachFromGLContext", "()V");
1176
1177 if (g_detach_from_gl_context_method == nullptr) {
1178 FML_LOG(ERROR) << "Could not locate detachFromGlContext method";
1179 return false;
1180 }
1183 env, env->FindClass("io/flutter/view/TextureRegistry$ImageConsumer"));
1185 FML_LOG(ERROR) << "Could not locate TextureRegistry.ImageConsumer class";
1186 return false;
1187 }
1188
1190 env->GetMethodID(g_image_consumer_texture_registry_interface->obj(),
1191 "acquireLatestImage", "()Landroid/media/Image;");
1192 if (g_acquire_latest_image_method == nullptr) {
1193 FML_LOG(ERROR) << "Could not locate acquireLatestImage on "
1194 "TextureRegistry.ImageConsumer class";
1195 return false;
1196 }
1197
1199 env, env->FindClass("android/media/Image"));
1200 if (g_image_class->is_null()) {
1201 FML_LOG(ERROR) << "Could not locate Image class";
1202 return false;
1203 }
1204
1205 // Ensure we don't have any pending exceptions.
1207
1209 env->GetMethodID(g_image_class->obj(), "getHardwareBuffer",
1210 "()Landroid/hardware/HardwareBuffer;");
1211
1212 if (g_image_get_hardware_buffer_method == nullptr) {
1213 // Continue on as this method may not exist at API <= 29.
1214 fml::jni::ClearException(env, true);
1215 }
1216
1217 g_image_close_method = env->GetMethodID(g_image_class->obj(), "close", "()V");
1218
1219 if (g_image_close_method == nullptr) {
1220 FML_LOG(ERROR) << "Could not locate close on Image class";
1221 return false;
1222 }
1223
1224 // Ensure we don't have any pending exceptions.
1227 env, env->FindClass("android/hardware/HardwareBuffer"));
1228
1229 if (!g_hardware_buffer_class->is_null()) {
1231 env->GetMethodID(g_hardware_buffer_class->obj(), "close", "()V");
1232 if (g_hardware_buffer_close_method == nullptr) {
1233 // Continue on as this class may not exist at API <= 26.
1234 fml::jni::ClearException(env, true);
1235 }
1236 } else {
1237 // Continue on as this class may not exist at API <= 26.
1238 fml::jni::ClearException(env, true);
1239 }
1240
1242 g_flutter_jni_class->obj(), "computePlatformResolvedLocale",
1243 "([Ljava/lang/String;)[Ljava/lang/String;");
1244
1246 FML_LOG(ERROR) << "Could not locate computePlatformResolvedLocale method";
1247 return false;
1248 }
1249
1250 g_request_dart_deferred_library_method = env->GetMethodID(
1251 g_flutter_jni_class->obj(), "requestDartDeferredLibrary", "(I)V");
1252
1254 FML_LOG(ERROR) << "Could not locate requestDartDeferredLibrary method";
1255 return false;
1256 }
1257
1259 env, env->FindClass("java/lang/Long"));
1260 if (g_java_long_class->is_null()) {
1261 FML_LOG(ERROR) << "Could not locate java.lang.Long class";
1262 return false;
1263 }
1264
1265 // Android path class and methods.
1267 env, env->FindClass("android/graphics/Path"));
1268 if (path_class->is_null()) {
1269 FML_LOG(ERROR) << "Could not locate android.graphics.Path class";
1270 return false;
1271 }
1272
1273 path_constructor = env->GetMethodID(path_class->obj(), "<init>", "()V");
1274 if (path_constructor == nullptr) {
1275 FML_LOG(ERROR) << "Could not locate android.graphics.Path constructor";
1276 return false;
1277 }
1278
1279 path_set_fill_type_method = env->GetMethodID(
1280 path_class->obj(), "setFillType", "(Landroid/graphics/Path$FillType;)V");
1281 if (path_set_fill_type_method == nullptr) {
1282 FML_LOG(ERROR)
1283 << "Could not locate android.graphics.Path.setFillType method";
1284 return false;
1285 }
1286
1287 path_move_to_method = env->GetMethodID(path_class->obj(), "moveTo", "(FF)V");
1288 if (path_move_to_method == nullptr) {
1289 FML_LOG(ERROR) << "Could not locate android.graphics.Path.moveTo method";
1290 return false;
1291 }
1292 path_line_to_method = env->GetMethodID(path_class->obj(), "lineTo", "(FF)V");
1293 if (path_line_to_method == nullptr) {
1294 FML_LOG(ERROR) << "Could not locate android.graphics.Path.lineTo method";
1295 return false;
1296 }
1298 env->GetMethodID(path_class->obj(), "quadTo", "(FFFF)V");
1299 if (path_quad_to_method == nullptr) {
1300 FML_LOG(ERROR) << "Could not locate android.graphics.Path.quadTo method";
1301 return false;
1302 }
1304 env->GetMethodID(path_class->obj(), "cubicTo", "(FFFFFF)V");
1305 if (path_cubic_to_method == nullptr) {
1306 FML_LOG(ERROR) << "Could not locate android.graphics.Path.cubicTo method";
1307 return false;
1308 }
1309 // Ensure we don't have any pending exceptions.
1311
1313 env->GetMethodID(path_class->obj(), "conicTo", "(FFFFF)V");
1314 if (path_conic_to_method == nullptr) {
1315 // Continue on as this method may not exist at API <= 34.
1316 fml::jni::ClearException(env, true);
1317 }
1318 path_close_method = env->GetMethodID(path_class->obj(), "close", "()V");
1319 if (path_close_method == nullptr) {
1320 FML_LOG(ERROR) << "Could not locate android.graphics.Path.close method";
1321 return false;
1322 }
1323
1325 env, env->FindClass("android/graphics/Path$FillType"));
1326 if (g_path_fill_type_class->is_null()) {
1327 FML_LOG(ERROR) << "Could not locate android.graphics.Path$FillType class";
1328 return false;
1329 }
1330
1332 env->GetStaticFieldID(g_path_fill_type_class->obj(), "WINDING",
1333 "Landroid/graphics/Path$FillType;");
1334 if (g_path_fill_type_winding_field == nullptr) {
1335 FML_LOG(ERROR) << "Could not locate Path.FillType.WINDING field";
1336 return false;
1337 }
1338
1340 env->GetStaticFieldID(g_path_fill_type_class->obj(), "EVEN_ODD",
1341 "Landroid/graphics/Path$FillType;");
1342 if (g_path_fill_type_even_odd_field == nullptr) {
1343 FML_LOG(ERROR) << "Could not locate Path.FillType.EVEN_ODD field";
1344 return false;
1345 }
1346
1347 return RegisterApi(env);
1348}
#define FML_LOG(severity)
Definition logging.h:101
static jmethodID g_hardware_buffer_close_method
static jmethodID g_mutators_stack_init_method
static jmethodID g_request_dart_deferred_library_method
bool RegisterApi(JNIEnv *env)
static jmethodID g_mutators_stack_push_clippath_method
static fml::jni::ScopedJavaGlobalRef< jclass > * path_class
static fml::jni::ScopedJavaGlobalRef< jclass > * g_java_long_class
static jmethodID g_acquire_latest_image_method
static jmethodID g_mutators_stack_push_transform_method
static jmethodID path_line_to_method
static jmethodID path_quad_to_method
static jmethodID g_attach_to_gl_context_method
static jfieldID g_path_fill_type_even_odd_field
static jfieldID g_path_fill_type_winding_field
static fml::jni::ScopedJavaGlobalRef< jclass > * g_texture_wrapper_class
static jmethodID g_java_weak_reference_get_method
static jmethodID g_image_get_hardware_buffer_method
static jmethodID g_mutators_stack_push_cliprect_method
static jmethodID g_mutators_stack_push_cliprrect_method
static jmethodID g_get_transform_matrix_method
static jmethodID path_cubic_to_method
static jmethodID g_compute_platform_resolved_locale_method
static fml::jni::ScopedJavaGlobalRef< jclass > * g_flutter_jni_class
static jmethodID g_surface_texture_wrapper_should_update
static fml::jni::ScopedJavaGlobalRef< jclass > * g_image_class
static jmethodID g_flutter_callback_info_constructor
static jmethodID path_set_fill_type_method
static fml::jni::ScopedJavaGlobalRef< jclass > * g_path_fill_type_class
static jmethodID path_move_to_method
static jmethodID g_update_tex_image_method
static fml::jni::ScopedJavaGlobalRef< jclass > * g_java_weak_reference_class
static jmethodID g_image_close_method
static jmethodID g_mutators_stack_push_opacity_method
static fml::jni::ScopedJavaGlobalRef< jclass > * g_image_consumer_texture_registry_interface
static jmethodID path_constructor
static fml::jni::ScopedJavaGlobalRef< jclass > * g_flutter_callback_info_class
static fml::jni::ScopedJavaGlobalRef< jclass > * g_mutators_stack_class
static jmethodID path_close_method
static jmethodID g_detach_from_gl_context_method
static jmethodID path_conic_to_method
static fml::jni::ScopedJavaGlobalRef< jclass > * g_hardware_buffer_class
bool ClearException(JNIEnv *env, bool silent)
Definition jni_util.cc:188
bool CheckException(JNIEnv *env)
Definition jni_util.cc:199

References fml::jni::CheckException(), fml::jni::ClearException(), FML_CHECK, FML_LOG, flutter::g_acquire_latest_image_method, flutter::g_attach_to_gl_context_method, flutter::g_compute_platform_resolved_locale_method, flutter::g_detach_from_gl_context_method, flutter::g_flutter_callback_info_class, flutter::g_flutter_callback_info_constructor, flutter::g_flutter_jni_class, flutter::g_get_transform_matrix_method, flutter::g_hardware_buffer_class, flutter::g_hardware_buffer_close_method, flutter::g_image_class, flutter::g_image_close_method, flutter::g_image_consumer_texture_registry_interface, flutter::g_image_get_hardware_buffer_method, flutter::g_java_long_class, flutter::g_java_weak_reference_class, flutter::g_java_weak_reference_get_method, flutter::g_mutators_stack_class, flutter::g_mutators_stack_init_method, flutter::g_mutators_stack_push_clippath_method, flutter::g_mutators_stack_push_cliprect_method, flutter::g_mutators_stack_push_cliprrect_method, flutter::g_mutators_stack_push_opacity_method, flutter::g_mutators_stack_push_transform_method, flutter::g_path_fill_type_class, flutter::g_path_fill_type_even_odd_field, flutter::g_path_fill_type_winding_field, flutter::g_request_dart_deferred_library_method, flutter::g_surface_texture_wrapper_should_update, flutter::g_texture_wrapper_class, flutter::g_update_tex_image_method, flutter::path_class, flutter::path_close_method, flutter::path_conic_to_method, flutter::path_constructor, flutter::path_cubic_to_method, flutter::path_line_to_method, flutter::path_move_to_method, flutter::path_quad_to_method, flutter::path_set_fill_type_method, and flutter::RegisterApi().

Referenced by JNI_OnLoad(), and flutter::testing::TEST_F().

◆ RegisterExternalTexture()

void flutter::PlatformViewAndroid::RegisterExternalTexture ( int64_t  texture_id,
const fml::jni::ScopedJavaGlobalRef< jobject > &  surface_texture 
)

Definition at line 337 of file platform_view_android.cc.

339 {
340 switch (android_context_->RenderingApi()) {
342 // Impeller GLES.
343 RegisterTexture(std::make_shared<SurfaceTextureExternalTextureGLImpeller>(
344 std::static_pointer_cast<impeller::ContextGLES>(
345 android_context_->GetImpellerContext()), //
346 texture_id, //
347 surface_texture, //
348 jni_facade_ //
349 ));
350 break;
351#if !SLIMPELLER
353 // Legacy GL.
354 RegisterTexture(std::make_shared<SurfaceTextureExternalTextureGLSkia>(
355 texture_id, //
356 surface_texture, //
357 jni_facade_ //
358 ));
359 break;
361 FML_LOG(INFO) << "Software rendering does not support external textures.";
362 break;
363#endif // !SLIMPELLER
365 FML_LOG(IMPORTANT)
366 << "Flutter recommends migrating plugins that create and "
367 "register surface textures to the new surface producer "
368 "API. See https://docs.flutter.dev/release/breaking-changes/"
369 "android-surface-plugins";
370 RegisterTexture(std::make_shared<SurfaceTextureExternalTextureVKImpeller>(
371 std::static_pointer_cast<impeller::ContextVK>(
372 android_context_->GetImpellerContext()), //
373 texture_id, //
374 surface_texture, //
375 jni_facade_ //
376 ));
377 break;
379 default:
380 FML_CHECK(false);
381 break;
382 }
383}
void RegisterTexture(std::shared_ptr< flutter::Texture > texture)
Used by the embedder to specify a texture that it wants the rasterizer to composite within the Flutte...
int64_t texture_id

References FML_CHECK, FML_LOG, flutter::kImpellerAutoselect, flutter::kImpellerOpenGLES, flutter::kImpellerVulkan, flutter::kSkiaOpenGLES, flutter::kSoftware, flutter::PlatformView::RegisterTexture(), and texture_id.

◆ RegisterImageTexture()

void flutter::PlatformViewAndroid::RegisterImageTexture ( int64_t  texture_id,
const fml::jni::ScopedJavaGlobalRef< jobject > &  image_texture_entry,
ImageExternalTexture::ImageLifecycle  lifecycle 
)

Definition at line 385 of file platform_view_android.cc.

388 {
389 switch (android_context_->RenderingApi()) {
390#if !SLIMPELLER
392 // Legacy GL.
393 RegisterTexture(std::make_shared<ImageExternalTextureGLSkia>(
394 std::static_pointer_cast<AndroidContextGLSkia>(android_context_),
395 texture_id, image_texture_entry, jni_facade_, lifecycle));
396 break;
398 FML_LOG(INFO) << "Software rendering does not support external textures.";
399 break;
400#endif // !SLIMPELLER
402 // Impeller GLES.
403 RegisterTexture(std::make_shared<ImageExternalTextureGLImpeller>(
404 std::static_pointer_cast<impeller::ContextGLES>(
405 android_context_->GetImpellerContext()),
406 texture_id, image_texture_entry, jni_facade_, lifecycle));
407 break;
409 RegisterTexture(std::make_shared<ImageExternalTextureVKImpeller>(
410 std::static_pointer_cast<impeller::ContextVK>(
411 android_context_->GetImpellerContext()),
412 texture_id, image_texture_entry, jni_facade_, lifecycle));
413 break;
415 FML_CHECK(false);
416 break;
417 }
418}

References FML_CHECK, FML_LOG, flutter::kImpellerAutoselect, flutter::kImpellerOpenGLES, flutter::kImpellerVulkan, flutter::kSkiaOpenGLES, flutter::kSoftware, flutter::PlatformView::RegisterTexture(), and texture_id.

◆ SetupImpellerContext()

void flutter::PlatformViewAndroid::SetupImpellerContext ( )
overridevirtual

Performs any deferred setup of the Impeller context.

        This is intended to be called from the raster thread so that
        Impeller context creation can be moved off the startup path. 

Reimplemented from flutter::PlatformView.

Definition at line 567 of file platform_view_android.cc.

567 {
568 android_context_->SetupImpellerContext();
569 android_surface_->SetupImpellerSurface();
570}

◆ UpdateAssetResolverByType()

void flutter::PlatformViewAndroid::UpdateAssetResolverByType ( std::unique_ptr< AssetResolver updated_asset_resolver,
AssetResolver::AssetResolverType  type 
)
overridevirtual

Replaces the asset resolver handled by the engine's AssetManager of the specified type with updated_asset_resolver. The matching AssetResolver is removed and replaced with updated_asset_resolvers.

AssetResolvers should be updated when the existing resolver becomes obsolete and a newer one becomes available that provides updated access to the same type of assets as the existing one. This update process is meant to be performed at runtime.

If a null resolver is provided, nothing will be done. If no matching resolver is found, the provided resolver will be added to the end of the AssetManager resolvers queue. The replacement only occurs with the first matching resolver. Any additional matching resolvers are untouched.

Parameters
[in]updated_asset_resolverThe asset resolver to replace the resolver of matching type with.
[in]typeThe type of AssetResolver to update. Only resolvers of the specified type will be replaced by the updated resolver.

Reimplemented from flutter::PlatformView.

Definition at line 526 of file platform_view_android.cc.

528 {
529 delegate_.UpdateAssetResolverByType(std::move(updated_asset_resolver), type);
530}
virtual void UpdateAssetResolverByType(std::unique_ptr< AssetResolver > updated_asset_resolver, AssetResolver::AssetResolverType type)=0
Replaces the asset resolver handled by the engine's AssetManager of the specified type with updated_a...
impeller::ShaderType type

References flutter::PlatformView::delegate_, type, and flutter::PlatformView::Delegate::UpdateAssetResolverByType().


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