| 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 162 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

Definition at line 86 of file FlutterPlatformViews.mm.

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

References flutter::IOSSurface::CreateGPUSurface().

## ◆ GetUnusedLayers

- (vector<) std: |  |  |

Definition at line 155 of file FlutterPlatformViews.mm.

155 {
156 std::vector<std::shared_ptr<FlutterPlatformViewLayer>> results;
157 for (size_t i = available_layer_index_; i < layers_.size(); i++) {
158 results.push_back(layers_[i]);
159 }
160 return results;
161 }

## ◆ RecycleLayers

- (void) FlutterPlatformViewLayerPool: |  |  |

Definition at line 150 of file FlutterPlatformViews.mm.

150 {
151 available_layer_index_ = 0;
152 }

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:29
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