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_;
Holds state that is shared across Android surfaces.
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)