Skip to content

Commit

Permalink
Fix incorrect texture format with OpenGL ES
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghongxun authored and robert-ancell committed Mar 11, 2021
1 parent 867d4f2 commit f104bad
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
24 changes: 24 additions & 0 deletions shell/platform/linux/fl_backing_store_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 12 additions & 0 deletions shell/platform/linux/testing/mock_epoxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit f104bad

Please sign in to comment.