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