Flutter iOS Embedder
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 167 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 82 of file FlutterPlatformViews.mm.

85  {
86  if (available_layer_index_ >= layers_.size()) {
87  std::shared_ptr<FlutterPlatformViewLayer> layer;
88  fml::scoped_nsobject<UIView> overlay_view;
89  fml::scoped_nsobject<UIView> overlay_view_wrapper;
90 
91  bool impeller_enabled = !!ios_context->GetImpellerContext();
92  if (!gr_context && !impeller_enabled) {
93  overlay_view.reset([[FlutterOverlayView alloc] init]);
94  overlay_view_wrapper.reset([[FlutterOverlayView alloc] init]);
95 
96  auto ca_layer = fml::scoped_nsobject<CALayer>{[overlay_view.get() layer]};
97  std::unique_ptr<IOSSurface> ios_surface = IOSSurface::Create(ios_context, ca_layer);
98  std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface();
99 
100  layer = std::make_shared<FlutterPlatformViewLayer>(
101  std::move(overlay_view), std::move(overlay_view_wrapper), std::move(ios_surface),
102  std::move(surface));
103  } else {
104  CGFloat screenScale = [UIScreen mainScreen].scale;
105  overlay_view.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale
106  pixelFormat:pixel_format]);
107  overlay_view_wrapper.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale
108  pixelFormat:pixel_format]);
109 
110  auto ca_layer = fml::scoped_nsobject<CALayer>{[overlay_view.get() layer]};
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:
FlutterOverlayView
Definition: FlutterOverlayView.h:22
flutter::IOSSurface::Create
static std::unique_ptr< IOSSurface > Create(std::shared_ptr< IOSContext > context, const fml::scoped_nsobject< CALayer > &layer)
Definition: ios_surface.mm:16