shell.h 28.1 KB
Newer Older
M
Michael Goderbauer 已提交
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef SHELL_COMMON_SHELL_H_
#define SHELL_COMMON_SHELL_H_
7

8
#include <functional>
9
#include <mutex>
10
#include <string_view>
11 12
#include <unordered_map>

13
#include "flutter/assets/directory_asset_bundle.h"
14
#include "flutter/common/graphics/texture.h"
15 16
#include "flutter/common/settings.h"
#include "flutter/common/task_runners.h"
17
#include "flutter/flow/surface.h"
18 19 20
#include "flutter/fml/closure.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/memory/ref_ptr.h"
21 22
#include "flutter/fml/memory/thread_checker.h"
#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/semantics/custom_accessibility_action.h"
29
#include "flutter/lib/ui/semantics/semantics_node.h"
30
#include "flutter/lib/ui/volatile_path_tracker.h"
31
#include "flutter/lib/ui/window/platform_message.h"
32
#include "flutter/runtime/dart_vm_lifecycle.h"
33 34
#include "flutter/runtime/service_protocol.h"
#include "flutter/shell/common/animator.h"
35
#include "flutter/shell/common/display_manager.h"
36 37 38
#include "flutter/shell/common/engine.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/rasterizer.h"
39
#include "flutter/shell/common/shell_io_manager.h"
40

