Flutter Engine
flutter::PlatformViewAndroid Class Referencefinal

#include <platform_view_android.h>

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

Public Member Functions

 PlatformViewAndroid (PlatformView::Delegate &delegate, flutter::TaskRunners task_runners, std::shared_ptr< PlatformViewAndroidJNI > jni_facade, bool use_software_rendering)
 
 PlatformViewAndroid (PlatformView::Delegate &delegate, 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. More...
 
 ~PlatformViewAndroid () override
 
void NotifyCreated (fml::RefPtr< AndroidNativeWindow > native_window)
 
void NotifySurfaceWindowChanged (fml::RefPtr< AndroidNativeWindow > native_window)
 
void NotifyChanged (const SkISize &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. More...
 
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 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. More...
 
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. More...
 
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. More...
 
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. More...
 
- Public Member Functions inherited from flutter::PlatformView
 PlatformView (Delegate &delegate, 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. More...
 
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. More...
 
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. More...
 
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. More...
 
void DispatchSemanticsAction (int32_t id, SemanticsAction action, fml::MallocMapping args)
 Used by embedders to dispatch an accessibility action to a running isolate hosted by the engine. More...
 
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. More...
 
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. More...
 
void SetViewportMetrics (const ViewportMetrics &metrics)
 Used by embedders to specify the updated viewport metrics. 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. More...
 
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. More...
 
virtual PointerDataDispatcherMaker GetDispatcherMaker ()
 Returns a platform-specific PointerDataDispatcherMaker so the Engine can construct the PointerDataPacketDispatcher based on platforms. More...
 
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. More...
 
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. More...
 
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. More...
 
void DispatchKeyDataPacket (std::unique_ptr< KeyDataPacket > packet, Delegate::KeyDataResponse callback)
 Dispatches key events from the embedder to the framework. Each key data packet contains one physical event and multiple logical key events. Each call to this method wakes up the UI thread. More...
 
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. More...
 
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. More...
 
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. More...
 

Static Public Member Functions

static bool Register (JNIEnv *env)
 

Additional Inherited Members

- Protected Attributes inherited from flutter::PlatformView
PlatformView::Delegatedelegate_
 
const TaskRunners task_runners_
 
PointerDataPacketConverter pointer_data_packet_converter_
 
SkISize size_
 
fml::WeakPtrFactory< PlatformViewweak_factory_
 

Detailed Description

Definition at line 41 of file platform_view_android.h.

Constructor & Destructor Documentation

◆ PlatformViewAndroid() [1/2]

flutter::PlatformViewAndroid::PlatformViewAndroid ( PlatformView::Delegate delegate,
flutter::TaskRunners  task_runners,
std::shared_ptr< PlatformViewAndroidJNI jni_facade,
bool  use_software_rendering 
)

Definition at line 58 of file platform_view_android.cc.

63  : PlatformViewAndroid(delegate,
64  std::move(task_runners),
65  std::move(jni_facade),
66  CreateAndroidContext(use_software_rendering)) {}
static std::shared_ptr< flutter::AndroidContext > CreateAndroidContext(bool use_software_rendering)
PlatformViewAndroid(PlatformView::Delegate &delegate, flutter::TaskRunners task_runners, std::shared_ptr< PlatformViewAndroidJNI > jni_facade, bool use_software_rendering)

◆ PlatformViewAndroid() [2/2]

flutter::PlatformViewAndroid::PlatformViewAndroid ( PlatformView::Delegate delegate,
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 68 of file platform_view_android.cc.

References FML_CHECK, and ~PlatformViewAndroid().

73  : PlatformView(delegate, std::move(task_runners)),
74  jni_facade_(jni_facade),
75  android_context_(std::move(android_context)),
76  platform_view_android_delegate_(jni_facade),
77  platform_message_handler_(new PlatformMessageHandlerAndroid(jni_facade)) {
78  // TODO(dnfield): always create a pbuffer surface for background use to
79  // resolve https://github.com/flutter/flutter/issues/73675
80  if (android_context_) {
81  FML_CHECK(android_context_->IsValid())
82  << "Could not create surface from invalid Android context.";
83  surface_factory_ = std::make_shared<AndroidSurfaceFactoryImpl>(
84  android_context_, jni_facade_);
85  android_surface_ = surface_factory_->CreateSurface();
86 
87  FML_CHECK(android_surface_ && android_surface_->IsValid())
88  << "Could not create an OpenGL, Vulkan or Software surface to set up "
89  "rendering.";
90  }
91 }
PlatformView(Delegate &delegate, 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:68

◆ ~PlatformViewAndroid()

flutter::PlatformViewAndroid::~PlatformViewAndroid ( )
overridedefault

Referenced by PlatformViewAndroid().

Member Function Documentation

◆ DispatchEmptyPlatformMessage()

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

Definition at line 180 of file platform_view_android.cc.

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

182  {
184  if (response_id) {
185  response = fml::MakeRefCounted<PlatformMessageResponseAndroid>(
186  response_id, jni_facade_, task_runners_.GetPlatformTaskRunner());
187  }
188 
190  std::make_unique<flutter::PlatformMessage>(std::move(name),
191  std::move(response)));
192 }
const TaskRunners task_runners_
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
Definition: task_runners.cc:30
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 char * name
Definition: fuchsia.cc:50

◆ DispatchPlatformMessage()

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

Definition at line 159 of file platform_view_android.cc.

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

163  {
164  uint8_t* message_data =
165  static_cast<uint8_t*>(env->GetDirectBufferAddress(java_message_data));
166  fml::MallocMapping message =
167  fml::MallocMapping::Copy(message_data, java_message_position);
168 
170  if (response_id) {
171  response = fml::MakeRefCounted<PlatformMessageResponseAndroid>(
172  response_id, jni_facade_, task_runners_.GetPlatformTaskRunner());
173  }
174 
176  std::make_unique<flutter::PlatformMessage>(
177  std::move(name), std::move(message), std::move(response)));
178 }
const TaskRunners task_runners_
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
Definition: task_runners.cc:30
void DispatchPlatformMessage(std::unique_ptr< PlatformMessage > message)
Used by embedders to dispatch a platform message to a running root isolate hosted by the engine...
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:147
const char * name
Definition: fuchsia.cc:50
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition: mapping.h:129

◆ DispatchSemanticsAction()

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

Definition at line 206 of file platform_view_android.cc.

References fml::MallocMapping::Copy(), flutter::PlatformView::DispatchSemanticsAction(), and flutter::PlatformViewAndroidDelegate::UpdateSemantics().

210  {
211  if (env->IsSameObject(args, NULL)) {
213  id, static_cast<flutter::SemanticsAction>(action),
215  return;
216  }
217 
218  uint8_t* args_data = static_cast<uint8_t*>(env->GetDirectBufferAddress(args));
219  auto args_vector = fml::MallocMapping::Copy(args_data, args_position);
220 
222  id, static_cast<flutter::SemanticsAction>(action),
223  std::move(args_vector));
224 }
G_BEGIN_DECLS FlValue * args
void DispatchSemanticsAction(int32_t id, SemanticsAction action, fml::MallocMapping args)
Used by embedders to dispatch an accessibility action to a running isolate hosted by the engine...
SemanticsAction action
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:147
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition: mapping.h:129

◆ GetAndroidContext()

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

Definition at line 108 of file platform_view_android.h.

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

108  {
109  return android_context_;
110  }

◆ 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 returing a thread-safe PlatformMessageHandler instead.

Reimplemented from flutter::PlatformView.

Definition at line 112 of file platform_view_android.h.

References FML_DISALLOW_COPY_AND_ASSIGN.

113  {
114  return platform_message_handler_;
115  }

◆ 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 313 of file platform_view_android.cc.

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

316  {
317  delegate_.LoadDartDeferredLibrary(loading_unit_id, std::move(snapshot_data),
318  std::move(snapshot_instructions));
319 }
PlatformView::Delegate & delegate_
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, the dart future returned by the originating loadLibrary() call completes.

◆ 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 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 322 of file platform_view_android.cc.

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

325  {
326  delegate_.LoadDartDeferredLibraryError(loading_unit_id, error_message,
327  transient);
328 }
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 ...
PlatformView::Delegate & delegate_

◆ NotifyChanged()

void flutter::PlatformViewAndroid::NotifyChanged ( const SkISize &  size)

Definition at line 145 of file platform_view_android.cc.

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

145  {
146  if (!android_surface_) {
147  return;
148  }
152  [&latch, surface = android_surface_.get(), size]() {
153  surface->OnScreenSurfaceResize(size);
154  latch.Signal();
155  });
156  latch.Wait();
157 }
const TaskRunners task_runners_
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
Definition: task_runners.cc:42

◆ NotifyCreated()

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

Definition at line 95 of file platform_view_android.cc.

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

96  {
97  if (android_surface_) {
98  InstallFirstFrameCallback();
99 
103  [&latch, surface = android_surface_.get(),
104  native_window = std::move(native_window)]() {
105  surface->SetNativeWindow(native_window);
106  latch.Signal();
107  });
108  latch.Wait();
109  }
110 
112 }
const TaskRunners task_runners_
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
Definition: task_runners.cc:42
void NotifyCreated()
Used by embedders to notify the shell that a platform view has been created. This notification is use...

