15 constexpr uint32_t kWindowFrameBufferId = 0;
18 struct FramebufferBackingStore {
26 impeller::ProcTableGLES::Resolver resolver,
28 : engine_(engine), resolver_(resolver), enable_impeller_(enable_impeller) {}
31 const FlutterBackingStoreConfig& config,
32 FlutterBackingStore* result) {
33 if (!is_initialized_ && !Initialize()) {
37 auto store = std::make_unique<FramebufferBackingStore>();
39 gl_->GenTextures(1, &store->texture_id);
40 gl_->GenFramebuffers(1, &store->framebuffer_id);
42 gl_->BindFramebuffer(GL_FRAMEBUFFER, store->framebuffer_id);
44 gl_->BindTexture(GL_TEXTURE_2D, store->texture_id);
45 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
46 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
47 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
48 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
49 gl_->TexImage2D(GL_TEXTURE_2D, 0, format_.general_format, config.size.width,
50 config.size.height, 0, format_.general_format,
51 GL_UNSIGNED_BYTE,
nullptr);
52 gl_->BindTexture(GL_TEXTURE_2D, 0);
54 if (enable_impeller_) {
57 gl_->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER,
58 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
59 store->texture_id, 0, 4);
63 gl_->GenRenderbuffers(1, &depth_stencil);
64 gl_->BindRenderbuffer(GL_RENDERBUFFER, depth_stencil);
65 gl_->RenderbufferStorageMultisampleEXT(
72 gl_->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
73 GL_RENDERBUFFER, depth_stencil);
74 gl_->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
75 GL_RENDERBUFFER, depth_stencil);
78 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
79 GL_TEXTURE_2D, store->texture_id, 0);
82 result->type = kFlutterBackingStoreTypeOpenGL;
83 result->open_gl.type = kFlutterOpenGLTargetTypeFramebuffer;
84 result->open_gl.framebuffer.name = store->framebuffer_id;
85 result->open_gl.framebuffer.target = format_.sized_format;
86 result->open_gl.framebuffer.user_data = store.release();
87 result->open_gl.framebuffer.destruction_callback = [](
void*
user_data) {
95 FML_DCHECK(is_initialized_);
96 FML_DCHECK(store->type == kFlutterBackingStoreTypeOpenGL);
97 FML_DCHECK(store->open_gl.type == kFlutterOpenGLTargetTypeFramebuffer);
99 auto user_data =
static_cast<FramebufferBackingStore*
>(
100 store->open_gl.framebuffer.user_data);
102 gl_->DeleteFramebuffers(1, &
user_data->framebuffer_id);
103 gl_->DeleteTextures(1, &
user_data->texture_id);
110 const FlutterLayer** layers,
111 size_t layers_count) {
112 FML_DCHECK(view !=
nullptr);
115 if (layers_count == 0) {
119 if (!is_initialized_ && !Initialize()) {
128 FML_DCHECK(is_initialized_);
129 FML_DCHECK(layers_count == 1);
130 FML_DCHECK(layers[0]->offset.x == 0 && layers[0]->offset.y == 0);
131 FML_DCHECK(layers[0]->
type == kFlutterLayerContentTypeBackingStore);
132 FML_DCHECK(layers[0]->backing_store->type == kFlutterBackingStoreTypeOpenGL);
133 FML_DCHECK(layers[0]->backing_store->open_gl.type ==
134 kFlutterOpenGLTargetTypeFramebuffer);
136 auto width = layers[0]->size.width;
137 auto height = layers[0]->size.height;
146 FML_DCHECK(view->
surface() !=
nullptr);
154 auto source_id = layers[0]->backing_store->open_gl.framebuffer.name;
159 gl_->Disable(GL_SCISSOR_TEST);
160 gl_->BindFramebuffer(GL_READ_FRAMEBUFFER, source_id);
161 gl_->BindFramebuffer(GL_DRAW_FRAMEBUFFER, kWindowFrameBufferId);
163 gl_->BlitFramebuffer(0,
183 bool CompositorOpenGL::Initialize() {
184 FML_DCHECK(!is_initialized_);
195 gl_ = std::make_unique<impeller::ProcTableGLES>(resolver_);
196 if (!gl_->IsValid()) {
201 if (gl_->GetDescription()->HasExtension(
"GL_EXT_texture_format_BGRA8888")) {
202 format_.sized_format = GL_BGRA8_EXT;
203 format_.general_format = GL_BGRA_EXT;
205 format_.sized_format = GL_RGBA8;
206 format_.general_format = GL_RGBA;
209 is_initialized_ =
true;
213 bool CompositorOpenGL::Clear(FlutterWindowsView* view) {
214 FML_DCHECK(is_initialized_);
217 if (!view->OnEmptyFrameGenerated()) {
222 FML_DCHECK(view->surface() !=
nullptr);
223 FML_DCHECK(view->surface()->IsValid());
225 egl::WindowSurface* surface = view->surface();
226 if (!surface->MakeCurrent()) {
230 gl_->ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
231 gl_->Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
233 if (!surface->SwapBuffers()) {
237 view->OnFramePresented();