15 constexpr uint32_t kWindowFrameBufferId = 0;
18 struct FramebufferBackingStore {
26 impeller::ProcTableGLES::Resolver resolver)
27 : engine_(engine), resolver_(resolver) {}
30 const FlutterBackingStoreConfig& config,
31 FlutterBackingStore* result) {
32 if (!is_initialized_ && !Initialize()) {
36 auto store = std::make_unique<FramebufferBackingStore>();
38 gl_->GenTextures(1, &store->texture_id);
39 gl_->GenFramebuffers(1, &store->framebuffer_id);
41 gl_->BindFramebuffer(GL_FRAMEBUFFER, store->framebuffer_id);
43 gl_->BindTexture(GL_TEXTURE_2D, store->texture_id);
44 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
45 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
46 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
47 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
48 gl_->TexImage2D(GL_TEXTURE_2D, 0, format_.general_format, config.size.width,
49 config.size.height, 0, format_.general_format,
50 GL_UNSIGNED_BYTE,
nullptr);
51 gl_->BindTexture(GL_TEXTURE_2D, 0);
53 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
54 store->texture_id, 0);
56 result->type = kFlutterBackingStoreTypeOpenGL;
57 result->open_gl.type = kFlutterOpenGLTargetTypeFramebuffer;
58 result->open_gl.framebuffer.name = store->framebuffer_id;
59 result->open_gl.framebuffer.target = format_.sized_format;
60 result->open_gl.framebuffer.user_data = store.release();
61 result->open_gl.framebuffer.destruction_callback = [](
void*
user_data) {
69 FML_DCHECK(is_initialized_);
70 FML_DCHECK(store->type == kFlutterBackingStoreTypeOpenGL);
71 FML_DCHECK(store->open_gl.type == kFlutterOpenGLTargetTypeFramebuffer);
73 auto user_data =
static_cast<FramebufferBackingStore*
>(
74 store->open_gl.framebuffer.user_data);
76 gl_->DeleteFramebuffers(1, &
user_data->framebuffer_id);
77 gl_->DeleteTextures(1, &
user_data->texture_id);
84 const FlutterLayer** layers,
85 size_t layers_count) {
86 FML_DCHECK(view !=
nullptr);
89 if (layers_count == 0) {
93 if (!is_initialized_ && !Initialize()) {
102 FML_DCHECK(is_initialized_);
103 FML_DCHECK(layers_count == 1);
104 FML_DCHECK(layers[0]->offset.x == 0 && layers[0]->offset.y == 0);
105 FML_DCHECK(layers[0]->
type == kFlutterLayerContentTypeBackingStore);
106 FML_DCHECK(layers[0]->backing_store->type == kFlutterBackingStoreTypeOpenGL);
107 FML_DCHECK(layers[0]->backing_store->open_gl.type ==
108 kFlutterOpenGLTargetTypeFramebuffer);
110 auto width = layers[0]->size.width;
111 auto height = layers[0]->size.height;
120 FML_DCHECK(view->
surface() !=
nullptr);
128 auto source_id = layers[0]->backing_store->open_gl.framebuffer.name;
133 gl_->Disable(GL_SCISSOR_TEST);
135 gl_->BindFramebuffer(GL_READ_FRAMEBUFFER, source_id);
136 gl_->BindFramebuffer(GL_DRAW_FRAMEBUFFER, kWindowFrameBufferId);
138 gl_->BlitFramebuffer(0,
158 bool CompositorOpenGL::Initialize() {
159 FML_DCHECK(!is_initialized_);
170 gl_ = std::make_unique<impeller::ProcTableGLES>(resolver_);
171 if (!gl_->IsValid()) {
176 if (gl_->GetDescription()->HasExtension(
"GL_EXT_texture_format_BGRA8888")) {
177 format_.sized_format = GL_BGRA8_EXT;
178 format_.general_format = GL_BGRA_EXT;
180 format_.sized_format = GL_RGBA8;
181 format_.general_format = GL_RGBA;
184 is_initialized_ =
true;
188 bool CompositorOpenGL::Clear(FlutterWindowsView* view) {
189 FML_DCHECK(is_initialized_);
192 if (!view->OnEmptyFrameGenerated()) {
197 FML_DCHECK(view->surface() !=
nullptr);
198 FML_DCHECK(view->surface()->IsValid());
200 egl::WindowSurface* surface = view->surface();
201 if (!surface->MakeCurrent()) {
205 gl_->ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
206 gl_->Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
208 if (!surface->SwapBuffers()) {
212 view->OnFramePresented();