Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
flutter::PlatformConfiguration Class Referencefinal

A class for holding and distributing platform-level information to and from the Dart code in Flutter's framework. More...

#include <platform_configuration.h>

Public Member Functions

 PlatformConfiguration (PlatformConfigurationClient *client)
 Creates a new PlatformConfiguration, typically created by the RuntimeController.
 
 PlatformConfiguration (const PlatformConfiguration &)=delete
 
PlatformConfigurationoperator= (const PlatformConfiguration &)=delete
 
 ~PlatformConfiguration ()
 
PlatformConfigurationClientclient () const
 Access to the platform configuration client (which typically is implemented by the RuntimeController).
 
void DidCreateIsolate ()
 Called by the RuntimeController once it has created the root isolate, so that the PlatformController can get a handle to the 'dart:ui' library.
 
bool AddView (int64_t view_id, const ViewportMetrics &view_metrics)
 Notify the framework that a new view is available.
 
bool RemoveView (int64_t view_id)
 Notify the framework that a view is no longer available.
 
bool SendFocusEvent (const ViewFocusEvent &event)
 Notify the isolate that the focus state of a native view has changed.
 
bool SetEngineId (int64_t engine_id)
 Sets the opaque identifier of the engine.
 
bool UpdateViewMetrics (int64_t view_id, const ViewportMetrics &metrics)
 Update the view metrics for the specified view.
 
void UpdateDisplays (const std::vector< DisplayData > &displays)
 Update the specified display data in the framework.
 
void UpdateLocales (const std::vector< std::string > &locales)
 Update the specified locale data in the framework.
 
void UpdateUserSettingsData (const std::string &data)
 Update the user settings data in the framework.
 
void UpdateInitialLifecycleState (const std::string &data)
 Updates the lifecycle state data in the framework.
 
void UpdateSemanticsEnabled (bool enabled)
 Notifies the PlatformConfiguration that the embedder has expressed an opinion about whether the accessibility tree should be generated or not. This call originates in the platform view and is forwarded to the PlatformConfiguration here by the engine.
 
void UpdateAccessibilityFeatures (int32_t flags)
 Forward the preference of accessibility features that must be enabled in the semantics tree to the framwork.
 
void DispatchPlatformMessage (std::unique_ptr< PlatformMessage > message)
 Notifies the PlatformConfiguration that the client has sent it a message. This call originates in the platform view and has been forwarded through the engine to here.
 
void DispatchPointerDataPacket (const PointerDataPacket &packet)
 Notifies the PlatformConfiguration that the client has sent it pointer events. This call originates in the platform view and has been forwarded through the engine to here.
 
HitTestResponse HitTest (int64_t view_id, const flutter::PointData offset)
 Requests to perform framework hit test from the engine.
 
void DispatchSemanticsAction (int64_t view_id, int32_t node_id, SemanticsAction action, fml::MallocMapping args)
 Notifies the framework that the embedder encountered an accessibility related action on the specified node. This call originates on the platform view and has been forwarded to the platform configuration here by the engine.
 
void BeginFrame (fml::TimePoint frame_time, uint64_t frame_number)
 Notifies the framework that it is time to begin working on a new frame previously scheduled via a call to PlatformConfigurationClient::ScheduleFrame. This call originates in the animator.
 
void ReportTimings (std::vector< int64_t > timings)
 Dart code cannot fully measure the time it takes for a specific frame to be rendered. This is because Dart code only runs on the UI task runner. That is only a small part of the overall frame workload. The raster task runner frame workload is executed on a thread where Dart code cannot run (and hence instrument). Besides, due to the pipelined nature of rendering in Flutter, there may be multiple frame workloads being processed at any given time. However, for non-Timeline based profiling, it is useful for trace collection and processing to happen in Dart. To do this, the raster task runner frame workloads need to be instrumented separately. After a set number of these profiles have been gathered, they need to be reported back to Dart code. The engine reports this extra instrumentation information back to the framework by invoking this method at predefined intervals.
 
const ViewportMetricsGetMetrics (int view_id)
 Retrieves the viewport metrics with the given ID managed by the PlatformConfiguration.
 
void CompletePlatformMessageResponse (int response_id, std::vector< uint8_t > data)
 Responds to a previous platform message to the engine from the framework.
 
void CompletePlatformMessageEmptyResponse (int response_id)
 Responds to a previous platform message to the engine from the framework with an empty response.
 
Dart_Handle on_error ()
 

Detailed Description

A class for holding and distributing platform-level information to and from the Dart code in Flutter's framework.

