Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
platform_view.h
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#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_PLATFORM_VIEW_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_PLATFORM_VIEW_H_
7
8#include <fuchsia/ui/composition/cpp/fidl.h>
9#include <fuchsia/ui/input/cpp/fidl.h>
10#include <fuchsia/ui/input3/cpp/fidl.h>
11#include <fuchsia/ui/pointer/cpp/fidl.h>
12#include <fuchsia/ui/test/input/cpp/fidl.h>
13#include <lib/fidl/cpp/binding.h>
14#include <lib/fit/function.h>
15#include <lib/sys/cpp/service_directory.h>
16
17#include <array>
18#include <functional>
19#include <map>
20#include <memory>
21#include <set>
22#include <string>
23#include <unordered_map>
24#include <vector>
25#include "flutter/fml/memory/weak_ptr.h"
26#include "flutter/shell/platform/fuchsia/flutter/external_view_embedder.h"
27
28#include "flow/embedded_views.h"
29#include "flutter/fml/macros.h"
30#include "flutter/fml/memory/weak_ptr.h"
31#include "flutter/fml/time/time_delta.h"
32#include "flutter/shell/common/platform_view.h"
33#include "flutter/shell/platform/fuchsia/flutter/keyboard.h"
34#include "flutter/shell/platform/fuchsia/flutter/vsync_waiter.h"
35#include "focus_delegate.h"
36#include "pointer_delegate.h"
38#include "text_delegate.h"
39
40namespace flutter_runner {
41
42using OnEnableWireframeCallback = fit::function<void(bool)>;
43using ViewCallback = std::function<void()>;
44using OnUpdateViewCallback = fit::function<void(int64_t, SkRect, bool, bool)>;
46 fit::function<std::unique_ptr<flutter::Surface>()>;
48 fit::function<void(flutter::SemanticsNodeUpdates, float)>;
49using OnRequestAnnounceCallback = fit::function<void(std::string)>;
51 fit::function<void(int64_t, ViewCallback, ViewCreatedCallback, bool, bool)>;
52using OnDestroyViewCallback = fit::function<void(int64_t, ViewIdCallback)>;
53
54// we use an std::function here because the fit::funtion causes problems with
55// std:bind since HandleFuchsiaShaderWarmupChannelPlatformMessage takes one of
56// these as its first argument.
58 std::function<void(const std::vector<std::string>&,
59 std::function<void(uint32_t)>,
60 uint64_t,
61 uint64_t)>;
62
63// PlatformView is the per-engine component residing on the platform thread that
64// is responsible for all platform specific integrations -- particularly
65// integration with the platform's accessibility, input, and windowing features.
66//
67// PlatformView communicates with the Dart code via "platform messages" handled
68// in HandlePlatformMessage. This communication is bidirectional. Platform
69// messages are notably responsible for communication related to input and
70// external views / windowing.
72 public:
75 flutter::TaskRunners task_runners,
76 fuchsia::ui::views::ViewRef view_ref,
77 std::shared_ptr<flutter::ExternalViewEmbedder> external_view_embedder,
78 fuchsia::ui::input::ImeServiceHandle ime_service,
79 fuchsia::ui::input3::KeyboardHandle keyboard,
80 fuchsia::ui::pointer::TouchSourceHandle touch_source,
81 fuchsia::ui::pointer::MouseSourceHandle mouse_source,
82 fuchsia::ui::views::FocuserHandle focuser,
83 fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused,
84 fuchsia::ui::composition::ParentViewportWatcherHandle
85 parent_viewport_watcher,
86 fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry,
87 OnEnableWireframeCallback wireframe_enabled_callback,
88 OnCreateViewCallback on_create_view_callback,
89 OnUpdateViewCallback on_update_view_callback,
90 OnDestroyViewCallback on_destroy_view_callback,
91 OnCreateSurfaceCallback on_create_surface_callback,
92 OnSemanticsNodeUpdateCallback on_semantics_node_update_callback,
93 OnRequestAnnounceCallback on_request_announce_callback,
94 OnShaderWarmupCallback on_shader_warmup_callback,
95 AwaitVsyncCallback await_vsync_callback,
97 await_vsync_for_secondary_callback_callback,
98 std::shared_ptr<sys::ServiceDirectory> dart_application_svc);
99
100 ~PlatformView() override;
101
102 void OnGetLayout(fuchsia::ui::composition::LayoutInfo info);
104 fuchsia::ui::composition::ParentViewportStatus status);
105 void OnChildViewStatus(uint64_t content_id,
106 fuchsia::ui::composition::ChildViewStatus status);
107 void OnChildViewViewRef(uint64_t content_id,
108 uint64_t view_id,
109 fuchsia::ui::views::ViewRef view_ref);
110
111 // |flutter::PlatformView|
112 void SetSemanticsEnabled(bool enabled) override;
113
114 // |flutter::PlatformView|
115 std::shared_ptr<flutter::ExternalViewEmbedder> CreateExternalViewEmbedder()
116 override;
117
118 private:
119 void RegisterPlatformMessageHandlers();
120
121 bool OnHandlePointerEvent(const fuchsia::ui::input::PointerEvent& pointer);
122
123 bool OnHandleFocusEvent(const fuchsia::ui::input::FocusEvent& focus);
124
125 // |flutter::PlatformView|
126 std::unique_ptr<flutter::VsyncWaiter> CreateVSyncWaiter() override;
127
128 // |flutter::PlatformView|
129 std::unique_ptr<flutter::Surface> CreateRenderingSurface() override;
130
131 // |flutter::PlatformView|
133 std::unique_ptr<flutter::PlatformMessage> message) override;
134
135 // |flutter::PlatformView|
136 void UpdateSemantics(
139
140 // Channel handler for kAccessibilityChannel. This is currently not
141 // being used, but it is necessary to handle accessibility messages
142 // that are sent by Flutter when semantics is enabled.
143 bool HandleAccessibilityChannelPlatformMessage(
144 std::unique_ptr<flutter::PlatformMessage> message);
145
146 // Channel handler for kFlutterPlatformChannel
147 bool HandleFlutterPlatformChannelPlatformMessage(
148 std::unique_ptr<flutter::PlatformMessage> message);
149
150 // Channel handler for kPlatformViewsChannel.
151 bool HandleFlutterPlatformViewsChannelPlatformMessage(
152 std::unique_ptr<flutter::PlatformMessage> message);
153
154 // Channel handler for kFuchsiaShaderWarmupChannel.
155 static bool HandleFuchsiaShaderWarmupChannelPlatformMessage(
156 OnShaderWarmupCallback on_shader_warmup_callback,
157 std::unique_ptr<flutter::PlatformMessage> message);
158
159 // Channel handler for kFuchsiaInputTestChannel.
160 bool HandleFuchsiaInputTestChannelPlatformMessage(
161 std::unique_ptr<flutter::PlatformMessage> message);
162
163 // Channel handler for kFuchsiaChildViewChannel.
164 bool HandleFuchsiaChildViewChannelPlatformMessage(
165 std::unique_ptr<flutter::PlatformMessage> message);
166
167 void OnCreateView(ViewCallback on_view_created,
168 int64_t view_id_raw,
169 bool hit_testable,
170 bool focusable);
171 void OnDisposeView(int64_t view_id_raw);
172
173 // Sends a 'View.viewConnected' platform message over 'flutter/platform_views'
174 // channel when a view gets created.
175 void OnChildViewConnected(uint64_t content_id);
176
177 // Sends a 'View.viewDisconnected' platform message over
178 // 'flutter/platform_views' channel when a view gets destroyed or the child
179 // view watcher channel of a view closes.
180 void OnChildViewDisconnected(uint64_t content_id);
181
182 // Utility function for coordinate massaging.
183 std::array<float, 2> ClampToViewSpace(const float x, const float y) const;
184
185 // Logical size and origin, and logical->physical ratio. These are optional
186 // to provide an "unset" state during program startup, before Scenic has sent
187 // any metrics-related events to provide initial values for these.
188 //
189 // The engine internally uses a default size of (0.f 0.f) with a default 1.f
190 // ratio, so there is no need to emit events until Scenic has actually sent a
191 // valid size and ratio.
192 std::optional<std::array<float, 2>> view_logical_size_;
193 std::optional<std::array<float, 2>> view_logical_origin_;
194 std::optional<float> view_pixel_ratio_;
195
196 std::shared_ptr<flutter::ExternalViewEmbedder> external_view_embedder_;
197
198 std::shared_ptr<FocusDelegate> focus_delegate_;
199 std::shared_ptr<PointerDelegate> pointer_delegate_;
200 std::unique_ptr<PointerInjectorDelegate> pointer_injector_delegate_;
201
202 // Text delegate is responsible for handling keyboard input and text editing.
203 std::unique_ptr<TextDelegate> text_delegate_;
204
205 std::set<int> down_pointers_;
206 std::map<std::string /* channel */,
207 std::function<bool /* response_handled */ (
208 std::unique_ptr<
209 flutter::PlatformMessage> /* message */)> /* handler */>
210 platform_message_handlers_;
211 // These are the channels that aren't registered and have been notified as
212 // such. Notifying via logs multiple times results in log-spam. See:
213 // https://github.com/flutter/flutter/issues/55966
214 std::set<std::string /* channel */> unregistered_channels_;
215
216 OnEnableWireframeCallback wireframe_enabled_callback_;
217 OnUpdateViewCallback on_update_view_callback_;
218 OnCreateSurfaceCallback on_create_surface_callback_;
219 OnSemanticsNodeUpdateCallback on_semantics_node_update_callback_;
220 OnRequestAnnounceCallback on_request_announce_callback_;
221 OnCreateViewCallback on_create_view_callback_;
222 OnDestroyViewCallback on_destroy_view_callback_;
223 OnShaderWarmupCallback on_shader_warmup_callback_;
224 AwaitVsyncCallback await_vsync_callback_;
226 await_vsync_for_secondary_callback_callback_;
227
228 // Proxies for input tests.
229 fuchsia::ui::test::input::TouchInputListenerPtr touch_input_listener_;
230 fuchsia::ui::test::input::KeyboardInputListenerPtr keyboard_input_listener_;
231 fuchsia::ui::test::input::MouseInputListenerPtr mouse_input_listener_;
232
233 // Component's service directory.
234 std::shared_ptr<sys::ServiceDirectory> dart_application_svc_;
235
236 // child_view_ids_ maintains a persistent mapping from Flatland ContentId's to
237 // flutter view ids, which are really zx_handle_t of ViewCreationToken.
238 struct ChildViewInfo {
239 ChildViewInfo(zx_handle_t token,
240 fuchsia::ui::composition::ChildViewWatcherPtr watcher)
241 : view_id(token), child_view_watcher(std::move(watcher)) {}
242 zx_handle_t view_id;
243 fuchsia::ui::composition::ChildViewWatcherPtr child_view_watcher;
244 };
245 std::unordered_map<uint64_t /*fuchsia::ui::composition::ContentId*/,
246 ChildViewInfo>
247 child_view_info_;
248
249 fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher_;
250 fuchsia::ui::composition::ParentViewportStatus parent_viewport_status_;
251
252 fml::WeakPtrFactory<PlatformView> weak_factory_; // Must be the last member.
253
254 FML_DISALLOW_COPY_AND_ASSIGN(PlatformView);
255};
256
257} // namespace flutter_runner
258
259#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_PLATFORM_VIEW_H_
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
Used to forward events from the platform view to interested subsystems. This forwarding is done by th...
Platform views are created by the shell on the platform task runner. Unless explicitly specified,...
std::unique_ptr< flutter::Surface > CreateRenderingSurface() override
~PlatformView() override
Destroys the platform view. The platform view is owned by the shell and will be destroyed by the same...
void SetSemanticsEnabled(bool enabled) override
Used by embedder to notify the running isolate hosted by the engine on the UI thread that the accessi...
std::shared_ptr< flutter::ExternalViewEmbedder > CreateExternalViewEmbedder() override
void OnChildViewStatus(uint64_t content_id, fuchsia::ui::composition::ChildViewStatus status)
void UpdateSemantics(flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions) override
Used by the framework to tell the embedder to apply the specified semantics node updates....
void HandlePlatformMessage(std::unique_ptr< flutter::PlatformMessage > message) override
Overridden by embedders to perform actions in response to platform messages sent from the framework t...
std::unique_ptr< flutter::VsyncWaiter > CreateVSyncWaiter() override
Invoked by the shell to obtain a platform specific vsync waiter. It is optional for platforms to over...
void OnGetLayout(fuchsia::ui::composition::LayoutInfo info)
void OnParentViewportStatus(fuchsia::ui::composition::ParentViewportStatus status)
void OnChildViewViewRef(uint64_t content_id, uint64_t view_id, fuchsia::ui::views::ViewRef view_ref)
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
Win32Message message
double y
double x
std::function< void(const std::vector< std::string > &, std::function< void(uint32_t)>, uint64_t, uint64_t)> OnShaderWarmupCallback
fit::function< void(int64_t, ViewCallback, ViewCreatedCallback, bool, bool)> OnCreateViewCallback
fit::function< void(int64_t, ViewIdCallback)> OnDestroyViewCallback
fit::function< void(int64_t, SkRect, bool, bool)> OnUpdateViewCallback
fit::function< std::unique_ptr< flutter::Surface >()> OnCreateSurfaceCallback
std::function< void()> ViewCallback
std::function< void(FireCallbackCallback)> AwaitVsyncForSecondaryCallbackCallback
fit::function< void(flutter::SemanticsNodeUpdates, float)> OnSemanticsNodeUpdateCallback
std::function< void(fuchsia::ui::composition::ContentId)> ViewIdCallback
std::function< void(FireCallbackCallback)> AwaitVsyncCallback
fit::function< void(std::string)> OnRequestAnnounceCallback
std::function< void(fuchsia::ui::composition::ContentId, fuchsia::ui::composition::ChildViewWatcherHandle child_view_watcher)> ViewCreatedCallback
fit::function< void(bool)> OnEnableWireframeCallback
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
Definition ref_ptr.h:256