| Flutter iOS Embedder |

overlay_layer_pool.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_IOS_FRAMEWORK_SOURCE_OVERLAY_LAYER_POOL_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_OVERLAY_LAYER_POOL_H_
7
8 #include <Metal/Metal.h>
9 #include <memory>
10
11 #import <UIKit/UIKit.h>
12
13 #include "flow/surface.h"
14
15 #import "flutter/shell/platform/darwin/ios/ios_context.h"
16
17 namespace flutter {
18
19 class IOSSurface;
20
21 /// @brief State holder for a Flutter overlay layer.
22 struct OverlayLayer {
23 OverlayLayer(UIView* overlay_view,
24 UIView* overlay_view_wrapper,
25 std::unique_ptr<IOSSurface> ios_surface,
26 std::unique_ptr<Surface> surface);
27
28 ~OverlayLayer() = default;
29
30 UIView* overlay_view;
31 UIView* overlay_view_wrapper;
32 std::unique_ptr<IOSSurface> ios_surface;
33 std::unique_ptr<Surface> surface;
34
35 // Whether a frame for this layer was submitted.
36 bool did_submit_last_frame;
37
38 void UpdateViewState(UIView* flutter_view, DlRect rect, int64_t view_id, int64_t overlay_id);
39 };
40
41 /// @brief Storage for Overlay layers across frames.
42 ///
43 /// Note: this class does not synchronize access to its layers or any layer removal. As it
44 /// is currently used, layers must be created on the platform thread but other methods of
45 /// it are called on the raster thread. This is safe as overlay layers are only ever added
46 /// while the raster thread is latched.
47 class OverlayLayerPool {
48 public:
49 OverlayLayerPool() = default;
50
51 ~OverlayLayerPool() = default;
52
53 /// @brief Gets a layer from the pool if available.
54 ///
55 /// The layer is marked as used until [RecycleLayers] is called.
56 std::shared_ptr<OverlayLayer> GetNextLayer();
57
58 /// @brief Create a new overlay layer.
59 ///
60 /// This method can only be called on the Platform thread.
61 void CreateLayer(const std::shared_ptr<IOSContext>& ios_context, MTLPixelFormat pixel_format);
62
63 /// @brief Removes unused layers from the pool. Returns the unused layers.
64 std::vector<std::shared_ptr<OverlayLayer>> RemoveUnusedLayers();
65
66 /// @brief Marks the layers in the pool as available for reuse.
67 void RecycleLayers();
68
69 /// @brief The count of layers currently in the pool.
70 size_t size() const;
71
72 private:
73 OverlayLayerPool(const OverlayLayerPool&) = delete;
74 OverlayLayerPool& operator=(const OverlayLayerPool&) = delete;
75
76 // The index of the entry in the layers_ vector that determines the beginning of the unused
77 // layers. For example, consider the following vector:
78 // _____
79 // | 0 |
80 /// |---|
81 /// | 1 | <-- available_layer_index_
82 /// |---|
83 /// | 2 |
84 /// |---|
85 ///
86 /// This indicates that entries starting from 1 can be reused meanwhile the entry at position 0
87 /// cannot be reused.
88 size_t available_layer_index_ = 0;
89 std::vector<std::shared_ptr<OverlayLayer>> layers_;
90 };
91
92 } // namespace flutter
93
94 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_OVERLAY_LAYER_POOL_H_
flutter::OverlayLayerPool
Storage for Overlay layers across frames.
Definition: overlay_layer_pool.h:47
flutter::OverlayLayerPool::RecycleLayers
void RecycleLayers()
Marks the layers in the pool as available for reuse.
Definition: overlay_layer_pool.mm:96
flutter::OverlayLayerPool::~OverlayLayerPool
~OverlayLayerPool()=default
flutter::OverlayLayerPool::RemoveUnusedLayers
std::vector< std::shared_ptr< OverlayLayer > > RemoveUnusedLayers()
Removes unused layers from the pool. Returns the unused layers.
Definition: overlay_layer_pool.mm:100
flutter::OverlayLayerPool::OverlayLayerPool
OverlayLayerPool()=default
flutter::OverlayLayerPool::size
size_t size() const
The count of layers currently in the pool.
Definition: overlay_layer_pool.mm:117
flutter::OverlayLayerPool::GetNextLayer
std::shared_ptr< OverlayLayer > GetNextLayer()
Gets a layer from the pool if available.
Definition: overlay_layer_pool.mm:46
flutter::OverlayLayerPool::CreateLayer
void CreateLayer(const std::shared_ptr< IOSContext > &ios_context, MTLPixelFormat pixel_format)
Create a new overlay layer.
Definition: overlay_layer_pool.mm:56
ios_context.h
flutter
Definition: accessibility_bridge.h:26
flutter::OverlayLayer
State holder for a Flutter overlay layer.
Definition: overlay_layer_pool.h:22
flutter::OverlayLayer::did_submit_last_frame
bool did_submit_last_frame
Definition: overlay_layer_pool.h:36
flutter::OverlayLayer::~OverlayLayer
~OverlayLayer()=default
flutter::OverlayLayer::surface
std::unique_ptr< Surface > surface
Definition: overlay_layer_pool.h:33
flutter::OverlayLayer::overlay_view_wrapper
UIView * overlay_view_wrapper
Definition: overlay_layer_pool.h:31
flutter::OverlayLayer::ios_surface
std::unique_ptr< IOSSurface > ios_surface
Definition: overlay_layer_pool.h:32
flutter::OverlayLayer::OverlayLayer
OverlayLayer(UIView *overlay_view, UIView *overlay_view_wrapper, std::unique_ptr< IOSSurface > ios_surface, std::unique_ptr< Surface > surface)
Definition: overlay_layer_pool.mm:12
flutter::OverlayLayer::overlay_view
UIView * overlay_view
Definition: overlay_layer_pool.h:30
flutter::OverlayLayer::UpdateViewState
void UpdateViewState(UIView *flutter_view, DlRect rect, int64_t view_id, int64_t overlay_id)
Definition: overlay_layer_pool.mm:21