5#include "flutter/lib/ui/window/platform_configuration.h"
9#include "flutter/common/constants.h"
10#include "flutter/lib/ui/compositing/scene.h"
11#include "flutter/lib/ui/ui_dart_state.h"
12#include "flutter/lib/ui/window/platform_message.h"
13#include "flutter/lib/ui/window/platform_message_response_dart.h"
14#include "flutter/lib/ui/window/platform_message_response_dart_port.h"
15#include "flutter/lib/ui/window/viewport_metrics.h"
49 update_window_metrics_.
Set(
57 update_user_settings_data_.
Set(
60 update_initial_lifecycle_state_.
Set(
63 update_semantics_enabled_.
Set(
66 update_accessibility_features_.
Set(
69 dispatch_platform_message_.
Set(
72 dispatch_pointer_data_packet_.
Set(
75 dispatch_semantics_action_.
Set(
88 auto [view_iterator, insertion_happened] =
89 metrics_.emplace(view_id, view_metrics);
90 if (!insertion_happened) {
91 FML_LOG(
ERROR) <<
"View #" << view_id <<
" already exists.";
95 std::shared_ptr<tonic::DartState> dart_state = add_view_.
dart_state().lock();
103 tonic::ToDart(view_id),
104 tonic::ToDart(view_metrics.device_pixel_ratio),
105 tonic::ToDart(view_metrics.physical_width),
106 tonic::ToDart(view_metrics.physical_height),
107 tonic::ToDart(view_metrics.physical_padding_top),
108 tonic::ToDart(view_metrics.physical_padding_right),
109 tonic::ToDart(view_metrics.physical_padding_bottom),
110 tonic::ToDart(view_metrics.physical_padding_left),
111 tonic::ToDart(view_metrics.physical_view_inset_top),
112 tonic::ToDart(view_metrics.physical_view_inset_right),
113 tonic::ToDart(view_metrics.physical_view_inset_bottom),
114 tonic::ToDart(view_metrics.physical_view_inset_left),
115 tonic::ToDart(view_metrics.physical_system_gesture_inset_top),
116 tonic::ToDart(view_metrics.physical_system_gesture_inset_right),
117 tonic::ToDart(view_metrics.physical_system_gesture_inset_bottom),
118 tonic::ToDart(view_metrics.physical_system_gesture_inset_left),
119 tonic::ToDart(view_metrics.physical_touch_slop),
120 tonic::ToDart(view_metrics.physical_display_features_bounds),
121 tonic::ToDart(view_metrics.physical_display_features_type),
122 tonic::ToDart(view_metrics.physical_display_features_state),
123 tonic::ToDart(view_metrics.display_id),
130 FML_LOG(
FATAL) <<
"The implicit view #" << view_id <<
" cannot be removed.";
133 size_t erased_elements = metrics_.erase(view_id);
134 if (erased_elements == 0) {
135 FML_LOG(
ERROR) <<
"View #" << view_id <<
" doesn't exist.";
139 std::shared_ptr<tonic::DartState> dart_state =
147 tonic::ToDart(view_id),
155 auto found_iter = metrics_.find(view_id);
156 if (found_iter == metrics_.end()) {
160 found_iter->second = view_metrics;
162 std::shared_ptr<tonic::DartState> dart_state =
169 update_window_metrics_.
Get(),
171 tonic::ToDart(view_id),
172 tonic::ToDart(view_metrics.device_pixel_ratio),
173 tonic::ToDart(view_metrics.physical_width),
174 tonic::ToDart(view_metrics.physical_height),
175 tonic::ToDart(view_metrics.physical_padding_top),
176 tonic::ToDart(view_metrics.physical_padding_right),
177 tonic::ToDart(view_metrics.physical_padding_bottom),
178 tonic::ToDart(view_metrics.physical_padding_left),
179 tonic::ToDart(view_metrics.physical_view_inset_top),
180 tonic::ToDart(view_metrics.physical_view_inset_right),
181 tonic::ToDart(view_metrics.physical_view_inset_bottom),
182 tonic::ToDart(view_metrics.physical_view_inset_left),
183 tonic::ToDart(view_metrics.physical_system_gesture_inset_top),
184 tonic::ToDart(view_metrics.physical_system_gesture_inset_right),
185 tonic::ToDart(view_metrics.physical_system_gesture_inset_bottom),
186 tonic::ToDart(view_metrics.physical_system_gesture_inset_left),
187 tonic::ToDart(view_metrics.physical_touch_slop),
188 tonic::ToDart(view_metrics.physical_display_features_bounds),
189 tonic::ToDart(view_metrics.physical_display_features_type),
190 tonic::ToDart(view_metrics.physical_display_features_state),
191 tonic::ToDart(view_metrics.display_id),
197 const std::vector<DisplayData>& displays) {
198 std::vector<DisplayId> ids;
199 std::vector<double>
widths;
200 std::vector<double> heights;
201 std::vector<double> device_pixel_ratios;
202 std::vector<double> refresh_rates;
203 for (
const auto& display : displays) {
204 ids.push_back(display.id);
205 widths.push_back(display.width);
206 heights.push_back(display.height);
207 device_pixel_ratios.push_back(display.pixel_ratio);
208 refresh_rates.push_back(display.refresh_rate);
210 std::shared_ptr<tonic::DartState> dart_state =
217 update_displays_.
Get(),
219 tonic::ToDart<std::vector<DisplayId>>(ids),
220 tonic::ToDart<std::vector<double>>(widths),
221 tonic::ToDart<std::vector<double>>(heights),
222 tonic::ToDart<std::vector<double>>(device_pixel_ratios),
223 tonic::ToDart<std::vector<double>>(refresh_rates),
228 const std::vector<std::string>& locales) {
229 std::shared_ptr<tonic::DartState> dart_state =
239 tonic::ToDart<std::vector<std::string>>(locales),
244 std::shared_ptr<tonic::DartState> dart_state =
245 update_user_settings_data_.
dart_state().lock();
253 tonic::StdStringToDart(data),
258 const std::string&
data) {
259 std::shared_ptr<tonic::DartState> dart_state =
260 update_initial_lifecycle_state_.
dart_state().lock();
266 update_initial_lifecycle_state_.
Get(), {
267 tonic::StdStringToDart(data),
272 std::shared_ptr<tonic::DartState> dart_state =
273 update_semantics_enabled_.
dart_state().lock();
281 {tonic::ToDart(enabled)}));
285 std::shared_ptr<tonic::DartState> dart_state =
286 update_accessibility_features_.
dart_state().lock();
293 update_accessibility_features_.
Get(), {tonic::ToDart(values)}));
297 std::unique_ptr<PlatformMessage>
message) {
298 std::shared_ptr<tonic::DartState> dart_state =
299 dispatch_platform_message_.
dart_state().lock();
302 <<
"Dropping platform message for lack of DartState on channel: "
311 <<
"Dropping platform message because of a Dart error on channel: "
317 if (
auto response =
message->response()) {
318 response_id = next_response_id_++;
319 pending_responses_[response_id] = response;
324 {tonic::ToDart(message->channel()), data_handle,
325 tonic::ToDart(response_id)}));
330 std::shared_ptr<tonic::DartState> dart_state =
331 dispatch_pointer_data_packet_.
dart_state().lock();
337 const std::vector<uint8_t>&
buffer = packet.
data();
351 std::shared_ptr<tonic::DartState> dart_state =
352 dispatch_semantics_action_.
dart_state().lock();
366 dispatch_semantics_action_.
Get(),
367 {tonic::ToDart(node_id), tonic::ToDart(static_cast<int32_t>(action)),
372 uint64_t frame_number) {
373 std::shared_ptr<tonic::DartState> dart_state =
380 int64_t microseconds = (frameTime -
fml::TimePoint()).ToMicroseconds();
384 Dart_NewInteger(microseconds),
385 Dart_NewInteger(frame_number),
394 std::shared_ptr<tonic::DartState> dart_state =
405 void*
data =
nullptr;
406 intptr_t num_acquired = 0;
409 FML_DCHECK(num_acquired ==
static_cast<int>(timings.size()));
411 memcpy(
data, timings.data(),
sizeof(int64_t) * timings.size());
421 auto found = metrics_.find(view_id);
422 if (found != metrics_.end()) {
423 return &found->second;
434 auto it = pending_responses_.find(response_id);
435 if (it == pending_responses_.end()) {
438 auto response = std::move(it->second);
439 pending_responses_.erase(it);
440 response->CompleteEmpty();
445 std::vector<uint8_t>
data) {
449 auto it = pending_responses_.find(response_id);
450 if (it == pending_responses_.end()) {
453 auto response = std::move(it->second);
454 pending_responses_.erase(it);
455 response->Complete(std::make_unique<fml::DataMapping>(std::move(
data)));
478 const std::string&
name,
483 std::make_unique<PlatformMessage>(
name, response));
486 const uint8_t*
buffer =
static_cast<const uint8_t*
>(
data.data());
495 const std::string&
name,
502 "SendPlatformMessage only works on the root isolate, see "
503 "SendPortPlatformMessage.");
508 response = fml::MakeRefCounted<PlatformMessageResponseDart>(
513 return HandlePlatformMessage(dart_state,
name, data_handle, response);
517 const std::string&
name,
530 fml::MakeRefCounted<PlatformMessageResponseDartPort>(
534 return HandlePlatformMessage(dart_state,
name, data_handle, response);
546 const uint8_t*
buffer =
static_cast<const uint8_t*
>(
data.data());
556 const std::string&
name) {
565 return current_performance_mode_;
582 if (!persistent_isolate_data) {
587 persistent_isolate_data->GetSize());
609 std::vector<std::string> supportedLocales =
611 supportedLocalesHandle);
613 std::vector<std::string> results =
637 int64_t root_isolate_token) {
640 auto platform_message_handler =
641 (*
static_cast<std::shared_ptr<PlatformMessageHandlerStorage>*
>(
644 auto weak_platform_message_handler =
645 platform_message_handler->GetPlatformMessageHandler(root_isolate_token);
656 double unscaled_font_size,
657 int configuration_id) {
const std::vector< uint8_t > & data() const
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
PlatformConfiguration * platform_configuration() const
bool IsRootIsolate() const
void FlushMicrotasksNow()
const TaskRunners & GetTaskRunners() const
void SetDebugName(const std::string &name)
int64_t GetRootIsolateToken() const
void SetPlatformMessageHandler(std::weak_ptr< PlatformMessageHandler > handler)
static UIDartState * Current()
static void ThrowIfUIOperationsProhibited()
Dart_Handle HandlePlatformMessage(std::unique_ptr< PlatformMessage > message)
A Mapping like NonOwnedMapping, but uses Free as its release proc.
static MallocMapping Copy(const T *begin, const T *end)
static Dart_Handle Create(const void *data, size_t length)
void Set(DartState *dart_state, Dart_Handle value)
const std::weak_ptr< DartState > & dart_state() const
static DartState * Current()
static SkString identifier(const FontFamilyDesc &family, const FontDesc &font)
@ Dart_PerformanceMode_Default
struct _Dart_Handle * Dart_Handle
DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, Dart_TypedData_Type *type, void **data, intptr_t *len)
DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, intptr_t length)
DART_EXPORT Dart_Handle Dart_Null(void)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name)
DART_EXPORT Dart_PerformanceMode Dart_SetPerformanceMode(Dart_PerformanceMode mode)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT void * Dart_CurrentIsolateGroupData(void)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_DLOG(severity)
#define FML_LOG(severity)
#define FML_CHECK(condition)
#define FML_DCHECK(condition)
constexpr int64_t kFlutterImplicitViewId
DEF_SWITCHES_START aot vmservice shared library name
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
std::chrono::time_point< std::chrono::high_resolution_clock > TimePoint
Dart_Handle ToDart(const T &object)
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
Dart_Handle DartInvokeVoid(Dart_Handle closure)
bool CheckAndHandleError(Dart_Handle handle)