It handles communication between the engine and the framework.

It communicates with the RuntimeController through the use of a PlatformConfigurationClient interface, which the RuntimeController defines.

Definition at line 307 of file platform_configuration.h.

Constructor & Destructor Documentation

◆ PlatformConfiguration() [1/2]

flutter::PlatformConfiguration::PlatformConfiguration ( PlatformConfigurationClient client)
explicit

Creates a new PlatformConfiguration, typically created by the RuntimeController.

Parameters
[in]clientThe PlatformConfigurationClient to be injected into the PlatformConfiguration. This client is used to forward requests to the RuntimeController.

Definition at line 34 of file platform_configuration.cc.

36 : client_(client) {}
PlatformConfigurationClient * client() const
Access to the platform configuration client (which typically is implemented by the RuntimeController)...

◆ PlatformConfiguration() [2/2]

flutter::PlatformConfiguration::PlatformConfiguration ( const PlatformConfiguration )
delete

◆ ~PlatformConfiguration()

flutter::PlatformConfiguration::~PlatformConfiguration ( )

Definition at line 38 of file platform_configuration.cc.

38{}

Member Function Documentation

◆ AddView()

bool flutter::PlatformConfiguration::AddView ( int64_t  view_id,
const ViewportMetrics view_metrics 
)

Notify the framework that a new view is available.

        A view must be added before other methods can refer to it,
        including the implicit view. Adding a view that already exists
        triggers an assertion.
Parameters
[in]view_idThe ID of the new view.
[in]viewport_metricsThe initial viewport metrics for the view.
Returns
Whether the view was added.

Definition at line 93 of file platform_configuration.cc.

94 {
95 auto [view_iterator, insertion_happened] =
96 metrics_.emplace(view_id, view_metrics);
97 if (!insertion_happened) {
98 FML_LOG(ERROR) << "View #" << view_id << " already exists.";
99 return false;
100 }
101
102 std::shared_ptr<tonic::DartState> dart_state = add_view_.dart_state().lock();
103 if (!dart_state) {
104 return false;
105 }
106 tonic::DartState::Scope scope(dart_state);
108 add_view_.Get(),
109 {
110 tonic::ToDart(view_id),
111 tonic::ToDart(view_metrics.device_pixel_ratio),
112 tonic::ToDart(view_metrics.physical_width),
113 tonic::ToDart(view_metrics.physical_height),
114 tonic::ToDart(view_metrics.physical_padding_top),
115 tonic::ToDart(view_metrics.physical_padding_right),
116 tonic::ToDart(view_metrics.physical_padding_bottom),
117 tonic::ToDart(view_metrics.physical_padding_left),
118 tonic::ToDart(view_metrics.physical_view_inset_top),
119 tonic::ToDart(view_metrics.physical_view_inset_right),
120 tonic::ToDart(view_metrics.physical_view_inset_bottom),
121 tonic::ToDart(view_metrics.physical_view_inset_left),
122 tonic::ToDart(view_metrics.physical_system_gesture_inset_top),
123 tonic::ToDart(view_metrics.physical_system_gesture_inset_right),
124 tonic::ToDart(view_metrics.physical_system_gesture_inset_bottom),
125 tonic::ToDart(view_metrics.physical_system_gesture_inset_left),
126 tonic::ToDart(view_metrics.physical_touch_slop),
127 tonic::ToDart(view_metrics.physical_display_features_bounds),
128 tonic::ToDart(view_metrics.physical_display_features_type),
129 tonic::ToDart(view_metrics.physical_display_features_state),
130 tonic::ToDart(view_metrics.display_id),
131 tonic::ToDart(view_metrics.physical_min_width_constraint),
132 tonic::ToDart(view_metrics.physical_max_width_constraint),
133 tonic::ToDart(view_metrics.physical_min_height_constraint),
134 tonic::ToDart(view_metrics.physical_max_height_constraint),
135 tonic::ToDart(view_metrics.physical_display_corner_radius_top_left),
136 tonic::ToDart(view_metrics.physical_display_corner_radius_top_right),
137 tonic::ToDart(
138 view_metrics.physical_display_corner_radius_bottom_right),
139 tonic::ToDart(
140 view_metrics.physical_display_corner_radius_bottom_left),
141 }));
142 return true;
143}
const std::weak_ptr< DartState > & dart_state() const
G_BEGIN_DECLS FlutterViewId view_id
#define FML_LOG(severity)
Definition logging.h:101
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
bool CheckAndHandleError(Dart_Handle handle)
Definition dart_error.cc:33

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), FML_LOG, tonic::DartPersistentValue::Get(), and view_id.

