Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
engine.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_SHELL_COMMON_ENGINE_H_
6#define FLUTTER_SHELL_COMMON_ENGINE_H_
7
8#include <memory>
9#include <string>
10
11#include "flutter/assets/asset_manager.h"
12#include "flutter/common/task_runners.h"
13#include "flutter/fml/macros.h"
14#include "flutter/fml/mapping.h"
15#include "flutter/fml/memory/weak_ptr.h"
16#include "flutter/lib/ui/painting/image_decoder.h"
17#include "flutter/lib/ui/painting/image_generator_registry.h"
18#include "flutter/lib/ui/semantics/custom_accessibility_action.h"
19#include "flutter/lib/ui/semantics/semantics_node.h"
20#include "flutter/lib/ui/snapshot_delegate.h"
21#include "flutter/lib/ui/text/font_collection.h"
22#include "flutter/lib/ui/volatile_path_tracker.h"
23#include "flutter/lib/ui/window/platform_message.h"
24#include "flutter/lib/ui/window/viewport_metrics.h"
25#include "flutter/runtime/dart_vm.h"
26#include "flutter/runtime/runtime_controller.h"
27#include "flutter/runtime/runtime_delegate.h"
28#include "flutter/shell/common/animator.h"
29#include "flutter/shell/common/display_manager.h"
30#include "flutter/shell/common/platform_view.h"
31#include "flutter/shell/common/pointer_data_dispatcher.h"
32#include "flutter/shell/common/run_configuration.h"
33#include "flutter/shell/common/shell_io_manager.h"
34
35namespace flutter {
36
37//------------------------------------------------------------------------------
38/// The engine is a component owned by the shell that resides on the UI task
39/// runner and is responsible for managing the needs of the root isolate and its
40/// runtime. The engine can only be created, accessed and collected on the UI
41/// task runner. Each shell owns exactly one instance of the engine.
42///
43/// The root isolate of Flutter application gets "window" bindings. Using these
44/// bindings, the application can schedule frames, post layer-trees for
45/// rendering, ask to decompress images and upload them to the GPU, etc..
46/// Non-root isolates of the VM do not get any of these capabilities and are run
47/// in a VM managed thread pool (so if they did have "window", the threading
48/// guarantees needed for engine operation would be violated).
49///
50/// The engine is responsible for the entire life-cycle of the root isolate.
51/// When the engine is collected, its owner assumes that the root isolate has
52/// been shutdown and appropriate resources collected. While each engine
53/// instance can only manage a single instance of a root isolate, it may restart
54/// that isolate on request. This is how the cold-restart development scenario
55/// is supported.
56///
57/// When the engine instance is initially created, the root isolate is created
58/// but it is not in the |DartIsolate::Phase::Running| phase yet. It only moves
59/// into that phase when a successful call to `Engine::Run` is made.
60///
61/// @see `Shell`
62///
63/// @note This name of this class is perhaps a bit unfortunate and has
64/// sometimes been the cause of confusion. For a class named "Engine"
65/// in the Flutter "Engine" repository, its responsibilities are
66/// decidedly unremarkable. But, it does happen to be the primary
67/// entry-point used by components higher up in the Flutter tech stack
68/// (usually in Dart code) to peer into the lower level functionality.
69/// Besides, the authors haven't been able to come up with a more apt
70/// name and it does happen to be one of the older classes in the
71/// repository.
72///
74 public:
75 //----------------------------------------------------------------------------
76 /// @brief Indicates the result of the call to `Engine::Run`.
77 ///
78 enum class RunStatus {
79 // NOLINTBEGIN(readability-identifier-naming)
80 //--------------------------------------------------------------------------
81 /// The call to |Engine::Run| was successful and the root isolate is in the
82 /// `DartIsolate::Phase::Running` phase with its entry-point invocation
83 /// already pending in the task queue.
84 ///
85 Success,
86
87 //--------------------------------------------------------------------------
88 /// The engine can only manage a single instance of a root isolate. If a
89 /// previous call to run the root isolate was successful, subsequent calls
90 /// to run the isolate (even if the new run configuration is different) will
91 /// be rejected.
92 ///
93 /// It is up to the caller to decide to re-purpose the running isolate,
94 /// terminate it, or use another shell to host the new isolate. This is
95 /// mostly used by embedders which have a fire-and-forget strategy to root
96 /// isolate launch. For example, the application may try to "launch" an
97 /// isolate when the embedders launches or resumes from a paused state. That
98 /// the isolate is running is not necessarily a failure condition for them.
99 /// But from the engine's perspective, the run configuration was rejected.
100 ///
102
103 //--------------------------------------------------------------------------
104 /// Used to indicate to the embedder that a root isolate was not already
105 /// running but the run configuration was not valid and root isolate could
106 /// not be moved into the `DartIsolate::Phase::Running` phase.
107 ///
108 /// The caller must attempt the run call again with a valid configuration.
109 /// The set of all failure modes is massive and can originate from a variety
110 /// of sub-components. The engine will attempt to log the same when
111 /// possible. With the aid of logs, the common causes of failure are:
112 ///
113 /// * AOT assets were given to JIT/DBC mode VM's and vice-versa.
114 /// * The assets could not be found in the asset manager. Callers must make
115 /// sure their run configuration asset managers have been correctly set
116 /// up.
117 /// * The assets themselves were corrupt or invalid. Callers must make sure
118 /// their asset delivery mechanisms are sound.
119 /// * The application entry-point or the root library of the entry-point
120 /// specified in the run configuration was invalid. Callers must make sure
121 /// that the entry-point is present in the application. If the name of the
122 /// entrypoint is not "main" in the root library, callers must also ensure
123 /// that the snapshotting process has not tree-shaken away this
124 /// entrypoint. This requires the decoration of the entrypoint with the
125 /// `@pragma('vm:entry-point')` directive. This problem will manifest in
126 /// AOT mode operation of the Dart VM.
127 ///
128 Failure,
129 // NOLINTEND(readability-identifier-naming)
130 };
131
132 //----------------------------------------------------------------------------
133 /// @brief While the engine operates entirely on the UI task runner, it
134 /// needs the capabilities of the other components to fulfill the
135 /// requirements of the root isolate. The shell is the only class
136 /// that implements this interface as no other component has
137 /// access to all components in a thread safe manner. The engine
138 /// delegates these tasks to the shell via this interface.
139 ///
140 class Delegate {
141 public:
142 //--------------------------------------------------------------------------
143 /// @brief When the accessibility tree has been updated by the Flutter
144 /// application, this new information needs to be conveyed to
145 /// the underlying platform. The engine delegates this task to
146 /// the shell via this call. The engine cannot access the
147 /// underlying platform directly because of threading
148 /// considerations. Most platform specific APIs to convey
149 /// accessibility information are only safe to access on the
150 /// platform task runner while the engine is running on the UI
151 /// task runner.
152 ///
153 /// @see `SemanticsNode`, `SemanticsNodeUpdates`,
154 /// `CustomAccessibilityActionUpdates`,
155 /// `PlatformView::UpdateSemantics`
156 ///
157 /// @param[in] updates A map with the stable semantics node identifier as
158 /// key and the node properties as the value.
159 /// @param[in] actions A map with the stable semantics node identifier as
160 /// key and the custom node action as the value.
161 ///
163 SemanticsNodeUpdates updates,
165
166 //--------------------------------------------------------------------------
167 /// @brief When the Flutter application has a message to send to the
168 /// underlying platform, the message needs to be forwarded to
169 /// the platform on the appropriate thread (via the platform
170 /// task runner). The engine delegates this task to the shell
171 /// via this method.
172 ///
173 /// @see `PlatformView::HandlePlatformMessage`
174 ///
175 /// @param[in] message The message from the Flutter application to send to
176 /// the underlying platform.
177 ///
179 std::unique_ptr<PlatformMessage> message) = 0;
180
181 //--------------------------------------------------------------------------
182 /// @brief Notifies the delegate that the root isolate of the
183 /// application is about to be discarded and a new isolate with
184 /// the same runtime started in its place. This should only
185 /// happen in the Flutter "debug" runtime mode in the
186 /// cold-restart scenario. The embedder may need to reset native
187 /// resource in response to the restart.
188 ///
189 /// @see `PlatformView::OnPreEngineRestart`
190 ///
191 virtual void OnPreEngineRestart() = 0;
192
193 //--------------------------------------------------------------------------
194 /// @brief Notifies the shell that the root isolate is created.
195 /// Currently, this information is to add to the service
196 /// protocol list of available root isolates running in the VM
197 /// and their names so that the appropriate isolate can be
198 /// selected in the tools for debugging and instrumentation.
199 ///
200 virtual void OnRootIsolateCreated() = 0;
201
202 //--------------------------------------------------------------------------
203 /// @brief Notifies the shell of the name of the root isolate and its
204 /// port when that isolate is launched, restarted (in the
205 /// cold-restart scenario) or the application itself updates the
206 /// name of the root isolate (via
207 /// `PlatformDispatcher.setIsolateDebugName` in
208 /// `platform_dispatcher.dart`). The name of the isolate is
209 /// meaningless to the engine but is used in instrumentation and
210 /// tooling. Currently, this information is to update the
211 /// service protocol list of available root isolates running in
212 /// the VM and their names so that the appropriate isolate can
213 /// be selected in the tools for debugging and instrumentation.
214 ///
215 /// @param[in] isolate_name The isolate name
216 /// @param[in] isolate_port The isolate port
217 ///
218 virtual void UpdateIsolateDescription(const std::string isolate_name,
219 int64_t isolate_port) = 0;
220
221 //--------------------------------------------------------------------------
222 /// @brief Notifies the shell that the application has an opinion about
223 /// whether its frame timings need to be reported backed to it.
224 /// Due to the asynchronous nature of rendering in Flutter, it
225 /// is not possible for the application to determine the total
226 /// time it took to render a specific frame. While the
227 /// layer-tree is constructed on the UI thread, it needs to be
228 /// rendering on the raster thread. Dart code cannot execute on
229 /// this thread. So any instrumentation about the frame times
230 /// gathered on this thread needs to be aggregated and sent back
231 /// to the UI thread for processing in Dart.
232 ///
233 /// When the application indicates that frame times need to be
234 /// reported, it collects this information till a specified
235 /// number of data points are gathered. Then this information is
236 /// sent back to Dart code via `Engine::ReportTimings`.
237 ///
238 /// This option is engine counterpart of the
239 /// `Window._setNeedsReportTimings` in `window.dart`.
240 ///
241 /// @param[in] needs_reporting If reporting information should be
242 /// collected and send back to Dart.
243 ///
244 virtual void SetNeedsReportTimings(bool needs_reporting) = 0;
245
246 //--------------------------------------------------------------------------
247 /// @brief Directly invokes platform-specific APIs to compute the
248 /// locale the platform would have natively resolved to.
249 ///
250 /// @param[in] supported_locale_data The vector of strings that represents
251 /// the locales supported by the app.
252 /// Each locale consists of three
253 /// strings: languageCode, countryCode,
254 /// and scriptCode in that order.
255 ///
256 /// @return A vector of 3 strings languageCode, countryCode, and
257 /// scriptCode that represents the locale selected by the
258 /// platform. Empty strings mean the value was unassigned. Empty
259 /// vector represents a null locale.
260 ///
261 virtual std::unique_ptr<std::vector<std::string>>
263 const std::vector<std::string>& supported_locale_data) = 0;
264
265 //--------------------------------------------------------------------------
266 /// @brief Invoked when the Dart VM requests that a deferred library
267 /// be loaded. Notifies the engine that the deferred library
268 /// identified by the specified loading unit id should be
269 /// downloaded and loaded into the Dart VM via
270 /// `LoadDartDeferredLibrary`
271 ///
272 /// Upon encountering errors or otherwise failing to load a
273 /// loading unit with the specified id, the failure should be
274 /// directly reported to dart by calling
275 /// `LoadDartDeferredLibraryFailure` to ensure the waiting dart
276 /// future completes with an error.
277 ///
278 /// @param[in] loading_unit_id The unique id of the deferred library's
279 /// loading unit. This id is to be passed
280 /// back into LoadDartDeferredLibrary
281 /// in order to identify which deferred
282 /// library to load.
283 ///
284 virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id) = 0;
285
286 //--------------------------------------------------------------------------
287 /// @brief Returns the current fml::TimePoint.
288 /// This method is primarily provided to allow tests to control
289 /// Any methods that rely on advancing the clock.
291
292 //----------------------------------------------------------------------------
293 /// @brief Returns the delegate object that handles PlatformMessage's from
294 /// Flutter to the host platform (and its responses).
295 virtual const std::shared_ptr<PlatformMessageHandler>&
297
298 //--------------------------------------------------------------------------
299 /// @brief Invoked when a listener is registered on a platform channel.
300 ///
301 /// @param[in] name The name of the platform channel to which a
302 /// listener has been registered or cleared.
303 ///
304 /// @param[in] listening Whether the listener has been set (true) or
305 /// cleared (false).
306 ///
307 virtual void OnEngineChannelUpdate(std::string name, bool listening) = 0;
308
309 //--------------------------------------------------------------------------
310 /// @brief Synchronously invokes platform-specific APIs to apply the
311 /// system text scaling on the given unscaled font size.
312 ///
313 /// Platforms that support this feature (currently it's only
314 /// implemented for Android SDK level 34+) will send a valid
315 /// configuration_id to potential callers, before this method
316 /// can be called.
317 ///
318 /// @param[in] unscaled_font_size The unscaled font size specified by the
319 /// app developer. The value is in logical
320 /// pixels, and is guaranteed to be finite
321 /// and non-negative.
322 /// @param[in] configuration_id The unique id of the configuration to
323 /// use for computing the scaled font size.
324 ///
325 /// @return The scaled font size in logical pixels, or -1 when the given
326 /// configuration_id did not match a valid configuration.
327 ///
328 virtual double GetScaledFontSize(double unscaled_font_size,
329 int configuration_id) const = 0;
330 };
331
332 //----------------------------------------------------------------------------
333 /// @brief Creates an instance of the engine with a supplied
334 /// `RuntimeController`. Use the other constructor except for
335 /// tests.
336 ///
337 Engine(Delegate& delegate,
338 const PointerDataDispatcherMaker& dispatcher_maker,
339 const std::shared_ptr<fml::ConcurrentTaskRunner>&
340 image_decoder_task_runner,
341 const TaskRunners& task_runners,
342 const Settings& settings,
343 std::unique_ptr<Animator> animator,
344 const fml::WeakPtr<IOManager>& io_manager,
345 const std::shared_ptr<FontCollection>& font_collection,
346 std::unique_ptr<RuntimeController> runtime_controller,
347 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch);
348
349 //----------------------------------------------------------------------------
350 /// @brief Creates an instance of the engine. This is done by the Shell
351 /// on the UI task runner.
352 ///
353 /// @param delegate The object used by the engine to perform
354 /// tasks that require access to components
355 /// that cannot be safely accessed by the
356 /// engine. This is the shell.
357 /// @param dispatcher_maker The callback provided by `PlatformView` for
358 /// engine to create the pointer data
359 /// dispatcher. Similar to other engine
360 /// resources, this dispatcher_maker and its
361 /// returned dispatcher is only safe to be
362 /// called from the UI thread.
363 /// @param vm An instance of the running Dart VM.
364 /// @param[in] isolate_snapshot The snapshot used to create the root
365 /// isolate. Even though the isolate is not
366 /// `DartIsolate::Phase::Running` phase, it is
367 /// created when the engine is created. This
368 /// requires access to the isolate snapshot
369 /// upfront.
370 // TODO(chinmaygarde): This is probably redundant now that the IO manager is
371 // it's own object.
372 /// @param[in] task_runners The task runners used by the shell that
373 /// hosts this engine.
374 /// @param[in] settings The settings used to initialize the shell
375 /// and the engine.
376 /// @param[in] animator The animator used to schedule frames.
377 // TODO(chinmaygarde): Move this to `Engine::Delegate`
378 /// @param[in] snapshot_delegate The delegate used to fulfill requests to
379 /// snapshot a specified scene. The engine
380 /// cannot snapshot a scene on the UI thread
381 /// directly because the scene (described via
382 /// a `DisplayList`) may reference resources on
383 /// the GPU and there is no GPU context current
384 /// on the UI thread. The delegate is a
385 /// component that has access to all the
386 /// requisite GPU resources.
387 /// @param[in] io_manager The IO manager used by this root isolate to
388 /// schedule tasks that manage resources on the
389 /// GPU.
390 ///
391 Engine(Delegate& delegate,
392 const PointerDataDispatcherMaker& dispatcher_maker,
393 DartVM& vm,
394 fml::RefPtr<const DartSnapshot> isolate_snapshot,
395 const TaskRunners& task_runners,
396 const PlatformData& platform_data,
397 const Settings& settings,
398 std::unique_ptr<Animator> animator,
399 fml::WeakPtr<IOManager> io_manager,
400 const fml::RefPtr<SkiaUnrefQueue>& unref_queue,
402 std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
403 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch,
404 impeller::RuntimeStageBackend runtime_stage_type =
406
407 //----------------------------------------------------------------------------
408 /// @brief Create a Engine that shares as many resources as
409 /// possible with the calling Engine such that together
410 /// they occupy less memory and be created faster.
411 /// @details This should only be called on running Engines.
412 /// @return A new Engine with a running isolate.
413 /// @see Engine::Engine
414 /// @see DartIsolate::SpawnIsolate
415 ///
416 std::unique_ptr<Engine> Spawn(
417 Delegate& delegate,
418 const PointerDataDispatcherMaker& dispatcher_maker,
419 const Settings& settings,
420 std::unique_ptr<Animator> animator,
421 const std::string& initial_route,
422 const fml::WeakPtr<IOManager>& io_manager,
424 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch) const;
425
426 //----------------------------------------------------------------------------
427 /// @brief Destroys the engine engine. Called by the shell on the UI task
428 /// runner. The running root isolate is terminated and will no
429 /// longer access the task runner after this call returns. This
430 /// allows the embedder to tear down the thread immediately if
431 /// needed.
432 ///
433 ~Engine() override;
434
435 //----------------------------------------------------------------------------
436 /// @return The pointer to this instance of the engine. The engine may
437 /// only be accessed safely on the UI task runner.
438 ///
440
441 //----------------------------------------------------------------------------
442 /// @brief Moves the root isolate to the `DartIsolate::Phase::Running`
443 /// phase on a successful call to this method.
444 ///
445 /// The isolate itself is created when the engine is created, but
446 /// it is not yet in the running phase. This is done to amortize
447 /// initial time taken to launch the root isolate. The isolate
448 /// snapshots used to run the isolate can be fetched on another
449 /// thread while the engine itself is launched on the UI task
450 /// runner.
451 ///
452 /// Repeated calls to this method after a successful run will be
453 /// rejected even if the run configuration is valid (with the
454 /// appropriate error returned).
455 ///
456 /// @param[in] configuration The configuration used to run the root isolate.
457 /// The configuration must be valid.
458 ///
459 /// @return The result of the call to run the root isolate.
460 ///
461 [[nodiscard]] RunStatus Run(RunConfiguration configuration);
462
463 //----------------------------------------------------------------------------
464 /// @brief Tears down an existing root isolate, reuses the components of
465 /// that isolate and attempts to launch a new isolate using the
466 /// given the run configuration. This is only used in the
467 /// "debug" Flutter runtime mode in the cold-restart scenario.
468 ///
469 /// @attention This operation must be performed with care as even a
470 /// non-successful restart will still tear down any existing root
471 /// isolate. In such cases, the engine and its shell must be
472 /// discarded.
473 ///
474 /// @param[in] configuration The configuration used to launch the new
475 /// isolate.
476 ///
477 /// @return Whether the restart was successful. If not, the engine and its
478 /// shell must be discarded.
479 ///
480 [[nodiscard]] bool Restart(RunConfiguration configuration);
481
482 //----------------------------------------------------------------------------
483 /// @brief Setup default font manager according to specific platform.
484 ///
486
487 //----------------------------------------------------------------------------
488 /// @brief Updates the asset manager referenced by the root isolate of a
489 /// Flutter application. This happens implicitly in the call to
490 /// `Engine::Run` and `Engine::Restart` as the asset manager is
491 /// referenced from the run configuration provided to those calls.
492 /// In addition to the `Engine::Run` and `Engine::Restart`
493 /// calls, the tooling may need to update the assets available to
494 /// the application as the user adds them to their project. For
495 /// example, these assets may be referenced by code that is newly
496 /// patched in after a hot-reload. Neither the shell or the
497 /// isolate in relaunched in such cases. The tooling usually
498 /// patches in the new assets in a temporary location and updates
499 /// the asset manager to point to that location.
500 ///
501 /// @param[in] asset_manager The new asset manager to use for the running
502 /// root isolate.
503 ///
504 /// @return If the asset manager was successfully replaced. This may fail
505 /// if the new asset manager is invalid.
506 ///
507 bool UpdateAssetManager(const std::shared_ptr<AssetManager>& asset_manager);
508
509 //----------------------------------------------------------------------------
510 /// @brief Notifies the engine that it is time to begin working on a new
511 /// frame previously scheduled via a call to
512 /// `Engine::ScheduleFrame`. This call originates in the animator.
513 ///
514 /// The frame time given as the argument indicates the point at
515 /// which the current frame interval began. It is very slightly
516 /// (because of scheduling overhead) in the past. If a new layer
517 /// tree is not produced and given to the raster task runner
518 /// within one frame interval from this point, the Flutter
519 /// application will jank.
520 ///
521 /// If a root isolate is running, this method calls the
522 /// `::_beginFrame` method in `hooks.dart`. If a root isolate is
523 /// not running, this call does nothing.
524 ///
525 /// This method encapsulates the entire UI thread frame workload.
526 /// The following (mis)behavior in the functioning of the method
527 /// will cause the jank in the Flutter application:
528 /// * The time taken by this method to create a layer-tree exceeds
529 /// one frame interval (for example, 16.66 ms on a 60Hz
530 /// display).
531 /// * The time take by this method to generate a new layer-tree
532 /// causes the current layer-tree pipeline depth to change. To
533 /// illustrate this point, note that maximum pipeline depth used
534 /// by layer tree in the engine is 2. If both the UI and GPU
535 /// task runner tasks finish within one frame interval, the
536 /// pipeline depth is one. If the UI thread happens to be
537 /// working on a frame when the raster thread is still not done
538 /// with the previous frame, the pipeline depth is 2. When the
539 /// pipeline depth changes from 1 to 2, animations and UI
540 /// interactions that cause the generation of the new layer tree
541 /// appropriate for (frame_time + one frame interval) will
542 /// actually end up at (frame_time + two frame intervals). This
543 /// is not what code running on the UI thread expected would
544 /// happen. This causes perceptible jank.
545 ///
546 /// @param[in] frame_time The point at which the current frame interval
547 /// began. May be used by animation interpolators,
548 /// physics simulations, etc..
549 ///
550 /// @param[in] frame_number The frame number recorded by the animator. Used
551 /// by the framework to associate frame specific
552 /// debug information with frame timings and timeline
553 /// events.
554 void BeginFrame(fml::TimePoint frame_time, uint64_t frame_number);
555
556 //----------------------------------------------------------------------------
557 /// @brief Notifies the engine that the UI task runner is not expected to
558 /// undertake a new frame workload till a specified timepoint. The
559 /// timepoint is measured in microseconds against the system's
560 /// monotonic clock. It is recommended that the clock be accessed
561 /// via `Dart_TimelineGetMicros` from `dart_api.h` for
562 /// consistency. In reality, the clocks used by Dart, FML and
563 /// std::steady_clock are all the same and the timepoints can be
564 /// converted from on clock type to another.
565 ///
566 /// The Dart VM uses this notification to schedule book-keeping
567 /// tasks that may include a garbage collection. In this way, it
568 /// is less likely for the VM to perform such (potentially long
569 /// running) tasks in the middle of a frame workload.
570 ///
571 /// This notification is advisory. That is, not providing this
572 /// notification does not mean garbage collection is postponed
573 /// till this call is made. If this notification is not provided,
574 /// garbage collection will happen based on the usual heuristics
575 /// used by the Dart VM.
576 ///
577 /// Currently, this idle notification is delivered to the engine
578 /// at two points. Once, the deadline is calculated based on how
579 /// much time in the current frame interval is left on the UI task
580 /// runner. Since the next frame workload cannot begin till at
581 /// least the next callback from the vsync waiter, this period may
582 /// be used to used as a "small" idle notification. On the other
583 /// hand, if no more frames are scheduled, a large (but arbitrary)
584 /// idle notification deadline is chosen for a "big" idle
585 /// notification. Again, this notification does not guarantee
586 /// collection, just gives the Dart VM more hints about opportune
587 /// moments to perform collections.
588 ///
589 ///
590 /// @param[in] deadline The deadline is used by the VM to determine if the
591 /// corresponding sweep can be performed within the
592 /// deadline.
593 ///
594 void NotifyIdle(fml::TimeDelta deadline);
595
596 //----------------------------------------------------------------------------
597 /// @brief Notifies the engine that the attached flutter view has been
598 /// destroyed.
599 /// This enables the engine to notify the Dart VM so it can do
600 /// some cleanp activities.
601 void NotifyDestroyed();
602
603 //----------------------------------------------------------------------------
604 /// @brief Dart code cannot fully measure the time it takes for a
605 /// specific frame to be rendered. This is because Dart code only
606 /// runs on the UI task runner. That is only a small part of the
607 /// overall frame workload. The raster task runner frame workload
608 /// is executed on a thread where Dart code cannot run (and hence
609 /// instrument). Besides, due to the pipelined nature of rendering
610 /// in Flutter, there may be multiple frame workloads being
611 /// processed at any given time. However, for non-Timeline based
612 /// profiling, it is useful for trace collection and processing to
613 /// happen in Dart. To do this, the raster task runner frame
614 /// workloads need to be instrumented separately. After a set
615 /// number of these profiles have been gathered, they need to be
616 /// reported back to Dart code. The shell reports this extra
617 /// instrumentation information back to Dart code running on the
618 /// engine by invoking this method at predefined intervals.
619 ///
620 /// @see `FrameTiming`
621 ///
622 // TODO(chinmaygarde): The use `int64_t` is added for ease of conversion to
623 // Dart but hurts readability. The phases and the units of the timepoints are
624 // not obvious without some sleuthing. The conversion can happen at the
625 // native interface boundary instead.
626 ///
627 /// @param[in] timings Collection of `FrameTiming::kCount` * `n` timestamps
628 /// for `n` frames whose timings have not been reported
629 /// yet. A collection of integers is reported here for
630 /// easier conversions to Dart objects. The timestamps
631 /// are measured against the system monotonic clock
632 /// measured in microseconds.
633 ///
634 void ReportTimings(std::vector<int64_t> timings);
635
636 //----------------------------------------------------------------------------
637 /// @brief Gets the main port of the root isolate. Since the isolate is
638 /// created immediately in the constructor of the engine, it is
639 /// possible to get its main port immediately (even before a call
640 /// to `Run` can be made). This is useful in registering the port
641 /// in a race free manner with a port nameserver.
642 ///
643 /// @return The main port of the root isolate.
644 ///
646
647 //----------------------------------------------------------------------------
648 /// @brief Gets the debug name of the root isolate. By default, the
649 /// debug name of the isolate is derived from its advisory script
650 /// URI, advisory main entrypoint and its main port name. For
651 /// example, "main.dart$main-1234" where the script URI is
652 /// "main.dart", the entrypoint is "main" and the port name
653 /// "1234". Once launched, the isolate may re-christen itself
654 /// using a name it selects via `setIsolateDebugName` in
655 /// `platform_dispatcher.dart`. This name is purely advisory and
656 /// only used by instrumentation and reporting purposes.
657 ///
658 /// @return The debug name of the root isolate.
659 ///
660 std::string GetUIIsolateName();
661
662 //----------------------------------------------------------------------------
663 /// @brief It is an unexpected challenge to determine when a Dart
664 /// application is "done". The application cannot simply terminate
665 /// the native process (and perhaps return an exit code) because
666 /// it does not have that power. After all, Flutter applications
667 /// reside within a host process that may have other
668 /// responsibilities besides just running Flutter applications.
669 /// Also, the `main` entry-points are run on an event loop and
670 /// returning from "main" (unlike in C/C++ applications) does not
671 /// mean termination of the process. Besides, the return value of
672 /// the main entrypoint is discarded.
673 ///
674 /// One technique used by embedders to determine "liveness" is to
675 /// count the outstanding live ports dedicated to the application.
676 /// These ports may be live as a result of pending timers,
677 /// scheduled tasks, pending IO on sockets, channels open with
678 /// other isolates, etc.. At regular intervals (sometimes as often
679 /// as after the UI task runner processes any task), embedders may
680 /// check for the "liveness" of the application and perform
681 /// teardown of the embedder when no more ports are live.
682 ///
683 /// @return Check if the root isolate has any live ports.
684 ///
686
687 //----------------------------------------------------------------------------
688 /// @brief Errors that are unhandled on the Dart message loop are kept
689 /// for further inspection till the next unhandled error comes
690 /// along. This accessor returns the last unhandled error
691 /// encountered by the root isolate.
692 ///
693 /// @return The ui isolate last error.
694 ///
696
697 //----------------------------------------------------------------------------
698 /// @brief As described in the discussion for `UIIsolateHasLivePorts`,
699 /// the "done-ness" of a Dart application is tricky to ascertain
700 /// and the return value from the main entrypoint is discarded
701 /// (because the Dart isolate is still running after the main
702 /// entrypoint returns). But, the concept of an exit code akin to
703 /// those returned by native applications is still useful. Short
704 /// lived Dart applications (usually tests), emulate this by
705 /// setting a per isolate "return value" and then indicating their
706 /// "done-ness" (usually via closing all live ports). This
707 /// accessor returns that "return value" is present.
708 ///
709 /// @see `UIIsolateHasLivePorts`
710 ///
711 /// @return The return code (if specified) by the isolate.
712 ///
713 std::optional<uint32_t> GetUIIsolateReturnCode();
714
715 //----------------------------------------------------------------------------
716 /// @brief Notify the Flutter application that a new view is available.
717 ///
718 /// A view must be added before other methods can refer to it,
719 /// including the implicit view. Adding a view that already exists
720 /// triggers an assertion.
721 ///
722 /// @param[in] view_id The ID of the new view.
723 /// @param[in] viewport_metrics The initial viewport metrics for the view.
724 /// @param[in] callback Callback that will be invoked once
725 /// the engine attempts to add the view.
726 ///
727 void AddView(int64_t view_id,
728 const ViewportMetrics& view_metrics,
729 std::function<void(bool added)> callback);
730
731 //----------------------------------------------------------------------------
732 /// @brief Notify the Flutter application that a view is no
733 /// longer available.
734 ///
735 /// Removing a view that does not exist triggers an assertion.
736 ///
737 /// The implicit view (kFlutterImplicitViewId) should never be
738 /// removed. Doing so triggers an assertion.
739 ///
740 /// @param[in] view_id The ID of the view.
741 ///
742 /// @return Whether the view was removed.
743 ///
744 bool RemoveView(int64_t view_id);
745
746 //----------------------------------------------------------------------------
747 /// @brief Updates the viewport metrics for a view. The viewport metrics
748 /// detail the size of the rendering viewport in texels as well as
749 /// edge insets if present.
750 ///
751 /// @see `ViewportMetrics`
752 ///
753 /// @param[in] view_id The ID for the view that `metrics` describes.
754 /// @param[in] metrics The metrics.
755 ///
756 void SetViewportMetrics(int64_t view_id, const ViewportMetrics& metrics);
757
758 //----------------------------------------------------------------------------
759 /// @brief Updates the display metrics for the currently running Flutter
760 /// application.
761 ///
762 /// @param[in] displays A complete list of displays
763 ///
764 void SetDisplays(const std::vector<DisplayData>& displays);
765
766 //----------------------------------------------------------------------------
767 /// @brief Notifies the engine that the embedder has sent it a message.
768 /// This call originates in the platform view and has been
769 /// forwarded to the engine on the UI task runner here.
770 ///
771 /// @param[in] message The message sent from the embedder to the Dart
772 /// application.
773 ///
774 void DispatchPlatformMessage(std::unique_ptr<PlatformMessage> message);
775
776 //----------------------------------------------------------------------------
777 /// @brief Notifies the engine that the embedder has sent it a pointer
778 /// data packet. A pointer data packet may contain multiple
779 /// input events. This call originates in the platform view and
780 /// the shell has forwarded the same to the engine on the UI task
781 /// runner here.
782 ///
783 /// @param[in] packet The pointer data packet containing multiple
784 /// input events.
785 /// @param[in] trace_flow_id The trace flow identifier associated with the
786 /// pointer data packet. The engine uses this trace
787 /// identifier to connect trace flows in the
788 /// timeline from the input event to the
789 /// frames generated due to those input events.
790 /// These flows are tagged as "PointerEvent" in the
791 /// timeline and allow grouping frames and input
792 /// events into logical chunks.
793 ///
794 void DispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet,
795 uint64_t trace_flow_id);
796
797 //----------------------------------------------------------------------------
798 /// @brief Notifies the engine that the embedder encountered an
799 /// accessibility related action on the specified node. This call
800 /// originates on the platform view and has been forwarded to the
801 /// engine here on the UI task runner by the shell.
802 ///
803 /// @param[in] node_id The identifier of the accessibility node.
804 /// @param[in] action The accessibility related action performed on the
805 /// node of the specified ID.
806 /// @param[in] args Optional data that applies to the specified action.
807 ///
808 void DispatchSemanticsAction(int node_id,
811
812 //----------------------------------------------------------------------------
813 /// @brief Notifies the engine that the embedder has expressed an opinion
814 /// about whether the accessibility tree should be generated or
815 /// not. This call originates in the platform view and is
816 /// forwarded to the engine here on the UI task runner by the
817 /// shell.
818 ///
819 /// @param[in] enabled Whether the accessibility tree is enabled or
820 /// disabled.
821 ///
822 void SetSemanticsEnabled(bool enabled);
823
824 //----------------------------------------------------------------------------
825 /// @brief Notifies the engine that the embedder has expressed an opinion
826 /// about where the flags to set on the accessibility tree. This
827 /// flag originates in the platform view and is forwarded to the
828 /// engine here on the UI task runner by the shell.
829 ///
830 /// The engine does not care about the accessibility feature flags
831 /// as all it does is forward this information from the embedder
832 /// to the framework. However, curious readers may refer to
833 /// `AccessibilityFeatures` in `window.dart` for currently
834 /// supported accessibility feature flags.
835 ///
836 /// @param[in] flags The features to enable in the accessibility tree.
837 ///
838 void SetAccessibilityFeatures(int32_t flags);
839
840 // |RuntimeDelegate|
841 void ScheduleFrame(bool regenerate_layer_trees) override;
842
843 /// Schedule a frame with the default parameter of regenerating the layer
844 /// tree.
845 void ScheduleFrame() { ScheduleFrame(true); }
846
847 // |RuntimeDelegate|
848 void OnAllViewsRendered() override;
849
850 // |RuntimeDelegate|
852
853 // |RuntimeDelegate|
854 std::shared_ptr<AssetManager> GetAssetManager() override;
855
856 // Return the weak_ptr of ImageDecoder.
858
859 //----------------------------------------------------------------------------
860 /// @brief Get the `ImageGeneratorRegistry` associated with the current
861 /// engine.
862 ///
863 /// @return The engine's `ImageGeneratorRegistry`.
864 ///
866
867 // |PointerDataDispatcher::Delegate|
868 void DoDispatchPacket(std::unique_ptr<PointerDataPacket> packet,
869 uint64_t trace_flow_id) override;
870
871 // |PointerDataDispatcher::Delegate|
872 void ScheduleSecondaryVsyncCallback(uintptr_t id,
873 const fml::closure& callback) override;
874
875 //----------------------------------------------------------------------------
876 /// @brief Get the last Entrypoint that was used in the RunConfiguration
877 /// when |Engine::Run| was called.
878 ///
879 const std::string& GetLastEntrypoint() const;
880
881 //----------------------------------------------------------------------------
882 /// @brief Get the last Entrypoint Library that was used in the
883 /// RunConfiguration when |Engine::Run| was called.
884 ///
885 const std::string& GetLastEntrypointLibrary() const;
886
887 //----------------------------------------------------------------------------
888 /// @brief Get the last Entrypoint Arguments that was used in the
889 /// RunConfiguration when |Engine::Run| was called.This is only
890 /// valid in debug mode.
891 ///
892 const std::vector<std::string>& GetLastEntrypointArgs() const;
893
894 //----------------------------------------------------------------------------
895 /// @brief Getter for the initial route. This can be set with a platform
896 /// message.
897 ///
898 const std::string& InitialRoute() const { return initial_route_; }
899
900 //--------------------------------------------------------------------------
901 /// @brief Loads the Dart shared library into the Dart VM. When the
902 /// Dart library is loaded successfully, the Dart future
903 /// returned by the originating loadLibrary() call completes.
904 ///
905 /// The Dart compiler may generate separate shared libraries
906 /// files called 'loading units' when libraries are imported
907 /// as deferred. Each of these shared libraries are identified
908 /// by a unique loading unit id. Callers should open and resolve
909 /// a SymbolMapping from the shared library. The Mappings should
910 /// be moved into this method, as ownership will be assumed by the
911 /// dart root isolate after successful loading and released after
912 /// shutdown of the root isolate. The loading unit may not be
913 /// used after isolate shutdown. If loading fails, the mappings
914 /// will be released.
915 ///
916 /// This method is paired with a RequestDartDeferredLibrary
917 /// invocation that provides the embedder with the loading unit id
918 /// of the deferred library to load.
919 ///
920 ///
921 /// @param[in] loading_unit_id The unique id of the deferred library's
922 /// loading unit, as passed in by
923 /// RequestDartDeferredLibrary.
924 ///
925 /// @param[in] snapshot_data Dart snapshot data of the loading unit's
926 /// shared library.
927 ///
928 /// @param[in] snapshot_data Dart snapshot instructions of the loading
929 /// unit's shared library.
930 ///
932 intptr_t loading_unit_id,
933 std::unique_ptr<const fml::Mapping> snapshot_data,
934 std::unique_ptr<const fml::Mapping> snapshot_instructions);
935
936 //--------------------------------------------------------------------------
937 /// @brief Indicates to the dart VM that the request to load a deferred
938 /// library with the specified loading unit id has failed.
939 ///
940 /// The dart future returned by the initiating loadLibrary() call
941 /// will complete with an error.
942 ///
943 /// @param[in] loading_unit_id The unique id of the deferred library's
944 /// loading unit, as passed in by
945 /// RequestDartDeferredLibrary.
946 ///
947 /// @param[in] error_message The error message that will appear in the
948 /// dart Future.
949 ///
950 /// @param[in] transient A transient error is a failure due to
951 /// temporary conditions such as no network.
952 /// Transient errors allow the dart VM to
953 /// re-request the same deferred library and
954 /// loading_unit_id again. Non-transient
955 /// errors are permanent and attempts to
956 /// re-request the library will instantly
957 /// complete with an error.
958 void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
959 const std::string& error_message,
960 bool transient);
961
962 //--------------------------------------------------------------------------
963 /// @brief Accessor for the RuntimeController.
964 ///
966 return runtime_controller_.get();
967 }
968
969 const std::weak_ptr<VsyncWaiter> GetVsyncWaiter() const;
970
971 //--------------------------------------------------------------------------
972 /// @brief Shuts down all registered platform isolates. Must be called
973 /// from the platform thread.
974 ///
976
977 private:
978 // |RuntimeDelegate|
979 std::string DefaultRouteName() override;
980
981 // |RuntimeDelegate|
982 void Render(int64_t view_id,
983 std::unique_ptr<flutter::LayerTree> layer_tree,
984 float device_pixel_ratio) override;
985
986 // |RuntimeDelegate|
988 CustomAccessibilityActionUpdates actions) override;
989
990 // |RuntimeDelegate|
991 void HandlePlatformMessage(std::unique_ptr<PlatformMessage> message) override;
992
993 // |RuntimeDelegate|
994 void OnRootIsolateCreated() override;
995
996 // |RuntimeDelegate|
997 void UpdateIsolateDescription(const std::string isolate_name,
998 int64_t isolate_port) override;
999
1000 // |RuntimeDelegate|
1001 std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
1002 const std::vector<std::string>& supported_locale_data) override;
1003
1004 // |RuntimeDelegate|
1005 void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
1006
1007 // |RuntimeDelegate|
1008 std::weak_ptr<PlatformMessageHandler> GetPlatformMessageHandler()
1009 const override;
1010
1011 // |RuntimeDelegate|
1012 void SendChannelUpdate(std::string name, bool listening) override;
1013
1014 // |RuntimeDelegate|
1015 double GetScaledFontSize(double unscaled_font_size,
1016 int configuration_id) const override;
1017
1018 void SetNeedsReportTimings(bool value) override;
1019
1020 bool HandleLifecyclePlatformMessage(PlatformMessage* message);
1021
1022 bool HandleNavigationPlatformMessage(
1023 std::unique_ptr<PlatformMessage> message);
1024
1025 bool HandleLocalizationPlatformMessage(PlatformMessage* message);
1026
1027 void HandleSettingsPlatformMessage(PlatformMessage* message);
1028
1029 void HandleAssetPlatformMessage(std::unique_ptr<PlatformMessage> message);
1030
1031 bool GetAssetAsBuffer(const std::string& name, std::vector<uint8_t>* data);
1032
1034
1036 const Settings settings_;
1037 std::unique_ptr<Animator> animator_;
1038 std::unique_ptr<RuntimeController> runtime_controller_;
1039
1040 // The pointer_data_dispatcher_ depends on animator_ and runtime_controller_.
1041 // So it should be defined after them to ensure that pointer_data_dispatcher_
1042 // is destructed first.
1043 std::unique_ptr<PointerDataDispatcher> pointer_data_dispatcher_;
1044
1045 std::string last_entry_point_;
1046 std::string last_entry_point_library_;
1047 std::vector<std::string> last_entry_point_args_;
1048 std::string initial_route_;
1049 std::shared_ptr<AssetManager> asset_manager_;
1050 std::shared_ptr<FontCollection> font_collection_;
1051 const std::unique_ptr<ImageDecoder> image_decoder_;
1052 ImageGeneratorRegistry image_generator_registry_;
1054 fml::WeakPtrFactory<Engine> weak_factory_; // Must be the last member.
1056};
1057
1058} // namespace flutter
1059
1060#endif // FLUTTER_SHELL_COMMON_ENGINE_H_
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
While the engine operates entirely on the UI task runner, it needs the capabilities of the other comp...
Definition engine.h:140
virtual fml::TimePoint GetCurrentTimePoint()=0
Returns the current fml::TimePoint. This method is primarily provided to allow tests to control Any m...
virtual double GetScaledFontSize(double unscaled_font_size, int configuration_id) const =0
Synchronously invokes platform-specific APIs to apply the system text scaling on the given unscaled f...
virtual void UpdateIsolateDescription(const std::string isolate_name, int64_t isolate_port)=0
Notifies the shell of the name of the root isolate and its port when that isolate is launched,...
virtual std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocale(const std::vector< std::string > &supported_locale_data)=0
Directly invokes platform-specific APIs to compute the locale the platform would have natively resolv...
virtual void OnPreEngineRestart()=0
Notifies the delegate that the root isolate of the application is about to be discarded and a new iso...
virtual void OnEngineChannelUpdate(std::string name, bool listening)=0
Invoked when a listener is registered on a platform channel.
virtual void OnEngineHandlePlatformMessage(std::unique_ptr< PlatformMessage > message)=0
When the Flutter application has a message to send to the underlying platform, the message needs to b...
virtual const std::shared_ptr< PlatformMessageHandler > & GetPlatformMessageHandler() const =0
Returns the delegate object that handles PlatformMessage's from Flutter to the host platform (and its...
virtual void SetNeedsReportTimings(bool needs_reporting)=0
Notifies the shell that the application has an opinion about whether its frame timings need to be rep...
virtual void OnEngineUpdateSemantics(SemanticsNodeUpdates updates, CustomAccessibilityActionUpdates actions)=0
When the accessibility tree has been updated by the Flutter application, this new information needs t...
virtual void OnRootIsolateCreated()=0
Notifies the shell that the root isolate is created. Currently, this information is to add to the ser...
virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id)=0
Invoked when the Dart VM requests that a deferred library be loaded. Notifies the engine that the def...
void SetAccessibilityFeatures(int32_t flags)
Notifies the engine that the embedder has expressed an opinion about where the flags to set on the ac...
Definition engine.cc:454
void SetupDefaultFontManager()
Setup default font manager according to specific platform.
Definition engine.cc:159
fml::WeakPtr< Engine > GetWeakPtr() const
Definition engine.cc:155
bool RemoveView(int64_t view_id)
Notify the Flutter application that a view is no longer available.
Definition engine.cc:306
std::string DefaultRouteName() override
Definition engine.cc:458
void NotifyIdle(fml::TimeDelta deadline)
Notifies the engine that the UI task runner is not expected to undertake a new frame workload till a ...
Definition engine.cc:271
void SetViewportMetrics(int64_t view_id, const ViewportMetrics &metrics)
Updates the viewport metrics for a view. The viewport metrics detail the size of the rendering viewpo...
Definition engine.cc:310
void ReportTimings(std::vector< int64_t > timings)
Dart code cannot fully measure the time it takes for a specific frame to be rendered....
Definition engine.cc:267
void OnAllViewsRendered() override
Definition engine.cc:469
void HandlePlatformMessage(std::unique_ptr< PlatformMessage > message) override
Definition engine.cc:493
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override
Definition engine.cc:576
void DispatchSemanticsAction(int node_id, SemanticsAction action, fml::MallocMapping args)
Notifies the engine that the embedder encountered an accessibility related action on the specified no...
Definition engine.cc:443
void ShutdownPlatformIsolates()
Shuts down all registered platform isolates. Must be called from the platform thread.
Definition engine.cc:621
void ScheduleFrame()
Definition engine.h:845
void SetDisplays(const std::vector< DisplayData > &displays)
Updates the display metrics for the currently running Flutter application.
Definition engine.cc:616
const std::weak_ptr< VsyncWaiter > GetVsyncWaiter() const
Definition engine.cc:612
void SendChannelUpdate(std::string name, bool listening) override
Definition engine.cc:585
void BeginFrame(fml::TimePoint frame_time, uint64_t frame_number)
Notifies the engine that it is time to begin working on a new frame previously scheduled via a call t...
Definition engine.cc:263
tonic::DartErrorHandleType GetUIIsolateLastError()
Errors that are unhandled on the Dart message loop are kept for further inspection till the next unha...
Definition engine.cc:296
FontCollection & GetFontCollection() override
Definition engine.cc:524
std::shared_ptr< AssetManager > GetAssetManager() override
Definition engine.cc:164
RunStatus Run(RunConfiguration configuration)
Moves the root isolate to the DartIsolate::Phase::Running phase on a successful call to this method.
Definition engine.cc:213
std::string GetUIIsolateName()
Gets the debug name of the root isolate. By default, the debug name of the isolate is derived from it...
Definition engine.cc:288
void OnRootIsolateCreated() override
Definition engine.cc:501
~Engine() override
Destroys the engine engine. Called by the shell on the UI task runner. The running root isolate is te...
const std::string & GetLastEntrypointLibrary() const
Get the last Entrypoint Library that was used in the RunConfiguration when |EngineRun| was called.
Definition engine.cc:567
bool UpdateAssetManager(const std::shared_ptr< AssetManager > &asset_manager)
Updates the asset manager referenced by the root isolate of a Flutter application....
Definition engine.cc:176
Dart_Port GetUIIsolateMainPort()
Gets the main port of the root isolate. Since the isolate is created immediately in the constructor o...
Definition engine.cc:284
void DispatchPointerDataPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id)
Notifies the engine that the embedder has sent it a pointer data packet. A pointer data packet may co...
Definition engine.cc:433
double GetScaledFontSize(double unscaled_font_size, int configuration_id) const override
Definition engine.cc:515
std::weak_ptr< PlatformMessageHandler > GetPlatformMessageHandler() const override
Definition engine.cc:580
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 ...
Definition engine.cc:603
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,...
Definition engine.cc:589
void AddView(int64_t view_id, const ViewportMetrics &view_metrics, std::function< void(bool added)> callback)
Notify the Flutter application that a new view is available.
Definition engine.cc:300
void DoDispatchPacket(std::unique_ptr< PointerDataPacket > packet, uint64_t trace_flow_id) override
Definition engine.cc:528
bool UIIsolateHasLivePorts()
It is an unexpected challenge to determine when a Dart application is "done". The application cannot ...
Definition engine.cc:292
const std::string & GetLastEntrypoint() const
Get the last Entrypoint that was used in the RunConfiguration when |EngineRun| was called.
Definition engine.cc:563
void Render(int64_t view_id, std::unique_ptr< flutter::LayerTree > layer_tree, float device_pixel_ratio) override
Definition engine.cc:473
RunStatus
Indicates the result of the call to Engine::Run.
Definition engine.h:78
bool Restart(RunConfiguration configuration)
Tears down an existing root isolate, reuses the components of that isolate and attempts to launch a n...
Definition engine.cc:201
const std::vector< std::string > & GetLastEntrypointArgs() const
Get the last Entrypoint Arguments that was used in the RunConfiguration when |EngineRun| was called....
Definition engine.cc:571
std::unique_ptr< Engine > Spawn(Delegate &delegate, const PointerDataDispatcherMaker &dispatcher_maker, const Settings &settings, std::unique_ptr< Animator > animator, const std::string &initial_route, const fml::WeakPtr< IOManager > &io_manager, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate, const std::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch) const
Create a Engine that shares as many resources as possible with the calling Engine such that together ...
Definition engine.cc:115
const std::string & InitialRoute() const
Getter for the initial route. This can be set with a platform message.
Definition engine.h:898
std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocale(const std::vector< std::string > &supported_locale_data) override
Definition engine.cc:510
void SetSemanticsEnabled(bool enabled)
Notifies the engine that the embedder has expressed an opinion about whether the accessibility tree s...
Definition engine.cc:450
void UpdateIsolateDescription(const std::string isolate_name, int64_t isolate_port) override
Definition engine.cc:505
void SetNeedsReportTimings(bool value) override
Definition engine.cc:520
void DispatchPlatformMessage(std::unique_ptr< PlatformMessage > message)
Notifies the engine that the embedder has sent it a message. This call originates in the platform vie...
Definition engine.cc:316
const RuntimeController * GetRuntimeController() const
Accessor for the RuntimeController.
Definition engine.h:965
fml::WeakPtr< ImageGeneratorRegistry > GetImageGeneratorRegistry()
Get the ImageGeneratorRegistry associated with the current engine.
Definition engine.cc:172
std::optional< uint32_t > GetUIIsolateReturnCode()
As described in the discussion for UIIsolateHasLivePorts, the "done-ness" of a Dart application is tr...
Definition engine.cc:280
fml::WeakPtr< ImageDecoder > GetImageDecoderWeakPtr()
Definition engine.cc:168
void UpdateSemantics(SemanticsNodeUpdates update, CustomAccessibilityActionUpdates actions) override
Definition engine.cc:488
void ScheduleSecondaryVsyncCallback(uintptr_t id, const fml::closure &callback) override
Schedule a secondary callback to be executed right after the main VsyncWaiter::AsyncWaitForVsync call...
Definition engine.cc:536
void NotifyDestroyed()
Notifies the engine that the attached flutter view has been destroyed. This enables the engine to not...
Definition engine.cc:275
Keeps a priority-ordered registry of image generator builders to be used when decoding images....
The interface for Engine to implement.
Specifies all the configuration required by the runtime library to launch the root isolate....
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition mapping.h:144
int64_t Dart_Port
Definition dart_api.h:1524
Settings settings_
std::unique_ptr< RuntimeController > runtime_controller_
TaskRunners task_runners_
std::unique_ptr< Animator > animator_
MockDelegate delegate_
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
Win32Message message
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
std::function< std::unique_ptr< PointerDataDispatcher >(PointerDataDispatcher::Delegate &)> PointerDataDispatcherMaker
Signature for constructing PointerDataDispatcher.
DEF_SWITCHES_START aot vmservice shared library name
Definition switches.h:32
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 switches.h:41
std::function< void()> closure
Definition closure.h:14
DartErrorHandleType
Definition dart_error.h:67