5#include "flutter/shell/platform/android/external_view_embedder/surface_pool.h"
12 std::unique_ptr<AndroidSurface> android_surface,
13 std::unique_ptr<Surface>
surface)
15 android_surface(
std::move(android_surface)),
27 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
28 const std::shared_ptr<AndroidSurfaceFactory>& surface_factory) {
29 std::lock_guard lock(mutex_);
31 if (requested_frame_size_ != current_frame_size_) {
32 DestroyLayersLocked(jni_facade);
34 intptr_t gr_context_key =
reinterpret_cast<intptr_t
>(gr_context);
36 if (available_layer_index_ >= layers_.size()) {
37 std::unique_ptr<AndroidSurface> android_surface =
38 surface_factory->CreateSurface();
40 FML_CHECK(android_surface && android_surface->IsValid())
41 <<
"Could not create an OpenGL, Vulkan or Software surface to set up "
44 std::unique_ptr<PlatformViewAndroidJNI::OverlayMetadata> java_metadata =
45 jni_facade->FlutterViewCreateOverlaySurface();
48 android_surface->SetNativeWindow(java_metadata->window);
50 std::unique_ptr<Surface>
surface =
51 android_surface->CreateGPUSurface(gr_context);
53 std::shared_ptr<OverlayLayer> layer =
54 std::make_shared<OverlayLayer>(java_metadata->id,
55 std::move(android_surface),
58 layer->gr_context_key = gr_context_key;
59 layers_.push_back(layer);
62 std::shared_ptr<OverlayLayer> layer = layers_[available_layer_index_];
65 if (gr_context_key != layer->gr_context_key) {
66 layer->gr_context_key = gr_context_key;
69 std::unique_ptr<Surface>
surface =
70 layer->android_surface->CreateGPUSurface(gr_context);
71 layer->surface = std::move(
surface);
73 available_layer_index_++;
74 current_frame_size_ = requested_frame_size_;
79 std::lock_guard lock(mutex_);
80 available_layer_index_ = 0;
84 std::lock_guard lock(mutex_);
85 return !layers_.empty();
89 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) {
90 std::lock_guard lock(mutex_);
91 DestroyLayersLocked(jni_facade);
94void SurfacePool::DestroyLayersLocked(
95 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) {
96 if (layers_.empty()) {
99 jni_facade->FlutterViewDestroyOverlaySurfaces();
101 available_layer_index_ = 0;
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]);
114 std::lock_guard lock(mutex_);
115 requested_frame_size_ = frame_size;
Holds state that is shared across Android surfaces.
void DestroyLayers(const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade)
void SetFrameSize(SkISize frame_size)
std::vector< std::shared_ptr< OverlayLayer > > GetUnusedLayers()
std::shared_ptr< OverlayLayer > GetLayer(GrDirectContext *gr_context, const AndroidContext &android_context, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade, const std::shared_ptr< AndroidSurfaceFactory > &surface_factory)
#define FML_CHECK(condition)
OverlayLayer(int id, std::unique_ptr< AndroidSurface > android_surface, std::unique_ptr< Surface > surface)