◆ BeginFrame()

void flutter::PlatformConfiguration::BeginFrame ( fml::TimePoint  frame_time,
uint64_t  frame_number 
)

Notifies the framework that it is time to begin working on a new frame previously scheduled via a call to PlatformConfigurationClient::ScheduleFrame. This call originates in the animator.

The frame time given as the argument indicates the point at which the current frame interval began. It is very slightly (because of scheduling overhead) in the past. If a new layer tree is not produced and given to the raster task runner within one frame interval from this point, the Flutter application will jank.

This method calls the ::_beginFrame method in hooks.dart.

Parameters
[in]frame_timeThe point at which the current frame interval began. May be used by animation interpolators, physics simulations, etc..
[in]frame_numberThe frame number recorded by the animator. Used by the framework to associate frame specific debug information with frame timings and timeline events.

Definition at line 454 of file platform_configuration.cc.

455 {
456 std::shared_ptr<tonic::DartState> dart_state =
457 begin_frame_.dart_state().lock();
458 if (!dart_state) {
459 return;
460 }
461 tonic::DartState::Scope scope(dart_state);
462
463 if (last_frame_number_ > frame_number) {
464 FML_LOG(ERROR) << "Frame number is out of order: " << frame_number << " < "
465 << last_frame_number_;
466 }
467 last_frame_number_ = frame_number;
468
469 // frameTime is not a delta; its the timestamp of the presentation.
470 // This is just a type conversion.
471 int64_t microseconds = frameTime.ToEpochDelta().ToMicroseconds();
472 if (last_microseconds_ > microseconds) {
473 // Do not allow time traveling frametimes
474 // github.com/flutter/flutter/issues/106277
475 FML_LOG(ERROR)
476 << "Reported frame time is older than the last one; clamping. "
477 << microseconds << " < " << last_microseconds_
478 << " ~= " << last_microseconds_ - microseconds;
479 microseconds = last_microseconds_;
480 }
481 last_microseconds_ = microseconds;
482
484 tonic::DartInvoke(begin_frame_.Get(), {
485 Dart_NewInteger(microseconds),
486 Dart_NewInteger(frame_number),
487 }));
488
490
492}
static UIDartState * Current()
Dart_Handle DartInvokeVoid(Dart_Handle closure)

References tonic::CheckAndHandleError(), flutter::UIDartState::Current(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), tonic::DartInvokeVoid(), flutter::UIDartState::FlushMicrotasksNow(), FML_LOG, tonic::DartPersistentValue::Get(), fml::TimePoint::ToEpochDelta(), and fml::TimeDelta::ToMicroseconds().

◆ client()

◆ CompletePlatformMessageEmptyResponse()

void flutter::PlatformConfiguration::CompletePlatformMessageEmptyResponse ( int  response_id)

Responds to a previous platform message to the engine from the framework with an empty response.

Parameters
[in]response_idThe unique id that identifies the original platform message to respond to.

Definition at line 530 of file platform_configuration.cc.

531 {
532 if (!response_id) {
533 return;
534 }
535 auto it = pending_responses_.find(response_id);
536 if (it == pending_responses_.end()) {
537 return;
538 }
539 auto response = std::move(it->second);
540 pending_responses_.erase(it);
541 response->CompleteEmpty();
542}

Referenced by flutter::PlatformConfigurationNativeApi::RespondToPlatformMessage().

◆ CompletePlatformMessageResponse()

void flutter::PlatformConfiguration::CompletePlatformMessageResponse ( int  response_id,
std::vector< uint8_t >  data 
)

Responds to a previous platform message to the engine from the framework.

Parameters
[in]response_idThe unique id that identifies the original platform message to respond to.
[in]dataThe data to send back in the response.

Definition at line 544 of file platform_configuration.cc.

546 {
547 if (!response_id) {
548 return;
549 }
550 auto it = pending_responses_.find(response_id);
551 if (it == pending_responses_.end()) {
552 return;
553 }
554 auto response = std::move(it->second);
555 pending_responses_.erase(it);
556 response->Complete(std::make_unique<fml::DataMapping>(std::move(data)));
557}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36

References flutter::data.

Referenced by flutter::PlatformConfigurationNativeApi::RespondToPlatformMessage().

◆ DidCreateIsolate()

void flutter::PlatformConfiguration::DidCreateIsolate ( )

Called by the RuntimeController once it has created the root isolate, so that the PlatformController can get a handle to the 'dart:ui' library.

It uses the handle to call the hooks in hooks.dart.

