Flutter Engine
flutter::SurfacePool Class Reference

#include <surface_pool.h>

Public Member Functions

 SurfacePool ()
 
 ~SurfacePool ()
 
std::shared_ptr< OverlayLayerGetLayer (GrDirectContext *gr_context, std::shared_ptr< AndroidContext > android_context, std::shared_ptr< PlatformViewAndroidJNI > jni_facade, std::shared_ptr< AndroidSurfaceFactory > surface_factory)
 
std::vector< std::shared_ptr< OverlayLayer > > GetUnusedLayers ()
 
void RecycleLayers ()
 
void DestroyLayers (std::shared_ptr< PlatformViewAndroidJNI > jni_facade)
 
void SetFrameSize (SkISize frame_size)
 

Detailed Description

Definition at line 45 of file surface_pool.h.

Constructor & Destructor Documentation

◆ SurfacePool()

flutter::SurfacePool::SurfacePool ( )
default

◆ ~SurfacePool()

flutter::SurfacePool::~SurfacePool ( )
default

Member Function Documentation

◆ DestroyLayers()

void flutter::SurfacePool::DestroyLayers ( std::shared_ptr< PlatformViewAndroidJNI jni_facade)

Definition at line 79 of file surface_pool.cc.

80  {
81  if (layers_.size() > 0) {
82  jni_facade->FlutterViewDestroyOverlaySurfaces();
83  }
84  layers_.clear();
85  available_layer_index_ = 0;
86 }

◆ GetLayer()

std::shared_ptr< OverlayLayer > flutter::SurfacePool::GetLayer ( GrDirectContext *  gr_context,
std::shared_ptr< AndroidContext android_context,
std::shared_ptr< PlatformViewAndroidJNI jni_facade,
std::shared_ptr< AndroidSurfaceFactory surface_factory 
)

Definition at line 22 of file surface_pool.cc.

References flutter::OverlayLayer::android_surface, FML_CHECK, flutter::OverlayLayer::gr_context_key, and flutter::OverlayLayer::surface.

26  {
27  // Destroy current layers in the pool if the frame size has changed.
28  if (requested_frame_size_ != current_frame_size_) {
29  DestroyLayers(jni_facade);
30  }
31 
32  intptr_t gr_context_key = reinterpret_cast<intptr_t>(gr_context);
33  // Allocate a new surface if there isn't one available.
34  if (available_layer_index_ >= layers_.size()) {
35  std::unique_ptr<AndroidSurface> android_surface =
36  surface_factory->CreateSurface();
37 
38  FML_CHECK(android_surface && android_surface->IsValid())
39  << "Could not create an OpenGL, Vulkan or Software surface to setup "
40  "rendering.";
41 
42  std::unique_ptr<PlatformViewAndroidJNI::OverlayMetadata> java_metadata =
43  jni_facade->FlutterViewCreateOverlaySurface();
44 
45  FML_CHECK(java_metadata->window);
46  android_surface->SetNativeWindow(java_metadata->window);
47 
48  std::unique_ptr<Surface> surface =
49  android_surface->CreateGPUSurface(gr_context);
50 
51  std::shared_ptr<OverlayLayer> layer =
52  std::make_shared<OverlayLayer>(java_metadata->id, //
53  std::move(android_surface), //
54  std::move(surface) //
55  );
56  layer->gr_context_key = gr_context_key;
57  layers_.push_back(layer);
58  }
59  std::shared_ptr<OverlayLayer> layer = layers_[available_layer_index_];
60  // Since the surfaces are recycled, it's possible that the GrContext is
61  // different.
62  if (gr_context_key != layer->gr_context_key) {
63  layer->gr_context_key = gr_context_key;
64  // The overlay already exists, but the GrContext was changed so we need to
65  // recreate the rendering surface with the new GrContext.
66  std::unique_ptr<Surface> surface =
67  layer->android_surface->CreateGPUSurface(gr_context);
68  layer->surface = std::move(surface);
69  }
70  available_layer_index_++;
71  current_frame_size_ = requested_frame_size_;
72  return layer;
73 }
#define FML_CHECK(condition)
Definition: logging.h:68
void DestroyLayers(std::shared_ptr< PlatformViewAndroidJNI > jni_facade)
Definition: surface_pool.cc:79

◆ GetUnusedLayers()

std::vector< std::shared_ptr< OverlayLayer > > flutter::SurfacePool::GetUnusedLayers ( )

Definition at line 88 of file surface_pool.cc.

88  {
89  std::vector<std::shared_ptr<OverlayLayer>> results;
90  for (size_t i = available_layer_index_; i < layers_.size(); i++) {
91  results.push_back(layers_[i]);
92  }
93  return results;
94 }

◆ RecycleLayers()

void flutter::SurfacePool::RecycleLayers ( )

Definition at line 75 of file surface_pool.cc.

75  {
76  available_layer_index_ = 0;
77 }

◆ SetFrameSize()

void flutter::SurfacePool::SetFrameSize ( SkISize  frame_size)

Definition at line 96 of file surface_pool.cc.

96  {
97  requested_frame_size_ = frame_size;
98 }

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