9
9
#include < list>
10
10
11
11
#include " flutter/fml/macros.h"
12
+ #import " flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController.h"
12
13
#include " flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
13
14
#include " flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h"
14
15
#include " flutter/shell/platform/embedder/embedder.h"
@@ -25,52 +26,57 @@ class FlutterCompositor {
25
26
// The view_provider is used to query FlutterViews from view IDs,
26
27
// which are used for presenting and creating backing stores.
27
28
// It must not be null, and is typically FlutterViewEngineProvider.
28
- explicit FlutterCompositor (id<FlutterViewProvider> view_provider);
29
+ explicit FlutterCompositor (
30
+ id <FlutterViewProvider> view_provider,
31
+ FlutterPlatformViewController* platform_views_controller,
32
+ id <MTLDevice > mtl_device);
29
33
30
- virtual ~FlutterCompositor () = default ;
34
+ ~FlutterCompositor () = default ;
31
35
32
- // Creates a BackingStore and saves updates the backing_store_out
33
- // data with the new BackingStore data.
34
- // If the backing store is being requested for the first time
35
- // for a given frame, this compositor does not create a new backing
36
- // store but rather returns the backing store associated with the
37
- // FlutterView's FlutterSurfaceManager.
36
+ // Creates a backing store and saves updates the backing_store_out data with
37
+ // the new FlutterBackingStore data.
38
38
//
39
- // Any additional state allocated for the backing store and
40
- // saved as user_data in the backing store must be collected
41
- // in the backing_store's destruction_callback field which will
42
- // be called when the embedder collects the backing store.
43
- virtual bool CreateBackingStore (const FlutterBackingStoreConfig* config,
44
- FlutterBackingStore* backing_store_out) = 0;
39
+ // If the backing store is being requested for the first time for a given
40
+ // frame, this compositor does not create a new backing store but rather
41
+ // returns the backing store associated with the FlutterView's
42
+ // FlutterSurfaceManager.
43
+ //
44
+ // Any additional state allocated for the backing store and saved as
45
+ // user_data in the backing store must be collected in the backing_store's
46
+ // destruction_callback field which will be called when the embedder collects
47
+ // the backing store.
48
+ bool CreateBackingStore (const FlutterBackingStoreConfig* config,
49
+ FlutterBackingStore* backing_store_out);
45
50
46
- // Releases the memory for any state used by the backing store.
47
- virtual bool CollectBackingStore (
48
- const FlutterBackingStore* backing_store) = 0 ;
51
+ // Releases the memory for any resources that were allocated for the
52
+ // specified backing store.
53
+ bool CollectBackingStore ( const FlutterBackingStore* backing_store);
49
54
50
55
// Presents the FlutterLayers by updating the FlutterView specified by
51
- // `view_id` using the layer content.
52
- // Present sets frame_started_ to false.
53
- virtual bool Present (uint64_t view_id,
54
- const FlutterLayer** layers,
55
- size_t layers_count) = 0;
56
+ // `view_id` using the layer content. Sets frame_started_ to false.
57
+ bool Present (uint64_t view_id,
58
+ const FlutterLayer** layers,
59
+ size_t layers_count);
56
60
61
+ // Callback triggered at the end of the Present function. has_flutter_content
62
+ // is true when Flutter content was rendered, otherwise false.
57
63
using PresentCallback = std::function<bool (bool has_flutter_content)>;
58
64
59
- // PresentCallback is called at the end of the Present function.
65
+ // Registers a callback to be triggered at the end of the Present function.
66
+ // If a callback was previously registered, it will be replaced.
60
67
void SetPresentCallback (const PresentCallback& present_callback);
61
68
62
- // Denotes the current status of the frame being composited.
63
- // Started: A new frame has begun and we have cleared the old layer tree
64
- // and are now creating backingstore(s) for the embedder to use.
69
+ // The status of the frame being composited.
70
+ // Started: A new frame has begun and we have cleared the old layer tree and
71
+ // are now creating backingstore(s) for the embedder to use.
65
72
// Presenting: the embedder has finished rendering into the provided
66
- // backingstore(s) and we are creating the layer tree for the
67
- // system compositor to present with.
68
- // Ended: The frame has been presented and we are no longer processing
69
- // it.
73
+ // backingstore(s) and we are creating the layer tree for the system
74
+ // compositor to present with.
75
+ // Ended: The frame has been presented and we are no longer processing it.
70
76
typedef enum { kStarted , kPresenting , kEnded } FrameStatus;
71
77
72
78
protected:
73
- // Get the view associated with the view ID.
79
+ // Returns the view associated with the view ID.
74
80
//
75
81
// Returns nil if the ID is invalid.
76
82
FlutterView* GetView (uint64_t view_id);
@@ -94,12 +100,25 @@ class FlutterCompositor {
94
100
CATransform3D transform = CATransform3DIdentity);
95
101
96
102
private:
103
+ // Presents the platform view layer represented by `layer`. `layer_index` is
104
+ // used to position the layer in the z-axis. If the layer does not have a
105
+ // superview, it will become subview of `default_base_view`.
106
+ void PresentPlatformView (FlutterView* default_base_view,
107
+ const FlutterLayer* layer,
108
+ size_t layer_position);
109
+
97
110
// A list of the active CALayer objects for the frame that need to be removed.
98
111
std::list<CALayer *> active_ca_layers_;
99
112
100
113
// Where the compositor can query FlutterViews. Must not be null.
101
114
id <FlutterViewProvider> const view_provider_;
102
115
116
+ // The controller used to manage creation and deletion of platform views.
117
+ const FlutterPlatformViewController* platform_view_controller_;
118
+
119
+ // The Metal device used to draw graphics.
120
+ const id <MTLDevice > mtl_device_;
121
+
103
122
// Callback set by the embedder to be called when the layer tree has been
104
123
// correctly set up for this frame.
105
124
PresentCallback present_callback_;
0 commit comments