Definition at line 40 of file platform_configuration.cc.

40 {
41 Dart_Handle library = Dart_LookupLibrary(tonic::ToDart("dart:ui"));
42
44 Dart_GetField(library, tonic::ToDart("_onError")));
46 Dart_GetField(library, tonic::ToDart("_addView")));
47 remove_view_.Set(tonic::DartState::Current(),
48 Dart_GetField(library, tonic::ToDart("_removeView")));
49 send_view_focus_event_.Set(
51 Dart_GetField(library, tonic::ToDart("_sendViewFocusEvent")));
52 set_engine_id_.Set(tonic::DartState::Current(),
53 Dart_GetField(library, tonic::ToDart("_setEngineId")));
54 update_window_metrics_.Set(
56 Dart_GetField(library, tonic::ToDart("_updateWindowMetrics")));
57 update_displays_.Set(
59 Dart_GetField(library, tonic::ToDart("_updateDisplays")));
60 update_locales_.Set(tonic::DartState::Current(),
61 Dart_GetField(library, tonic::ToDart("_updateLocales")));
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")));
81 Dart_GetField(library, tonic::ToDart("_hitTest")));
82 dispatch_semantics_action_.Set(
84 Dart_GetField(library, tonic::ToDart("_dispatchSemanticsAction")));
85 begin_frame_.Set(tonic::DartState::Current(),
86 Dart_GetField(library, tonic::ToDart("_beginFrame")));
87 draw_frame_.Set(tonic::DartState::Current(),
88 Dart_GetField(library, tonic::ToDart("_drawFrame")));
89 report_timings_.Set(tonic::DartState::Current(),
90 Dart_GetField(library, tonic::ToDart("_reportTimings")));
91}
void Set(DartState *dart_state, Dart_Handle value)
static DartState * Current()
Definition dart_state.cc:56
Dart_Handle ToDart(const T &object)

References tonic::DartState::Current(), tonic::DartPersistentValue::Set(), and tonic::ToDart().

◆ DispatchPlatformMessage()

void flutter::PlatformConfiguration::DispatchPlatformMessage ( std::unique_ptr< PlatformMessage message)

Notifies the PlatformConfiguration that the client has sent it a message. This call originates in the platform view and has been forwarded through the engine to here.

Parameters
[in]messageThe message sent from the embedder to the Dart application.

Definition at line 353 of file platform_configuration.cc.

354 {
355 std::shared_ptr<tonic::DartState> dart_state =
356 dispatch_platform_message_.dart_state().lock();
357 if (!dart_state) {
358 FML_DLOG(WARNING)
359 << "Dropping platform message for lack of DartState on channel: "
360 << message->channel();
361 return;
362 }
363 tonic::DartState::Scope scope(dart_state);
364 Dart_Handle data_handle =
365 (message->hasData()) ? ToByteData(message->data()) : Dart_Null();
366 if (Dart_IsError(data_handle)) {
367 FML_DLOG(WARNING)
368 << "Dropping platform message because of a Dart error on channel: "
369 << message->channel();
370 return;
371 }
372
373 int response_id = 0;
374 if (auto response = message->response()) {
375 response_id = next_response_id_++;
376 pending_responses_[response_id] = response;
377 }
378
380 tonic::DartInvoke(dispatch_platform_message_.Get(),
381 {tonic::ToDart(message->channel()), data_handle,
382 tonic::ToDart(response_id)}));
383}
const char * message
#define FML_DLOG(severity)
Definition logging.h:121

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), FML_DLOG, tonic::DartPersistentValue::Get(), and message.

◆ DispatchPointerDataPacket()

void flutter::PlatformConfiguration::DispatchPointerDataPacket ( const PointerDataPacket packet)

Notifies the PlatformConfiguration that the client has sent it pointer events. This call originates in the platform view and has been forwarded through the engine to here.

Parameters
[in]packetThe pointer event(s) serialized into a packet.

Definition at line 385 of file platform_configuration.cc.

386 {
387 std::shared_ptr<tonic::DartState> dart_state =
388 dispatch_pointer_data_packet_.dart_state().lock();
389 if (!dart_state) {
390 return;
391 }
392 tonic::DartState::Scope scope(dart_state);
393
394 const std::vector<uint8_t>& buffer = packet.data();
395 Dart_Handle data_handle =
397 if (Dart_IsError(data_handle)) {
398 return;
399 }
400
402 tonic::DartInvoke(dispatch_pointer_data_packet_.Get(), {data_handle}));
403}
static Dart_Handle Create(const void *data, size_t length)
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
Definition switch_defs.h:98

