Flutter Engine
runtime_controller.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_RUNTIME_RUNTIME_CONTROLLER_H_
6 #define FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_
7 
8 #include <memory>
9 #include <vector>
10 
11 #include "flutter/common/task_runners.h"
12 #include "flutter/flow/layers/layer_tree.h"
13 #include "flutter/fml/macros.h"
14 #include "flutter/fml/mapping.h"
15 #include "flutter/lib/ui/io_manager.h"
16 #include "flutter/lib/ui/painting/image_generator_registry.h"
17 #include "flutter/lib/ui/text/font_collection.h"
18 #include "flutter/lib/ui/ui_dart_state.h"
19 #include "flutter/lib/ui/volatile_path_tracker.h"
20 #include "flutter/lib/ui/window/platform_configuration.h"
21 #include "flutter/lib/ui/window/pointer_data_packet.h"
22 #include "flutter/runtime/dart_vm.h"
23 #include "flutter/runtime/platform_data.h"
24 #include "rapidjson/document.h"
25 #include "rapidjson/stringbuffer.h"
26 
27 namespace flutter {
28 
29 class Scene;
30 class RuntimeDelegate;
31 class View;
32 class Window;
33 
34 //------------------------------------------------------------------------------
35 /// Represents an instance of a running root isolate with window bindings. In
36 /// normal operation, a single instance of this object is owned by the engine
37 /// per shell. This object may only be created, used, and collected on the UI
38 /// task runner. Window state queried by the root isolate is stored by this
39 /// object. In cold-restart scenarios, the engine may collect this before
40 /// installing a new runtime controller in its place. The Clone method may be
41 /// used by the engine to copy the currently accumulated window state so it can
42 /// be referenced by the new runtime controller.
43 ///
45  public:
46  //----------------------------------------------------------------------------
47  /// @brief Creates a new instance of a runtime controller. This is
48  /// usually only done by the engine instance associated with the
49  /// shell.
50  ///
51  /// @param client The runtime delegate. This is
52  /// usually the `Engine` instance.
53  /// @param vm A reference to a running Dart VM.
54  /// The runtime controller must be
55  /// collected before the VM is
56  /// destroyed (this order is
57  /// guaranteed by the shell).
58  /// @param[in] idle_notification_callback The idle notification callback.
59  /// This allows callers to run native
60  /// code in isolate scope when the VM
61  /// is about to be notified that the
62  /// engine is going to be idle.
63  /// @param[in] platform_data The window data (if exists).
64  /// @param[in] isolate_create_callback The isolate create callback. This
65  /// allows callers to run native code
66  /// in isolate scope on the UI task
67  /// runner as soon as the root isolate
68  /// has been created.
69  /// @param[in] isolate_shutdown_callback The isolate shutdown callback.
70  /// This allows callers to run native
71  /// code in isolate scoped on the UI
72  /// task runner just as the root
73  /// isolate is about to be torn down.
74  /// @param[in] persistent_isolate_data Unstructured persistent read-only
75  /// data that the root isolate can
76  /// access in a synchronous manner.
77  /// @param[in] context Engine-owned state which is
78  /// accessed by the root dart isolate.
79  ///
81  RuntimeDelegate& p_client,
82  DartVM* vm,
83  fml::RefPtr<const DartSnapshot> p_isolate_snapshot,
84  const std::function<void(int64_t)>& idle_notification_callback,
85  const PlatformData& platform_data,
86  const fml::closure& isolate_create_callback,
87  const fml::closure& isolate_shutdown_callback,
88  std::shared_ptr<const fml::Mapping> p_persistent_isolate_data,
89  const UIDartState::Context& context);
90 
91  //----------------------------------------------------------------------------
92  /// @brief Create a RuntimeController that shares as many resources as
93  /// possible with the calling RuntimeController such that together
94  /// they occupy less memory.
95  /// @return A RuntimeController with a running isolate.
96  /// @see RuntimeController::RuntimeController
97  ///
98  std::unique_ptr<RuntimeController> Spawn(
99  RuntimeDelegate& p_client,
100  std::string advisory_script_uri,
101  std::string advisory_script_entrypoint,
102  const std::function<void(int64_t)>& idle_notification_callback,
103  const fml::closure& isolate_create_callback,
104  const fml::closure& isolate_shutdown_callback,
105  std::shared_ptr<const fml::Mapping> persistent_isolate_data) const;
106 
107  // |PlatformConfigurationClient|
108  ~RuntimeController() override;
109 
110  //----------------------------------------------------------------------------
111  /// @brief Launches the isolate using the window data associated with
112  /// this runtime controller. Before this call, the Dart isolate
113  /// has not been initialized. On successful return, the caller can
114  /// assume that the isolate is in the
115  /// `DartIsolate::Phase::Running` phase.
116  ///
117  /// This call will fail if a root isolate is already running. To
118  /// re-create an isolate with the window data associated with this
119  /// runtime controller, `Clone` this runtime controller and
120  /// Launch an isolate in that runtime controller instead.
121  ///
122  /// @param[in] settings The per engine instance settings.
123  /// @param[in] root_isolate_create_callback A callback invoked before the
124  /// root isolate has launched the Dart
125  /// program, but after it has been
126  /// created. This is called without
127  /// isolate scope, and after any root
128  /// isolate callback in the settings.
129  /// @param[in] dart_entrypoint The dart entrypoint. If
130  /// `std::nullopt` or empty, `main` will
131  /// be attempted.
132  /// @param[in] dart_entrypoint_library The dart entrypoint library. If
133  /// `std::nullopt` or empty, the core
134  /// library will be attempted.
135  /// @param[in] isolate_configuration The isolate configuration
136  ///
137  /// @return If the isolate could be launched and guided to the
138  /// `DartIsolate::Phase::Running` phase.
139  ///
140  [[nodiscard]] bool LaunchRootIsolate(
141  const Settings& settings,
142  fml::closure root_isolate_create_callback,
143  std::optional<std::string> dart_entrypoint,
144  std::optional<std::string> dart_entrypoint_library,
145  std::unique_ptr<IsolateConfiguration> isolate_configuration);
146 
147  //----------------------------------------------------------------------------
148  /// @brief Clone the the runtime controller. Launching an isolate with a
149  /// cloned runtime controller will use the same snapshots and
150  /// copies all window data to the new instance. This is usually
151  /// only used in the debug runtime mode to support the
152  /// cold-restart scenario.
153  ///
154  /// @return A clone of the existing runtime controller.
155  ///
156  std::unique_ptr<RuntimeController> Clone() const;
157 
158  //----------------------------------------------------------------------------
159  /// @brief Forward the specified viewport metrics to the running isolate.
160  /// If the isolate is not running, these metrics will be saved and
161  /// flushed to the isolate when it starts.
162  ///
163  /// @param[in] metrics The window's viewport metrics.
164  ///
165  /// @return If the window metrics were forwarded to the running isolate.
166  ///
167  bool SetViewportMetrics(const ViewportMetrics& metrics);
168 
169  //----------------------------------------------------------------------------
170  /// @brief Forward the specified locale data to the running isolate. If
171  /// the isolate is not running, this data will be saved and
172  /// flushed to the isolate when it starts running.
173  ///
174  /// @deprecated The persistent isolate data must be used for this purpose
175  /// instead.
176  ///
177  /// @param[in] locale_data The locale data. This should consist of groups of
178  /// 4 strings, each group representing a single locale.
179  ///
180  /// @return If the locale data was forwarded to the running isolate.
181  ///
182  bool SetLocales(const std::vector<std::string>& locale_data);
183 
184  //----------------------------------------------------------------------------
185  /// @brief Forward the user settings data to the running isolate. If the
186  /// isolate is not running, this data will be saved and flushed to
187  /// the isolate when it starts running.
188  ///
189  /// @deprecated The persistent isolate data must be used for this purpose
190  /// instead.
191  ///
192  /// @param[in] data The user settings data.
193  ///
194  /// @return If the user settings data was forwarded to the running
195  /// isolate.
196  ///
197  bool SetUserSettingsData(const std::string& data);
198 
199  //----------------------------------------------------------------------------
200  /// @brief Forward the lifecycle state data to the running isolate. If
201  /// the isolate is not running, this data will be saved and
202  /// flushed to the isolate when it starts running.
203  ///
204  /// @deprecated The persistent isolate data must be used for this purpose
205  /// instead.
206  ///
207  /// @param[in] data The lifecycle state data.
208  ///
209  /// @return If the lifecycle state data was forwarded to the running
210  /// isolate.
211  ///
212  bool SetLifecycleState(const std::string& data);
213 
214  //----------------------------------------------------------------------------
215  /// @brief Notifies the running isolate about whether the semantics tree
216  /// should be generated or not. If the isolate is not running,
217  /// this preference will be saved and flushed to the isolate when
218  /// it starts running.
219  ///
220  /// @param[in] enabled Indicates whether to generate the semantics tree.
221  ///
222  /// @return If the semantics tree generation preference was forwarded to
223  /// the running isolate.
224  ///
225  bool SetSemanticsEnabled(bool enabled);
226 
227  //----------------------------------------------------------------------------
228  /// @brief Forward the preference of accessibility features that must be
229  /// enabled in the semantics tree to the running isolate. If the
230  /// isolate is not running, this data will be saved and flushed to
231  /// the isolate when it starts running.
232  ///
233  /// @param[in] flags The accessibility features that must be generated in
234  /// the semantics tree.
235  ///
236  /// @return If the preference of accessibility features was forwarded to
237  /// the running isolate.
238  ///
239  bool SetAccessibilityFeatures(int32_t flags);
240 
241  //----------------------------------------------------------------------------
242  /// @brief Notifies the running isolate that it should start generating a
243  /// new frame.
244  ///
245  /// @see `Engine::BeginFrame` for more context.
246  ///
247  /// @param[in] frame_time The point at which the current frame interval
248  /// began. May be used by animation interpolators,
249  /// physics simulations, etc.
250  ///
251  /// @return If notification to begin frame rendering was delivered to the
252  /// running isolate.
253  ///
254  bool BeginFrame(fml::TimePoint frame_time, uint64_t frame_number);
255 
256  //----------------------------------------------------------------------------
257  /// @brief Dart code cannot fully measure the time it takes for a
258  /// specific frame to be rendered. This is because Dart code only
259  /// runs on the UI task runner. That is only a small part of the
260  /// overall frame workload. The raster task runner frame workload
261  /// is executed on a thread where Dart code cannot run (and hence
262  /// instrument). Besides, due to the pipelined nature of rendering
263  /// in Flutter, there may be multiple frame workloads being
264  /// processed at any given time. However, for non-Timeline based
265  /// profiling, it is useful for trace collection and processing to
266  /// happen in Dart. To do this, the raster task runner frame
267  /// workloads need to be instrumented separately. After a set
268  /// number of these profiles have been gathered, they need to be
269  /// reported back to Dart code. The engine reports this extra
270  /// instrumentation information back to Dart code running on the
271  /// engine by invoking this method at predefined intervals.
272  ///
273  /// @see `Engine::ReportTimings`, `FrameTiming`
274  ///
275  /// @param[in] timings Collection of `FrameTiming::kCount` * `n` timestamps
276  /// for `n` frames whose timings have not been reported
277  /// yet. A collection of integers is reported here for
278  /// easier conversions to Dart objects. The timestamps
279  /// are measured against the system monotonic clock
280  /// measured in microseconds.
281  ///
282  bool ReportTimings(std::vector<int64_t> timings);
283 
284  //----------------------------------------------------------------------------
285  /// @brief Notify the Dart VM that no frame workloads are expected on the
286  /// UI task runner till the specified deadline. The VM uses this
287  /// opportunity to perform garbage collection operations is a
288  /// manner that interferes as little as possible with frame
289  /// rendering.
290  ///
291  /// NotifyIdle is advisory. The VM may or may not run a garbage collection
292  /// when this is called, and will eventually perform garbage collections even
293  /// if it is not called or it is called with insufficient deadlines.
294  ///
295  /// The garbage collection mechanism and its thresholds are internal
296  /// implementation details and absolutely no guarantees are made about the
297  /// threshold discussed below. This discussion is also an oversimplification
298  /// but hopefully serves to calibrate expectations about GC behavior:
299  /// * When the Dart VM and its root isolate are initialized, the memory
300  /// consumed upto that point are treated as a baseline.
301  /// * A fixed percentage of the memory consumed (~20%) over the baseline is
302  /// treated as the hard threshold.
303  /// * The memory in play is divided into old space and new space. The new
304  /// space is typically very small and fills up rapidly.
305  /// * The baseline plus the threshold is considered the old space while the
306  /// small new space is a separate region (typically a few pages).
307  /// * The total old space size minus the max new space size is treated as the
308  /// soft threshold.
309  /// * In a world where there is no call to NotifyIdle, when the total
310  /// allocation exceeds the soft threshold, a concurrent mark is initiated in
311  /// the VM. There is a “small” pause that occurs when the concurrent mark is
312  /// initiated and another pause when the mark concludes and a sweep is
313  /// initiated.
314  /// * If the total allocations exceeds the the hard threshold, a “big”
315  /// stop-the-world pause is initiated.
316  /// * If after either the sweep after the concurrent mark, or, the
317  /// stop-the-world pause, the consumption returns to be below the soft
318  /// threshold, the dance begins anew.
319  /// * If after both the “small” and “big” pauses, memory usage is still over
320  /// the hard threshold, i.e, the objects are still reachable, that amount of
321  /// memory is treated as the new baseline and a fixed percentage of the new
322  /// baseline over the new baseline is now the new hard threshold.
323  /// * Updating the baseline will continue till memory for the updated old
324  /// space can be allocated from the operating system. These allocations will
325  /// typically fail due to address space exhaustion on 32-bit systems and
326  /// page table exhaustion on 64-bit systems.
327  /// * NotifyIdle initiates the concurrent mark preemptively. The deadline is
328  /// used by the VM to determine if the corresponding sweep can be performed
329  /// within the deadline. This way, jank due to “small” pauses can be
330  /// ameliorated.
331  /// * There is no ability to stop a “big” pause on reaching the hard threshold
332  /// in the old space. The best you can do is release (by making them
333  /// unreachable) objects eagerly so that the are marked as unreachable in
334  /// the concurrent mark initiated by either reaching the soft threshold or
335  /// an explicit NotifyIdle.
336  /// * If you are running out of memory, its because too many large objects
337  /// were allocation and remained reachable such that the the old space kept
338  /// growing till it could grow no more.
339  /// * At the edges of allocation thresholds, failures can occur gracefully if
340  /// the instigating allocation was made in the Dart VM or rather gracelessly
341  /// if the allocation is made by some native component.
342  ///
343  /// @see `Dart_TimelineGetMicros`
344  ///
345  /// @bug The `deadline` argument must be converted to `std::chrono`
346  /// instead of a raw integer.
347  ///
348  /// @param[in] deadline The deadline measures in microseconds against the
349  /// system's monotonic time. The clock can be accessed via
350  /// `Dart_TimelineGetMicros`.
351  ///
352  /// @return If the idle notification was forwarded to the running isolate.
353  ///
354  virtual bool NotifyIdle(int64_t deadline);
355 
356  //----------------------------------------------------------------------------
357  /// @brief Returns if the root isolate is running. The isolate must be
358  /// transitioned to the running phase manually. The isolate can
359  /// stop running if it terminates execution on its own.
360  ///
361  /// @return True if root isolate running, False otherwise.
362  ///
363  virtual bool IsRootIsolateRunning();
364 
365  //----------------------------------------------------------------------------
366  /// @brief Dispatch the specified platform message to running root
367  /// isolate.
368  ///
369  /// @param[in] message The message to dispatch to the isolate.
370  ///
371  /// @return If the message was dispatched to the running root isolate.
372  /// This may fail is an isolate is not running.
373  ///
374  virtual bool DispatchPlatformMessage(
375  std::unique_ptr<PlatformMessage> message);
376 
377  //----------------------------------------------------------------------------
378  /// @brief Dispatch the specified pointer data message to the running
379  /// root isolate.
380  ///
381  /// @param[in] packet The pointer data message to dispatch to the isolate.
382  ///
383  /// @return If the pointer data message was dispatched. This may fail is
384  /// an isolate is not running.
385  ///
386  bool DispatchPointerDataPacket(const PointerDataPacket& packet);
387 
388  //----------------------------------------------------------------------------
389  /// @brief Dispatch the specified pointer data message to the running
390  /// root isolate.
391  ///
392  /// @param[in] packet The key data message to dispatch to the isolate.
393  /// @param[in] callback Called when the framework has decided whether
394  /// to handle this key data.
395  ///
396  /// @return If the key data message was dispatched. This may fail is
397  /// an isolate is not running.
398  ///
399  bool DispatchKeyDataPacket(const KeyDataPacket& packet,
401 
402  //----------------------------------------------------------------------------
403  /// @brief Dispatch the semantics action to the specified accessibility
404  /// node.
405  ///
406  /// @param[in] id The identified of the accessibility node.
407  /// @param[in] action The semantics action to perform on the specified
408  /// accessibility node.
409  /// @param[in] args Optional data that applies to the specified action.
410  ///
411  /// @return If the semantics action was dispatched. This may fail if an
412  /// isolate is not running.
413  ///
414  bool DispatchSemanticsAction(int32_t id,
417 
418  //----------------------------------------------------------------------------
419  /// @brief Gets the main port identifier of the root isolate.
420  ///
421  /// @return The main port identifier. If no root isolate is running,
422  /// returns `ILLEGAL_PORT`.
423  ///
424  Dart_Port GetMainPort();
425 
426  //----------------------------------------------------------------------------
427  /// @brief Gets the debug name of the root isolate. But default, the
428  /// debug name of the isolate is derived from its advisory script
429  /// URI, advisory main entrypoint and its main port name. For
430  /// example, "main.dart$main-1234" where the script URI is
431  /// "main.dart", the entrypoint is "main" and the port name
432  /// "1234". Once launched, the isolate may re-christen itself
433  /// using a name it selects via `setIsolateDebugName` in
434  /// `window.dart`. This name is purely advisory and only used by
435  /// instrumentation and reporting purposes.
436  ///
437  /// @return The debug name of the root isolate.
438  ///
439  std::string GetIsolateName();
440 
441  //----------------------------------------------------------------------------
442  /// @brief Returns if the root isolate has any live receive ports.
443  ///
444  /// @return True if there are live receive ports, False otherwise. Return
445  /// False if the root isolate is not running as well.
446  ///
447  bool HasLivePorts();
448 
449  //----------------------------------------------------------------------------
450  /// @brief Get the last error encountered by the microtask queue.
451  ///
452  /// @return The last error encountered by the microtask queue.
453  ///
455 
456  //----------------------------------------------------------------------------
457  /// @brief Get the service ID of the root isolate if the root isolate is
458  /// running.
459  ///
460  /// @return The root isolate service id.
461  ///
462  std::optional<std::string> GetRootIsolateServiceID() const;
463 
464  //----------------------------------------------------------------------------
465  /// @brief Get the return code specified by the root isolate (if one is
466  /// present).
467  ///
468  /// @return The root isolate return code if the isolate has specified one.
469  ///
470  std::optional<uint32_t> GetRootIsolateReturnCode();
471 
472  //----------------------------------------------------------------------------
473  /// @brief Get an identifier that represents the Dart isolate group the
474  /// root isolate is in.
475  ///
476  /// @return The root isolate isolate group identifier, zero if one can't
477  /// be established.
478  uint64_t GetRootIsolateGroup() const;
479 
480  //--------------------------------------------------------------------------
481  /// @brief Loads the Dart shared library into the Dart VM. When the
482  /// Dart library is loaded successfully, the Dart future
483  /// returned by the originating loadLibrary() call completes.
484  ///
485  /// The Dart compiler may generate separate shared libraries
486  /// files called 'loading units' when libraries are imported
487  /// as deferred. Each of these shared libraries are identified
488  /// by a unique loading unit id. Callers should open and resolve
489  /// a SymbolMapping from the shared library. The Mappings should
490  /// be moved into this method, as ownership will be assumed by the
491  /// dart root isolate after successful loading and released after
492  /// shutdown of the root isolate. The loading unit may not be
493  /// used after isolate shutdown. If loading fails, the mappings
494  /// will be released.
495  ///
496  /// This method is paired with a RequestDartDeferredLibrary
497  /// invocation that provides the embedder with the loading unit id
498  /// of the deferred library to load.
499  ///
500  ///
501  /// @param[in] loading_unit_id The unique id of the deferred library's
502  /// loading unit, as passed in by
503  /// RequestDartDeferredLibrary.
504  ///
505  /// @param[in] snapshot_data Dart snapshot data of the loading unit's
506  /// shared library.
507  ///
508  /// @param[in] snapshot_data Dart snapshot instructions of the loading
509  /// unit's shared library.
510  ///
512  intptr_t loading_unit_id,
513  std::unique_ptr<const fml::Mapping> snapshot_data,
514  std::unique_ptr<const fml::Mapping> snapshot_instructions);
515 
516  //--------------------------------------------------------------------------
517  /// @brief Indicates to the dart VM that the request to load a deferred
518  /// library with the specified loading unit id has failed.
519  ///
520  /// The dart future returned by the initiating loadLibrary() call
521  /// will complete with an error.
522  ///
523  /// @param[in] loading_unit_id The unique id of the deferred library's
524  /// loading unit, as passed in by
525  /// RequestDartDeferredLibrary.
526  ///
527  /// @param[in] error_message The error message that will appear in the
528  /// dart Future.
529  ///
530  /// @param[in] transient A transient error is a failure due to
531  /// temporary conditions such as no network.
532  /// Transient errors allow the dart VM to
533  /// re-request the same deferred library and
534  /// and loading_unit_id again. Non-transient
535  /// errors are permanent and attempts to
536  /// re-request the library will instantly
537  /// complete with an error.
538  virtual void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
539  const std::string error_message,
540  bool transient);
541 
542  // |PlatformConfigurationClient|
543  void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
545  return context_.io_manager;
546  }
547 
548  virtual DartVM* GetDartVM() const { return vm_; }
549 
551  return isolate_snapshot_;
552  }
553 
554  const PlatformData& GetPlatformData() const { return platform_data_; }
555 
557  return context_.unref_queue;
558  }
559 
561  return context_.snapshot_delegate;
562  }
563 
564  protected:
565  /// Constructor for Mocks.
566  RuntimeController(RuntimeDelegate& p_client, TaskRunners task_runners);
567 
568  private:
569  struct Locale {
570  Locale(std::string language_code_,
571  std::string country_code_,
572  std::string script_code_,
573  std::string variant_code_);
574 
575  ~Locale();
576 
577  std::string language_code;
578  std::string country_code;
579  std::string script_code;
580  std::string variant_code;
581  };
582 
583  RuntimeDelegate& client_;
584  DartVM* const vm_;
585  fml::RefPtr<const DartSnapshot> isolate_snapshot_;
586  std::function<void(int64_t)> idle_notification_callback_;
587  PlatformData platform_data_;
588  std::weak_ptr<DartIsolate> root_isolate_;
589  std::weak_ptr<DartIsolate> spawning_isolate_;
590  std::optional<uint32_t> root_isolate_return_code_;
591  const fml::closure isolate_create_callback_;
592  const fml::closure isolate_shutdown_callback_;
593  std::shared_ptr<const fml::Mapping> persistent_isolate_data_;
594  UIDartState::Context context_;
595 
596  PlatformConfiguration* GetPlatformConfigurationIfAvailable();
597 
598  bool FlushRuntimeStateToIsolate();
599 
600  // |PlatformConfigurationClient|
601  std::string DefaultRouteName() override;
602 
603  // |PlatformConfigurationClient|
604  void ScheduleFrame() override;
605 
606  // |PlatformConfigurationClient|
607  void Render(Scene* scene) override;
608 
609  // |PlatformConfigurationClient|
610  void UpdateSemantics(SemanticsUpdate* update) override;
611 
612  // |PlatformConfigurationClient|
613  void HandlePlatformMessage(std::unique_ptr<PlatformMessage> message) override;
614 
615  // |PlatformConfigurationClient|
616  FontCollection& GetFontCollection() override;
617 
618  // |PlatformConfigurationClient|
619  void UpdateIsolateDescription(const std::string isolate_name,
620  int64_t isolate_port) override;
621 
622  // |PlatformConfigurationClient|
623  void SetNeedsReportTimings(bool value) override;
624 
625  // |PlatformConfigurationClient|
626  std::shared_ptr<const fml::Mapping> GetPersistentIsolateData() override;
627 
628  // |PlatformConfigurationClient|
629  std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
630  const std::vector<std::string>& supported_locale_data) override;
631 
633 };
634 
635 } // namespace flutter
636 
637 #endif // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_
const fml::RefPtr< SkiaUnrefQueue > & GetSkiaUnrefQueue() const
bool DispatchSemanticsAction(int32_t id, SemanticsAction action, fml::MallocMapping args)
Dispatch the semantics action to the specified accessibility node.
G_BEGIN_DECLS FlValue * args
fml::RefPtr< SkiaUnrefQueue > unref_queue
Definition: ui_dart_state.h:71
fml::WeakPtr< SnapshotDelegate > snapshot_delegate
Definition: ui_dart_state.h:64
fml::WeakPtr< IOManager > io_manager
The IO manager used by the isolate for asynchronous texture uploads.
Definition: ui_dart_state.h:67
bool SetSemanticsEnabled(bool enabled)
Notifies the running isolate about whether the semantics tree should be generated or not...
virtual bool IsRootIsolateRunning()
Returns if the root isolate is running. The isolate must be transitioned to the running phase manuall...
const fml::RefPtr< const DartSnapshot > & GetIsolateSnapshot() const
bool SetAccessibilityFeatures(int32_t flags)
Forward the preference of accessibility features that must be enabled in the semantics tree to the ru...
Dart_NativeFunction function
Definition: fuchsia.cc:51
std::unique_ptr< RuntimeController > Spawn(RuntimeDelegate &p_client, std::string advisory_script_uri, std::string advisory_script_entrypoint, const std::function< void(int64_t)> &idle_notification_callback, const fml::closure &isolate_create_callback, const fml::closure &isolate_shutdown_callback, std::shared_ptr< const fml::Mapping > persistent_isolate_data) const
Create a RuntimeController that shares as many resources as possible with the calling RuntimeControll...
std::unique_ptr< RuntimeController > Clone() const
Clone the the runtime controller. Launching an isolate with a cloned runtime controller will use the ...
virtual bool NotifyIdle(int64_t deadline)
Notify the Dart VM that no frame workloads are expected on the UI task runner till the specified dead...
bool SetUserSettingsData(const std::string &data)
Forward the user settings data to the running isolate. If the isolate is not running, this data will be saved and flushed to the isolate when it starts running.
bool LaunchRootIsolate(const Settings &settings, fml::closure root_isolate_create_callback, std::optional< std::string > dart_entrypoint, std::optional< std::string > dart_entrypoint_library, std::unique_ptr< IsolateConfiguration > isolate_configuration)
Launches the isolate using the window data associated with this runtime controller. Before this call, the Dart isolate has not been initialized. On successful return, the caller can assume that the isolate is in the DartIsolate::Phase::Running phase.
RuntimeController(RuntimeDelegate &p_client, DartVM *vm, fml::RefPtr< const DartSnapshot > p_isolate_snapshot, const std::function< void(int64_t)> &idle_notification_callback, const PlatformData &platform_data, const fml::closure &isolate_create_callback, const fml::closure &isolate_shutdown_callback, std::shared_ptr< const fml::Mapping > p_persistent_isolate_data, const UIDartState::Context &context)
Creates a new instance of a runtime controller. This is usually only done by the engine instance asso...
bool SetLifecycleState(const std::string &data)
Forward the lifecycle state data to the running isolate. If the isolate is not running, this data will be saved and flushed to the isolate when it starts running.
FlKeyEvent FlKeyResponderAsyncCallback callback
bool BeginFrame(fml::TimePoint frame_time, uint64_t frame_number)
Notifies the running isolate that it should start generating a new frame.
DartErrorHandleType
Definition: dart_error.h:18
uint64_t GetRootIsolateGroup() const
Get an identifier that represents the Dart isolate group the root isolate is in.
const PlatformData & GetPlatformData() const
A client interface that the RuntimeController uses to define handlers for PlatformConfiguration reque...
bool HasLivePorts()
Returns if the root isolate has any live receive ports.
std::function< void()> closure
Definition: closure.h:14
uint8_t value
std::string GetIsolateName()
Gets the debug name of the root isolate. But default, the debug name of the isolate is derived from i...
bool SetLocales(const std::vector< std::string > &locale_data)
Forward the specified locale data to the running isolate. If the isolate is not running, this data will be saved and flushed to the isolate when it starts running.
virtual bool DispatchPlatformMessage(std::unique_ptr< PlatformMessage > message)
Dispatch the specified platform message to running root isolate.
const fml::WeakPtr< SnapshotDelegate > & GetSnapshotDelegate() const
SemanticsAction action
Dart_Handle ComputePlatformResolvedLocale(Dart_Handle supportedLocalesHandle)
Dart_Port GetMainPort()
Gets the main port identifier of the root isolate.
The subset of state which is owned by the shell or engine and passed through the RuntimeController in...
Definition: ui_dart_state.h:43
std::optional< uint32_t > GetRootIsolateReturnCode()
Get the return code specified by the root isolate (if one is present).
tonic::DartErrorHandleType GetLastError()
Get the last error encountered by the microtask queue.
Describes a running instance of the Dart VM. There may only be one running instance of the Dart VM in...
Definition: dart_vm.h:61
bool DispatchKeyDataPacket(const KeyDataPacket &packet, KeyDataResponse callback)
Dispatch the specified pointer data message to the running root isolate.
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition: mapping.h:129
A class for holding and distributing platform-level information to and from the Dart code in Flutter&#39;...
bool 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 Dart code running on the engine by invoking this method at predefined intervals.
std::function< void(bool)> KeyDataResponse
bool SetViewportMetrics(const ViewportMetrics &metrics)
Forward the specified viewport metrics to the running isolate. If the isolate is not running...
std::optional< std::string > GetRootIsolateServiceID() const
Get the service ID of the root isolate if the root isolate is running.
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27
const fml::WeakPtr< IOManager > & GetIOManager() const
void LoadDartDeferredLibrary(intptr_t loading_unit_id, std::unique_ptr< const fml::Mapping > snapshot_data, std::unique_ptr< const fml::Mapping > snapshot_instructions)
Loads the Dart shared library into the Dart VM. When the Dart library is loaded successfully, the Dart future returned by the originating loadLibrary() call completes.
bool DispatchPointerDataPacket(const PointerDataPacket &packet)
Dispatch the specified pointer data message to the running root isolate.
virtual void LoadDartDeferredLibraryError(intptr_t loading_unit_id, const std::string error_message, bool transient)
Indicates to the dart VM that the request to load a deferred library with the specified loading unit ...
DEF_SWITCHES_START snapshot asset Path to the directory containing the four files specified by VmSnapshotInstructions and IsolateSnapshotInstructions vm snapshot The VM instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present isolate snapshot The isolate instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present icu symbol Prefix for the symbols representing ICU data linked into the Flutter library dart flags
Definition: switches.h:66
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override
Invoked when the Dart VM requests that a deferred library be loaded. Notifies the engine that the def...
virtual DartVM * GetDartVM() const