Flutter macOS Embedder
FlutterCompositor.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_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERCOMPOSITOR_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERCOMPOSITOR_H_
7 
8 #include <functional>
9 #include <list>
10 #include <unordered_map>
11 #include <variant>
12 
13 #include "flutter/fml/macros.h"
18 #include "flutter/shell/platform/embedder/embedder.h"
19 
20 @class FlutterMutatorView;
22 
23 namespace flutter {
24 
26  std::vector<FlutterRect> paint_region;
27 };
28 
29 using LayerVariant = std::variant<PlatformViewLayer, BackingStoreLayer>;
30 
31 // FlutterCompositor creates and manages the backing stores used for
32 // rendering Flutter content and presents Flutter content and Platform views.
33 // Platform views are not yet supported.
34 //
35 // TODO(cbracken): refactor for testability. https://github.com/flutter/flutter/issues/137648
37  public:
38  // Create a FlutterCompositor with a view provider.
39  //
40  // The view_provider is used to query FlutterViews from view IDs,
41  // which are used for presenting and creating backing stores.
42  // It must not be null, and is typically FlutterViewEngineProvider.
43  FlutterCompositor(id<FlutterViewProvider> view_provider,
44  FlutterTimeConverter* time_converter,
45  FlutterPlatformViewController* platform_views_controller);
46 
47  ~FlutterCompositor() = default;
48 
49  // Creates a backing store and saves updates the backing_store_out data with
50  // the new FlutterBackingStore data.
51  //
52  // If the backing store is being requested for the first time for a given
53  // frame, this compositor does not create a new backing store but rather
54  // returns the backing store associated with the FlutterView's
55  // FlutterSurfaceManager.
56  //
57  // Any additional state allocated for the backing store and saved as
58  // user_data in the backing store must be collected in the backing_store's
59  // destruction_callback field which will be called when the embedder collects
60  // the backing store.
61  bool CreateBackingStore(const FlutterBackingStoreConfig* config,
62  FlutterBackingStore* backing_store_out);
63 
64  // Presents the FlutterLayers by updating the FlutterView specified by
65  // `view_id` using the layer content.
66  bool Present(FlutterViewIdentifier view_id, const FlutterLayer** layers, size_t layers_count);
67 
68  private:
69  // A class that contains the information for a view to be presented.
70  class ViewPresenter {
71  public:
72  ViewPresenter();
73 
74  void PresentPlatformViews(FlutterView* default_base_view,
75  const std::vector<LayerVariant>& layers,
76  const FlutterPlatformViewController* platform_views_controller);
77 
78  private:
79  // Platform view to FlutterMutatorView that contains it.
80  NSMapTable<NSView*, FlutterMutatorView*>* mutator_views_;
81 
82  // Coordinates mouse cursor changes between platform views and overlays.
83  FlutterCursorCoordinator* cursor_coordinator_;
84 
85  // Presents the platform view layer represented by `layer`. `layer_index` is
86  // used to position the layer in the z-axis. If the layer does not have a
87  // superview, it will become subview of `default_base_view`.
88  FlutterMutatorView* PresentPlatformView(
89  FlutterView* default_base_view,
90  const PlatformViewLayer& layer,
91  size_t layer_position,
92  const FlutterPlatformViewController* platform_views_controller);
93 
94  FML_DISALLOW_COPY_AND_ASSIGN(ViewPresenter);
95  };
96 
97  // Where the compositor can query FlutterViews. Must not be null.
98  id<FlutterViewProvider> const view_provider_;
99 
100  // Converts between engine time and core animation media time.
101  FlutterTimeConverter* const time_converter_;
102 
103  // The controller used to manage creation and deletion of platform views.
104  const FlutterPlatformViewController* platform_view_controller_;
105 
106  std::unordered_map<int64_t, ViewPresenter> presenters_;
107 
108  FML_DISALLOW_COPY_AND_ASSIGN(FlutterCompositor);
109 };
110 
111 } // namespace flutter
112 
113 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERCOMPOSITOR_H_
FlutterMutatorView.h
FlutterMutatorView
Definition: FlutterMutatorView.h:63
FlutterCursorCoordinator
Definition: FlutterMutatorView.h:45
flutter::FlutterCompositor::~FlutterCompositor
~FlutterCompositor()=default
flutter::BackingStoreLayer
Definition: FlutterCompositor.h:25
flutter::LayerVariant
std::variant< PlatformViewLayer, BackingStoreLayer > LayerVariant
Definition: FlutterCompositor.h:29
FlutterTimeConverter.h
FlutterPlatformViewController
Definition: FlutterPlatformViewController.h:17
FlutterPlatformViewController.h
FlutterViewProvider.h
flutter::FlutterCompositor
Definition: FlutterCompositor.h:36
flutter::FlutterCompositor::FlutterCompositor
FlutterCompositor(id< FlutterViewProvider > view_provider, FlutterTimeConverter *time_converter, FlutterPlatformViewController *platform_views_controller)
Definition: FlutterCompositor.mm:35
flutter::FlutterCompositor::CreateBackingStore
bool CreateBackingStore(const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
Definition: FlutterCompositor.mm:44
flutter
Definition: AccessibilityBridgeMac.h:16
flutter::FlutterCompositor::Present
bool Present(FlutterViewIdentifier view_id, const FlutterLayer **layers, size_t layers_count)
Definition: FlutterCompositor.mm:64
flutter::BackingStoreLayer::paint_region
std::vector< FlutterRect > paint_region
Definition: FlutterCompositor.h:26
FlutterTimeConverter
Converts between the time representation used by Flutter Engine and CAMediaTime.
Definition: FlutterTimeConverter.h:13
FlutterView
Definition: FlutterView.h:35
flutter::PlatformViewLayer
Represents a platform view layer, including all mutations.
Definition: FlutterMutatorView.h:16
FlutterViewIdentifier
int64_t FlutterViewIdentifier
Definition: FlutterViewController.h:21