References flutter::buffer, tonic::CheckAndHandleError(), tonic::DartByteData::Create(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), flutter::PointerDataPacket::data(), and tonic::DartPersistentValue::Get().

◆ DispatchSemanticsAction()

void flutter::PlatformConfiguration::DispatchSemanticsAction ( int64_t  view_id,
int32_t  node_id,
SemanticsAction  action,
fml::MallocMapping  args 
)

Notifies the framework that the embedder encountered an accessibility related action on the specified node. This call originates on the platform view and has been forwarded to the platform configuration here by the engine.

Parameters
[in]view_idThe identifier of the view.
[in]node_idThe identifier of the accessibility node.
[in]actionThe accessibility related action performed on the node of the specified ID.
[in]argsOptional data that applies to the specified action.

Definition at line 430 of file platform_configuration.cc.

433 {
434 std::shared_ptr<tonic::DartState> dart_state =
435 dispatch_semantics_action_.dart_state().lock();
436 if (!dart_state) {
437 return;
438 }
439 tonic::DartState::Scope scope(dart_state);
440
441 Dart_Handle args_handle =
442 (args.GetSize() <= 0) ? Dart_Null() : ToByteData(args);
443
444 if (Dart_IsError(args_handle)) {
445 return;
446 }
447
449 dispatch_semantics_action_.Get(),
450 {tonic::ToDart(view_id), tonic::ToDart(node_id),
451 tonic::ToDart(static_cast<int32_t>(action)), args_handle}));
452}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args

References args, tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), and tonic::DartPersistentValue::Get().

◆ GetMetrics()

const ViewportMetrics * flutter::PlatformConfiguration::GetMetrics ( int  view_id)

Retrieves the viewport metrics with the given ID managed by the PlatformConfiguration.

Parameters
[in]view_idThe id of the view's viewport metrics to return.
Returns
a pointer to the ViewportMetrics. Returns nullptr if the ID is not found.

Definition at line 521 of file platform_configuration.cc.

521 {
522 auto found = metrics_.find(view_id);
523 if (found != metrics_.end()) {
524 return &found->second;
525 } else {
526 return nullptr;
527 }
528}

References view_id.

Referenced by flutter::testing::TEST_F(), flutter::testing::TEST_F(), and flutter::testing::TEST_F().

◆ HitTest()

HitTestResponse flutter::PlatformConfiguration::HitTest ( int64_t  view_id,
const flutter::PointData  offset 
)

Requests to perform framework hit test from the engine.

Parameters
[in]view_idThe identifier of the flutter view that should be hit tested.
[in]offsetThe position in the view that should be hit tested.
Returns
The hit test response.

Definition at line 405 of file platform_configuration.cc.

407 {
408 std::shared_ptr<tonic::DartState> dart_state = hit_test_.dart_state().lock();
409 if (!dart_state) {
410 return {.has_platform_view = false};
411 }
412 tonic::DartState::Scope scope(dart_state);
413
414 Dart_Handle dart_result = tonic::DartInvoke(
415 hit_test_.Get(), {tonic::ToDart(view_id), tonic::ToDart(offset.x),
416 tonic::ToDart(offset.y)});
417 if (tonic::CheckAndHandleError(dart_result)) {
418 return {.has_platform_view = false};
419 }
420
421 Dart_Handle has_platform_view_handle =
422 Dart_GetField(dart_result, tonic::ToDart("hasPlatformView"));
423 if (tonic::CheckAndHandleError(has_platform_view_handle)) {
424 return {.has_platform_view = false};
425 }
426 return {.has_platform_view =
427 tonic::DartConverter<bool>::FromDart(has_platform_view_handle)};
428}

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), tonic::DartPersistentValue::Get(), and tonic::ToDart().

◆ on_error()

Dart_Handle flutter::PlatformConfiguration::on_error ( )
inline

Definition at line 583 of file platform_configuration.h.

583{ return on_error_.Get(); }

References tonic::DartPersistentValue::Get().

◆ operator=()

PlatformConfiguration & flutter::PlatformConfiguration::operator= ( const PlatformConfiguration )
delete

◆ RemoveView()

bool flutter::PlatformConfiguration::RemoveView ( int64_t  view_id)

Notify the framework that a view is no longer available.

        Removing a view that does not exist triggers an assertion.

        The implicit view (kFlutterImplicitViewId) should never be
        removed. Doing so triggers an assertion.
Parameters
[in]view_idThe ID of the view.
Returns
Whether the view was removed.

