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