Flutter Engine
shell.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 SHELL_COMMON_SHELL_H_
6 #define SHELL_COMMON_SHELL_H_
7 
8 #include <functional>
9 #include <mutex>
10 #include <string_view>
11 #include <unordered_map>
12 
13 #include "flutter/assets/directory_asset_bundle.h"
14 #include "flutter/common/graphics/texture.h"
15 #include "flutter/common/settings.h"
16 #include "flutter/common/task_runners.h"
17 #include "flutter/flow/surface.h"
18 #include "flutter/fml/closure.h"
19 #include "flutter/fml/macros.h"
20 #include "flutter/fml/memory/ref_ptr.h"
21 #include "flutter/fml/memory/thread_checker.h"
22 #include "flutter/fml/memory/weak_ptr.h"
23 #include "flutter/fml/status.h"
24 #include "flutter/fml/synchronization/sync_switch.h"
25 #include "flutter/fml/synchronization/waitable_event.h"
26 #include "flutter/fml/thread.h"
27 #include "flutter/fml/time/time_point.h"
28 #include "flutter/lib/ui/painting/image_generator_registry.h"
29 #include "flutter/lib/ui/semantics/custom_accessibility_action.h"
30 #include "flutter/lib/ui/semantics/semantics_node.h"
31 #include "flutter/lib/ui/volatile_path_tracker.h"
32 #include "flutter/lib/ui/window/platform_message.h"
33 #include "flutter/runtime/dart_vm_lifecycle.h"
34 #include "flutter/runtime/platform_data.h"
35 #include "flutter/runtime/service_protocol.h"
36 #include "flutter/shell/common/animator.h"
37 #include "flutter/shell/common/display_manager.h"
38 #include "flutter/shell/common/engine.h"
39 #include "flutter/shell/common/platform_view.h"
40 #include "flutter/shell/common/rasterizer.h"
41 #include "flutter/shell/common/shell_io_manager.h"
42 
43 namespace flutter {
44 
45 /// Error exit codes for the Dart isolate.
46 enum class DartErrorCode {
47  /// No error has occurred.
48  NoError = 0,
49  /// The Dart error code for an API error.
50  ApiError = 253,
51  /// The Dart error code for a compilation error.
52  CompilationError = 254,
53  /// The Dart error code for an unknown error.
54  UnknownError = 255
55 };
56 
57 /// Values for |Shell::SetGpuAvailability|.
58 enum class GpuAvailability {
59  /// Indicates that GPU operations should be permitted.
60  kAvailable = 0,
61  /// Indicates that the GPU is about to become unavailable, and to attempt to
62  /// flush any GPU related resources now.
64  /// Indicates that the GPU is unavailable, and that no attempt should be made
65  /// to even flush GPU objects until it is available again.
66  kUnavailable = 2
67 };
68 
69 //------------------------------------------------------------------------------
70 /// Perhaps the single most important class in the Flutter engine repository.
71 /// When embedders create a Flutter application, they are referring to the
72 /// creation of an instance of a shell. Creation and destruction of the shell is
73 /// synchronous and the embedder only holds a unique pointer to the shell. The
74 /// shell does not create the threads its primary components run on. Instead, it
75 /// is the embedder's responsibility to create threads and give the shell task
76 /// runners for those threads. Due to deterministic destruction of the shell,
77 /// the embedder can terminate all threads immediately after collecting the
78 /// shell. The shell must be created and destroyed on the same thread, but,
79 /// different shells (i.e. a separate instances of a Flutter application) may be
80 /// run on different threads simultaneously. The task runners themselves do not
81 /// have to be unique. If all task runner references given to the shell during
82 /// shell creation point to the same task runner, the Flutter application is
83 /// effectively single threaded.
84 ///
85 /// The shell is the central nervous system of the Flutter application. None of
86 /// the shell components are thread safe and must be created, accessed and
87 /// destroyed on the same thread. To interact with one another, the various
88 /// components delegate to the shell for communication. Instead of using back
89 /// pointers to the shell, a delegation pattern is used by all components that
90 /// want to communicate with one another. Because of this, the shell implements
91 /// the delegate interface for all these components.
92 ///
93 /// All shell methods accessed by the embedder may only be called on the
94 /// platform task runner. In case the embedder wants to directly access a shell
95 /// subcomponent, it is the embedder's responsibility to acquire a weak pointer
96 /// to that component and post a task to the task runner used by the component
97 /// to access its methods. The shell must also be destroyed on the platform
98 /// task runner.
99 ///
100 /// There is no explicit API to bootstrap and shutdown the Dart VM. The first
101 /// instance of the shell in the process bootstraps the Dart VM and the
102 /// destruction of the last shell instance destroys the same. Since different
103 /// shells may be created and destroyed on different threads. VM bootstrap may
104 /// happen on one thread but its collection on another. This behavior is thread
105 /// safe.
106 ///
107 class Shell final : public PlatformView::Delegate,
108  public Animator::Delegate,
109  public Engine::Delegate,
110  public Rasterizer::Delegate,
111  public ServiceProtocol::Handler {
112  public:
113  template <class T>
114  using CreateCallback = std::function<std::unique_ptr<T>(Shell&)>;
115  typedef std::function<std::unique_ptr<Engine>(
116  Engine::Delegate& delegate,
117  const PointerDataDispatcherMaker& dispatcher_maker,
118  DartVM& vm,
119  fml::RefPtr<const DartSnapshot> isolate_snapshot,
120  TaskRunners task_runners,
121  const PlatformData& platform_data,
122  Settings settings,
123  std::unique_ptr<Animator> animator,
124  fml::WeakPtr<IOManager> io_manager,
125  fml::RefPtr<SkiaUnrefQueue> unref_queue,
126  fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
127  std::shared_ptr<VolatilePathTracker> volatile_path_tracker)>
129 
130  //----------------------------------------------------------------------------
131  /// @brief Creates a shell instance using the provided settings. The
132  /// callbacks to create the various shell subcomponents will be
133  /// called on the appropriate threads before this method returns.
134  /// If this is the first instance of a shell in the process, this
135  /// call also bootstraps the Dart VM.
136  /// @note The root isolate which will run this Shell's Dart code takes
137  /// its instructions from the passed in settings. This allows
138  /// embedders to host multiple Shells with different Dart code.
139  ///
140  /// @param[in] task_runners The task runners
141  /// @param[in] settings The settings
142  /// @param[in] on_create_platform_view The callback that must return a
143  /// platform view. This will be called on
144  /// the platform task runner before this
145  /// method returns.
146  /// @param[in] on_create_rasterizer That callback that must provide a
147  /// valid rasterizer. This will be called
148  /// on the render task runner before this
149  /// method returns.
150  /// @param[in] is_gpu_disabled The default value for the switch that
151  /// turns off the GPU.
152  ///
153  /// @return A full initialized shell if the settings and callbacks are
154  /// valid. The root isolate has been created but not yet launched.
155  /// It may be launched by obtaining the engine weak pointer and
156  /// posting a task onto the UI task runner with a valid run
157  /// configuration to run the isolate. The embedder must always
158  /// check the validity of the shell (using the IsSetup call)
159  /// immediately after getting a pointer to it.
160  ///
161  static std::unique_ptr<Shell> Create(
162  const PlatformData& platform_data,
163  TaskRunners task_runners,
164  Settings settings,
165  const CreateCallback<PlatformView>& on_create_platform_view,
166  const CreateCallback<Rasterizer>& on_create_rasterizer,
167  bool is_gpu_disabled = false);
168 
169  //----------------------------------------------------------------------------
170  /// @brief Destroys the shell. This is a synchronous operation and
171  /// synchronous barrier blocks are introduced on the various
172  /// threads to ensure shutdown of all shell sub-components before
173  /// this method returns.
174  ///
175  ~Shell();
176 
177  //----------------------------------------------------------------------------
178  /// @brief Creates one Shell from another Shell where the created Shell
179  /// takes the opportunity to share any internal components it can.
180  /// This results is a Shell that has a smaller startup time cost
181  /// and a smaller memory footprint than an Shell created with the
182  /// Create function.
183  ///
184  /// The new Shell is returned in a running state so RunEngine
185  /// shouldn't be called again on the Shell. Once running, the
186  /// second Shell is mostly independent from the original Shell
187  /// and the original Shell doesn't need to keep running for the
188  /// spawned Shell to keep functioning.
189  /// @param[in] run_configuration A RunConfiguration used to run the Isolate
190  /// associated with this new Shell. It doesn't have to be the same
191  /// configuration as the current Shell but it needs to be in the
192  /// same snapshot or AOT.
193  ///
194  /// @see http://flutter.dev/go/multiple-engines
195  std::unique_ptr<Shell> Spawn(
196  RunConfiguration run_configuration,
197  const std::string& initial_route,
198  const CreateCallback<PlatformView>& on_create_platform_view,
199  const CreateCallback<Rasterizer>& on_create_rasterizer) const;
200 
201  //----------------------------------------------------------------------------
202  /// @brief Starts an isolate for the given RunConfiguration.
203  ///
204  void RunEngine(RunConfiguration run_configuration);
205 
206  //----------------------------------------------------------------------------
207  /// @brief Starts an isolate for the given RunConfiguration. The
208  /// result_callback will be called with the status of the
209  /// operation.
210  ///
211  void RunEngine(RunConfiguration run_configuration,
212  const std::function<void(Engine::RunStatus)>& result_callback);
213 
214  //------------------------------------------------------------------------------
215  /// @return The settings used to launch this shell.
216  ///
217  const Settings& GetSettings() const;
218 
219  //------------------------------------------------------------------------------
220  /// @brief If callers wish to interact directly with any shell
221  /// subcomponents, they must (on the platform thread) obtain a
222  /// task runner that the component is designed to run on and a
223  /// weak pointer to that component. They may then post a task to
224  /// that task runner, do the validity check on that task runner
225  /// before performing any operation on that component. This
226  /// accessor allows callers to access the task runners for this
227  /// shell.
228  ///
229  /// @return The task runners current in use by the shell.
230  ///
231  const TaskRunners& GetTaskRunners() const override;
232 
233  //------------------------------------------------------------------------------
234  /// @brief Getting the raster thread merger from parent shell, it can be
235  /// a null RefPtr when it's a root Shell or the
236  /// embedder_->SupportsDynamicThreadMerging() returns false.
237  ///
238  /// @return The raster thread merger used by the parent shell.
239  ///
240  const fml::RefPtr<fml::RasterThreadMerger> GetParentRasterThreadMerger()
241  const override;
242 
243  //----------------------------------------------------------------------------
244  /// @brief Rasterizers may only be accessed on the raster task runner.
245  ///
246  /// @return A weak pointer to the rasterizer.
247  ///
248  fml::TaskRunnerAffineWeakPtr<Rasterizer> GetRasterizer() const;
249 
250  //------------------------------------------------------------------------------
251  /// @brief Engines may only be accessed on the UI thread. This method is
252  /// deprecated, and implementers should instead use other API
253  /// available on the Shell or the PlatformView.
254  ///
255  /// @return A weak pointer to the engine.
256  ///
257  fml::WeakPtr<Engine> GetEngine();
258 
259  //----------------------------------------------------------------------------
260  /// @brief Platform views may only be accessed on the platform task
261  /// runner.
262  ///
263  /// @return A weak pointer to the platform view.
264  ///
265  fml::WeakPtr<PlatformView> GetPlatformView();
266 
267  //----------------------------------------------------------------------------
268  /// @brief The IO Manager may only be accessed on the IO task runner.
269  ///
270  /// @return A weak pointer to the IO manager.
271  ///
272  fml::WeakPtr<ShellIOManager> GetIOManager();
273 
274  // Embedders should call this under low memory conditions to free up
275  // internal caches used.
276  //
277  // This method posts a task to the raster threads to signal the Rasterizer to
278  // free resources.
279 
280  //----------------------------------------------------------------------------
281  /// @brief Used by embedders to notify that there is a low memory
282  /// warning. The shell will attempt to purge caches. Current, only
283  /// the rasterizer cache is purged.
284  void NotifyLowMemoryWarning() const;
285 
286  //----------------------------------------------------------------------------
287  /// @brief Used by embedders to check if all shell subcomponents are
288  /// initialized. It is the embedder's responsibility to make this
289  /// call before accessing any other shell method. A shell that is
290  /// not set up must be discarded and another one created with
291  /// updated settings.
292  ///
293  /// @return Returns if the shell has been set up. Once set up, this does
294  /// not change for the life-cycle of the shell.
295  ///
296  bool IsSetup() const;
297 
298  //----------------------------------------------------------------------------
299  /// @brief Captures a screenshot and optionally Base64 encodes the data
300  /// of the last layer tree rendered by the rasterizer in this
301  /// shell.
302  ///
303  /// @param[in] type The type of screenshot to capture.
304  /// @param[in] base64_encode If the screenshot data should be base64
305  /// encoded.
306  ///
307  /// @return The screenshot result.
308  ///
310  bool base64_encode);
311 
312  //----------------------------------------------------------------------------
313  /// @brief Pauses the calling thread until the first frame is presented.
314  ///
315  /// @param[in] timeout The duration to wait before timing out. If this
316  /// duration would cause an overflow when added to
317  /// std::chrono::steady_clock::now(), this method will
318  /// wait indefinitely for the first frame.
319  ///
320  /// @return 'kOk' when the first frame has been presented before the
321  /// timeout successfully, 'kFailedPrecondition' if called from the
322  /// GPU or UI thread, 'kDeadlineExceeded' if there is a timeout.
323  ///
324  fml::Status WaitForFirstFrame(fml::TimeDelta timeout);
325 
326  //----------------------------------------------------------------------------
327  /// @brief Used by embedders to reload the system fonts in
328  /// FontCollection.
329  /// It also clears the cached font families and send system
330  /// channel message to framework to rebuild affected widgets.
331  ///
332  /// @return Returns if shell reloads system fonts successfully.
333  ///
334  bool ReloadSystemFonts();
335 
336  //----------------------------------------------------------------------------
337  /// @brief Used by embedders to get the last error from the Dart UI
338  /// Isolate, if one exists.
339  ///
340  /// @return Returns the last error code from the UI Isolate.
341  ///
342  std::optional<DartErrorCode> GetUIIsolateLastError() const;
343 
344  //----------------------------------------------------------------------------
345  /// @brief Used by embedders to check if the Engine is running and has
346  /// any live ports remaining. For example, the Flutter tester uses
347  /// this method to check whether it should continue to wait for
348  /// a running test or not.
349  ///
350  /// @return Returns if the shell has an engine and the engine has any live
351  /// Dart ports.
352  ///
353  bool EngineHasLivePorts() const;
354 
355  //----------------------------------------------------------------------------
356  /// @brief Accessor for the disable GPU SyncSwitch.
357  std::shared_ptr<const fml::SyncSwitch> GetIsGpuDisabledSyncSwitch()
358  const override;
359 
360  //----------------------------------------------------------------------------
361  /// @brief Marks the GPU as available or unavailable.
362  void SetGpuAvailability(GpuAvailability availability);
363 
364  //----------------------------------------------------------------------------
365  /// @brief Get a pointer to the Dart VM used by this running shell
366  /// instance.
367  ///
368  /// @return The Dart VM pointer.
369  ///
370  DartVM* GetDartVM();
371 
372  //----------------------------------------------------------------------------
373  /// @brief Notifies the display manager of the updates.
374  ///
375  void OnDisplayUpdates(DisplayUpdateType update_type,
376  std::vector<Display> displays);
377 
378  //----------------------------------------------------------------------------
379  /// @brief Queries the `DisplayManager` for the main display refresh rate.
380  ///
381  double GetMainDisplayRefreshRate();
382 
383  //----------------------------------------------------------------------------
384  /// @brief Install a new factory that can match against and decode image
385  /// data.
386  /// @param[in] factory Callback that produces `ImageGenerator`s for
387  /// compatible input data.
388  /// @param[in] priority The priority used to determine the order in which
389  /// factories are tried. Higher values mean higher
390  /// priority. The built-in Skia decoders are installed
391  /// at priority 0, and so a priority > 0 takes precedent
392  /// over the builtin decoders. When multiple decoders
393  /// are added with the same priority, those which are
394  /// added earlier take precedent.
395  /// @see `CreateCompatibleGenerator`
396  void RegisterImageDecoder(ImageGeneratorFactory factory, int32_t priority);
397 
398  private:
399  using ServiceProtocolHandler =
401  rapidjson::Document*)>;
402 
404  const fml::RefPtr<fml::RasterThreadMerger> parent_raster_thread_merger_;
405  const Settings settings_;
406  DartVMRef vm_;
407  mutable std::mutex time_recorder_mutex_;
408  std::optional<fml::TimePoint> latest_frame_target_time_;
409  std::unique_ptr<PlatformView> platform_view_; // on platform task runner
410  std::unique_ptr<Engine> engine_; // on UI task runner
411  std::unique_ptr<Rasterizer> rasterizer_; // on raster task runner
412  std::unique_ptr<ShellIOManager> io_manager_; // on IO task runner
413  std::shared_ptr<fml::SyncSwitch> is_gpu_disabled_sync_switch_;
414  std::shared_ptr<VolatilePathTracker> volatile_path_tracker_;
415 
416  fml::WeakPtr<Engine> weak_engine_; // to be shared across threads
418  weak_rasterizer_; // to be shared across threads
420  weak_platform_view_; // to be shared across threads
421 
422  std::unordered_map<std::string_view, // method
423  std::pair<fml::RefPtr<fml::TaskRunner>,
424  ServiceProtocolHandler> // task-runner/function
425  // pair
426  >
427  service_protocol_handlers_;
428  bool is_setup_ = false;
429  bool is_added_to_service_protocol_ = false;
430  uint64_t next_pointer_flow_id_ = 0;
431 
432  bool first_frame_rasterized_ = false;
433  std::atomic<bool> waiting_for_first_frame_ = true;
434  std::mutex waiting_for_first_frame_mutex_;
435  std::condition_variable waiting_for_first_frame_condition_;
436 
437  // Written in the UI thread and read from the raster thread. Hence make it
438  // atomic.
439  std::atomic<bool> needs_report_timings_{false};
440 
441  // Whether there's a task scheduled to report the timings to Dart through
442  // ui.Window.onReportTimings.
443  bool frame_timings_report_scheduled_ = false;
444 
445  // Vector of FrameTiming::kCount * n timestamps for n frames whose timings
446  // have not been reported yet. Vector of ints instead of FrameTiming is stored
447  // here for easier conversions to Dart objects.
448  std::vector<int64_t> unreported_timings_;
449 
450  /// Manages the displays. This class is thread safe, can be accessed from any
451  /// of the threads.
452  std::unique_ptr<DisplayManager> display_manager_;
453 
454  // protects expected_frame_size_ which is set on platform thread and read on
455  // raster thread
456  std::mutex resize_mutex_;
457 
458  // used to discard wrong size layer tree produced during interactive resizing
459  SkISize expected_frame_size_ = SkISize::MakeEmpty();
460 
461  // How many frames have been timed since last report.
462  size_t UnreportedFramesCount() const;
463 
464  sk_sp<GrDirectContext> shared_resource_context_;
465 
466  Shell(DartVMRef vm,
467  TaskRunners task_runners,
469  Settings settings,
470  std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
471  bool is_gpu_disabled);
472 
473  static std::unique_ptr<Shell> CreateShellOnPlatformThread(
474  DartVMRef vm,
476  TaskRunners task_runners,
477  const PlatformData& platform_data,
478  Settings settings,
479  fml::RefPtr<const DartSnapshot> isolate_snapshot,
480  const Shell::CreateCallback<PlatformView>& on_create_platform_view,
481  const Shell::CreateCallback<Rasterizer>& on_create_rasterizer,
482  const EngineCreateCallback& on_create_engine,
483  bool is_gpu_disabled);
484  static std::unique_ptr<Shell> CreateWithSnapshot(
485  const PlatformData& platform_data,
486  TaskRunners task_runners,
487  fml::RefPtr<fml::RasterThreadMerger> parent_thread_merger,
488  Settings settings,
489  DartVMRef vm,
490  fml::RefPtr<const DartSnapshot> isolate_snapshot,
491  const CreateCallback<PlatformView>& on_create_platform_view,
492  const CreateCallback<Rasterizer>& on_create_rasterizer,
493  const EngineCreateCallback& on_create_engine,
494  bool is_gpu_disabled);
495 
496  bool Setup(std::unique_ptr<PlatformView> platform_view,
497  std::unique_ptr<Engine> engine,
498  std::unique_ptr<Rasterizer> rasterizer,
499  std::unique_ptr<ShellIOManager> io_manager);
500 
501  void ReportTimings();
502 
503  // |PlatformView::Delegate|
504  void OnPlatformViewCreated(std::unique_ptr<Surface> surface) override;
505 
506  // |PlatformView::Delegate|
507  void OnPlatformViewDestroyed() override;
508 
509  // |PlatformView::Delegate|
510  void OnPlatformViewSetViewportMetrics(
511  const ViewportMetrics& metrics) override;
512 
513  // |PlatformView::Delegate|
514  void OnPlatformViewDispatchPlatformMessage(
515  std::unique_ptr<PlatformMessage> message) override;
516 
517  // |PlatformView::Delegate|
518  void OnPlatformViewDispatchPointerDataPacket(
519  std::unique_ptr<PointerDataPacket> packet) override;
520 
521  // |PlatformView::Delegate|
522  void OnPlatformViewDispatchKeyDataPacket(
523  std::unique_ptr<KeyDataPacket> packet,
524  std::function<void(bool /* handled */)> callback) override;
525 
526  // |PlatformView::Delegate|
527  void OnPlatformViewDispatchSemanticsAction(int32_t id,
529  fml::MallocMapping args) override;
530 
531  // |PlatformView::Delegate|
532  void OnPlatformViewSetSemanticsEnabled(bool enabled) override;
533 
534  // |shell:PlatformView::Delegate|
535  void OnPlatformViewSetAccessibilityFeatures(int32_t flags) override;
536 
537  // |PlatformView::Delegate|
538  void OnPlatformViewRegisterTexture(
539  std::shared_ptr<flutter::Texture> texture) override;
540 
541  // |PlatformView::Delegate|
542  void OnPlatformViewUnregisterTexture(int64_t texture_id) override;
543 
544  // |PlatformView::Delegate|
545  void OnPlatformViewMarkTextureFrameAvailable(int64_t texture_id) override;
546 
547  // |PlatformView::Delegate|
548  void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override;
549 
550  // |PlatformView::Delegate|
552  intptr_t loading_unit_id,
553  std::unique_ptr<const fml::Mapping> snapshot_data,
554  std::unique_ptr<const fml::Mapping> snapshot_instructions) override;
555 
556  void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
557  const std::string error_message,
558  bool transient) override;
559 
560  // |PlatformView::Delegate|
561  void UpdateAssetResolverByType(
562  std::unique_ptr<AssetResolver> updated_asset_resolver,
564 
565  // |Animator::Delegate|
566  void OnAnimatorBeginFrame(fml::TimePoint frame_target_time,
567  uint64_t frame_number) override;
568 
569  // |Animator::Delegate|
570  void OnAnimatorNotifyIdle(int64_t deadline) override;
571 
572  // |Animator::Delegate|
573  void OnAnimatorDraw(
574  std::shared_ptr<Pipeline<flutter::LayerTree>> pipeline,
575  std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder) override;
576 
577  // |Animator::Delegate|
578  void OnAnimatorDrawLastLayerTree(
579  std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder) override;
580 
581  // |Engine::Delegate|
582  void OnEngineUpdateSemantics(
583  SemanticsNodeUpdates update,
584  CustomAccessibilityActionUpdates actions) override;
585 
586  // |Engine::Delegate|
587  void OnEngineHandlePlatformMessage(
588  std::unique_ptr<PlatformMessage> message) override;
589 
590  void HandleEngineSkiaMessage(std::unique_ptr<PlatformMessage> message);
591 
592  // |Engine::Delegate|
593  void OnPreEngineRestart() override;
594 
595  // |Engine::Delegate|
596  void OnRootIsolateCreated() override;
597 
598  // |Engine::Delegate|
599  void UpdateIsolateDescription(const std::string isolate_name,
600  int64_t isolate_port) override;
601 
602  // |Engine::Delegate|
603  void SetNeedsReportTimings(bool value) override;
604 
605  // |Engine::Delegate|
606  std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
607  const std::vector<std::string>& supported_locale_data) override;
608 
609  // |Engine::Delegate|
610  void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
611 
612  // |Engine::Delegate|
613  fml::TimePoint GetCurrentTimePoint() override;
614 
615  // |Rasterizer::Delegate|
616  void OnFrameRasterized(const FrameTiming&) override;
617 
618  // |Rasterizer::Delegate|
619  fml::Milliseconds GetFrameBudget() override;
620 
621  // |Rasterizer::Delegate|
622  fml::TimePoint GetLatestFrameTargetTime() const override;
623 
624  // |ServiceProtocol::Handler|
625  fml::RefPtr<fml::TaskRunner> GetServiceProtocolHandlerTaskRunner(
626  std::string_view method) const override;
627 
628  // |ServiceProtocol::Handler|
629  bool HandleServiceProtocolMessage(
630  std::string_view method, // one if the extension names specified above.
631  const ServiceProtocolMap& params,
632  rapidjson::Document* response) override;
633 
634  // |ServiceProtocol::Handler|
635  ServiceProtocol::Handler::Description GetServiceProtocolDescription()
636  const override;
637 
638  // Service protocol handler
639  bool OnServiceProtocolScreenshot(
641  rapidjson::Document* response);
642 
643  // Service protocol handler
644  bool OnServiceProtocolScreenshotSKP(
646  rapidjson::Document* response);
647 
648  // Service protocol handler
649  bool OnServiceProtocolRunInView(
651  rapidjson::Document* response);
652 
653  // Service protocol handler
654  bool OnServiceProtocolFlushUIThreadTasks(
656  rapidjson::Document* response);
657 
658  // Service protocol handler
659  bool OnServiceProtocolSetAssetBundlePath(
661  rapidjson::Document* response);
662 
663  // Service protocol handler
664  bool OnServiceProtocolGetDisplayRefreshRate(
666  rapidjson::Document* response);
667 
668  // Service protocol handler
669  //
670  // The returned SkSLs are base64 encoded. Decode before storing them to files.
671  bool OnServiceProtocolGetSkSLs(
673  rapidjson::Document* response);
674 
675  // Service protocol handler
676  bool OnServiceProtocolEstimateRasterCacheMemory(
678  rapidjson::Document* response);
679 
680  // Creates an asset bundle from the original settings asset path or
681  // directory.
682  std::unique_ptr<DirectoryAssetBundle> RestoreOriginalAssetResolver();
683 
684  // For accessing the Shell via the raster thread, necessary for various
685  // rasterizer callbacks.
686  std::unique_ptr<fml::TaskRunnerAffineWeakPtrFactory<Shell>> weak_factory_gpu_;
687 
688  fml::WeakPtrFactory<Shell> weak_factory_;
689  friend class testing::ShellTest;
690 
692 };
693 
694 } // namespace flutter
695 
696 #endif // SHELL_COMMON_SHELL_H_
G_BEGIN_DECLS FlValue * args
KeyCallType type
fml::WeakPtr< IOManager > io_manager_
G_BEGIN_DECLS FlTexture * texture
While the engine operates entirely on the UI task runner, it needs the capabilities of the other comp...
Definition: engine.h:140
std::function< std::unique_ptr< T >(Shell &)> CreateCallback
Definition: shell.h:114
std::map< std::string_view, std::string_view > ServiceProtocolMap
std::unique_ptr< flutter::PlatformViewIOS > platform_view
The Dart error code for an API error.
Dart_NativeFunction function
Definition: fuchsia.cc:51
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
int64_t texture_id
std::function< std::unique_ptr< PointerDataDispatcher >(PointerDataDispatcher::Delegate &)> PointerDataDispatcherMaker
Signature for constructing PointerDataDispatcher.
DartErrorCode
Error exit codes for the Dart isolate.
Definition: shell.h:46
FlKeyEvent FlKeyResponderAsyncCallback callback
The Dart error code for an unknown error.
static void NotifyLowMemoryWarning(JNIEnv *env, jobject obj, jlong shell_holder)
AssetResolverType
Identifies the type of AssetResolver an instance is.
std::function< void()> closure
Definition: closure.h:14
Indicates that GPU operations should be permitted.
A POD type used to return the screenshot data along with the size of the frame.
Definition: rasterizer.h:275
uint8_t value
ScreenshotType
The type of the screenshot to obtain of the previously rendered layer tree.
Definition: rasterizer.h:245
Specifies all the configuration required by the runtime library to launch the root isolate...
SemanticsAction action
Dart_Handle ComputePlatformResolvedLocale(Dart_Handle supportedLocalesHandle)
static void LoadDartDeferredLibrary(JNIEnv *env, jobject obj, jlong shell_holder, jint jLoadingUnitId, jobjectArray jSearchPaths)
Used to forward events from the rasterizer to interested subsystems. Currently, the shell sets itself...
Definition: rasterizer.h:57
std::function< std::shared_ptr< ImageGenerator >(sk_sp< SkData > buffer)> ImageGeneratorFactory
ImageGeneratorFactory is the top level primitive for specifying an image decoder in Flutter...
std::function< std::unique_ptr< Engine > Engine::Delegate &delegate, const PointerDataDispatcherMaker &dispatcher_maker, DartVM &vm, fml::RefPtr< const DartSnapshot > isolate_snapshot, TaskRunners task_runners, const PlatformData &platform_data, Settings settings, std::unique_ptr< Animator > animator, fml::WeakPtr< IOManager > io_manager, fml::RefPtr< SkiaUnrefQueue > unref_queue, fml::WeakPtr< SnapshotDelegate > snapshot_delegate, std::shared_ptr< VolatilePathTracker > volatile_path_tracker)> EngineCreateCallback
Definition: shell.h:128
GpuAvailability
Values for |Shell::SetGpuAvailability|.
Definition: shell.h:58
Describes a running instance of the Dart VM. There may only be one running instance of the Dart VM in...
Definition: dart_vm.h:61
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition: mapping.h:129
TaskRunners task_runners_
RunStatus
Indicates the result of the call to Engine::Run.
Definition: engine.h:80
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27
Used to forward events from the platform view to interested subsystems. This forwarding is done by th...
Definition: platform_view.h:53
The Dart error code for a compilation error.
Settings settings_
std::chrono::duration< double, std::milli > Milliseconds
Definition: time_delta.h:18
DEF_SWITCHES_START snapshot asset Path to the directory containing the four files specified by VmSnapshotInstructions and IsolateSnapshotInstructions vm snapshot The VM instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present isolate snapshot The isolate instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present icu symbol Prefix for the symbols representing ICU data linked into the Flutter library dart flags
Definition: switches.h:66
No error has occurred.