41
namespace flutter {
42

D
Dan Field 已提交
43 44 45 46 47 48 49 50 51 52 53 54
/// Error exit codes for the Dart isolate.
enum class DartErrorCode {
  /// No error has occurred.
  NoError = 0,
  /// The Dart error code for an API error.
  ApiError = 253,
  /// The Dart error code for a compilation error.
  CompilationError = 254,
  /// The Dart error code for an unkonwn error.
  UnknownError = 255
};

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
//------------------------------------------------------------------------------
/// Perhaps the single most important class in the Flutter engine repository.
/// When embedders create a Flutter application, they are referring to the
/// creation of an instance of a shell. Creation and destruction of the shell is
/// synchronous and the embedder only holds a unique pointer to the shell. The
/// shell does not create the threads its primary components run on. Instead, it
/// is the embedder's responsibility to create threads and give the shell task
/// runners for those threads. Due to deterministic destruction of the shell,
/// the embedder can terminate all threads immediately after collecting the
/// shell. The shell must be created and destroyed on the same thread, but,
/// different shells (i.e. a separate instances of a Flutter application) may be
/// run on different threads simultaneously. The task runners themselves do not
/// have to be unique. If all task runner references given to the shell during
/// shell creation point to the same task runner, the Flutter application is
/// effectively single threaded.
///
/// The shell is the central nervous system of the Flutter application. None of
/// the shell components are thread safe and must be created, accessed and
/// destroyed on the same thread. To interact with one another, the various
/// components delegate to the shell for communication. Instead of using back
/// pointers to the shell, a delegation pattern is used by all components that
/// want to communicate with one another. Because of this, the shell implements
/// the delegate interface for all these components.
///
/// All shell methods accessed by the embedder may only be called on the
/// platform task runner. In case the embedder wants to directly access a shell
/// subcomponent, it is the embedder's responsibility to acquire a weak pointer
/// to that component and post a task to the task runner used by the component
83 84
/// to access its methods. The shell must also be destroyed on the platform
/// task runner.
85 86 87 88 89 90 91 92
///
/// There is no explicit API to bootstrap and shutdown the Dart VM. The first
/// instance of the shell in the process bootstraps the Dart VM and the
/// destruction of the last shell instance destroys the same. Since different
/// shells may be created and destroyed on different threads. VM bootstrap may
/// happen on one thread but its collection on another. This behavior is thread
/// safe.
///
93 94 95
class Shell final : public PlatformView::Delegate,
                    public Animator::Delegate,
                    public Engine::Delegate,
96
                    public Rasterizer::Delegate,
97
                    public ServiceProtocol::Handler {
98
 public:
99 100
  template <class T>
  using CreateCallback = std::function<std::unique_ptr<T>(Shell&)>;
101

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  //----------------------------------------------------------------------------
  /// @brief      Creates a shell instance using the provided settings. The
  ///             callbacks to create the various shell subcomponents will be
  ///             called on the appropriate threads before this method returns.
  ///             If this is the first instance of a shell in the process, this
  ///             call also bootstraps the Dart VM.
  ///
  /// @param[in]  task_runners             The task runners
  /// @param[in]  settings                 The settings
  /// @param[in]  on_create_platform_view  The callback that must return a
  ///                                      platform view. This will be called on
  ///                                      the platform task runner before this
  ///                                      method returns.
  /// @param[in]  on_create_rasterizer     That callback that must provide a
  ///                                      valid rasterizer. This will be called
  ///                                      on the render task runner before this
  ///                                      method returns.
  ///
  /// @return     A full initialized shell if the settings and callbacks are
  ///             valid. The root isolate has been created but not yet launched.
  ///             It may be launched by obtaining the engine weak pointer and
  ///             posting a task onto the UI task runner with a valid run
  ///             configuration to run the isolate. The embedder must always
  ///             check the validity of the shell (using the IsSetup call)
  ///             immediately after getting a pointer to it.
  ///
128
  static std::unique_ptr<Shell> Create(
129 130
      TaskRunners task_runners,
      Settings settings,
131 132
      const CreateCallback<PlatformView>& on_create_platform_view,
      const CreateCallback<Rasterizer>& on_create_rasterizer);
133

134 135 136 137 138 139 140 141 142 143
  //----------------------------------------------------------------------------
  /// @brief      Creates a shell instance using the provided settings. The
  ///             callbacks to create the various shell subcomponents will be
  ///             called on the appropriate threads before this method returns.
  ///             Unlike the simpler variant of this factory method, this method
  ///             allows for specification of window data. If this is the first
  ///             instance of a shell in the process, this call also bootstraps
  ///             the Dart VM.
  ///
  /// @param[in]  task_runners             The task runners
144
  /// @param[in]  platform_data            The default data for setting up
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
  ///                                      ui.Window that attached to this
  ///                                      intance.
  /// @param[in]  settings                 The settings
  /// @param[in]  on_create_platform_view  The callback that must return a
  ///                                      platform view. This will be called on
  ///                                      the platform task runner before this
  ///                                      method returns.
  /// @param[in]  on_create_rasterizer     That callback that must provide a
  ///                                      valid rasterizer. This will be called
  ///                                      on the render task runner before this
  ///                                      method returns.
  ///
  /// @return     A full initialized shell if the settings and callbacks are
  ///             valid. The root isolate has been created but not yet launched.
  ///             It may be launched by obtaining the engine weak pointer and
  ///             posting a task onto the UI task runner with a valid run
  ///             configuration to run the isolate. The embedder must always
  ///             check the validity of the shell (using the IsSetup call)
  ///             immediately after getting a pointer to it.
  ///
  static std::unique_ptr<Shell> Create(
      TaskRunners task_runners,
167
      const PlatformData platform_data,
168 169 170 171
      Settings settings,
      CreateCallback<PlatformView> on_create_platform_view,
      CreateCallback<Rasterizer> on_create_rasterizer);

172 173 174 175 176 177 178 179 180 181
  //----------------------------------------------------------------------------
  /// @brief      Creates a shell instance using the provided settings. The
  ///             callbacks to create the various shell subcomponents will be
  ///             called on the appropriate threads before this method returns.
  ///             Unlike the simpler variant of this factory method, this method
  ///             allows for the specification of an isolate snapshot that
  ///             cannot be adequately described in the settings. This call also
  ///             requires the specification of a running VM instance.
  ///
  /// @param[in]  task_runners             The task runners
182
  /// @param[in]  platform_data            The default data for setting up
183 184
  ///                                      ui.Window that attached to this
  ///                                      intance.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
  /// @param[in]  settings                 The settings
  /// @param[in]  isolate_snapshot         A custom isolate snapshot. Takes
  ///                                      precedence over any snapshots
  ///                                      specified in the settings.
  /// @param[in]  on_create_platform_view  The callback that must return a
  ///                                      platform view. This will be called on
  ///                                      the platform task runner before this
  ///                                      method returns.
  /// @param[in]  on_create_rasterizer     That callback that must provide a
  ///                                      valid rasterizer. This will be called
  ///                                      on the render task runner before this
  ///                                      method returns.
  /// @param[in]  vm                       A running VM instance.
  ///
  /// @return     A full initialized shell if the settings and callbacks are
  ///             valid. The root isolate has been created but not yet launched.
  ///             It may be launched by obtaining the engine weak pointer and
  ///             posting a task onto the UI task runner with a valid run
  ///             configuration to run the isolate. The embedder must always
  ///             check the validity of the shell (using the IsSetup call)
  ///             immediately after getting a pointer to it.
  ///
207
  static std::unique_ptr<Shell> Create(
208
      TaskRunners task_runners,
209
      const PlatformData platform_data,
210 211
      Settings settings,
      fml::RefPtr<const DartSnapshot> isolate_snapshot,
212 213
      const CreateCallback<PlatformView>& on_create_platform_view,
      const CreateCallback<Rasterizer>& on_create_rasterizer,
214
      DartVMRef vm);
215

216 217 218 219 220 221
  //----------------------------------------------------------------------------
  /// @brief      Destroys the shell. This is a synchronous operation and
  ///             synchronous barrier blocks are introduced on the various
  ///             threads to ensure shutdown of all shell sub-components before
  ///             this method returns.
  ///
222 223
  ~Shell();

D
Dan Field 已提交
224 225 226 227 228 229 230 231 232 233 234
  //----------------------------------------------------------------------------
  /// @brief      Starts an isolate for the given RunConfiguration.
  ///
  void RunEngine(RunConfiguration run_configuration);

  //----------------------------------------------------------------------------
  /// @brief      Starts an isolate for the given RunConfiguration. The
  ///             result_callback will be called with the status of the
  ///             operation.
  ///
  void RunEngine(RunConfiguration run_configuration,
235
                 const std::function<void(Engine::RunStatus)>& result_callback);
D
Dan Field 已提交
236

237 238 239
  //------------------------------------------------------------------------------
  /// @return     The settings used to launch this shell.
  ///
240
  const Settings& GetSettings() const;
241

242 243 244 245 246 247 248 249 250 251 252 253
  //------------------------------------------------------------------------------
  /// @brief      If callers wish to interact directly with any shell
  ///             subcomponents, they must (on the platform thread) obtain a
  ///             task runner that the component is designed to run on and a
  ///             weak pointer to that component. They may then post a task to
  ///             that task runner, do the validity check on that task runner
  ///             before performing any operation on that component. This
  ///             accessor allows callers to access the task runners for this
  ///             shell.
  ///
  /// @return     The task runners current in use by the shell.
  ///
254
  const TaskRunners& GetTaskRunners() const override;
A
Adam Barth 已提交
255

256
  //----------------------------------------------------------------------------
257
  /// @brief      Rasterizers may only be accessed on the raster task runner.
258 259 260
  ///
  /// @return     A weak pointer to the rasterizer.
  ///
261
  fml::TaskRunnerAffineWeakPtr<Rasterizer> GetRasterizer() const;
262

263
  //------------------------------------------------------------------------------
D
Dan Field 已提交
264 265 266
  /// @brief      Engines may only be accessed on the UI thread. This method is
  ///             deprecated, and implementers should instead use other API
  ///             available on the Shell or the PlatformView.
267 268 269
  ///
  /// @return     A weak pointer to the engine.
  ///
270
  fml::WeakPtr<Engine> GetEngine();
271

272 273 274 275 276 277
  //----------------------------------------------------------------------------
  /// @brief      Platform views may only be accessed on the platform task
  ///             runner.
  ///
  /// @return     A weak pointer to the platform view.
  ///
278
  fml::WeakPtr<PlatformView> GetPlatformView();
279

280 281 282 283 284 285 286
  //----------------------------------------------------------------------------
  /// @brief      The IO Manager may only be accessed on the IO task runner.
  ///
  /// @return     A weak pointer to the IO manager.
  ///
  fml::WeakPtr<ShellIOManager> GetIOManager();

287 288 289
  // Embedders should call this under low memory conditions to free up
  // internal caches used.
  //
290
  // This method posts a task to the raster threads to signal the Rasterizer to
291
  // free resources.
292 293 294 295 296

  //----------------------------------------------------------------------------
  /// @brief      Used by embedders to notify that there is a low memory
  ///             warning. The shell will attempt to purge caches. Current, only
  ///             the rasterizer cache is purged.
297 298
  void NotifyLowMemoryWarning() const;

299 300 301 302 303 304 305 306 307 308
  //----------------------------------------------------------------------------
  /// @brief      Used by embedders to check if all shell subcomponents are
  ///             initialized. It is the embedder's responsibility to make this
  ///             call before accessing any other shell method. A shell that is
  ///             not setup must be discarded and another one created with
  ///             updated settings.
  ///
  /// @return     Returns if the shell has been setup. Once set up, this does
  ///             not change for the life-cycle of the shell.
  ///
309
  bool IsSetup() const;
310

311 312 313 314 315 316 317 318 319 320 321
  //----------------------------------------------------------------------------
  /// @brief      Captures a screenshot and optionally Base64 encodes the data
  ///             of the last layer tree rendered by the rasterizer in this
  ///             shell.
  ///
  /// @param[in]  type           The type of screenshot to capture.
  /// @param[in]  base64_encode  If the screenshot data should be base64
  ///                            encoded.
  ///
  /// @return     The screenshot result.
  ///
322 323
  Rasterizer::Screenshot Screenshot(Rasterizer::ScreenshotType type,
                                    bool base64_encode);
324

325 326 327 328 329 330 331 332 333
  //----------------------------------------------------------------------------
  /// @brief   Pauses the calling thread until the first frame is presented.
  ///
  /// @return  'kOk' when the first frame has been presented before the timeout
  ///          successfully, 'kFailedPrecondition' if called from the GPU or UI
  ///          thread, 'kDeadlineExceeded' if there is a timeout.
  ///
  fml::Status WaitForFirstFrame(fml::TimeDelta timeout);

334 335 336 337 338 339 340 341 342 343
  //----------------------------------------------------------------------------
  /// @brief      Used by embedders to reload the system fonts in
  /// FontCollection.
  ///             It also clears the cached font families and send system
  ///             channel message to framework to rebuild affected widgets.
  ///
  /// @return     Returns if shell reloads system fonts successfully.
  ///
  bool ReloadSystemFonts();

D
Dan Field 已提交
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
  //----------------------------------------------------------------------------
  /// @brief      Used by embedders to get the last error from the Dart UI
  ///             Isolate, if one exists.
  ///
  /// @return     Returns the last error code from the UI Isolate.
  ///
  std::optional<DartErrorCode> GetUIIsolateLastError() const;

  //----------------------------------------------------------------------------
  /// @brief      Used by embedders to check if the Engine is running and has
  ///             any live ports remaining. For example, the Flutter tester uses
  ///             this method to check whether it should continue to wait for
  ///             a running test or not.
  ///
  /// @return     Returns if the shell has an engine and the engine has any live
  ///             Dart ports.
  ///
  bool EngineHasLivePorts() const;

363 364
  //----------------------------------------------------------------------------
  /// @brief     Accessor for the disable GPU SyncSwitch
365
  std::shared_ptr<fml::SyncSwitch> GetIsGpuDisabledSyncSwitch() const override;
366

367 368 369 370 371 372 373 374
  //----------------------------------------------------------------------------
  /// @brief      Get a pointer to the Dart VM used by this running shell
  ///             instance.
  ///
  /// @return     The Dart VM pointer.
  ///
  DartVM* GetDartVM();

375 376 377 378 379 380 381 382 383 384 385
  //----------------------------------------------------------------------------
  /// @brief      Notifies the display manager of the updates.
  ///
  void OnDisplayUpdates(DisplayUpdateType update_type,
                        std::vector<Display> displays);

  //----------------------------------------------------------------------------
  /// @brief Queries the `DisplayManager` for the main display refresh rate.
  ///
  double GetMainDisplayRefreshRate();

386
 private:
387 388
  using ServiceProtocolHandler =
      std::function<bool(const ServiceProtocol::Handler::ServiceProtocolMap&,
Z
Zachary Anderson 已提交
389
                         rapidjson::Document*)>;
390

391 392 393
  const TaskRunners task_runners_;
  const Settings settings_;
  DartVMRef vm_;
394 395
  mutable std::mutex time_recorder_mutex_;
  std::optional<fml::TimePoint> latest_frame_target_time_;
396 397
  std::unique_ptr<PlatformView> platform_view_;  // on platform task runner
  std::unique_ptr<Engine> engine_;               // on UI task runner
398
  std::unique_ptr<Rasterizer> rasterizer_;       // on raster task runner
399
  std::unique_ptr<ShellIOManager> io_manager_;   // on IO task runner
400
  std::shared_ptr<fml::SyncSwitch> is_gpu_disabled_sync_switch_;
401
  std::shared_ptr<VolatilePathTracker> volatile_path_tracker_;
402

403 404 405
  fml::WeakPtr<Engine> weak_engine_;  // to be shared across threads
  fml::TaskRunnerAffineWeakPtr<Rasterizer>
      weak_rasterizer_;  // to be shared across threads
406 407
  fml::WeakPtr<PlatformView>
      weak_platform_view_;  // to be shared across threads
408

409
  std::unordered_map<std::string_view,  // method
410
                     std::pair<fml::RefPtr<fml::TaskRunner>,
411 412 413 414 415
                               ServiceProtocolHandler>  // task-runner/function
                                                        // pair
                     >
      service_protocol_handlers_;
  bool is_setup_ = false;
416
  bool is_added_to_service_protocol_ = false;
417 418
  uint64_t next_pointer_flow_id_ = 0;

419
  bool first_frame_rasterized_ = false;
420 421 422
  std::atomic<bool> waiting_for_first_frame_ = true;
  std::mutex waiting_for_first_frame_mutex_;
  std::condition_variable waiting_for_first_frame_condition_;
423

424
  // Written in the UI thread and read from the raster thread. Hence make it
425 426 427 428 429 430 431 432 433 434 435 436
  // atomic.
  std::atomic<bool> needs_report_timings_{false};

  // Whether there's a task scheduled to report the timings to Dart through
  // ui.Window.onReportTimings.
  bool frame_timings_report_scheduled_ = false;

  // Vector of FrameTiming::kCount * n timestamps for n frames whose timings
  // have not been reported yet. Vector of ints instead of FrameTiming is stored
  // here for easier conversions to Dart objects.
  std::vector<int64_t> unreported_timings_;

437 438 439
  /// Manages the displays. This class is thread safe, can be accessed from any
  /// of the threads.
  std::unique_ptr<DisplayManager> display_manager_;
440

441 442 443 444 445 446 447
  // protects expected_frame_size_ which is set on platform thread and read on
  // raster thread
  std::mutex resize_mutex_;

  // used to discard wrong size layer tree produced during interactive resizing
  SkISize expected_frame_size_ = SkISize::MakeEmpty();

448 449 450
  // How many frames have been timed since last report.
  size_t UnreportedFramesCount() const;

451 452 453 454
  Shell(DartVMRef vm,
        TaskRunners task_runners,
        Settings settings,
        std::shared_ptr<VolatilePathTracker> volatile_path_tracker);
455 456

  static std::unique_ptr<Shell> CreateShellOnPlatformThread(
457 458
      DartVMRef vm,
      TaskRunners task_runners,
459
      const PlatformData platform_data,
460 461
      Settings settings,
      fml::RefPtr<const DartSnapshot> isolate_snapshot,
462 463
      const Shell::CreateCallback<PlatformView>& on_create_platform_view,
      const Shell::CreateCallback<Rasterizer>& on_create_rasterizer);
464 465 466 467

  bool Setup(std::unique_ptr<PlatformView> platform_view,
             std::unique_ptr<Engine> engine,
             std::unique_ptr<Rasterizer> rasterizer,
468
             std::unique_ptr<ShellIOManager> io_manager);
469

470 471
  void ReportTimings();

472
  // |PlatformView::Delegate|
473
  void OnPlatformViewCreated(std::unique_ptr<Surface> surface) override;
474

475
  // |PlatformView::Delegate|
476
  void OnPlatformViewDestroyed() override;
477

478
  // |PlatformView::Delegate|
479
  void OnPlatformViewSetViewportMetrics(
480
      const ViewportMetrics& metrics) override;
481

482
  // |PlatformView::Delegate|
483
  void OnPlatformViewDispatchPlatformMessage(
484
      fml::RefPtr<PlatformMessage> message) override;
485

486
  // |PlatformView::Delegate|
487
  void OnPlatformViewDispatchPointerDataPacket(
488
      std::unique_ptr<PointerDataPacket> packet) override;
489

490
  // |PlatformView::Delegate|
491 492
  void OnPlatformViewDispatchSemanticsAction(
      int32_t id,
493
      SemanticsAction action,
494 495
      std::vector<uint8_t> args) override;

496
  // |PlatformView::Delegate|
497
  void OnPlatformViewSetSemanticsEnabled(bool enabled) override;
498

499
  // |shell:PlatformView::Delegate|
500
  void OnPlatformViewSetAccessibilityFeatures(int32_t flags) override;
501

502
  // |PlatformView::Delegate|
503
  void OnPlatformViewRegisterTexture(
504
      std::shared_ptr<flutter::Texture> texture) override;
505

506
  // |PlatformView::Delegate|
507
  void OnPlatformViewUnregisterTexture(int64_t texture_id) override;
508

509
  // |PlatformView::Delegate|
510
  void OnPlatformViewMarkTextureFrameAvailable(int64_t texture_id) override;
511

512
  // |PlatformView::Delegate|
513
  void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override;
514

515
  // |PlatformView::Delegate|
G
Gary Qian 已提交
516 517 518 519
  void LoadDartDeferredLibrary(
      intptr_t loading_unit_id,
      std::unique_ptr<const fml::Mapping> snapshot_data,
      std::unique_ptr<const fml::Mapping> snapshot_instructions) override;
520

521 522 523 524
  void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
                                    const std::string error_message,
                                    bool transient) override;

525 526 527
  // |PlatformView::Delegate|
  void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) override;

