Flutter Engine
The Flutter Engine
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"
14#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMutatorView.h"
15#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController.h"
16#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTimeConverter.h"
17#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h"
18#include "flutter/shell/platform/embedder/embedder.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 // 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.
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_
FlutterCompositor(id< FlutterViewProvider > view_provider, FlutterTimeConverter *time_converter, FlutterPlatformViewController *platform_views_controller)
bool CreateBackingStore(const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
bool Present(FlutterViewIdentifier view_id, const FlutterLayer **layers, size_t layers_count)
Represents a platform view layer, including all mutations.
#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
std::vector< FlutterRect > paint_region