| Flutter iOS Embedder |

Public Member Functions | List of all members
flutter::OverlayLayerPool Class Reference

Storage for Overlay layers across frames. More...

`#include <overlay_layer_pool.h>`

## Public Member Functions
| OverlayLayerPool ()=default
| ~OverlayLayerPool ()=default
std::shared_ptr< OverlayLayer > | GetNextLayer ()
| Gets a layer from the pool if available. More...
void | CreateLayer (const std::shared_ptr< IOSContext > &ios_context, MTLPixelFormat pixel_format)
| Create a new overlay layer. More...
std::vector< std::shared_ptr< OverlayLayer > > | RemoveUnusedLayers ()
| Removes unused layers from the pool. Returns the unused layers. More...
void | RecycleLayers ()
| Marks the layers in the pool as available for reuse. More...
size_t | size () const
| The count of layers currently in the pool. More...

## Detailed Description

Storage for Overlay layers across frames.

Note: this class does not synchronize access to its layers or any layer removal. As it is currently used, layers must be created on the platform thread but other methods of it are called on the raster thread. This is safe as overlay layers are only ever added while the raster thread is latched.

Definition at line 47 of file overlay_layer_pool.h.

## Constructor & Destructor Documentation

## ◆ OverlayLayerPool()

flutter::OverlayLayerPool::OverlayLayerPool | ( |  | ) |
| default

## ◆ ~OverlayLayerPool()

flutter::OverlayLayerPool::~OverlayLayerPool | ( |  | ) |
| default

## Member Function Documentation

## ◆ CreateLayer()

void flutter::OverlayLayerPool::CreateLayer | ( | const std::shared_ptr< IOSContext > & | ios_context,
|  | MTLPixelFormat | pixel_format
| ) |  |

Create a new overlay layer.

This method can only be called on the Platform thread.

Definition at line 55 of file overlay_layer_pool.mm.

56 {
57 FML_DCHECK([[NSThread currentThread] isMainThread]);
58 std::shared_ptr<OverlayLayer> layer;
59 UIView* overlay_view;
60 UIView* overlay_view_wrapper;
61
62 CGFloat screenScale = [UIScreen mainScreen].scale;
63 overlay_view = [[FlutterOverlayView alloc] initWithContentsScale:screenScale
64 pixelFormat:pixel_format];
65 overlay_view_wrapper = [[FlutterOverlayView alloc] initWithContentsScale:screenScale
66 pixelFormat:pixel_format];
67
68 CALayer* ca_layer = overlay_view.layer;
69 std::unique_ptr<IOSSurface> ios_surface = IOSSurface::Create(ios_context, ca_layer);
70 std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface();
71
72 layer = std::make_shared<OverlayLayer>(overlay_view, overlay_view_wrapper, std::move(ios_surface),
73 std::move(surface));
74
75 // The overlay view wrapper masks the overlay view.
76 // This is required to keep the backing surface size unchanged between frames.
77 //
78 // Otherwise, changing the size of the overlay would require a new surface,
79 // which can be very expensive.
80 //
81 // This is the case of an animation in which the overlay size is changing in every frame.
82 //
83 // +------------------------+
84 // | overlay_view |
85 // | +--------------+ | +--------------+
86 // | | wrapper | | == mask => | overlay_view |
87 // | +--------------+ | +--------------+
88 // +------------------------+
89 layer->overlay_view_wrapper.clipsToBounds = YES;
90 [layer->overlay_view_wrapper addSubview:layer->overlay_view];
91
92 layers_.push_back(layer);
93 }
flutter::IOSSurface::Create
static std::unique_ptr< IOSSurface > Create(std::shared_ptr< IOSContext > context, CALayer *layer)
Definition: ios_surface.mm:18
FlutterOverlayView
Definition: FlutterOverlayView.h:23

References flutter::IOSSurface::Create().

## ◆ GetNextLayer()

std::shared_ptr< OverlayLayer > flutter::OverlayLayerPool::GetNextLayer | ( |  | ) |

Gets a layer from the pool if available.

The layer is marked as used until [RecycleLayers] is called.

Definition at line 45 of file overlay_layer_pool.mm.

45 {
46 std::shared_ptr<OverlayLayer> result;
47 if (available_layer_index_ < layers_.size()) {
48 result = layers_[available_layer_index_];
49 available_layer_index_++;
50 }
51
52 return result;
53 }

## ◆ RecycleLayers()

void flutter::OverlayLayerPool::RecycleLayers | ( |  | ) |

Marks the layers in the pool as available for reuse.

Definition at line 95 of file overlay_layer_pool.mm.

95 {
96 available_layer_index_ = 0;
97 }

## ◆ RemoveUnusedLayers()

std::vector< std::shared_ptr< OverlayLayer > > flutter::OverlayLayerPool::RemoveUnusedLayers | ( |  | ) |

Removes unused layers from the pool. Returns the unused layers.

Definition at line 99 of file overlay_layer_pool.mm.

99 {
100 std::vector<std::shared_ptr<OverlayLayer>> results;
101 for (size_t i = available_layer_index_; i < layers_.size(); i++) {
102 results.push_back(layers_[i]);
103 }
104 // Leave at least one overlay layer, to work around cases where scrolling
105 // platform views under an app bar continually adds and removes an
106 // overlay layer. This logic could be removed if https://github.com/flutter/flutter/issues/150646
107 // is fixed.
108 static constexpr size_t kLeakLayerCount = 1;
109 size_t erase_offset = std::max(available_layer_index_, kLeakLayerCount);
110 if (erase_offset < layers_.size()) {
111 layers_.erase(layers_.begin() + erase_offset, layers_.end());
112 }
113 return results;
114 }

## ◆ size()

size_t flutter::OverlayLayerPool::size | ( |  | ) | const

The count of layers currently in the pool.

Definition at line 116 of file overlay_layer_pool.mm.

116 {
117 return layers_.size();
118 }

The documentation for this class was generated from the following files:

- shell/platform/darwin/ios/framework/Source/overlay_layer_pool.h
- shell/platform/darwin/ios/framework/Source/overlay_layer_pool.mm