528
  // |Animator::Delegate|
529
  void OnAnimatorBeginFrame(fml::TimePoint frame_target_time) override;
530

531
  // |Animator::Delegate|
532
  void OnAnimatorNotifyIdle(int64_t deadline) override;
533

534
  // |Animator::Delegate|
535
  void OnAnimatorDraw(fml::RefPtr<Pipeline<flutter::LayerTree>> pipeline,
536
                      fml::TimePoint frame_target_time) override;
537

538
  // |Animator::Delegate|
539
  void OnAnimatorDrawLastLayerTree() override;
540

541
  // |Engine::Delegate|
542
  void OnEngineUpdateSemantics(
543 544
      SemanticsNodeUpdates update,
      CustomAccessibilityActionUpdates actions) override;
545

546
  // |Engine::Delegate|
547
  void OnEngineHandlePlatformMessage(
548
      fml::RefPtr<PlatformMessage> message) override;
549

550
  void HandleEngineSkiaMessage(fml::RefPtr<PlatformMessage> message);
551

552
  // |Engine::Delegate|
553 554
  void OnPreEngineRestart() override;

555 556 557
  // |Engine::Delegate|
  void OnRootIsolateCreated() override;

558
  // |Engine::Delegate|
559 560 561
  void UpdateIsolateDescription(const std::string isolate_name,
                                int64_t isolate_port) override;

