Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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
42
50
54
58
63
65 std::unique_ptr<Surface> surface;
66 // Threading: We want to use the platform view on the non-platform thread.
67 // Using the weak pointer is illegal. But, we are going to introduce a latch
68 // so that the platform view is not collected till the surface is obtained.
69 auto* platform_view = this;
73 surface = platform_view->CreateRenderingSurface();
74 if (surface && !surface->IsValid()) {
75 surface.reset();
76 }
77 latch.Signal();
78 });
79 latch.Wait();
80 if (!surface) {
81 FML_LOG(ERROR) << "Failed to create platform view rendering surface";
82 return;
83 }
84 delegate_.OnPlatformViewCreated(std::move(surface));
85}
86
87void PlatformView::NotifyDestroyed() {
88 delegate_.OnPlatformViewDestroyed();
89}
90
91void PlatformView::ScheduleFrame() {
92 delegate_.OnPlatformViewScheduleFrame();
93}
94
95void PlatformView::AddView(int64_t view_id,
96 const ViewportMetrics& viewport_metrics,
98 delegate_.OnPlatformViewAddView(view_id, viewport_metrics,
99 std::move(callback));
100}
101
102void PlatformView::RemoveView(int64_t view_id, RemoveViewCallback callback) {
103 delegate_.OnPlatformViewRemoveView(view_id, std::move(callback));
104}
105
106void PlatformView::SendViewFocusEvent(const ViewFocusEvent& event) {
107 delegate_.OnPlatformViewSendViewFocusEvent(event);
108}
109
110sk_sp<GrDirectContext> PlatformView::CreateResourceContext() const {
111 FML_DLOG(WARNING) << "This platform does not set up the resource "
112 "context on the IO thread for async texture uploads.";
113 return nullptr;
114}
115
116std::shared_ptr<impeller::Context> PlatformView::GetImpellerContext() const {
117 return nullptr;
118}
119
120void PlatformView::ReleaseResourceContext() const {}
121
122PointerDataDispatcherMaker PlatformView::GetDispatcherMaker() {
123 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
124 return std::make_unique<DefaultPointerDataDispatcher>(delegate);
125 };
126}
127
128fml::WeakPtr<PlatformView> PlatformView::GetWeakPtr() const {
129 return weak_factory_.GetWeakPtr();
130}
131
132void PlatformView::UpdateSemantics(
133 int64_t view_id,
134 SemanticsNodeUpdates update, // NOLINT(performance-unnecessary-value-param)
135 // NOLINTNEXTLINE(performance-unnecessary-value-param)
137
138void PlatformView::SetApplicationLocale(
139 std::string locale // NOLINT(performance-unnecessary-value-param)
140) {}
141
142void PlatformView::SetSemanticsTreeEnabled(
143 bool enabled // NOLINT(performance-unnecessary-value-param)
144) {}
145
146void PlatformView::SendChannelUpdate(const std::string& name, bool listening) {}
147
148void PlatformView::HandlePlatformMessage(
149 std::unique_ptr<PlatformMessage> message) {
150 if (auto response = message->response()) {
151 response->CompleteEmpty();
152 }
153}
154
155void PlatformView::OnPreEngineRestart() const {}
156
157void PlatformView::RegisterTexture(std::shared_ptr<flutter::Texture> texture) {
158 delegate_.OnPlatformViewRegisterTexture(std::move(texture));
159}
160
161void PlatformView::UnregisterTexture(int64_t texture_id) {
162 delegate_.OnPlatformViewUnregisterTexture(texture_id);
163}
164
165void PlatformView::MarkTextureFrameAvailable(int64_t texture_id) {
166 delegate_.OnPlatformViewMarkTextureFrameAvailable(texture_id);
167}
168
169std::unique_ptr<Surface> PlatformView::CreateRenderingSurface() {
170 // We have a default implementation because tests create a platform view but
171 // never a rendering surface.
172 FML_DCHECK(false) << "This platform does not provide a rendering surface but "
173 "it was notified of surface rendering surface creation.";
174 return nullptr;
175}
176
177std::shared_ptr<ExternalViewEmbedder>
178PlatformView::CreateExternalViewEmbedder() {
179 FML_DLOG(WARNING)
180 << "This platform doesn't support embedding external views.";
181 return nullptr;
182}
183
184void PlatformView::SetNextFrameCallback(const fml::closure& closure) {
185 if (!closure) {
186 return;
187 }
188
189 delegate_.OnPlatformViewSetNextFrameCallback(closure);
190}
191
192std::unique_ptr<std::vector<std::string>>
193PlatformView::ComputePlatformResolvedLocales(
194 const std::vector<std::string>& supported_locale_data) {
195 std::unique_ptr<std::vector<std::string>> out =
196 std::make_unique<std::vector<std::string>>();
197 return out;
198}
199
200void PlatformView::RequestDartDeferredLibrary(intptr_t loading_unit_id) {}
201
202void PlatformView::LoadDartDeferredLibrary(
203 intptr_t loading_unit_id,
204 std::unique_ptr<const fml::Mapping> snapshot_data,
205 std::unique_ptr<const fml::Mapping> snapshot_instructions) {}
206
207void PlatformView::LoadDartDeferredLibraryError(
208 intptr_t loading_unit_id,
209 const std::string
210 error_message, // NOLINT(performance-unnecessary-value-param)
211 bool transient) {}
212
213void PlatformView::UpdateAssetResolverByType(
214 std::unique_ptr<AssetResolver> updated_asset_resolver,
216 delegate_.UpdateAssetResolverByType(std::move(updated_asset_resolver), type);
217}
218
219std::unique_ptr<SnapshotSurfaceProducer>
220PlatformView::CreateSnapshotSurfaceProducer() {
221 return nullptr;
222}
223
224std::shared_ptr<PlatformMessageHandler>
225PlatformView::GetPlatformMessageHandler() const {
226 return nullptr;
227}
228
229const Settings& PlatformView::GetSettings() const {
230 return delegate_.OnPlatformViewGetSettings();
231}
232
233double PlatformView::GetScaledFontSize(double unscaled_font_size,
234 int configuration_id) const {
235 // Unreachable by default, as most platforms do not support nonlinear scaling
236 // and the Flutter application never invokes this method.
238 return -1;
239}
240
241void PlatformView::RequestViewFocusChange(
242 const ViewFocusChangeRequest& request) {
243 // No-op by default.
244}
245
246} // 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 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 HitTestResponse OnPlatformViewHitTest(int64_t view_id, const flutter::PointData offset)=0
Requests the delegate to perform framework hit test from the engine. This API must be called from the...
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_
HitTestResponse HitTest(int64_t view_id, const flutter::PointData offset)
Requests to perform framework hit test from the engine.
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
const char * message
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
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:50
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
impeller::ShaderType type
int64_t texture_id