Skip to content

Commit 8f5e9b0

Browse files
[Linux] Make glBlitFramebuffer optional in the OpenGL compositor (#189476)
glBlitFramebuffer is a GLES3 / OpenGL 3.0 function and is not guaranteed to be present, so the Linux embedder should treat it as optional. The compositor was calling it unconditionally to blit the first layer, which breaks on OpenGL 2.0 drivers without the GL_EXT_framebuffer_blit extension and on drivers with a broken implementation (NVIDIA, Vivante, ARM per #152099). Restore the blit-availability detection (GL version >= 3.0 or the GL_EXT_framebuffer_blit extension, plus the driver blacklist) and fall back to shader-based compositing for the first layer when blit is unavailable. This regressed in e983e59 ("Perform OpenGL compositing in the Flutter thread and write to a framebuffer." #172090), which consolidated compositing and dropped the has_gl_framebuffer_blit check. Strengthen the NoBlitFramebuffer and BlitFramebufferNvidia tests to assert glBlitFramebuffer is never called. Fixes #189322
1 parent a6882e4 commit 8f5e9b0

2 files changed

Lines changed: 67 additions & 6 deletions

File tree

‎engine/src/flutter/shell/platform/linux/fl_compositor_opengl.cc‎

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <epoxy/egl.h>
88
#include <epoxy/gl.h>
99

10+
#include <cstring>
11+
1012
#include "flutter/common/constants.h"
1113
#include "flutter/shell/platform/embedder/embedder.h"
1214
#include "flutter/shell/platform/linux/fl_compositor_opengl_shader.h"
@@ -19,6 +21,9 @@ struct _FlCompositorOpenGL {
1921
// TRUE if can share framebuffers between contexts.
2022
gboolean shareable;
2123

24+
// TRUE if glBlitFramebuffer can be used to composite the first layer.
25+
gboolean can_blit;
26+
2227
// Flutter OpenGL contexts.
2328
FlOpenGLManager* opengl_manager;
2429

@@ -52,6 +57,41 @@ static void fl_compositor_opengl_class_init(FlCompositorOpenGLClass* klass) {
5257

5358
static void fl_compositor_opengl_init(FlCompositorOpenGL* self) {}
5459

60+
// Checks if the current OpenGL driver is known to have a broken or unsupported
61+
// glBlitFramebuffer implementation.
62+
static gboolean driver_supports_blit() {
63+
const gchar* vendor = reinterpret_cast<const gchar*>(glGetString(GL_VENDOR));
64+
if (vendor == nullptr) {
65+
return TRUE;
66+
}
67+
68+
// Note: List of unsupported vendors due to issue
69+
// https://github.com/flutter/flutter/issues/152099
70+
const char* unsupported_vendors_exact[] = {"Vivante Corporation", "ARM"};
71+
const char* unsupported_vendors_fuzzy[] = {"NVIDIA"};
72+
73+
for (const char* unsupported : unsupported_vendors_fuzzy) {
74+
if (strstr(vendor, unsupported) != nullptr) {
75+
return FALSE;
76+
}
77+
}
78+
for (const char* unsupported : unsupported_vendors_exact) {
79+
if (strcmp(vendor, unsupported) == 0) {
80+
return FALSE;
81+
}
82+
}
83+
return TRUE;
84+
}
85+
86+
// Checks if glBlitFramebuffer can be used. It is a GLES3 / OpenGL 3.0 function
87+
// and may not be present on older drivers, so treat it as optional and fall
88+
// back to compositing with the shader when it is unavailable.
89+
static gboolean can_blit_framebuffer() {
90+
return driver_supports_blit() &&
91+
(epoxy_gl_version() >= 30 ||
92+
epoxy_has_gl_extension("GL_EXT_framebuffer_blit"));
93+
}
94+
5595
FlCompositorOpenGL* fl_compositor_opengl_new(FlOpenGLManager* opengl_manager,
5696
gboolean shareable) {
5797
FlCompositorOpenGL* self = FL_COMPOSITOR_OPENGL(
@@ -61,6 +101,10 @@ FlCompositorOpenGL* fl_compositor_opengl_new(FlOpenGLManager* opengl_manager,
61101
self->opengl_manager = FL_OPENGL_MANAGER(g_object_ref(opengl_manager));
62102
self->shader = fl_compositor_opengl_shader_new(opengl_manager);
63103

104+
// Determine once whether glBlitFramebuffer is available on this driver.
105+
fl_opengl_manager_make_current(opengl_manager);
106+
self->can_blit = can_blit_framebuffer();
107+
64108
return self;
65109
}
66110

@@ -165,21 +209,22 @@ gboolean fl_compositor_opengl_composite_layers(FlCompositorOpenGL* self,
165209
const FlutterBackingStore* backing_store = layer->backing_store;
166210
FlFramebuffer* framebuffer =
167211
FL_FRAMEBUFFER(backing_store->open_gl.framebuffer.user_data);
168-
glBindFramebuffer(GL_READ_FRAMEBUFFER,
169-
fl_framebuffer_get_id(framebuffer));
170212
// The first layer can be blitted, and following layers composited with
171-
// this.
172-
if (first_layer) {
213+
// this. If glBlitFramebuffer is unavailable, composite the first layer
214+
// with the shader instead.
215+
if (first_layer && self->can_blit) {
216+
glBindFramebuffer(GL_READ_FRAMEBUFFER,
217+
fl_framebuffer_get_id(framebuffer));
173218
glBlitFramebuffer(layer->offset.x, layer->offset.y, layer->size.width,
174219
layer->size.height, layer->offset.x,
175220
layer->offset.y, layer->size.width,
176221
layer->size.height, GL_COLOR_BUFFER_BIT,
177222
GL_NEAREST);
178-
first_layer = FALSE;
179223
} else {
180224
composite_layer(self, framebuffer, layer->offset.x, layer->offset.y,
181225
width, height);
182226
}
227+
first_layer = FALSE;
183228
} break;
184229
case kFlutterLayerContentTypePlatformView: {
185230
// TODO(robert-ancell) Not implemented -

‎engine/src/flutter/shell/platform/linux/fl_compositor_opengl_test.cc‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class FlCompositorOpenGLTest : public flutter::testing::LinuxTest {
2424
void SetUp() override {
2525
opengl_manager = fl_opengl_manager_new();
2626
renderable = fl_mock_renderable_new();
27-
compositor = fl_compositor_opengl_new(opengl_manager, FALSE);
2827
fl_engine_set_implicit_view(engine, FL_RENDERABLE(renderable));
2928
}
3029

@@ -44,6 +43,7 @@ TEST_F(FlCompositorOpenGLTest, Render) {
4443
// Present layer from a thread.
4544
constexpr size_t width = 100;
4645
constexpr size_t height = 100;
46+
compositor = fl_compositor_opengl_new(opengl_manager, FALSE);
4747
g_autoptr(FlFramebuffer) framebuffer =
4848
fl_framebuffer_new(GL_RGB, width, height, FALSE);
4949
FlutterBackingStore backing_store = {
@@ -79,6 +79,7 @@ TEST_F(FlCompositorOpenGLTest, Resize) {
7979
// Present a layer that is the old size.
8080
constexpr size_t width1 = 90;
8181
constexpr size_t height1 = 90;
82+
compositor = fl_compositor_opengl_new(opengl_manager, FALSE);
8283
g_autoptr(FlFramebuffer) framebuffer1 =
8384
fl_framebuffer_new(GL_RGB, width1, height1, FALSE);
8485
FlutterBackingStore backing_store1 = {
@@ -135,6 +136,8 @@ TEST_F(FlCompositorOpenGLTest, RestoresGLState) {
135136
ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(true));
136137
ON_CALL(epoxy, epoxy_gl_version).WillByDefault(::testing::Return(30));
137138

139+
compositor = fl_compositor_opengl_new(opengl_manager, FALSE);
140+
138141
g_autoptr(FlFramebuffer) framebuffer =
139142
fl_framebuffer_new(GL_RGB, width, height, FALSE);
140143
FlutterBackingStore backing_store = {
@@ -186,6 +189,8 @@ TEST_F(FlCompositorOpenGLTest, BlitFramebuffer) {
186189

187190
EXPECT_CALL(epoxy, glBlitFramebuffer);
188191

192+
compositor = fl_compositor_opengl_new(opengl_manager, FALSE);
193+
189194
g_autoptr(FlFramebuffer) framebuffer =
190195
fl_framebuffer_new(GL_RGB, width, height, FALSE);
191196
FlutterBackingStore backing_store = {
@@ -230,6 +235,8 @@ TEST_F(FlCompositorOpenGLTest, BlitFramebufferExtension) {
230235

231236
EXPECT_CALL(epoxy, glBlitFramebuffer);
232237

238+
compositor = fl_compositor_opengl_new(opengl_manager, FALSE);
239+
233240
g_autoptr(FlFramebuffer) framebuffer =
234241
fl_framebuffer_new(GL_RGB, width, height, FALSE);
235242
FlutterBackingStore backing_store = {
@@ -267,6 +274,10 @@ TEST_F(FlCompositorOpenGLTest, NoBlitFramebuffer) {
267274
ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(true));
268275
EXPECT_CALL(epoxy, epoxy_gl_version).WillRepeatedly(::testing::Return(20));
269276

277+
EXPECT_CALL(epoxy, glBlitFramebuffer).Times(0);
278+
279+
compositor = fl_compositor_opengl_new(opengl_manager, FALSE);
280+
270281
g_autoptr(FlFramebuffer) framebuffer =
271282
fl_framebuffer_new(GL_RGB, width, height, FALSE);
272283
FlutterBackingStore backing_store = {
@@ -305,6 +316,10 @@ TEST_F(FlCompositorOpenGLTest, BlitFramebufferNvidia) {
305316
ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(true));
306317
EXPECT_CALL(epoxy, epoxy_gl_version).WillRepeatedly(::testing::Return(30));
307318

319+
EXPECT_CALL(epoxy, glBlitFramebuffer).Times(0);
320+
321+
compositor = fl_compositor_opengl_new(opengl_manager, FALSE);
322+
308323
g_autoptr(FlFramebuffer) framebuffer =
309324
fl_framebuffer_new(GL_RGB, width, height, FALSE);
310325
FlutterBackingStore backing_store = {
@@ -335,6 +350,7 @@ TEST_F(FlCompositorOpenGLTest, RenderResizeCrash) {
335350
// Present layer of size 100x100.
336351
constexpr size_t width = 100;
337352
constexpr size_t height = 100;
353+
compositor = fl_compositor_opengl_new(opengl_manager, FALSE);
338354
g_autoptr(FlFramebuffer) framebuffer =
339355
fl_framebuffer_new(GL_RGB, width, height, FALSE);
340356
FlutterBackingStore backing_store = {

0 commit comments

Comments
 (0)