Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f104bad

Browse files
huanghongxunrobert-ancell
authored andcommitted
Fix incorrect texture format with OpenGL ES
1 parent 867d4f2 commit f104bad

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

shell/platform/linux/fl_backing_store_provider.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,31 @@ uint32_t fl_backing_store_provider_get_gl_target(FlBackingStoreProvider* self) {
7777
return GL_TEXTURE_2D;
7878
}
7979

80+
static int gl_version(uint32_t major, uint32_t minor) {
81+
return (major << 16) | minor;
82+
}
83+
8084
uint32_t fl_backing_store_provider_get_gl_format(FlBackingStoreProvider* self) {
85+
// Flutter defines SK_R32_SHIFT=16, so SK_PMCOLOR_BYTE_ORDER should be BGRA.
86+
// In Linux kN32_SkColorType is assumed to be kBGRA_8888_SkColorType.
87+
// So we must choose a valid gl format to be compatible with surface format
88+
// BGRA8.
89+
// Following logics are copied from Skia GrGLCaps.cpp
90+
91+
if (epoxy_is_desktop_gl()) {
92+
if (epoxy_gl_version() >= gl_version(1, 2) ||
93+
epoxy_has_gl_extension("GL_EXT_bgra")) {
94+
return GL_RGBA8;
95+
}
96+
} else {
97+
// For OpenGL ES.
98+
if (epoxy_has_gl_extension("GL_EXT_texture_format_BGRA8888") ||
99+
(epoxy_has_gl_extension("GL_APPLE_texture_format_BGRA8888") &&
100+
epoxy_gl_version() >= gl_version(3, 0))) {
101+
return GL_BGRA8_EXT;
102+
}
103+
}
104+
g_critical("Failed to determine valid GL format for Flutter rendering");
81105
return GL_RGBA8;
82106
}
83107

shell/platform/linux/testing/mock_epoxy.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,18 @@ static void _glTexImage2D(GLenum target,
374374
GLenum type,
375375
const void* pixels) {}
376376

377+
bool epoxy_has_gl_extension(const char* extension) {
378+
return false;
379+
}
380+
381+
bool epoxy_is_desktop_gl(void) {
382+
return false;
383+
}
384+
385+
int epoxy_gl_version(void) {
386+
return 0;
387+
}
388+
377389
#ifdef __GNUC__
378390
#define CONSTRUCT(_func) static void _func(void) __attribute__((constructor));
379391
#define DESTRUCT(_func) static void _func(void) __attribute__((destructor));

0 commit comments

Comments
 (0)