◆ 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 130 of file platform_view_android.cc.

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

130  {
132 
133  if (android_surface_) {
137  [&latch, surface = android_surface_.get()]() {
138  surface->TeardownOnScreenContext();
139  latch.Signal();
140  });
141  latch.Wait();
142  }
143 }
const TaskRunners task_runners_
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
Definition: task_runners.cc:42
virtual void NotifyDestroyed()
Used by embedders to notify the shell that the platform view has been destroyed. This notification us...

◆ NotifySurfaceWindowChanged()

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

Definition at line 114 of file platform_view_android.cc.

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

115  {
116  if (android_surface_) {
120  [&latch, surface = android_surface_.get(),
121  native_window = std::move(native_window)]() {
122  surface->TeardownOnScreenContext();
123  surface->SetNativeWindow(native_window);
124  latch.Signal();
125  });
126  latch.Wait();
127  }
128 }
const TaskRunners task_runners_
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
Definition: task_runners.cc:42

◆ Register()

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

Definition at line 924 of file platform_view_android_jni_impl.cc.

References FML_LOG, fml::jni::JavaRef< T >::obj(), and flutter::RegisterApi().

Referenced by JNI_OnLoad().

924  {
925  if (env == nullptr) {
926  FML_LOG(ERROR) << "No JNIEnv provided";
927  return false;
928  }
929 
931  env, env->FindClass("io/flutter/view/FlutterCallbackInformation"));
932  if (g_flutter_callback_info_class->is_null()) {
933  FML_LOG(ERROR) << "Could not locate FlutterCallbackInformation class";
934  return false;
935  }
936 
937  g_flutter_callback_info_constructor = env->GetMethodID(
938  g_flutter_callback_info_class->obj(), "<init>",
939  "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
940  if (g_flutter_callback_info_constructor == nullptr) {
941  FML_LOG(ERROR) << "Could not locate FlutterCallbackInformation constructor";
942  return false;
943  }
944 
946  env, env->FindClass("io/flutter/embedding/engine/FlutterJNI"));
947  if (g_flutter_jni_class->is_null()) {
948  FML_LOG(ERROR) << "Failed to find FlutterJNI Class.";
949  return false;
950  }
951 
953  env,
954  env->FindClass(
955  "io/flutter/embedding/engine/mutatorsstack/FlutterMutatorsStack"));
956  if (g_mutators_stack_class == nullptr) {
957  FML_LOG(ERROR) << "Could not locate FlutterMutatorsStack";
958  return false;
959  }
960 
962  env->GetMethodID(g_mutators_stack_class->obj(), "<init>", "()V");
963  if (g_mutators_stack_init_method == nullptr) {
964  FML_LOG(ERROR) << "Could not locate FlutterMutatorsStack.init method";
965  return false;
966  }
967 
969  env->GetMethodID(g_mutators_stack_class->obj(), "pushTransform", "([F)V");
971  FML_LOG(ERROR)
972  << "Could not locate FlutterMutatorsStack.pushTransform method";
973  return false;
974  }
975 
976  g_mutators_stack_push_cliprect_method = env->GetMethodID(
977  g_mutators_stack_class->obj(), "pushClipRect", "(IIII)V");
978  if (g_mutators_stack_push_cliprect_method == nullptr) {
979  FML_LOG(ERROR)
980  << "Could not locate FlutterMutatorsStack.pushClipRect method";
981  return false;
982  }
983 
984  g_mutators_stack_push_cliprrect_method = env->GetMethodID(
985  g_mutators_stack_class->obj(), "pushClipRRect", "(IIII[F)V");
986  if (g_mutators_stack_push_cliprect_method == nullptr) {
987  FML_LOG(ERROR)
988  << "Could not locate FlutterMutatorsStack.pushClipRRect method";
989  return false;
990  }
991 
993  env->GetMethodID(g_flutter_jni_class->obj(), "onDisplayPlatformView",
994  "(IIIIIIILio/flutter/embedding/engine/mutatorsstack/"
995  "FlutterMutatorsStack;)V");
996 
997  if (g_on_display_platform_view_method == nullptr) {
998  FML_LOG(ERROR) << "Could not locate onDisplayPlatformView method";
999  return false;
1000  }
1001 
1003  env->GetMethodID(g_flutter_jni_class->obj(), "onBeginFrame", "()V");
1004 
1005  if (g_on_begin_frame_method == nullptr) {
1006  FML_LOG(ERROR) << "Could not locate onBeginFrame method";
1007  return false;
1008  }
1009 
1011  env->GetMethodID(g_flutter_jni_class->obj(), "onEndFrame", "()V");
1012 
1013  if (g_on_end_frame_method == nullptr) {
1014  FML_LOG(ERROR) << "Could not locate onEndFrame method";
1015  return false;
1016  }
1017 
1018  g_on_display_overlay_surface_method = env->GetMethodID(
1019  g_flutter_jni_class->obj(), "onDisplayOverlaySurface", "(IIIII)V");
1020 
1021  if (g_on_display_overlay_surface_method == nullptr) {
1022  FML_LOG(ERROR) << "Could not locate onDisplayOverlaySurface method";
1023  return false;
1024  }
1025 
1027  env, env->FindClass("java/lang/ref/WeakReference"));
1028  if (g_java_weak_reference_class->is_null()) {
1029  FML_LOG(ERROR) << "Could not locate WeakReference class";
1030  return false;
1031  }
1032 
1033  g_java_weak_reference_get_method = env->GetMethodID(
1034  g_java_weak_reference_class->obj(), "get", "()Ljava/lang/Object;");
1035  if (g_java_weak_reference_get_method == nullptr) {
1036  FML_LOG(ERROR) << "Could not locate WeakReference.get method";
1037  return false;
1038  }
1039 
1041  env, env->FindClass(
1042  "io/flutter/embedding/engine/renderer/SurfaceTextureWrapper"));
1043  if (g_texture_wrapper_class->is_null()) {
1044  FML_LOG(ERROR) << "Could not locate SurfaceTextureWrapper class";
1045  return false;
1046  }
1047 
1048  g_attach_to_gl_context_method = env->GetMethodID(
1049  g_texture_wrapper_class->obj(), "attachToGLContext", "(I)V");
1050 
1051  if (g_attach_to_gl_context_method == nullptr) {
1052  FML_LOG(ERROR) << "Could not locate attachToGlContext method";
1053  return false;
1054  }
1055 
1057  env->GetMethodID(g_texture_wrapper_class->obj(), "updateTexImage", "()V");
1058 
1059  if (g_update_tex_image_method == nullptr) {
1060  FML_LOG(ERROR) << "Could not locate updateTexImage method";
1061  return false;
1062  }
1063 
1064  g_get_transform_matrix_method = env->GetMethodID(
1065  g_texture_wrapper_class->obj(), "getTransformMatrix", "([F)V");
1066 
1067  if (g_get_transform_matrix_method == nullptr) {
1068  FML_LOG(ERROR) << "Could not locate getTransformMatrix method";
1069  return false;
1070  }
1071 
1072  g_detach_from_gl_context_method = env->GetMethodID(
1073  g_texture_wrapper_class->obj(), "detachFromGLContext", "()V");
1074 
1075  if (g_detach_from_gl_context_method == nullptr) {
1076  FML_LOG(ERROR) << "Could not locate detachFromGlContext method";
1077  return false;
1078  }
1079 
1080  g_compute_platform_resolved_locale_method = env->GetMethodID(
1081  g_flutter_jni_class->obj(), "computePlatformResolvedLocale",
1082  "([Ljava/lang/String;)[Ljava/lang/String;");
1083 
1085  FML_LOG(ERROR) << "Could not locate computePlatformResolvedLocale method";
1086  return false;
1087  }
1088 
1089  g_request_dart_deferred_library_method = env->GetMethodID(
1090  g_flutter_jni_class->obj(), "requestDartDeferredLibrary", "(I)V");
1091 
1092  if (g_request_dart_deferred_library_method == nullptr) {
1093  FML_LOG(ERROR) << "Could not locate requestDartDeferredLibrary method";
1094  return false;
1095  }
1096 
1098  env, env->FindClass("java/lang/Long"));
1099  if (g_java_long_class->is_null()) {
1100  FML_LOG(ERROR) << "Could not locate java.lang.Long class";
1101  return false;
1102  }
1103 
1104  return RegisterApi(env);
1105 }
static fml::jni::ScopedJavaGlobalRef< jclass > * g_java_weak_reference_class
static fml::jni::ScopedJavaGlobalRef< jclass > * g_mutators_stack_class
static jmethodID g_on_begin_frame_method
static jmethodID g_get_transform_matrix_method
static jmethodID g_mutators_stack_push_cliprrect_method
static fml::jni::ScopedJavaGlobalRef< jclass > * g_texture_wrapper_class
static jmethodID g_request_dart_deferred_library_method
static jmethodID g_java_weak_reference_get_method
static jmethodID g_attach_to_gl_context_method
#define FML_LOG(severity)
Definition: logging.h:65
static fml::jni::ScopedJavaGlobalRef< jclass > * g_java_long_class
static fml::jni::ScopedJavaGlobalRef< jclass > * g_flutter_jni_class
static jmethodID g_mutators_stack_push_cliprect_method
static jmethodID g_flutter_callback_info_constructor
static jmethodID g_mutators_stack_init_method
static jmethodID g_mutators_stack_push_transform_method
static jmethodID g_on_display_platform_view_method
static jmethodID g_on_end_frame_method
static jmethodID g_detach_from_gl_context_method
static jmethodID g_update_tex_image_method
static jmethodID g_compute_platform_resolved_locale_method
bool RegisterApi(JNIEnv *env)
static fml::jni::ScopedJavaGlobalRef< jclass > * g_flutter_callback_info_class
static jmethodID g_on_display_overlay_surface_method

