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
6
7#include <utility>
8
12#include "third_party/skia/include/gpu/ganesh/gl/GrGLInterface.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}
37
45
49
53
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
101void PlatformView::SendViewFocusEvent(const ViewFocusEvent& event) {
102 delegate_.OnPlatformViewSendViewFocusEvent(event);
103}
104
105sk_sp<GrDirectContext> PlatformView::CreateResourceContext() const {
106 FML_DLOG(WARNING) << "This platform does not set up the resource "
107 "context on the IO thread for async texture uploads.";
108 return nullptr;
109}
110
111std::shared_ptr<impeller::Context> PlatformView::GetImpellerContext() const {
112 return nullptr;
113}
114
115void PlatformView::ReleaseResourceContext() const {}
116
117PointerDataDispatcherMaker PlatformView::GetDispatcherMaker() {
118 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
119 return std::make_unique<DefaultPointerDataDispatcher>(delegate);
120 };
121}
122
123fml::WeakPtr<PlatformView> PlatformView::GetWeakPtr() const {
124 return weak_factory_.GetWeakPtr();
125}
126
127void PlatformView::UpdateSemantics(
128 int64_t view_id,
129 SemanticsNodeUpdates update, // NOLINT(performance-unnecessary-value-param)
130 // NOLINTNEXTLINE(performance-unnecessary-value-param)
132
133void PlatformView::SetApplicationLocale(
134 std::string locale // NOLINT(performance-unnecessary-value-param)
135) {}
136
137void PlatformView::SetSemanticsTreeEnabled(
138 bool enabled // NOLINT(performance-unnecessary-value-param)
139) {}
140
141void PlatformView::SendChannelUpdate(const std::string& name, bool listening) {}
142
143void PlatformView::HandlePlatformMessage(
144 std::unique_ptr<PlatformMessage> message) {
145 if (auto response = message->response()) {
146 response->CompleteEmpty();
147 }
148}
149
150void PlatformView::OnPreEngineRestart() const {}
151
152void PlatformView::RegisterTexture(std::shared_ptr<flutter::Texture> texture) {
153 delegate_.OnPlatformViewRegisterTexture(std::move(texture));
154}
155
156void PlatformView::UnregisterTexture(int64_t texture_id) {
157 delegate_.OnPlatformViewUnregisterTexture(texture_id);
158}
159
160void PlatformView::MarkTextureFrameAvailable(int64_t texture_id) {
161 delegate_.OnPlatformViewMarkTextureFrameAvailable(texture_id);
162}
163
164std::unique_ptr<Surface> PlatformView::CreateRenderingSurface() {
165 // We have a default implementation because tests create a platform view but
166 // never a rendering surface.
167 FML_DCHECK(false) << "This platform does not provide a rendering surface but "
168 "it was notified of surface rendering surface creation.";
169 return nullptr;
170}
171
172std::shared_ptr<ExternalViewEmbedder>
173PlatformView::CreateExternalViewEmbedder() {
174 FML_DLOG(WARNING)
175 << "This platform doesn't support embedding external views.";
176 return nullptr;
177}
178
179void PlatformView::SetNextFrameCallback(const fml::closure& closure) {
180 if (!closure) {
181 return;
182 }
183
184 delegate_.OnPlatformViewSetNextFrameCallback(closure);
185}
186
187std::unique_ptr<std::vector<std::string>>
188PlatformView::ComputePlatformResolvedLocales(
189 const std::vector<std::string>& supported_locale_data) {
190 std::unique_ptr<std::vector<std::string>> out =
191 std::make_unique<std::vector<std::string>>();
192 return out;
193}
194
195void PlatformView::RequestDartDeferredLibrary(intptr_t loading_unit_id) {}
196
197void PlatformView::LoadDartDeferredLibrary(
198 intptr_t loading_unit_id,
199 std::unique_ptr<const fml::Mapping> snapshot_data,
200 std::unique_ptr<const fml::Mapping> snapshot_instructions) {}
201
202void PlatformView::LoadDartDeferredLibraryError(
203 intptr_t loading_unit_id,
204 const std::string
205 error_message, // NOLINT(performance-unnecessary-value-param)
206 bool transient) {}
207
208void PlatformView::UpdateAssetResolverByType(
209 std::unique_ptr<AssetResolver> updated_asset_resolver,
211 delegate_.UpdateAssetResolverByType(std::move(updated_asset_resolver), type);
212}
213
214std::unique_ptr<SnapshotSurfaceProducer>
215PlatformView::CreateSnapshotSurfaceProducer() {
216 return nullptr;
217}
218
219std::shared_ptr<PlatformMessageHandler>
220PlatformView::GetPlatformMessageHandler() const {
221 return nullptr;
222}
223
224const Settings& PlatformView::GetSettings() const {
225 return delegate_.OnPlatformViewGetSettings();
226}
227
228double PlatformView::GetScaledFontSize(double unscaled_font_size,
229 int configuration_id) const {
230 // Unreachable by default, as most platforms do not support nonlinear scaling
231 // and the Flutter application never invokes this method.
233 return -1;
234}
235
236void PlatformView::RequestViewFocusChange(
237 const ViewFocusChangeRequest& request) {
238 // No-op by default.
239}
240
241} // namespace flutter
std::unique_ptr< flutter::PlatformViewIOS > platform_view
GLenum type
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 OnPlatformViewDispatchSemanticsAction(int64_t view_id, 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 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 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...
std::function< void(bool removed)> RemoveViewCallback
virtual void SetSemanticsEnabled(bool enabled)
Used by embedder to notify the running isolate hosted by the engine on the UI thread that the accessi...
void DispatchSemanticsAction(int64_t view_id, 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.
virtual ~PlatformView()
Destroys the platform view. The platform view is owned by the shell and will be destroyed by the same...
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,...
std::function< void(bool added)> AddViewCallback
void DispatchPlatformMessage(std::unique_ptr< PlatformMessage > message)
Used by embedders to dispatch a platform message to a running root isolate hosted by the engine....
PlatformView::Delegate & delegate_
void NotifyCreated()
Used by embedders to notify the shell that a platform view has been created. This notification is use...
virtual std::unique_ptr< VsyncWaiter > CreateVSyncWaiter()
Invoked by the shell to obtain a platform specific vsync waiter. It is optional for platforms to over...
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...
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_
The interface for Engine to implement.
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:65
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS GBytes * message
G_BEGIN_DECLS FlutterViewId view_id
FlutterDesktopBinaryReply callback
#define FML_DLOG(severity)
Definition logging.h:121
#define FML_LOG(severity)
Definition logging.h:101
#define FML_UNREACHABLE()
Definition logging.h:128
#define FML_DCHECK(condition)
Definition logging.h:122
const char * name
Definition fuchsia.cc:49
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