41 Dart_Handle library = Dart_LookupLibrary(
tonic::ToDart(
"dart:ui"));
49 send_view_focus_event_.
Set(
51 Dart_GetField(library,
tonic::ToDart(
"_sendViewFocusEvent")));
54 update_window_metrics_.
Set(
56 Dart_GetField(library,
tonic::ToDart(
"_updateWindowMetrics")));
62 update_user_settings_data_.
Set(
64 Dart_GetField(library,
tonic::ToDart(
"_updateUserSettingsData")));
65 update_initial_lifecycle_state_.
Set(
67 Dart_GetField(library,
tonic::ToDart(
"_updateInitialLifecycleState")));
68 update_semantics_enabled_.
Set(
70 Dart_GetField(library,
tonic::ToDart(
"_updateSemanticsEnabled")));
71 update_accessibility_features_.
Set(
73 Dart_GetField(library,
tonic::ToDart(
"_updateAccessibilityFeatures")));
74 dispatch_platform_message_.
Set(
76 Dart_GetField(library,
tonic::ToDart(
"_dispatchPlatformMessage")));
77 dispatch_pointer_data_packet_.
Set(
79 Dart_GetField(library,
tonic::ToDart(
"_dispatchPointerDataPacket")));
80 dispatch_semantics_action_.
Set(
82 Dart_GetField(library,
tonic::ToDart(
"_dispatchSemanticsAction")));
93 auto [view_iterator, insertion_happened] =
94 metrics_.emplace(
view_id, view_metrics);
95 if (!insertion_happened) {
100 std::shared_ptr<tonic::DartState> dart_state = add_view_.
dart_state().lock();
108 tonic::ToDart(view_id),
109 tonic::ToDart(view_metrics.device_pixel_ratio),
110 tonic::ToDart(view_metrics.physical_width),
111 tonic::ToDart(view_metrics.physical_height),
112 tonic::ToDart(view_metrics.physical_padding_top),
113 tonic::ToDart(view_metrics.physical_padding_right),
114 tonic::ToDart(view_metrics.physical_padding_bottom),
115 tonic::ToDart(view_metrics.physical_padding_left),
116 tonic::ToDart(view_metrics.physical_view_inset_top),
117 tonic::ToDart(view_metrics.physical_view_inset_right),
118 tonic::ToDart(view_metrics.physical_view_inset_bottom),
119 tonic::ToDart(view_metrics.physical_view_inset_left),
120 tonic::ToDart(view_metrics.physical_system_gesture_inset_top),
121 tonic::ToDart(view_metrics.physical_system_gesture_inset_right),
122 tonic::ToDart(view_metrics.physical_system_gesture_inset_bottom),
123 tonic::ToDart(view_metrics.physical_system_gesture_inset_left),
124 tonic::ToDart(view_metrics.physical_touch_slop),
125 tonic::ToDart(view_metrics.physical_display_features_bounds),
126 tonic::ToDart(view_metrics.physical_display_features_type),
127 tonic::ToDart(view_metrics.physical_display_features_state),
128 tonic::ToDart(view_metrics.display_id),
129 tonic::ToDart(view_metrics.physical_min_width_constraint),
130 tonic::ToDart(view_metrics.physical_max_width_constraint),
131 tonic::ToDart(view_metrics.physical_min_height_constraint),
132 tonic::ToDart(view_metrics.physical_max_height_constraint),
139 FML_LOG(FATAL) <<
"The implicit view #" <<
view_id <<
" cannot be removed.";
142 size_t erased_elements = metrics_.erase(
view_id);
143 if (erased_elements == 0) {
148 std::shared_ptr<tonic::DartState> dart_state =
156 tonic::ToDart(view_id),
162 std::shared_ptr<tonic::DartState> dart_state =
169 send_view_focus_event_.
Get(), {
170 tonic::ToDart(event.view_id()),
171 tonic::ToDart(event.state()),
172 tonic::ToDart(event.direction()),
178 std::shared_ptr<tonic::DartState> dart_state =
186 tonic::ToDart(engine_id),
194 auto found_iter = metrics_.find(
view_id);
195 if (found_iter == metrics_.end()) {
199 found_iter->second = view_metrics;
201 std::shared_ptr<tonic::DartState> dart_state =
208 update_window_metrics_.
Get(),
210 tonic::ToDart(view_id),
211 tonic::ToDart(view_metrics.device_pixel_ratio),
212 tonic::ToDart(view_metrics.physical_width),
213 tonic::ToDart(view_metrics.physical_height),
214 tonic::ToDart(view_metrics.physical_padding_top),
215 tonic::ToDart(view_metrics.physical_padding_right),
216 tonic::ToDart(view_metrics.physical_padding_bottom),
217 tonic::ToDart(view_metrics.physical_padding_left),
218 tonic::ToDart(view_metrics.physical_view_inset_top),
219 tonic::ToDart(view_metrics.physical_view_inset_right),
220 tonic::ToDart(view_metrics.physical_view_inset_bottom),
221 tonic::ToDart(view_metrics.physical_view_inset_left),
222 tonic::ToDart(view_metrics.physical_system_gesture_inset_top),
223 tonic::ToDart(view_metrics.physical_system_gesture_inset_right),
224 tonic::ToDart(view_metrics.physical_system_gesture_inset_bottom),
225 tonic::ToDart(view_metrics.physical_system_gesture_inset_left),
226 tonic::ToDart(view_metrics.physical_touch_slop),
227 tonic::ToDart(view_metrics.physical_display_features_bounds),
228 tonic::ToDart(view_metrics.physical_display_features_type),
229 tonic::ToDart(view_metrics.physical_display_features_state),
230 tonic::ToDart(view_metrics.display_id),
231 tonic::ToDart(view_metrics.physical_min_width_constraint),
232 tonic::ToDart(view_metrics.physical_max_width_constraint),
233 tonic::ToDart(view_metrics.physical_min_height_constraint),
234 tonic::ToDart(view_metrics.physical_max_height_constraint),
240 const std::vector<DisplayData>&
displays) {
241 std::vector<DisplayId> ids;
242 std::vector<double> widths;
243 std::vector<double> heights;
244 std::vector<double> device_pixel_ratios;
245 std::vector<double> refresh_rates;
246 for (
const auto& display :
displays) {
247 ids.push_back(display.id);
248 widths.push_back(display.width);
249 heights.push_back(display.height);
250 device_pixel_ratios.push_back(display.pixel_ratio);
251 refresh_rates.push_back(display.refresh_rate);
253 std::shared_ptr<tonic::DartState> dart_state =
260 update_displays_.
Get(),
262 tonic::ToDart<std::vector<DisplayId>>(ids),
263 tonic::ToDart<std::vector<double>>(widths),
264 tonic::ToDart<std::vector<double>>(heights),
265 tonic::ToDart<std::vector<double>>(device_pixel_ratios),
266 tonic::ToDart<std::vector<double>>(refresh_rates),
271 const std::vector<std::string>& locales) {
272 std::shared_ptr<tonic::DartState> dart_state =
282 tonic::ToDart<std::vector<std::string>>(locales),
287 std::shared_ptr<tonic::DartState> dart_state =
288 update_user_settings_data_.
dart_state().lock();
296 tonic::StdStringToDart(data),
301 const std::string&
data) {
302 std::shared_ptr<tonic::DartState> dart_state =
303 update_initial_lifecycle_state_.
dart_state().lock();
309 update_initial_lifecycle_state_.
Get(), {
310 tonic::StdStringToDart(data),
315 std::shared_ptr<tonic::DartState> dart_state =
316 update_semantics_enabled_.
dart_state().lock();
324 {tonic::ToDart(enabled)}));
328 std::shared_ptr<tonic::DartState> dart_state =
329 update_accessibility_features_.
dart_state().lock();
336 update_accessibility_features_.
Get(), {tonic::ToDart(values)}));
340 std::unique_ptr<PlatformMessage>
message) {
341 std::shared_ptr<tonic::DartState> dart_state =
342 dispatch_platform_message_.
dart_state().lock();
345 <<
"Dropping platform message for lack of DartState on channel: "
350 Dart_Handle data_handle =
352 if (Dart_IsError(data_handle)) {
354 <<
"Dropping platform message because of a Dart error on channel: "
360 if (
auto response =
message->response()) {
361 response_id = next_response_id_++;
362 pending_responses_[response_id] = response;
367 {tonic::ToDart(message->channel()), data_handle,
368 tonic::ToDart(response_id)}));
373 std::shared_ptr<tonic::DartState> dart_state =
374 dispatch_pointer_data_packet_.
dart_state().lock();
380 const std::vector<uint8_t>&
buffer = packet.
data();
381 Dart_Handle data_handle =
383 if (Dart_IsError(data_handle)) {
395 std::shared_ptr<tonic::DartState> dart_state =
396 dispatch_semantics_action_.
dart_state().lock();
402 Dart_Handle args_handle =
403 (
args.GetSize() <= 0) ? Dart_Null() : ToByteData(
args);
405 if (Dart_IsError(args_handle)) {
410 dispatch_semantics_action_.
Get(),
411 {tonic::ToDart(view_id), tonic::ToDart(node_id),
412 tonic::ToDart(static_cast<int32_t>(action)), args_handle}));
416 uint64_t frame_number) {
417 std::shared_ptr<tonic::DartState> dart_state =
424 if (last_frame_number_ > frame_number) {
425 FML_LOG(ERROR) <<
"Frame number is out of order: " << frame_number <<
" < "
426 << last_frame_number_;
428 last_frame_number_ = frame_number;
433 if (last_microseconds_ > microseconds) {
437 <<
"Reported frame time is older than the last one; clamping. "
438 << microseconds <<
" < " << last_microseconds_
439 <<
" ~= " << last_microseconds_ - microseconds;
440 microseconds = last_microseconds_;
442 last_microseconds_ = microseconds;
446 Dart_NewInteger(microseconds),
447 Dart_NewInteger(frame_number),
456 std::shared_ptr<tonic::DartState> dart_state =
463 Dart_Handle data_handle =
464 Dart_NewTypedData(Dart_TypedData_kInt64, timings.size());
466 Dart_TypedData_Type
type;
467 void*
data =
nullptr;
468 intptr_t num_acquired = 0;
470 Dart_TypedDataAcquireData(data_handle, &
type, &
data, &num_acquired)));
471 FML_DCHECK(num_acquired ==
static_cast<int>(timings.size()));
473 memcpy(
data, timings.data(),
sizeof(int64_t) * timings.size());
474 FML_CHECK(Dart_TypedDataReleaseData(data_handle));
483 auto found = metrics_.find(
view_id);
484 if (found != metrics_.end()) {
485 return &found->second;
496 auto it = pending_responses_.find(response_id);
497 if (it == pending_responses_.end()) {
500 auto response = std::move(it->second);
501 pending_responses_.erase(it);
502 response->CompleteEmpty();
507 std::vector<uint8_t>
data) {
511 auto it = pending_responses_.find(response_id);
512 if (it == pending_responses_.end()) {
515 auto response = std::move(it->second);
516 pending_responses_.erase(it);
517 response->Complete(std::make_unique<fml::DataMapping>(std::move(
data)));
538Dart_Handle HandlePlatformMessage(
540 const std::string&
name,
541 Dart_Handle data_handle,
543 if (Dart_IsNull(data_handle)) {
545 std::make_unique<PlatformMessage>(
name, response));
548 const uint8_t* buffer =
static_cast<const uint8_t*
>(
data.data());
557 const std::string&
name,
559 Dart_Handle data_handle) {
564 "SendPlatformMessage only works on the root isolate, see "
565 "SendPortPlatformMessage.");
570 response = fml::MakeRefCounted<PlatformMessageResponseDart>(
575 return HandlePlatformMessage(dart_state,
name, data_handle, response);
579 const std::string&
name,
580 Dart_Handle identifier,
581 Dart_Handle send_port,
582 Dart_Handle data_handle) {
587 if (c_send_port == ILLEGAL_PORT) {
592 fml::MakeRefCounted<PlatformMessageResponseDartPort>(
596 return HandlePlatformMessage(dart_state,
name, data_handle, response);
613 if (Dart_IsNull(
data.dart_handle())) {
619 const uint8_t*
buffer =
static_cast<const uint8_t*
>(
data.data());
629 const std::string&
name) {
634Dart_PerformanceMode PlatformConfigurationNativeApi::current_performance_mode_ =
635 Dart_PerformanceMode_Default;
638 return current_performance_mode_;
643 current_performance_mode_ =
static_cast<Dart_PerformanceMode
>(
mode);
644 return Dart_SetPerformanceMode(current_performance_mode_);
655 if (!persistent_isolate_data) {
660 persistent_isolate_data->GetSize());
697 Dart_Handle supportedLocalesHandle) {
699 std::vector<std::string> supportedLocales =
701 supportedLocalesHandle);
703 std::vector<std::string> results =
727 int64_t root_isolate_token) {
730 auto platform_message_handler =
731 (*
static_cast<std::shared_ptr<PlatformMessageHandlerStorage>*
>(
732 Dart_CurrentIsolateGroupData()));
734 auto weak_platform_message_handler =
735 platform_message_handler->GetPlatformMessageHandler(root_isolate_token);
746 double unscaled_font_size,
747 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)
constexpr int64_t ToMicroseconds() const
constexpr TimeDelta ToEpochDelta() const
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()
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)
#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
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all 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
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 disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
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)