Definition at line 145 of file platform_configuration.cc.

145 {
147 FML_LOG(FATAL) << "The implicit view #" << view_id << " cannot be removed.";
148 return false;
149 }
150 size_t erased_elements = metrics_.erase(view_id);
151 if (erased_elements == 0) {
152 FML_LOG(ERROR) << "View #" << view_id << " doesn't exist.";
153 return false;
154 }
155
156 std::shared_ptr<tonic::DartState> dart_state =
157 remove_view_.dart_state().lock();
158 if (!dart_state) {
159 return false;
160 }
161 tonic::DartState::Scope scope(dart_state);
163 tonic::DartInvoke(remove_view_.Get(), {
164 tonic::ToDart(view_id),
165 }));
166 return true;
167}
constexpr int64_t kFlutterImplicitViewId
Definition constants.h:35

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), FML_LOG, tonic::DartPersistentValue::Get(), flutter::kFlutterImplicitViewId, and view_id.

◆ ReportTimings()

void flutter::PlatformConfiguration::ReportTimings ( std::vector< int64_t >  timings)

Dart code cannot fully measure the time it takes for a specific frame to be rendered. This is because Dart code only runs on the UI task runner. That is only a small part of the overall frame workload. The raster task runner frame workload is executed on a thread where Dart code cannot run (and hence instrument). Besides, due to the pipelined nature of rendering in Flutter, there may be multiple frame workloads being processed at any given time. However, for non-Timeline based profiling, it is useful for trace collection and processing to happen in Dart. To do this, the raster task runner frame workloads need to be instrumented separately. After a set number of these profiles have been gathered, they need to be reported back to Dart code. The engine reports this extra instrumentation information back to the framework by invoking this method at predefined intervals.

See also
FrameTiming
Parameters
[in]timingsCollection of FrameTiming::kStatisticsCount * 'n' values for n frames whose timings have not been reported yet. Many of the values are timestamps, but a collection of integers is reported here for easier conversions to Dart objects. The timestamps are measured against the system monotonic clock measured in microseconds.

Definition at line 494 of file platform_configuration.cc.

494 {
495 std::shared_ptr<tonic::DartState> dart_state =
496 report_timings_.dart_state().lock();
497 if (!dart_state) {
498 return;
499 }
500 tonic::DartState::Scope scope(dart_state);
501
502 Dart_Handle data_handle =
503 Dart_NewTypedData(Dart_TypedData_kInt64, timings.size());
504
505 Dart_TypedData_Type type;
506 void* data = nullptr;
507 intptr_t num_acquired = 0;
508 FML_CHECK(!Dart_IsError(
509 Dart_TypedDataAcquireData(data_handle, &type, &data, &num_acquired)));
510 FML_DCHECK(num_acquired == static_cast<int>(timings.size()));
511
512 memcpy(data, timings.data(), sizeof(int64_t) * timings.size());
513 FML_CHECK(Dart_TypedDataReleaseData(data_handle));
514
516 tonic::DartInvoke(report_timings_.Get(), {
517 data_handle,
518 }));
519}
#define FML_CHECK(condition)
Definition logging.h:104
#define FML_DCHECK(condition)
Definition logging.h:122
impeller::ShaderType type

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), flutter::data, FML_CHECK, FML_DCHECK, tonic::DartPersistentValue::Get(), and type.

◆ SendFocusEvent()

bool flutter::PlatformConfiguration::SendFocusEvent ( const ViewFocusEvent event)

Notify the isolate that the focus state of a native view has changed.

Parameters
[in]eventThe focus event describing the change.
Returns
Whether the focus event was sent.

Definition at line 169 of file platform_configuration.cc.

169 {
170 std::shared_ptr<tonic::DartState> dart_state =
171 remove_view_.dart_state().lock();
172 if (!dart_state) {
173 return false;
174 }
175 tonic::DartState::Scope scope(dart_state);
177 send_view_focus_event_.Get(), {
178 tonic::ToDart(event.view_id()),
179 tonic::ToDart(event.state()),
180 tonic::ToDart(event.direction()),
181 }));
182 return true;
183}

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), and tonic::DartPersistentValue::Get().

◆ SetEngineId()

bool flutter::PlatformConfiguration::SetEngineId ( int64_t  engine_id)

Sets the opaque identifier of the engine.

       The identifier can be passed from Dart to native code to
       retrieve the engine instance.
Returns
Whether the identifier was set.

Definition at line 185 of file platform_configuration.cc.

