28 {
29 std::lock_guard lock(mutex_);
30
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
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
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),
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
64
65 if (gr_context_key != layer->gr_context_key) {
66 layer->gr_context_key = gr_context_key;
67
68
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}
#define FML_CHECK(condition)