562 563 564
  // |Engine::Delegate|
  void SetNeedsReportTimings(bool value) override;

565 566 567 568
  // |Engine::Delegate|
  std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
      const std::vector<std::string>& supported_locale_data) override;

569 570 571
  // |Engine::Delegate|
  void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;

572 573 574
  // |Rasterizer::Delegate|
  void OnFrameRasterized(const FrameTiming&) override;

575
  // |Rasterizer::Delegate|
D
Dan Field 已提交
576 577
  fml::Milliseconds GetFrameBudget() override;

D
Dan Field 已提交
578 579
  // |Rasterizer::Delegate|
  fml::TimePoint GetLatestFrameTargetTime() const override;
580

581
  // |ServiceProtocol::Handler|
582
  fml::RefPtr<fml::TaskRunner> GetServiceProtocolHandlerTaskRunner(
583
      std::string_view method) const override;
584

585
  // |ServiceProtocol::Handler|
586
  bool HandleServiceProtocolMessage(
587
      std::string_view method,  // one if the extension names specified above.
588
      const ServiceProtocolMap& params,
Z
Zachary Anderson 已提交
589
      rapidjson::Document* response) override;
590

591 592
  // |ServiceProtocol::Handler|
  ServiceProtocol::Handler::Description GetServiceProtocolDescription()
