Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 uint8_t msaa_samples);
51
52 //----------------------------------------------------------------------------
53 /// @brief Creates a new PlatformViewAndroid but using an existing
54 /// Android GPU context to create new surfaces. This maximizes
55 /// resource sharing between 2 PlatformViewAndroids of 2 Shells.
56 ///
58 PlatformView::Delegate& delegate,
59 const flutter::TaskRunners& task_runners,
60 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
61 const std::shared_ptr<flutter::AndroidContext>& android_context);
62
64
66
69
70 void NotifyChanged(const SkISize& size);
71
72 // |PlatformView|
73 void NotifyDestroyed() override;
74
75 void DispatchPlatformMessage(JNIEnv* env,
76 std::string name,
77 jobject message_data,
78 jint message_position,
79 jint response_id);
80
82 std::string name,
83 jint response_id);
84
85 void DispatchSemanticsAction(JNIEnv* env,
86 jint id,
87 jint action,
88 jobject args,
89 jint args_position);
90
92 int64_t texture_id,
93 const fml::jni::ScopedJavaGlobalRef<jobject>& surface_texture);
94
96 int64_t texture_id,
97 const fml::jni::ScopedJavaGlobalRef<jobject>& image_texture_entry);
98
99 // |PlatformView|
101 intptr_t loading_unit_id,
102 std::unique_ptr<const fml::Mapping> snapshot_data,
103 std::unique_ptr<const fml::Mapping> snapshot_instructions) override;
104
105 void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
106 const std::string error_message,
107 bool transient) override;
108
109 // |PlatformView|
111 std::unique_ptr<AssetResolver> updated_asset_resolver,
113
114 const std::shared_ptr<AndroidContext>& GetAndroidContext() {
115 return android_context_;
116 }
117
118 std::shared_ptr<PlatformMessageHandler> GetPlatformMessageHandler()
119 const override {
120 return platform_message_handler_;
121 }
122
123 private:
124 const std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
125 std::shared_ptr<AndroidContext> android_context_;
126 std::shared_ptr<AndroidSurfaceFactoryImpl> surface_factory_;
127
128 PlatformViewAndroidDelegate platform_view_android_delegate_;
129
130 std::unique_ptr<AndroidSurface> android_surface_;
131 std::shared_ptr<PlatformMessageHandlerAndroid> platform_message_handler_;
132
133 // |PlatformView|
134 void UpdateSemantics(
137
138 // |PlatformView|
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|
160
161 // |PlatformView|
162 void ReleaseResourceContext() const override;
163
164 // |PlatformView|
165 std::shared_ptr<impeller::Context> GetImpellerContext() const override;
166
167 // |PlatformView|
168 std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocales(
169 const std::vector<std::string>& supported_locale_data) override;
170
171 // |PlatformView|
172 void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
173
174 void InstallFirstFrameCallback();
175
176 void FireFirstFrameCallback();
177
178 double GetScaledFontSize(double unscaled_font_size,
179 int configuration_id) const override;
180
182};
183} // namespace flutter
184
185#endif // FLUTTER_SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_H_
std::unique_ptr< AndroidSurface > CreateSurface() override
AssetResolverType
Identifies the type of AssetResolver an instance is.
void OnPreEngineRestart() const override
Gives embedders a chance to react to a "cold restart" of the running isolate. The default implementat...
void DispatchPlatformMessage(JNIEnv *env, std::string name, jobject message_data, jint message_position, jint response_id)
sk_sp< GrDirectContext > CreateResourceContext() const override
Used by the shell to obtain a Skia GPU context that is capable of operating on the IO thread....
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::unique_ptr< SnapshotSurfaceProducer > CreateSnapshotSurfaceProducer() override
Creates an object that produces surfaces suitable for raster snapshotting. The rasterizer will reques...
std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocales(const std::vector< std::string > &supported_locale_data) override
Directly invokes platform-specific APIs to compute the locale the platform would have natively resolv...
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)
void ReleaseResourceContext() const override
Used by the shell to notify the embedder that the resource context previously obtained via a call to ...
const std::shared_ptr< AndroidContext > & GetAndroidContext()
void DispatchEmptyPlatformMessage(JNIEnv *env, std::string name, jint response_id)
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override
Invoked when the dart VM requests that a deferred library be loaded. Notifies the engine that the def...
void NotifyDestroyed() override
Used by embedders to notify the shell that the platform view has been destroyed. This notification us...
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...
std::shared_ptr< ExternalViewEmbedder > CreateExternalViewEmbedder() override
void DispatchSemanticsAction(JNIEnv *env, jint id, jint action, jobject args, jint args_position)
void HandlePlatformMessage(std::unique_ptr< flutter::PlatformMessage > message) override
Overridden by embedders to perform actions in response to platform messages sent from the framework t...
std::unique_ptr< VsyncWaiter > CreateVSyncWaiter() override
Invoked by the shell to obtain a platform specific vsync waiter. It is optional for platforms to over...
std::shared_ptr< impeller::Context > GetImpellerContext() const override
std::unique_ptr< Surface > CreateRenderingSurface() override
void UpdateSemantics(flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions) override
Used by the framework to tell the embedder to apply the specified semantics node updates....
double GetScaledFontSize(double unscaled_font_size, int configuration_id) const override
Synchronously invokes platform-specific APIs to apply the system text scaling on the given unscaled f...
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...
Platform views are created by the shell on the platform task runner. Unless explicitly specified,...
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
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
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
int64_t texture_id