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