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