Flutter Engine
The 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 FLUTTER_SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_H_
6#define FLUTTER_SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_H_
7
8#include <memory>
9#include <string>
10#include <unordered_map>
11#include <vector>
12
13#include <android/hardware_buffer_jni.h>
14#include "flutter/fml/memory/weak_ptr.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/common/snapshot_surface_producer.h"
19#include "flutter/shell/platform/android/context/android_context.h"
20#include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
21#include "flutter/shell/platform/android/platform_message_handler_android.h"
22#include "flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate.h"
23#include "flutter/shell/platform/android/surface/android_native_window.h"
24#include "flutter/shell/platform/android/surface/android_surface.h"
25
26namespace flutter {
27
29 public:
30 AndroidSurfaceFactoryImpl(const std::shared_ptr<AndroidContext>& context,
31 bool enable_impeller);
32
34
35 std::unique_ptr<AndroidSurface> CreateSurface() override;
36
37 private:
38 const std::shared_ptr<AndroidContext>& android_context_;
39 const bool enable_impeller_;
40};
41
42class PlatformViewAndroid final : public PlatformView {
43 public:
44 static bool Register(JNIEnv* env);
45
47 const flutter::TaskRunners& task_runners,
48 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
49 bool use_software_rendering);
50
51 //----------------------------------------------------------------------------
52 /// @brief Creates a new PlatformViewAndroid but using an existing
53 /// Android GPU context to create new surfaces. This maximizes
54 /// resource sharing between 2 PlatformViewAndroids of 2 Shells.
55 ///
57 PlatformView::Delegate& delegate,
58 const flutter::TaskRunners& task_runners,
59 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
60 const std::shared_ptr<flutter::AndroidContext>& android_context);
61
63
65
68
69 void NotifyChanged(const SkISize& size);
70
71 // |PlatformView|
72 void NotifyDestroyed() override;
73
74 void DispatchPlatformMessage(JNIEnv* env,
75 std::string name,
76 jobject message_data,
77 jint message_position,
78 jint response_id);
79
81 std::string name,
82 jint response_id);
83
84 void DispatchSemanticsAction(JNIEnv* env,
85 jint id,
86 jint action,
87 jobject args,
88 jint args_position);
89
91 int64_t texture_id,
92 const fml::jni::ScopedJavaGlobalRef<jobject>& surface_texture);
93
95 int64_t texture_id,
96 const fml::jni::ScopedJavaGlobalRef<jobject>& image_texture_entry);
97
98 // |PlatformView|
100 intptr_t loading_unit_id,
101 std::unique_ptr<const fml::Mapping> snapshot_data,
102 std::unique_ptr<const fml::Mapping> snapshot_instructions) override;
103
104 void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
105 const std::string error_message,
106 bool transient) override;
107
108 // |PlatformView|
110 std::unique_ptr<AssetResolver> updated_asset_resolver,
112
113 const std::shared_ptr<AndroidContext>& GetAndroidContext() {
114 return android_context_;
115 }
116
117 std::shared_ptr<PlatformMessageHandler> GetPlatformMessageHandler()
118 const override {
119 return platform_message_handler_;
120 }
121
122 private:
123 const std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
124 std::shared_ptr<AndroidContext> android_context_;
125 std::shared_ptr<AndroidSurfaceFactoryImpl> surface_factory_;
126
127 PlatformViewAndroidDelegate platform_view_android_delegate_;
128
129 std::unique_ptr<AndroidSurface> android_surface_;
130 std::shared_ptr<PlatformMessageHandlerAndroid> platform_message_handler_;
131
132 // |PlatformView|
133 void UpdateSemantics(
136
137 // |PlatformView|
138 void HandlePlatformMessage(
139 std::unique_ptr<flutter::PlatformMessage> message) override;
140
141 // |PlatformView|
142 void OnPreEngineRestart() const override;
143
144 // |PlatformView|
145 std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;
146
147 // |PlatformView|
148 std::unique_ptr<Surface> CreateRenderingSurface() override;
149
150 // |PlatformView|
151 std::shared_ptr<ExternalViewEmbedder> CreateExternalViewEmbedder() override;
152
153 // |PlatformView|
154 std::unique_ptr<SnapshotSurfaceProducer> CreateSnapshotSurfaceProducer()
155 override;
156
157 // |PlatformView|
158 sk_sp<GrDirectContext> CreateResourceContext() const override;
159
160 // |PlatformView|
161 void ReleaseResourceContext() const override;
162
163 // |PlatformView|
164 std::shared_ptr<impeller::Context> GetImpellerContext() const override;
165
166 // |PlatformView|
167 std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocales(
168 const std::vector<std::string>& supported_locale_data) override;
169
170 // |PlatformView|
171 void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
172
173 void InstallFirstFrameCallback();
174
175 void FireFirstFrameCallback();
176
177 double GetScaledFontSize(double unscaled_font_size,
178 int configuration_id) const override;
179
180 FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewAndroid);
181};
182} // namespace flutter
183
184#endif // FLUTTER_SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_H_
GLenum type
std::unique_ptr< AndroidSurface > CreateSurface() override
AndroidSurfaceFactoryImpl(const std::shared_ptr< AndroidContext > &context, bool enable_impeller)
AssetResolverType
Identifies the type of AssetResolver an instance is.
void DispatchPlatformMessage(JNIEnv *env, std::string name, jobject message_data, jint message_position, jint response_id)
void NotifyChanged(const SkISize &size)
void RegisterExternalTexture(int64_t texture_id, const fml::jni::ScopedJavaGlobalRef< jobject > &surface_texture)
void NotifySurfaceWindowChanged(fml::RefPtr< AndroidNativeWindow > native_window)
std::shared_ptr< PlatformMessageHandler > GetPlatformMessageHandler() const override
Specifies a delegate that will receive PlatformMessages from Flutter to the host platform.
void RegisterImageTexture(int64_t texture_id, const fml::jni::ScopedJavaGlobalRef< jobject > &image_texture_entry)
const std::shared_ptr< AndroidContext > & GetAndroidContext()
void DispatchEmptyPlatformMessage(JNIEnv *env, std::string name, jint response_id)
void NotifyDestroyed() override
Used by embedders to notify the shell that the platform view has been destroyed. This notification us...
PlatformViewAndroid(PlatformView::Delegate &delegate, const flutter::TaskRunners &task_runners, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade, bool use_software_rendering)
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_a...
void DispatchSemanticsAction(JNIEnv *env, jint id, jint action, jobject args, jint args_position)
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 ...
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,...
Used to forward events from the platform view to interested subsystems. This forwarding is done by th...
Definition: platform_view.h:60
Platform views are created by the shell on the platform task runner. Unless explicitly specified,...
Definition: platform_view.h:51
void NotifyCreated()
Used by embedders to notify the shell that a platform view has been created. This notification is use...
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Win32Message message
Definition: __init__.py:1
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
it will be possible to load the file into Perfetto s trace viewer 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
Definition: switches.h:259
Definition: update.py:1
Definition: SkSize.h:16
int64_t texture_id