185 {
186 std::shared_ptr<tonic::DartState> dart_state =
187 set_engine_id_.dart_state().lock();
188 if (!dart_state) {
189 return false;
190 }
191 tonic::DartState::Scope scope(dart_state);
193 tonic::DartInvoke(set_engine_id_.Get(), {
194 tonic::ToDart(engine_id),
195 }));
196 return true;
197}

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), and tonic::DartPersistentValue::Get().

◆ UpdateAccessibilityFeatures()

void flutter::PlatformConfiguration::UpdateAccessibilityFeatures ( int32_t  flags)

Forward the preference of accessibility features that must be enabled in the semantics tree to the framwork.

Parameters
[in]flagsThe accessibility features that must be generated in the semantics tree.

Definition at line 341 of file platform_configuration.cc.

341 {
342 std::shared_ptr<tonic::DartState> dart_state =
343 update_accessibility_features_.dart_state().lock();
344 if (!dart_state) {
345 return;
346 }
347 tonic::DartState::Scope scope(dart_state);
348
350 update_accessibility_features_.Get(), {tonic::ToDart(values)}));
351}

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), and tonic::DartPersistentValue::Get().

◆ UpdateDisplays()

void flutter::PlatformConfiguration::UpdateDisplays ( const std::vector< DisplayData > &  displays)

Update the specified display data in the framework.

Parameters
[in]displaysThe display data to send to Dart.

Definition at line 253 of file platform_configuration.cc.

254 {
255 std::vector<DisplayId> ids;
256 std::vector<double> widths;
257 std::vector<double> heights;
258 std::vector<double> device_pixel_ratios;
259 std::vector<double> refresh_rates;
260 for (const auto& display : displays) {
261 ids.push_back(display.id);
262 widths.push_back(display.width);
263 heights.push_back(display.height);
264 device_pixel_ratios.push_back(display.pixel_ratio);
265 refresh_rates.push_back(display.refresh_rate);
266 }
267 std::shared_ptr<tonic::DartState> dart_state =
268 update_displays_.dart_state().lock();
269 if (!dart_state) {
270 return;
271 }
272 tonic::DartState::Scope scope(dart_state);
274 update_displays_.Get(),
275 {
276 tonic::ToDart<std::vector<DisplayId>>(ids),
277 tonic::ToDart<std::vector<double>>(widths),
278 tonic::ToDart<std::vector<double>>(heights),
279 tonic::ToDart<std::vector<double>>(device_pixel_ratios),
280 tonic::ToDart<std::vector<double>>(refresh_rates),
281 }));
282}
std::vector< FlutterEngineDisplay > * displays

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), displays, and tonic::DartPersistentValue::Get().

◆ UpdateInitialLifecycleState()

void flutter::PlatformConfiguration::UpdateInitialLifecycleState ( const std::string &  data)

Updates the lifecycle state data in the framework.

Parameters
[in]dataThe lifecycle state data.

Definition at line 314 of file platform_configuration.cc.

315 {
316 std::shared_ptr<tonic::DartState> dart_state =
317 update_initial_lifecycle_state_.dart_state().lock();
318 if (!dart_state) {
319 return;
320 }
321 tonic::DartState::Scope scope(dart_state);
323 update_initial_lifecycle_state_.Get(), {
324 tonic::StdStringToDart(data),
325 }));
326}

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), and tonic::DartPersistentValue::Get().

◆ UpdateLocales()

void flutter::PlatformConfiguration::UpdateLocales ( const std::vector< std::string > &  locales)

Update the specified locale data in the framework.

Parameters
[in]locale_dataThe locale data. This should consist of groups of 4 strings, each group representing a single locale.

Definition at line 284 of file platform_configuration.cc.

285 {
286 std::shared_ptr<tonic::DartState> dart_state =
287 update_locales_.dart_state().lock();
288 if (!dart_state) {
289 return;
290 }
291
292 tonic::DartState::Scope scope(dart_state);
294 tonic::DartInvoke(update_locales_.Get(),
295 {
296 tonic::ToDart<std::vector<std::string>>(locales),
297 }));
298}

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), and tonic::DartPersistentValue::Get().

◆ UpdateSemanticsEnabled()

void flutter::PlatformConfiguration::UpdateSemanticsEnabled ( bool  enabled)

Notifies the PlatformConfiguration that the embedder has expressed an opinion about whether the accessibility tree should be generated or not. This call originates in the platform view and is forwarded to the PlatformConfiguration here by the engine.

Parameters
[in]enabledWhether the accessibility tree is enabled or disabled.

Definition at line 328 of file platform_configuration.cc.

