Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
platform_view.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
5#include "flutter/shell/common/platform_view.h"
6
7#include <utility>
8
9#include "flutter/fml/make_copyable.h"
10#include "flutter/fml/synchronization/waitable_event.h"
11#include "flutter/shell/common/vsync_waiter_fallback.h"
13
14namespace flutter {
15
16PlatformView::PlatformView(Delegate& delegate, const TaskRunners& task_runners)
17 : delegate_(delegate), task_runners_(task_runners), weak_factory_(this) {}
18
20
21std::unique_ptr<VsyncWaiter> PlatformView::CreateVSyncWaiter() {
22 FML_DLOG(WARNING)
23 << "This platform does not provide a Vsync waiter implementation. A "
24 "simple timer based fallback is being used.";
25 return std::make_unique<VsyncWaiterFallback>(task_runners_);
26}
27
29 std::unique_ptr<PlatformMessage> message) {
31}
32
34 std::unique_ptr<PointerDataPacket> packet) {
36 pointer_data_packet_converter_.Convert(std::move(packet)));
37}
38
45
49
53
55 const ViewportMetrics& metrics) {
57}
58
60 std::unique_ptr<Surface> surface;
61 // Threading: We want to use the platform view on the non-platform thread.
62 // Using the weak pointer is illegal. But, we are going to introduce a latch
63 // so that the platform view is not collected till the surface is obtained.
64 auto* platform_view = this;
68 surface = platform_view->CreateRenderingSurface();
69 if (surface && !surface->IsValid()) {
70 surface.reset();
71 }
72 latch.Signal();
73 });
74 latch.Wait();
75 if (!surface) {
76 FML_LOG(ERROR) << "Failed to create platform view rendering surface";
77 return;
78 }
79 delegate_.OnPlatformViewCreated(std::move(surface));
80}
81
82void PlatformView::NotifyDestroyed() {
83 delegate_.OnPlatformViewDestroyed();
84}
85
86void PlatformView::ScheduleFrame() {
87 delegate_.OnPlatformViewScheduleFrame();
88}
89
90void PlatformView::AddView(int64_t view_id,
91 const ViewportMetrics& viewport_metrics,
93 delegate_.OnPlatformViewAddView(view_id, viewport_metrics,
94 std::move(callback));
95}
96
97void PlatformView::RemoveView(int64_t view_id, RemoveViewCallback callback) {
98 delegate_.OnPlatformViewRemoveView(view_id, std::move(callback));
99}
100
101sk_sp<GrDirectContext> PlatformView::CreateResourceContext() const {
102 FML_DLOG(WARNING) << "This platform does not set up the resource "
103 "context on the IO thread for async texture uploads.";
104 return nullptr;
105}
106
107std::shared_ptr<impeller::Context> PlatformView::GetImpellerContext() const {
108 return nullptr;
109}
110
111void PlatformView::ReleaseResourceContext() const {}
112
113PointerDataDispatcherMaker PlatformView::GetDispatcherMaker() {
114 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
115 return std::make_unique<DefaultPointerDataDispatcher>(delegate);
116 };
117}
118
119fml::WeakPtr<PlatformView> PlatformView::GetWeakPtr() const {
120 return weak_factory_.GetWeakPtr();
121}
122
123void PlatformView::UpdateSemantics(
124 SemanticsNodeUpdates update, // NOLINT(performance-unnecessary-value-param)
125 // NOLINTNEXTLINE(performance-unnecessary-value-param)
127
128void PlatformView::SendChannelUpdate(const std::string& name, bool listening) {}
129
130void PlatformView::HandlePlatformMessage(
131 std::unique_ptr<PlatformMessage> message) {
132 if (auto response = message->response()) {
133 response->CompleteEmpty();
134 }
135}
136
137void PlatformView::OnPreEngineRestart() const {}
138
139void PlatformView::RegisterTexture(std::shared_ptr<flutter::Texture> texture) {
140 delegate_.OnPlatformViewRegisterTexture(std::move(texture));
141}
142
143void PlatformView::UnregisterTexture(int64_t texture_id) {
144 delegate_.OnPlatformViewUnregisterTexture(texture_id);
145}
146
147void PlatformView::MarkTextureFrameAvailable(int64_t texture_id) {
148 delegate_.OnPlatformViewMarkTextureFrameAvailable(texture_id);
149}
150
151std::unique_ptr<Surface> PlatformView::CreateRenderingSurface() {
152 // We have a default implementation because tests create a platform view but
153 // never a rendering surface.
154 FML_DCHECK(false) << "This platform does not provide a rendering surface but "
155 "it was notified of surface rendering surface creation.";
156 return nullptr;
157}
158
159std::shared_ptr<ExternalViewEmbedder>
160PlatformView::CreateExternalViewEmbedder() {
161 FML_DLOG(WARNING)
162 << "This platform doesn't support embedding external views.";
163 return nullptr;
164}
165
166void PlatformView::SetNextFrameCallback(const fml::closure& closure) {
167 if (!closure) {
168 return;
169 }
170
171 delegate_.OnPlatformViewSetNextFrameCallback(closure);
172}
173
174std::unique_ptr<std::vector<std::string>>
175PlatformView::ComputePlatformResolvedLocales(
176 const std::vector<std::string>& supported_locale_data) {
177 std::unique_ptr<std::vector<std::string>> out =
178 std::make_unique<std::vector<std::string>>();
179 return out;
180}
181
182void PlatformView::RequestDartDeferredLibrary(intptr_t loading_unit_id) {}
183
184void PlatformView::LoadDartDeferredLibrary(
185 intptr_t loading_unit_id,
186 std::unique_ptr<const fml::Mapping> snapshot_data,
187 std::unique_ptr<const fml::Mapping> snapshot_instructions) {}
188
189void PlatformView::LoadDartDeferredLibraryError(
190 intptr_t loading_unit_id,
191 const std::string
192 error_message, // NOLINT(performance-unnecessary-value-param)
193 bool transient) {}
194
195void PlatformView::UpdateAssetResolverByType(
196 std::unique_ptr<AssetResolver> updated_asset_resolver,
198 delegate_.UpdateAssetResolverByType(std::move(updated_asset_resolver), type);
199}
200
201std::unique_ptr<SnapshotSurfaceProducer>
202PlatformView::CreateSnapshotSurfaceProducer() {
203 return nullptr;
204}
205
206std::shared_ptr<PlatformMessageHandler>
207PlatformView::GetPlatformMessageHandler() const {
208 return nullptr;
209}
210
211const Settings& PlatformView::GetSettings() const {
212 return delegate_.OnPlatformViewGetSettings();
213}
214
215double PlatformView::GetScaledFontSize(double unscaled_font_size,
216 int configuration_id) const {
217 // Unreachable by default, as most platforms do not support nonlinear scaling
218 // and the Flutter application never invokes this method.
220 return -1;
221}
222
223} // namespace flutter
std::unique_ptr< flutter::PlatformViewIOS > platform_view
AssetResolverType
Identifies the type of AssetResolver an instance is.
Used to forward events from the platform view to interested subsystems. This forwarding is done by th...
virtual void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr< PointerDataPacket > packet)=0
Notifies the delegate that the platform view has encountered a pointer event. This pointer event need...
virtual void OnPlatformViewSetViewportMetrics(int64_t view_id, const ViewportMetrics &metrics)=0
Notifies the delegate the viewport metrics of a view have been updated. The rasterizer will need to b...
virtual void OnPlatformViewSetAccessibilityFeatures(int32_t flags)=0
Notifies the delegate that the embedder has expressed an opinion about the features to enable in the ...
virtual void OnPlatformViewDispatchSemanticsAction(int32_t node_id, SemanticsAction action, fml::MallocMapping args)=0
Notifies the delegate that the platform view has encountered an accessibility related action on the s...
virtual void OnPlatformViewSetSemanticsEnabled(bool enabled)=0
Notifies the delegate that the embedder has expressed an opinion about whether the accessibility tree...
virtual void OnPlatformViewDispatchPlatformMessage(std::unique_ptr< PlatformMessage > message)=0
Notifies the delegate that the platform has dispatched a platform message from the embedder to the Fl...
void DispatchPlatformMessage(std::unique_ptr< PlatformMessage > message)
Used by embedders to dispatch a platform message to a running root isolate hosted by the engine....
virtual ~PlatformView()
Destroys the platform view. The platform view is owned by the shell and will be destroyed by the same...
std::function< void(bool removed)> RemoveViewCallback
virtual void SetAccessibilityFeatures(int32_t flags)
Used by the embedder to specify the features to enable in the accessibility tree generated by the iso...
PlatformView(Delegate &delegate, const TaskRunners &task_runners)
Creates a platform view with the specified delegate and task runner. The base class by itself does no...
virtual std::unique_ptr< VsyncWaiter > CreateVSyncWaiter()
Invoked by the shell to obtain a platform specific vsync waiter. It is optional for platforms to over...
void DispatchSemanticsAction(int32_t node_id, SemanticsAction action, fml::MallocMapping args)
Used by embedders to dispatch an accessibility action to a running isolate hosted by the engine.
std::function< void(bool added)> AddViewCallback
PlatformView::Delegate & delegate_
void NotifyCreated()
Used by embedders to notify the shell that a platform view has been created. This notification is use...
void SetViewportMetrics(int64_t view_id, const ViewportMetrics &metrics)
Used by embedders to specify the updated viewport metrics for a view. In response to this call,...
void DispatchPointerDataPacket(std::unique_ptr< PointerDataPacket > packet)
Dispatches pointer events from the embedder to the framework. Each pointer data packet may contain mu...
const TaskRunners task_runners_
PointerDataPacketConverter pointer_data_packet_converter_
virtual void SetSemanticsEnabled(bool enabled)
Used by embedder to notify the running isolate hosted by the engine on the UI thread that the accessi...
The interface for Engine to implement.
std::unique_ptr< PointerDataPacket > Convert(std::unique_ptr< PointerDataPacket > packet)
Converts pointer data packet into a form that framework understands. The raw pointer data packet from...
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition mapping.h:144
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
TaskRunners task_runners_
MockDelegate delegate_
VkSurfaceKHR surface
Definition main.cc:49
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_DLOG(severity)
Definition logging.h:102
#define FML_LOG(severity)
Definition logging.h:82
#define FML_UNREACHABLE()
Definition logging.h:109
#define FML_DCHECK(condition)
Definition logging.h:103
const char * name
Definition fuchsia.cc:50
Win32Message message
FlTexture * texture
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
std::function< std::unique_ptr< PointerDataDispatcher >(PointerDataDispatcher::Delegate &)> PointerDataDispatcherMaker
Signature for constructing PointerDataDispatcher.
std::function< void()> closure
Definition closure.h:14
int64_t texture_id
#define ERROR(message)