Flutter Engine
 
Loading...
Searching...
No Matches
platform_view_embedder.cc
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
6
7#include <utility>
8
10
11namespace flutter {
12
14 : public PlatformMessageHandler {
15 public:
18 fml::RefPtr<fml::TaskRunner> platform_task_runner)
19 : parent_(std::move(parent)),
20 platform_task_runner_(std::move(platform_task_runner)) {}
21
22 virtual void HandlePlatformMessage(std::unique_ptr<PlatformMessage> message) {
23 platform_task_runner_->PostTask(fml::MakeCopyable(
24 [parent = parent_, message = std::move(message)]() mutable {
25 if (parent) {
26 parent->HandlePlatformMessage(std::move(message));
27 } else {
28 FML_DLOG(WARNING) << "Deleted engine dropping message on channel "
29 << message->channel();
30 }
31 }));
32 }
33
35 return true;
36 }
37
39 int response_id,
40 std::unique_ptr<fml::Mapping> mapping) {}
41 virtual void InvokePlatformMessageEmptyResponseCallback(int response_id) {}
42
43 private:
45 fml::RefPtr<fml::TaskRunner> platform_task_runner_;
46};
47
49 PlatformView::Delegate& delegate,
50 const flutter::TaskRunners& task_runners,
52 software_dispatch_table,
53 PlatformDispatchTable platform_dispatch_table,
54 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
55 : PlatformView(delegate, task_runners),
56 external_view_embedder_(std::move(external_view_embedder)),
57 embedder_surface_(
58 std::make_unique<EmbedderSurfaceSoftware>(software_dispatch_table,
59 external_view_embedder_)),
60 platform_message_handler_(new EmbedderPlatformMessageHandler(
61 GetWeakPtr(),
62 task_runners.GetPlatformTaskRunner())),
63 platform_dispatch_table_(std::move(platform_dispatch_table)) {}
64
65#ifdef SHELL_ENABLE_GL
67 PlatformView::Delegate& delegate,
68 const flutter::TaskRunners& task_runners,
69 std::unique_ptr<EmbedderSurface> embedder_surface,
70 PlatformDispatchTable platform_dispatch_table,
71 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
72 : PlatformView(delegate, task_runners),
73 external_view_embedder_(std::move(external_view_embedder)),
74 embedder_surface_(std::move(embedder_surface)),
75 platform_message_handler_(new EmbedderPlatformMessageHandler(
76 GetWeakPtr(),
77 task_runners.GetPlatformTaskRunner())),
78 platform_dispatch_table_(std::move(platform_dispatch_table)) {}
79#endif
80
81#ifdef SHELL_ENABLE_METAL
83 PlatformView::Delegate& delegate,
84 const flutter::TaskRunners& task_runners,
85 std::unique_ptr<EmbedderSurface> embedder_surface,
86 PlatformDispatchTable platform_dispatch_table,
87 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
88 : PlatformView(delegate, task_runners),
89 external_view_embedder_(std::move(external_view_embedder)),
90 embedder_surface_(std::move(embedder_surface)),
91 platform_message_handler_(new EmbedderPlatformMessageHandler(
92 GetWeakPtr(),
93 task_runners.GetPlatformTaskRunner())),
94 platform_dispatch_table_(std::move(platform_dispatch_table)) {}
95#endif
96
97#ifdef SHELL_ENABLE_VULKAN
99 PlatformView::Delegate& delegate,
100 const flutter::TaskRunners& task_runners,
101 std::unique_ptr<EmbedderSurfaceVulkan> embedder_surface,
102 PlatformDispatchTable platform_dispatch_table,
103 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
104 : PlatformView(delegate, task_runners),
105 external_view_embedder_(std::move(external_view_embedder)),
106 embedder_surface_(std::move(embedder_surface)),
107 platform_message_handler_(new EmbedderPlatformMessageHandler(
108 GetWeakPtr(),
109 task_runners.GetPlatformTaskRunner())),
110 platform_dispatch_table_(std::move(platform_dispatch_table)) {}
111#endif
112
114
116 int64_t view_id,
119 if (platform_dispatch_table_.update_semantics_callback != nullptr) {
120 platform_dispatch_table_.update_semantics_callback(
121 view_id, std::move(update), std::move(actions));
122 }
123}
124
126 std::unique_ptr<flutter::PlatformMessage> message) {
127 if (!message) {
128 return;
129 }
130
131 if (platform_dispatch_table_.platform_message_response_callback == nullptr) {
132 if (message->response()) {
133 message->response()->CompleteEmpty();
134 }
135 return;
136 }
137
138 platform_dispatch_table_.platform_message_response_callback(
139 std::move(message));
140}
141
142// |PlatformView|
143std::unique_ptr<Surface> PlatformViewEmbedder::CreateRenderingSurface() {
144 if (embedder_surface_ == nullptr) {
145 FML_LOG(ERROR) << "Embedder surface was null.";
146 return nullptr;
147 }
148 return embedder_surface_->CreateGPUSurface();
149}
150
151// |PlatformView|
152std::shared_ptr<ExternalViewEmbedder>
153PlatformViewEmbedder::CreateExternalViewEmbedder() {
154 return external_view_embedder_;
155}
156
157std::shared_ptr<impeller::Context> PlatformViewEmbedder::GetImpellerContext()
158 const {
159 return embedder_surface_->CreateImpellerContext();
160}
161
162// |PlatformView|
163sk_sp<GrDirectContext> PlatformViewEmbedder::CreateResourceContext() const {
164 if (embedder_surface_ == nullptr) {
165 FML_LOG(ERROR) << "Embedder surface was null.";
166 return nullptr;
167 }
168 return embedder_surface_->CreateResourceContext();
169}
170
171// |PlatformView|
172std::unique_ptr<VsyncWaiter> PlatformViewEmbedder::CreateVSyncWaiter() {
173 if (!platform_dispatch_table_.vsync_callback) {
174 // Superclass implementation creates a timer based fallback.
176 }
177
178 return std::make_unique<VsyncWaiterEmbedder>(
179 platform_dispatch_table_.vsync_callback, task_runners_);
180}
181
182// |PlatformView|
183std::unique_ptr<std::vector<std::string>>
184PlatformViewEmbedder::ComputePlatformResolvedLocales(
185 const std::vector<std::string>& supported_locale_data) {
186 if (platform_dispatch_table_.compute_platform_resolved_locale_callback !=
187 nullptr) {
188 return platform_dispatch_table_.compute_platform_resolved_locale_callback(
189 supported_locale_data);
190 }
191 std::unique_ptr<std::vector<std::string>> out =
192 std::make_unique<std::vector<std::string>>();
193 return out;
194}
195
196// |PlatformView|
197void PlatformViewEmbedder::OnPreEngineRestart() const {
198 if (platform_dispatch_table_.on_pre_engine_restart_callback != nullptr) {
199 platform_dispatch_table_.on_pre_engine_restart_callback();
200 }
201}
202
203// |PlatformView|
204void PlatformViewEmbedder::SendChannelUpdate(const std::string& name,
205 bool listening) {
206 if (platform_dispatch_table_.on_channel_update != nullptr) {
207 platform_dispatch_table_.on_channel_update(name, listening);
208 }
209}
210
211void PlatformViewEmbedder::RequestViewFocusChange(
212 const ViewFocusChangeRequest& request) {
213 if (platform_dispatch_table_.view_focus_change_request_callback != nullptr) {
214 platform_dispatch_table_.view_focus_change_request_callback(request);
215 }
216}
217
218std::shared_ptr<PlatformMessageHandler>
220 return platform_message_handler_;
221}
222
223} // namespace flutter
Used to forward events from the platform view to interested subsystems. This forwarding is done by th...
virtual void InvokePlatformMessageResponseCallback(int response_id, std::unique_ptr< fml::Mapping > mapping)
EmbedderPlatformMessageHandler(fml::WeakPtr< PlatformView > parent, fml::RefPtr< fml::TaskRunner > platform_task_runner)
virtual void HandlePlatformMessage(std::unique_ptr< PlatformMessage > message)
void UpdateSemantics(int64_t view_id, flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions) override
Used by the framework to tell the embedder to apply the specified semantics node updates....
PlatformViewEmbedder(PlatformView::Delegate &delegate, const flutter::TaskRunners &task_runners, const EmbedderSurfaceSoftware::SoftwareDispatchTable &software_dispatch_table, PlatformDispatchTable platform_dispatch_table, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder)
void HandlePlatformMessage(std::unique_ptr< PlatformMessage > message) override
Overridden by embedders to perform actions in response to platform messages sent from the framework t...
std::shared_ptr< PlatformMessageHandler > GetPlatformMessageHandler() const override
Specifies a delegate that will receive PlatformMessages from Flutter to the host platform.
Platform views are created by the shell on the platform task runner. Unless explicitly specified,...
virtual std::unique_ptr< VsyncWaiter > CreateVSyncWaiter()
Invoked by the shell to obtain a platform specific vsync waiter. It is optional for platforms to over...
const TaskRunners task_runners_
virtual void PostTask(const fml::closure &task) override
G_BEGIN_DECLS GBytes * message
G_BEGIN_DECLS FlutterViewId view_id
#define FML_DLOG(severity)
Definition logging.h:121
#define FML_LOG(severity)
Definition logging.h:101
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition ref_ptr.h:261
ComputePlatformResolvedLocaleCallback compute_platform_resolved_locale_callback
PlatformMessageResponseCallback platform_message_response_callback