593 594 595 596
      const override;

  // Service protocol handler
  bool OnServiceProtocolScreenshot(
597
      const ServiceProtocol::Handler::ServiceProtocolMap& params,
Z
Zachary Anderson 已提交
598
      rapidjson::Document* response);
599 600 601

  // Service protocol handler
  bool OnServiceProtocolScreenshotSKP(
602
      const ServiceProtocol::Handler::ServiceProtocolMap& params,
Z
Zachary Anderson 已提交
603
      rapidjson::Document* response);
604 605 606

  // Service protocol handler
  bool OnServiceProtocolRunInView(
607
      const ServiceProtocol::Handler::ServiceProtocolMap& params,
Z
Zachary Anderson 已提交
608
      rapidjson::Document* response);
609 610 611

  // Service protocol handler
  bool OnServiceProtocolFlushUIThreadTasks(
612
      const ServiceProtocol::Handler::ServiceProtocolMap& params,
Z
Zachary Anderson 已提交
613
      rapidjson::Document* response);
614 615 616

  // Service protocol handler
  bool OnServiceProtocolSetAssetBundlePath(
617
      const ServiceProtocol::Handler::ServiceProtocolMap& params,
Z
Zachary Anderson 已提交
618
      rapidjson::Document* response);
619

620 621
  // Service protocol handler
  bool OnServiceProtocolGetDisplayRefreshRate(
622
      const ServiceProtocol::Handler::ServiceProtocolMap& params,
Z
Zachary Anderson 已提交
623
      rapidjson::Document* response);
