Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
flutter::SurfacePool Class Reference

#include <surface_pool.h>

Public Member Functions

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

Detailed Description

Definition at line 46 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 ( const std::shared_ptr< PlatformViewAndroidJNI > &  jni_facade)

Definition at line 88 of file surface_pool.cc.

89 {
90 std::lock_guard lock(mutex_);
91 DestroyLayersLocked(jni_facade);
92}

◆ GetLayer()

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

Definition at line 24 of file surface_pool.cc.

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

◆ GetUnusedLayers()

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

Definition at line 104 of file surface_pool.cc.

104 {
105 std::lock_guard lock(mutex_);
106 std::vector<std::shared_ptr<OverlayLayer>> results;
107 for (size_t i = available_layer_index_; i < layers_.size(); i++) {
108 results.push_back(layers_[i]);
109 }
110 return results;
111}

◆ HasLayers()

bool flutter::SurfacePool::HasLayers ( )

Definition at line 83 of file surface_pool.cc.

83 {
84 std::lock_guard lock(mutex_);
85 return !layers_.empty();
86}

◆ RecycleLayers()

void flutter::SurfacePool::RecycleLayers ( )

Definition at line 78 of file surface_pool.cc.

78 {
79 std::lock_guard lock(mutex_);
80 available_layer_index_ = 0;
81}

◆ SetFrameSize()

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

Definition at line 113 of file surface_pool.cc.

113 {
114 std::lock_guard lock(mutex_);
115 requested_frame_size_ = frame_size;
116}

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