[GLUtils] Add support for GL_SRGB8_ALPHA8.
When a GL surface is configured as EGL_GL_COLORSPACE_SRGB_KHR, the pixel value
from fragment shader will be gamma-ed, to de-gamma the pixel value in fragment
shader, the texture uploaded through glTexImage2D needs to specify the internal
format as GL_SRGB8_ALPHA8. For backward compatibility, GLUtils should never
pick this internal format by itself, but it should allow developer to pass this
internal format if they really want to.
BUG: N/A
Test: Build, flash, boot and run my own test apk
Change-Id: Ic43c2f2e3533ebb41c1a85b33964c1f19ac74a7c
diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp
index b163597..a45b493 100644
--- a/core/jni/android/opengl/util.cpp
+++ b/core/jni/android/opengl/util.cpp
@@ -622,13 +622,17 @@
// ---------------------------------------------------------------------------
+// The internal format is no longer the same as pixel format, per Table 2 in
+// https://www.khronos.org/registry/OpenGL-Refpages/es3.1/html/glTexImage2D.xhtml
static int checkInternalFormat(SkColorType colorType, int internalformat,
int type)
{
switch(colorType) {
case kN32_SkColorType:
return (type == GL_UNSIGNED_BYTE &&
- internalformat == GL_RGBA) ? 0 : -1;
+ internalformat == GL_RGBA) ||
+ (type == GL_UNSIGNED_BYTE &&
+ internalformat == GL_SRGB8_ALPHA8) ? 0 : -1;
case kAlpha_8_SkColorType:
return (type == GL_UNSIGNED_BYTE &&
internalformat == GL_ALPHA) ? 0 : -1;