Flutter Engine
The Flutter Engine
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}
37
42 std::move(args));
43}
44
47}
48
51}
52
54 const ViewportMetrics& metrics) {
56}
57
59 std::unique_ptr<Surface> surface;
60 // Threading: We want to use the platform view on the non-platform thread.
61 // Using the weak pointer is illegal. But, we are going to introduce a latch
62 // so that the platform view is not collected till the surface is obtained.
63 auto* platform_view = this;
67 surface = platform_view->CreateRenderingSurface();
68 if (surface && !surface->IsValid()) {
69 surface.reset();
70 }
71 latch.Signal();
72 });
73 latch.Wait();
74 if (!surface) {
75 FML_LOG(ERROR) << "Failed to create platform view rendering surface";
76 return;
77 }
78 delegate_.OnPlatformViewCreated(std::move(surface));
79}
80
81void PlatformView::NotifyDestroyed() {
82 delegate_.OnPlatformViewDestroyed();
83}
84
86 delegate_.OnPlatformViewScheduleFrame();
87}
88
89void PlatformView::AddView(int64_t view_id,
90 const ViewportMetrics& viewport_metrics,
92 delegate_.OnPlatformViewAddView(view_id, viewport_metrics,
93 std::move(callback));
94}
95
96void PlatformView::RemoveView(int64_t view_id, RemoveViewCallback callback) {
97 delegate_.OnPlatformViewRemoveView(view_id, std::move(callback));
98}
99
100sk_sp<GrDirectContext> PlatformView::CreateResourceContext() const {
101 FML_DLOG(WARNING) << "This platform does not set up the resource "
102 "context on the IO thread for async texture uploads.";
103 return nullptr;
104}
105
106std::shared_ptr<impeller::Context> PlatformView::GetImpellerContext() const {
107 return nullptr;
108}
109
110void PlatformView::ReleaseResourceContext() const {}
111
112PointerDataDispatcherMaker PlatformView::GetDispatcherMaker() {
113 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
114 return std::make_unique<DefaultPointerDataDispatcher>(delegate);
115 };
116}
117
118fml::WeakPtr<PlatformView> PlatformView::GetWeakPtr() const {
119 return weak_factory_.GetWeakPtr();
120}
121
122void PlatformView::UpdateSemantics(
123 SemanticsNodeUpdates update, // NOLINT(performance-unnecessary-value-param)
124 // NOLINTNEXTLINE(performance-unnecessary-value-param)
126
127void PlatformView::SendChannelUpdate(const std::string& name, bool listening) {}
128
129void PlatformView::HandlePlatformMessage(
130 std::unique_ptr<PlatformMessage> message) {
131 if (auto response = message->response()) {
132 response->CompleteEmpty();
133 }
134}
135
136void PlatformView::OnPreEngineRestart() const {}
137
138void PlatformView::RegisterTexture(std::shared_ptr<flutter::Texture> texture) {
139 delegate_.OnPlatformViewRegisterTexture(std::move(texture));
140}
141
143 delegate_.OnPlatformViewUnregisterTexture(texture_id);
144}
145
147 delegate_.OnPlatformViewMarkTextureFrameAvailable(texture_id);
148}
149
150std::unique_ptr<Surface> PlatformView::CreateRenderingSurface() {
151 // We have a default implementation because tests create a platform view but
152 // never a rendering surface.
153 FML_DCHECK(false) << "This platform does not provide a rendering surface but "
154 "it was notified of surface rendering surface creation.";
155 return nullptr;
156}
157
158std::shared_ptr<ExternalViewEmbedder>
159PlatformView::CreateExternalViewEmbedder() {
160 FML_DLOG(WARNING)
161 << "This platform doesn't support embedding external views.";
162 return nullptr;
163}
164
165void PlatformView::SetNextFrameCallback(const fml::closure& closure) {
166 if (!closure) {
167 return;
168 }
169
170 delegate_.OnPlatformViewSetNextFrameCallback(closure);
171}
172
173std::unique_ptr<std::vector<std::string>>
174PlatformView::ComputePlatformResolvedLocales(
175 const std::vector<std::string>& supported_locale_data) {
176 std::unique_ptr<std::vector<std::string>> out =
177 std::make_unique<std::vector<std::string>>();
178 return out;
179}
180
181void PlatformView::RequestDartDeferredLibrary(intptr_t loading_unit_id) {}
182
184 intptr_t loading_unit_id,
185 std::unique_ptr<const fml::Mapping> snapshot_data,
186 std::unique_ptr<const fml::Mapping> snapshot_instructions) {}
187
188void PlatformView::LoadDartDeferredLibraryError(
189 intptr_t loading_unit_id,
190 const std::string
191 error_message, // NOLINT(performance-unnecessary-value-param)
192 bool transient) {}
193
194void PlatformView::UpdateAssetResolverByType(
195 std::unique_ptr<AssetResolver> updated_asset_resolver,
197 delegate_.UpdateAssetResolverByType(std::move(updated_asset_resolver), type);
198}
199
200std::unique_ptr<SnapshotSurfaceProducer>
201PlatformView::CreateSnapshotSurfaceProducer() {
202 return nullptr;
203}
204
205std::shared_ptr<PlatformMessageHandler>
206PlatformView::GetPlatformMessageHandler() const {
207 return nullptr;
208}
209
210const Settings& PlatformView::GetSettings() const {
211 return delegate_.OnPlatformViewGetSettings();
212}
213
214double PlatformView::GetScaledFontSize(double unscaled_font_size,
215 int configuration_id) const {
216 // Unreachable by default, as most platforms do not support nonlinear scaling
217 // and the Flutter application never invokes this method.
219 return -1;
220}
221
222} // 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...
Definition: platform_view.h:60
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...
std::function< void(bool removed)> RemoveViewCallback
Definition: platform_view.h:54
virtual void SetSemanticsEnabled(bool enabled)
Used by embedder to notify the running isolate hosted by the engine on the UI thread that the accessi...
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
Definition: platform_view.h:53
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...
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.
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
Definition: task_runners.cc:42
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)
Definition: task_runner.cc:55
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
Win32Message message
FlTexture * texture
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
static void MarkTextureFrameAvailable(JNIEnv *env, jobject jcaller, jlong shell_holder, jlong texture_id)
std::function< std::unique_ptr< PointerDataDispatcher >(PointerDataDispatcher::Delegate &)> PointerDataDispatcherMaker
Signature for constructing PointerDataDispatcher.
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
static void LoadDartDeferredLibrary(JNIEnv *env, jobject obj, jlong shell_holder, jint jLoadingUnitId, jobjectArray jSearchPaths)
static void ScheduleFrame(JNIEnv *env, jobject jcaller, jlong shell_holder)
static void UnregisterTexture(JNIEnv *env, jobject jcaller, jlong shell_holder, jlong texture_id)
static void RegisterTexture(JNIEnv *env, jobject jcaller, jlong shell_holder, jlong texture_id, jobject surface_texture)
std::function< void()> closure
Definition: closure.h:14
Definition: update.py:1
int64_t texture_id
#define ERROR(message)
Definition: elf_loader.cc:260