Flutter Engine
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 88 of file FlutterPlatformViews_Internal.h.

Constructor & Destructor Documentation

◆ FlutterPlatformViewLayerPool()

- FlutterPlatformViewLayerPool:

◆ ~FlutterPlatformViewLayerPool()

- FlutterPlatformViewLayerPool:

Method Documentation

◆ GetLayer()

- (shared_ptr< FlutterPlatformViewLayer >) flutter: (GrDirectContext *)  gr_context
(std::shared_ptr< IOSContext >)  ios_context 

Definition at line 24 of file FlutterPlatformViews.mm.

References flutter::IOSSurface::Create(), flutter::IOSSurface::CreateGPUSurface(), fml::scoped_nsprotocol< NST *>::get(), and fml::scoped_nsprotocol< NST *>::reset().

Referenced by flutter::FlutterPlatformViewsController::SubmitFrame.

26  {
27  if (available_layer_index_ >= layers_.size()) {
28  std::shared_ptr<FlutterPlatformViewLayer> layer;
30  fml::scoped_nsobject<FlutterOverlayView> overlay_view_wrapper;
31 
32  if (!gr_context) {
33  overlay_view.reset([[FlutterOverlayView alloc] init]);
34  overlay_view_wrapper.reset([[FlutterOverlayView alloc] init]);
35 
36  auto ca_layer = fml::scoped_nsobject<CALayer>{[[overlay_view.get() layer] retain]};
37  std::unique_ptr<IOSSurface> ios_surface = IOSSurface::Create(ios_context, ca_layer);
38  std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface();
39 
40  layer = std::make_shared<FlutterPlatformViewLayer>(
41  std::move(overlay_view), std::move(overlay_view_wrapper), std::move(ios_surface),
42  std::move(surface));
43  } else {
44  CGFloat screenScale = [UIScreen mainScreen].scale;
45  overlay_view.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale]);
46  overlay_view_wrapper.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale]);
47 
48  auto ca_layer = fml::scoped_nsobject<CALayer>{[[overlay_view.get() layer] retain]};
49  std::unique_ptr<IOSSurface> ios_surface = IOSSurface::Create(ios_context, ca_layer);
50  std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(gr_context);
51 
52  layer = std::make_shared<FlutterPlatformViewLayer>(
53  std::move(overlay_view), std::move(overlay_view_wrapper), std::move(ios_surface),
54  std::move(surface));
55  layer->gr_context = gr_context;
56  }
57  // The overlay view wrapper masks the overlay view.
58  // This is required to keep the backing surface size unchanged between frames.
59  //
60  // Otherwise, changing the size of the overlay would require a new surface,
61  // which can be very expensive.
62  //
63  // This is the case of an animation in which the overlay size is changing in every frame.
64  //
65  // +------------------------+
66  // | overlay_view |
67  // | +--------------+ | +--------------+
68  // | | wrapper | | == mask => | overlay_view |
69  // | +--------------+ | +--------------+
70  // +------------------------+
71  overlay_view_wrapper.get().clipsToBounds = YES;
72  [overlay_view_wrapper.get() addSubview:overlay_view];
73  layers_.push_back(layer);
74  }
75  std::shared_ptr<FlutterPlatformViewLayer> layer = layers_[available_layer_index_];
76  if (gr_context != layer->gr_context) {
77  layer->gr_context = gr_context;
78  // The overlay already exists, but the GrContext was changed so we need to recreate
79  // the rendering surface with the new GrContext.
80  IOSSurface* ios_surface = layer->ios_surface.get();
81  std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(gr_context);
82  layer->surface = std::move(surface);
83  }
84  available_layer_index_++;
85  return layer;
86 }
void reset(NST * object=nil)
static std::unique_ptr< IOSSurface > Create(std::shared_ptr< IOSContext > context, fml::scoped_nsobject< CALayer > layer)
Definition: ios_surface.mm:18

◆ GetUnusedLayers()

- (vector<) std:

Definition at line 93 of file FlutterPlatformViews.mm.

93  {
94  std::vector<std::shared_ptr<FlutterPlatformViewLayer>> results;
95  for (size_t i = available_layer_index_; i < layers_.size(); i++) {
96  results.push_back(layers_[i]);
97  }
98  return results;
99 }

◆ RecycleLayers()

- (void) FlutterPlatformViewLayerPool:

Definition at line 88 of file FlutterPlatformViews.mm.

88  {
89  available_layer_index_ = 0;
90 }

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