Flutter Engine
platform_view_android.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_H_
6 #define SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_H_
7 
8 #include <memory>
9 #include <string>
10 #include <unordered_map>
11 #include <vector>
12 
13 #include "flutter/fml/memory/weak_ptr.h"
14 #include "flutter/fml/platform/android/scoped_java_ref.h"
15 #include "flutter/lib/ui/window/platform_message.h"
16 #include "flutter/shell/common/platform_view.h"
17 #include "flutter/shell/common/snapshot_surface_producer.h"
18 #include "flutter/shell/platform/android/context/android_context.h"
19 #include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
20 #include "flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate.h"
21 #include "flutter/shell/platform/android/surface/android_native_window.h"
22 #include "flutter/shell/platform/android/surface/android_surface.h"
23 
24 namespace flutter {
25 
27  public:
28  AndroidSurfaceFactoryImpl(const std::shared_ptr<AndroidContext>& context,
29  std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
30 
31  ~AndroidSurfaceFactoryImpl() override;
32 
33  std::unique_ptr<AndroidSurface> CreateSurface() override;
34 
35  private:
36  const std::shared_ptr<AndroidContext>& android_context_;
37  std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
38 };
39 
40 class PlatformViewAndroid final : public PlatformView {
41  public:
42  static bool Register(JNIEnv* env);
43 
45  flutter::TaskRunners task_runners,
46  std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
47  bool use_software_rendering);
48 
49  //----------------------------------------------------------------------------
50  /// @brief Creates a new PlatformViewAndroid but using an existing
51  /// Android GPU context to create new surfaces. This maximizes
52  /// resource sharing between 2 PlatformViewAndroids of 2 Shells.
53  ///
55  PlatformView::Delegate& delegate,
56  flutter::TaskRunners task_runners,
57  const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
58  const std::shared_ptr<flutter::AndroidContext>& android_context);
59 
60  ~PlatformViewAndroid() override;
61 
62  void NotifyCreated(fml::RefPtr<AndroidNativeWindow> native_window);
63 
64  void NotifySurfaceWindowChanged(
65  fml::RefPtr<AndroidNativeWindow> native_window);
66 
67  void NotifyChanged(const SkISize& size);
68 
69  // |PlatformView|
70  void NotifyDestroyed() override;
71 
72  void DispatchPlatformMessage(JNIEnv* env,
73  std::string name,
74  jobject message_data,
75  jint message_position,
76  jint response_id);
77 
78  void DispatchEmptyPlatformMessage(JNIEnv* env,
79  std::string name,
80  jint response_id);
81 
83  jint response_id,
84  jobject java_response_data,
85  jint java_response_position);
86 
88  jint response_id);
89 
90  void DispatchSemanticsAction(JNIEnv* env,
91  jint id,
92  jint action,
93  jobject args,
94  jint args_position);
95 
96  void RegisterExternalTexture(
97  int64_t texture_id,
98  const fml::jni::ScopedJavaGlobalRef<jobject>& surface_texture);
99 
100  // |PlatformView|
102  intptr_t loading_unit_id,
103  std::unique_ptr<const fml::Mapping> snapshot_data,
104  std::unique_ptr<const fml::Mapping> snapshot_instructions) override;
105 
106  void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
107  const std::string error_message,
108  bool transient) override;
109 
110  // |PlatformView|
111  void UpdateAssetResolverByType(
112  std::unique_ptr<AssetResolver> updated_asset_resolver,
114 
115  const std::shared_ptr<AndroidContext>& GetAndroidContext() {
116  return android_context_;
117  }
118 
119  private:
120  const std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
121  std::shared_ptr<AndroidContext> android_context_;
122  std::shared_ptr<AndroidSurfaceFactoryImpl> surface_factory_;
123 
124  PlatformViewAndroidDelegate platform_view_android_delegate_;
125 
126  std::unique_ptr<AndroidSurface> android_surface_;
127 
128  // We use id 0 to mean that no response is expected.
129  int next_response_id_ = 1;
130  std::unordered_map<int, fml::RefPtr<flutter::PlatformMessageResponse>>
131  pending_responses_;
132 
133  // |PlatformView|
134  void UpdateSemantics(
137 
138  // |PlatformView|
139  void HandlePlatformMessage(
140  std::unique_ptr<flutter::PlatformMessage> message) override;
141 
142  // |PlatformView|
143  void OnPreEngineRestart() const override;
144 
145  // |PlatformView|
146  std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;
147 
148  // |PlatformView|
149  std::unique_ptr<Surface> CreateRenderingSurface() override;
150 
151  // |PlatformView|
152  std::shared_ptr<ExternalViewEmbedder> CreateExternalViewEmbedder() override;
153 
154  // |PlatformView|
155  std::unique_ptr<SnapshotSurfaceProducer> CreateSnapshotSurfaceProducer()
156  override;
157 
158  // |PlatformView|
159  sk_sp<GrDirectContext> CreateResourceContext() const override;
160 
161  // |PlatformView|
162  void ReleaseResourceContext() const override;
163 
164  // |PlatformView|
165  std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocales(
166  const std::vector<std::string>& supported_locale_data) override;
167 
168  // |PlatformView|
169  void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
170 
171  void InstallFirstFrameCallback();
172 
173  void FireFirstFrameCallback();
174 
176 };
177 } // namespace flutter
178 
179 #endif // SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_H_
std::unique_ptr< AndroidSurface > CreateSurface() override
G_BEGIN_DECLS FlValue * args
static void InvokePlatformMessageEmptyResponseCallback(JNIEnv *env, jobject jcaller, jlong shell_holder, jint responseId)
KeyCallType type
const std::shared_ptr< AndroidContext > & GetAndroidContext()
static void DispatchSemanticsAction(JNIEnv *env, jobject jcaller, jlong shell_holder, jint id, jint action, jobject args, jint args_position)
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
int64_t texture_id
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:46
AndroidSurfaceFactoryImpl(const std::shared_ptr< AndroidContext > &context, std::shared_ptr< PlatformViewAndroidJNI > jni_facade)
AssetResolverType
Identifies the type of AssetResolver an instance is.
static void InvokePlatformMessageResponseCallback(JNIEnv *env, jobject jcaller, jlong shell_holder, jint responseId, jobject message, jint position)
SemanticsAction action
static void LoadDartDeferredLibrary(JNIEnv *env, jobject obj, jlong shell_holder, jint jLoadingUnitId, jobjectArray jSearchPaths)
static void DispatchPlatformMessage(JNIEnv *env, jobject jcaller, jlong shell_holder, jstring channel, jobject message, jint position, jint responseId)
const char * name
Definition: fuchsia.cc:50
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
static void DispatchEmptyPlatformMessage(JNIEnv *env, jobject jcaller, jlong shell_holder, jstring channel, jint responseId)
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27
Used to forward events from the platform view to interested subsystems. This forwarding is done by th...
Definition: platform_view.h:53