Flutter Engine
 
Loading...
Searching...
No Matches
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"
19
22
23namespace flutter {
24
26 std::vector<FlutterRect> paint_region;
27};
28
29using 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 // Allocate the resources for displaying a view.
50 //
51 // This method must be called when a view is added to FlutterEngine, and must be
52 // called on the main dispatch queue, or an assertion will be thrown.
54
55 // Deallocate the resources for displaying a view.
56 //
57 // This method must be called when a view is removed from FlutterEngine, and
58 // must be called on the main dispatch queue, or an assertion will be thrown.
60
61 // Creates a backing store and saves updates the backing_store_out data with
62 // the new FlutterBackingStore data.
63 //
64 // If the backing store is being requested for the first time for a given
65 // frame, this compositor does not create a new backing store but rather
66 // returns the backing store associated with the FlutterView's
67 // FlutterSurfaceManager.
68 //
69 // Any additional state allocated for the backing store and saved as
70 // user_data in the backing store must be collected in the backing_store's
71 // destruction_callback field which will be called when the embedder collects
72 // the backing store.
74 FlutterBackingStore* backing_store_out);
75
76 // Presents the FlutterLayers by updating the FlutterView specified by
77 // `view_id` using the layer content.
79
80 // The number of views that the FlutterCompositor is keeping track of.
81 //
82 // This method must only be used in unit tests.
83 size_t DebugNumViews();
84
85 private:
86 // A class that contains the information for a view to be presented.
87 class ViewPresenter {
88 public:
89 ViewPresenter();
90
91 void PresentPlatformViews(FlutterView* default_base_view,
92 const std::vector<LayerVariant>& layers,
93 const FlutterPlatformViewController* platform_views_controller);
94
95 private:
96 // Platform view to FlutterMutatorView that contains it.
97 NSMapTable<NSView*, FlutterMutatorView*>* mutator_views_;
98
99 // Coordinates mouse cursor changes between platform views and overlays.
100 FlutterCursorCoordinator* cursor_coordinator_;
101
102 // Presents the platform view layer represented by `layer`. `layer_index` is
103 // used to position the layer in the z-axis. If the layer does not have a
104 // superview, it will become subview of `default_base_view`.
105 FlutterMutatorView* PresentPlatformView(
106 FlutterView* default_base_view,
107 const PlatformViewLayer& layer,
108 size_t layer_position,
109 const FlutterPlatformViewController* platform_views_controller);
110
111 FML_DISALLOW_COPY_AND_ASSIGN(ViewPresenter);
112 };
113
114 // Where the compositor can query FlutterViews. Must not be null.
115 id<FlutterViewProvider> const view_provider_;
116
117 // Converts between engine time and core animation media time.
118 FlutterTimeConverter* const time_converter_;
119
120 // The controller used to manage creation and deletion of platform views.
121 const FlutterPlatformViewController* platform_view_controller_;
122
123 // The view presenters for views. Each key is a view ID.
124 std::unordered_map<FlutterViewId, ViewPresenter> presenters_;
125
127};
128
129} // namespace flutter
130
131#endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERCOMPOSITOR_H_
bool CreateBackingStore(const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
bool Present(FlutterViewIdentifier view_id, const FlutterLayer **layers, size_t layers_count)
void AddView(FlutterViewId view_id)
void RemoveView(FlutterViewId view_id)
Represents a platform view layer, including all mutations.
const FlutterLayer size_t layers_count
const FlutterLayer ** layers
G_BEGIN_DECLS FlutterViewId view_id
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
Converts between the time representation used by Flutter Engine and CAMediaTime.
int64_t FlutterViewIdentifier
std::variant< PlatformViewLayer, BackingStoreLayer > LayerVariant
int64_t FlutterViewId
std::vector< FlutterRect > paint_region