Fix incorrect texture format with OpenGL ES

This commit is contained in:
huanghongxun
2021-03-11 22:03:17 +08:00
committed by Robert Ancell
parent f98d97d32f
commit 87509d8518
2 changed files with 36 additions and 0 deletions

View File

@@ -77,7 +77,31 @@ uint32_t fl_backing_store_provider_get_gl_target(FlBackingStoreProvider* self) {
return GL_TEXTURE_2D;
}
static int gl_version(uint32_t major, uint32_t minor) {
return (major << 16) | minor;
}
uint32_t fl_backing_store_provider_get_gl_format(FlBackingStoreProvider* self) {
// Flutter defines SK_R32_SHIFT=16, so SK_PMCOLOR_BYTE_ORDER should be BGRA.
// In Linux kN32_SkColorType is assumed to be kBGRA_8888_SkColorType.
// So we must choose a valid gl format to be compatible with surface format
// BGRA8.
// Following logics are copied from Skia GrGLCaps.cpp
if (epoxy_is_desktop_gl()) {
if (epoxy_gl_version() >= gl_version(1, 2) ||
epoxy_has_gl_extension("GL_EXT_bgra")) {
return GL_RGBA8;
}
} else {
// For OpenGL ES.
if (epoxy_has_gl_extension("GL_EXT_texture_format_BGRA8888") ||
(epoxy_has_gl_extension("GL_APPLE_texture_format_BGRA8888") &&
epoxy_gl_version() >= gl_version(3, 0))) {
return GL_BGRA8_EXT;
}
}
g_critical("Failed to determine valid GL format for Flutter rendering");
return GL_RGBA8;
}

View File

@@ -374,6 +374,18 @@ static void _glTexImage2D(GLenum target,
GLenum type,
const void* pixels) {}
bool epoxy_has_gl_extension(const char* extension) {
return false;
}
bool epoxy_is_desktop_gl(void) {
return false;
}
int epoxy_gl_version(void) {
return 0;
}
#ifdef __GNUC__
#define CONSTRUCT(_func) static void _func(void) __attribute__((constructor));
#define DESTRUCT(_func) static void _func(void) __attribute__((destructor));