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/jni_weak_ref.h"
15 #include "flutter/fml/platform/android/scoped_java_ref.h"
16 #include "flutter/lib/ui/window/platform_message.h"
17 #include "flutter/shell/common/platform_view.h"
18 #include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
19 #include "flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate.h"
20 #include "flutter/shell/platform/android/surface/android_native_window.h"
21 #include "flutter/shell/platform/android/surface/android_surface.h"
22 
23 namespace flutter {
24 
26  public:
27  AndroidSurfaceFactoryImpl(std::shared_ptr<AndroidContext> context,
28  std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
29 
30  ~AndroidSurfaceFactoryImpl() override;
31 
32  std::unique_ptr<AndroidSurface> CreateSurface() override;
33 
35  std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder);
36 
37  private:
38  std::shared_ptr<AndroidContext> android_context_;
39  std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
40  std::weak_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
41 };
42 
43 class PlatformViewAndroid final : public PlatformView {
44  public:
45  static bool Register(JNIEnv* env);
46 
47  // Creates a PlatformViewAndroid with no rendering surface for use with
48  // background execution.
50  flutter::TaskRunners task_runners,
51  std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
52 
53  // Creates a PlatformViewAndroid with a rendering surface.
55  flutter::TaskRunners task_runners,
56  std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
57  bool use_software_rendering);
58 
59  ~PlatformViewAndroid() override;
60 
61  void NotifyCreated(fml::RefPtr<AndroidNativeWindow> native_window);
62 
63  void NotifySurfaceWindowChanged(
64  fml::RefPtr<AndroidNativeWindow> native_window);
65 
66  void NotifyChanged(const SkISize& size);
67 
68  // |PlatformView|
69  void NotifyDestroyed() override;
70 
71  void DispatchPlatformMessage(JNIEnv* env,
72  std::string name,
73  jobject message_data,
74  jint message_position,
75  jint response_id);
76 
77  void DispatchEmptyPlatformMessage(JNIEnv* env,
78  std::string name,
79  jint response_id);
80 
82  jint response_id,
83  jobject java_response_data,
84  jint java_response_position);
85 
87  jint response_id);
88 
89  void DispatchSemanticsAction(JNIEnv* env,
90  jint id,
91  jint action,
92  jobject args,
93  jint args_position);
94 
95  void RegisterExternalTexture(
96  int64_t texture_id,
97  const fml::jni::JavaObjectWeakGlobalRef& surface_texture);
98 
99  private:
100  const std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
101  std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
102  std::shared_ptr<AndroidSurfaceFactoryImpl> surface_factory_;
103 
104  PlatformViewAndroidDelegate platform_view_android_delegate_;
105 
106  std::unique_ptr<AndroidSurface> android_surface_;
107  // We use id 0 to mean that no response is expected.
108  int next_response_id_ = 1;
109  std::unordered_map<int, fml::RefPtr<flutter::PlatformMessageResponse>>
110  pending_responses_;
111 
112  // |PlatformView|
113  void UpdateSemantics(
116 
117  // |PlatformView|
118  void HandlePlatformMessage(
119  fml::RefPtr<flutter::PlatformMessage> message) override;
120 
121  // |PlatformView|
122  void OnPreEngineRestart() const override;
123 
124  // |PlatformView|
125  std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;
126 
127  // |PlatformView|
128  std::unique_ptr<Surface> CreateRenderingSurface() override;
129 
130  // |PlatformView|
131  sk_sp<GrDirectContext> CreateResourceContext() const override;
132 
133  // |PlatformView|
134  void ReleaseResourceContext() const override;
135 
136  // |PlatformView|
137  std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocales(
138  const std::vector<std::string>& supported_locale_data) override;
139 
140  void InstallFirstFrameCallback();
141 
142  void FireFirstFrameCallback();
143 
145 };
146 } // namespace flutter
147 
148 #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)
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
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
AndroidSurfaceFactoryImpl(std::shared_ptr< AndroidContext > context, std::shared_ptr< PlatformViewAndroidJNI > jni_facade)
Platform views are created by the shell on the platform task runner. Unless explicitly specified...
Definition: platform_view.h:44
static void InvokePlatformMessageResponseCallback(JNIEnv *env, jobject jcaller, jlong shell_holder, jint responseId, jobject message, jint position)
SemanticsAction action
static void DispatchPlatformMessage(JNIEnv *env, jobject jcaller, jlong shell_holder, jstring channel, jobject message, jint position, jint responseId)
void SetExternalViewEmbedder(std::shared_ptr< AndroidExternalViewEmbedder > external_view_embedder)
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:51