| Flutter iOS Embedder |

Instance Methods | List of all members
flutter::FlutterPlatformViewLayerPool Class Reference

`#import <FlutterPlatformViews_Internal.h>`

## Instance Methods
() | - FlutterPlatformViewLayerPool
() | - ~FlutterPlatformViewLayerPool
(std::shared_ptr< FlutterPlatformViewLayer >) | - GetLayer
(std::vector< std::shared_ptr< FlutterPlatformViewLayer > >) | - GetUnusedLayers
(void) | - RecycleLayers

## Detailed Description

Definition at line 165 of file FlutterPlatformViews_Internal.h.

## Constructor & Destructor Documentation

## ◆ FlutterPlatformViewLayerPool

- FlutterPlatformViewLayerPool: |  |  |

## ◆ ~FlutterPlatformViewLayerPool

- FlutterPlatformViewLayerPool: |  |  |

## Method Documentation

## ◆ GetLayer

- (shared_ptr< FlutterPlatformViewLayer >) flutter: |  | (GrDirectContext *) | gr_context
|  | (const std::shared_ptr< IOSContext > &) | ios_context
|  | (MTLPixelFormat) | pixel_format

Definition at line 88 of file FlutterPlatformViews.mm.

91 {
92 if (available_layer_index_ >= layers_.size()) {
93 std::shared_ptr<FlutterPlatformViewLayer> layer;
94 fml::scoped_nsobject<UIView> overlay_view;
95 fml::scoped_nsobject<UIView> overlay_view_wrapper;
96
97 bool impeller_enabled = !!ios_context->GetImpellerContext();
98 if (!gr_context && !impeller_enabled) {
99 overlay_view.reset([[FlutterOverlayView alloc] init]);
100 overlay_view_wrapper.reset([[FlutterOverlayView alloc] init]);
101
102 auto ca_layer = fml::scoped_nsobject<CALayer>{[[overlay_view.get() layer] retain]};
103 std::unique_ptr<IOSSurface> ios_surface = IOSSurface::Create(ios_context, ca_layer);
104 std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface();
105
106 layer = std::make_shared<FlutterPlatformViewLayer>(
107 std::move(overlay_view), std::move(overlay_view_wrapper), std::move(ios_surface),
108 std::move(surface));
109 } else {
110 CGFloat screenScale = [UIScreen mainScreen].scale;
111 overlay_view.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale
112 pixelFormat:pixel_format]);
113 overlay_view_wrapper.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale
114 pixelFormat:pixel_format]);
115
116 auto ca_layer = fml::scoped_nsobject<CALayer>{[[overlay_view.get() layer] retain]};
117 std::unique_ptr<IOSSurface> ios_surface = IOSSurface::Create(ios_context, ca_layer);
118 std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(gr_context);
119
120 layer = std::make_shared<FlutterPlatformViewLayer>(
121 std::move(overlay_view), std::move(overlay_view_wrapper), std::move(ios_surface),
122 std::move(surface));
123 layer->gr_context = gr_context;
124 }
125 // The overlay view wrapper masks the overlay view.
126 // This is required to keep the backing surface size unchanged between frames.
127 //
128 // Otherwise, changing the size of the overlay would require a new surface,
129 // which can be very expensive.
130 //
131 // This is the case of an animation in which the overlay size is changing in every frame.
132 //
133 // +------------------------+
134 // | overlay_view |
135 // | +--------------+ | +--------------+
136 // | | wrapper | | == mask => | overlay_view |
137 // | +--------------+ | +--------------+
138 // +------------------------+
139 layer->overlay_view_wrapper.get().clipsToBounds = YES;
140 [layer->overlay_view_wrapper.get() addSubview:layer->overlay_view];
141 layers_.push_back(layer);
142 }
143 std::shared_ptr<FlutterPlatformViewLayer> layer = layers_[available_layer_index_];
144 if (gr_context != layer->gr_context) {
145 layer->gr_context = gr_context;
146 // The overlay already exists, but the GrContext was changed so we need to recreate
147 // the rendering surface with the new GrContext.
148 IOSSurface* ios_surface = layer->ios_surface.get();
149 std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(gr_context);
150 layer->surface = std::move(surface);
151 }
152 available_layer_index_++;
153 return layer;
154 }

References flutter::IOSSurface::CreateGPUSurface().

## ◆ GetUnusedLayers

- (vector<) std: |  |  |

Definition at line 161 of file FlutterPlatformViews.mm.

161 {
162 std::vector<std::shared_ptr<FlutterPlatformViewLayer>> results;
163 for (size_t i = available_layer_index_; i < layers_.size(); i++) {
164 results.push_back(layers_[i]);
165 }
166 return results;
167 }

## ◆ RecycleLayers

- (void) FlutterPlatformViewLayerPool: |  |  |

Definition at line 156 of file FlutterPlatformViews.mm.

156 {
157 available_layer_index_ = 0;
158 }

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

- shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h
- shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm

FlutterOverlayView
Definition: FlutterOverlayView.h:31
flutter::IOSSurface::Create
static std::unique_ptr< IOSSurface > Create(std::shared_ptr< IOSContext > context, const fml::scoped_nsobject< CALayer > &layer)
Definition: ios_surface.mm:18