From 87509d8518cea0e90912cc30b08192b1dd4da760 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Thu, 11 Mar 2021 22:03:17 +0800 Subject: [PATCH] Fix incorrect texture format with OpenGL ES --- .../linux/fl_backing_store_provider.cc | 24 +++++++++++++++++++ .../platform/linux/testing/mock_epoxy.cc | 12 ++++++++++ 2 files changed, 36 insertions(+) diff --git a/engine/src/flutter/shell/platform/linux/fl_backing_store_provider.cc b/engine/src/flutter/shell/platform/linux/fl_backing_store_provider.cc index d76b7ab6ce..af4e9fdf73 100644 --- a/engine/src/flutter/shell/platform/linux/fl_backing_store_provider.cc +++ b/engine/src/flutter/shell/platform/linux/fl_backing_store_provider.cc @@ -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; } diff --git a/engine/src/flutter/shell/platform/linux/testing/mock_epoxy.cc b/engine/src/flutter/shell/platform/linux/testing/mock_epoxy.cc index a8012cd988..329b598f39 100644 --- a/engine/src/flutter/shell/platform/linux/testing/mock_epoxy.cc +++ b/engine/src/flutter/shell/platform/linux/testing/mock_epoxy.cc @@ -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));