624

625 626 627 628 629
  // Service protocol handler
  //
  // The returned SkSLs are base64 encoded. Decode before storing them to files.
  bool OnServiceProtocolGetSkSLs(
      const ServiceProtocol::Handler::ServiceProtocolMap& params,
Z
Zachary Anderson 已提交
630
      rapidjson::Document* response);
631

632 633 634 635 636
  // Service protocol handler
  bool OnServiceProtocolEstimateRasterCacheMemory(
      const ServiceProtocol::Handler::ServiceProtocolMap& params,
      rapidjson::Document* response);

637 638 639 640
  // Creates an asset bundle from the original settings asset path or
  // directory.
  std::unique_ptr<DirectoryAssetBundle> RestoreOriginalAssetResolver();

641
  // For accessing the Shell via the raster thread, necessary for various
642
  // rasterizer callbacks.
643
  std::unique_ptr<fml::TaskRunnerAffineWeakPtrFactory<Shell>> weak_factory_gpu_;
644

645
  fml::WeakPtrFactory<Shell> weak_factory_;
646 647
  friend class testing::ShellTest;

648
  FML_DISALLOW_COPY_AND_ASSIGN(Shell);
649 650
};

651
}  // namespace flutter
652

653
#endif  // SHELL_COMMON_SHELL_H_