◆ RegisterExternalTexture()

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

Definition at line 233 of file platform_view_android.cc.

References flutter::ShellIOManager::CreateCompatibleResourceLoadingContext(), FML_DLOG, flutter::GPUSurfaceGLDelegate::GetDefaultPlatformGLInterface(), flutter::PlatformView::RegisterTexture(), and flutter::PlatformView::task_runners_.

235  {
236  RegisterTexture(std::make_shared<AndroidExternalTextureGL>(
237  texture_id, surface_texture, std::move(jni_facade_)));
238 }
int64_t texture_id
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...

◆ 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 331 of file platform_view_android.cc.

References flutter::PlatformView::delegate_, flutter::TaskRunners::GetPlatformTaskRunner(), flutter::PlatformView::GetWeakPtr(), platform_view, flutter::PlatformView::SetNextFrameCallback(), flutter::PlatformView::task_runners_, and flutter::PlatformView::Delegate::UpdateAssetResolverByType().

333  {
334  delegate_.UpdateAssetResolverByType(std::move(updated_asset_resolver), type);
335 }
KeyCallType type
PlatformView::Delegate & delegate_
virtual void UpdateAssetResolverByType(std::unique_ptr< AssetResolver > updated_asset_resolver, AssetResolver::AssetResolverType type)=0
Replaces the asset resolver handled by the engine&#39;s AssetManager of the specified type with updated_a...

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