328 {
329 std::shared_ptr<tonic::DartState> dart_state =
330 update_semantics_enabled_.dart_state().lock();
331 if (!dart_state) {
332 return;
333 }
334 tonic::DartState::Scope scope(dart_state);
336
337 tonic::CheckAndHandleError(tonic::DartInvoke(update_semantics_enabled_.Get(),
338 {tonic::ToDart(enabled)}));
339}
static void ThrowIfUIOperationsProhibited()

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), tonic::DartPersistentValue::Get(), and flutter::UIDartState::ThrowIfUIOperationsProhibited().

◆ UpdateUserSettingsData()

void flutter::PlatformConfiguration::UpdateUserSettingsData ( const std::string &  data)

Update the user settings data in the framework.

Parameters
[in]dataThe user settings data.

Definition at line 300 of file platform_configuration.cc.

300 {
301 std::shared_ptr<tonic::DartState> dart_state =
302 update_user_settings_data_.dart_state().lock();
303 if (!dart_state) {
304 return;
305 }
306 tonic::DartState::Scope scope(dart_state);
307
308 tonic::CheckAndHandleError(tonic::DartInvoke(update_user_settings_data_.Get(),
309 {
310 tonic::StdStringToDart(data),
311 }));
312}

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), and tonic::DartPersistentValue::Get().

◆ UpdateViewMetrics()

bool flutter::PlatformConfiguration::UpdateViewMetrics ( int64_t  view_id,
const ViewportMetrics metrics 
)

Update the view metrics for the specified view.

        If the view is not found, silently return false.
Parameters
[in]view_idThe ID of the view.
[in]metricsThe new metrics of the view.
Returns
Whether the view is found.

Definition at line 199 of file platform_configuration.cc.

201 {
202 auto found_iter = metrics_.find(view_id);
203 if (found_iter == metrics_.end()) {
204 return false;
205 }
206
207 found_iter->second = view_metrics;
208
209 std::shared_ptr<tonic::DartState> dart_state =
210 update_window_metrics_.dart_state().lock();
211 if (!dart_state) {
212 return false;
213 }
214 tonic::DartState::Scope scope(dart_state);
216 update_window_metrics_.Get(),
217 {
218 tonic::ToDart(view_id),
219 tonic::ToDart(view_metrics.device_pixel_ratio),
220 tonic::ToDart(view_metrics.physical_width),
221 tonic::ToDart(view_metrics.physical_height),
222 tonic::ToDart(view_metrics.physical_padding_top),
223 tonic::ToDart(view_metrics.physical_padding_right),
224 tonic::ToDart(view_metrics.physical_padding_bottom),
225 tonic::ToDart(view_metrics.physical_padding_left),
226 tonic::ToDart(view_metrics.physical_view_inset_top),
227 tonic::ToDart(view_metrics.physical_view_inset_right),
228 tonic::ToDart(view_metrics.physical_view_inset_bottom),
229 tonic::ToDart(view_metrics.physical_view_inset_left),
230 tonic::ToDart(view_metrics.physical_system_gesture_inset_top),
231 tonic::ToDart(view_metrics.physical_system_gesture_inset_right),
232 tonic::ToDart(view_metrics.physical_system_gesture_inset_bottom),
233 tonic::ToDart(view_metrics.physical_system_gesture_inset_left),
234 tonic::ToDart(view_metrics.physical_touch_slop),
235 tonic::ToDart(view_metrics.physical_display_features_bounds),
236 tonic::ToDart(view_metrics.physical_display_features_type),
237 tonic::ToDart(view_metrics.physical_display_features_state),
238 tonic::ToDart(view_metrics.display_id),
239 tonic::ToDart(view_metrics.physical_min_width_constraint),
240 tonic::ToDart(view_metrics.physical_max_width_constraint),
241 tonic::ToDart(view_metrics.physical_min_height_constraint),
242 tonic::ToDart(view_metrics.physical_max_height_constraint),
243 tonic::ToDart(view_metrics.physical_display_corner_radius_top_left),
244 tonic::ToDart(view_metrics.physical_display_corner_radius_top_right),
245 tonic::ToDart(
246 view_metrics.physical_display_corner_radius_bottom_right),
247 tonic::ToDart(
248 view_metrics.physical_display_corner_radius_bottom_left),
249 }));
250 return true;
251}

References tonic::CheckAndHandleError(), tonic::DartPersistentValue::dart_state(), tonic::DartInvoke(), tonic::DartPersistentValue::Get(), and view_id.

Referenced by flutter::testing::TEST_F().


The documentation for this class was generated from the following files: