[GLUtils] Pass the correct format into glTexImage2D and glTexSubImage2D.
Previously, the format and internal format are the same, however, per
https://www.khronos.org/registry/OpenGL-Refpages/es3.1/html/glTexImage2D.xhtml,
this is no longer the case, thus we need to convert to proper format when we
have the sized format.
BUG: 72065799
Test: none
Change-Id: Ib1f90db6692b3629928ed664e5c775adfb4f63dd
diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp
index f3aeb32..888db32 100644
--- a/core/jni/android/opengl/util.cpp
+++ b/core/jni/android/opengl/util.cpp
@@ -622,7 +622,7 @@
// ---------------------------------------------------------------------------
-static int checkFormat(SkColorType colorType, int format, int type)
+static int checkInternalFormat(SkColorType colorType, int format, int type)
{
switch(colorType) {
case kN32_SkColorType:
@@ -651,6 +651,20 @@
return -1;
}
+// 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 getPixelFormatFromInternalFormat(uint32_t internalFormat) {
+ switch (internalFormat) {
+ // For sized internal format.
+ case GL_RGBA16F:
+ return GL_RGBA;
+ // Base internal formats and pixel formats are still the same, see Table 1 in
+ // https://www.khronos.org/registry/OpenGL-Refpages/es3.1/html/glTexImage2D.xhtml
+ default:
+ return internalFormat;
+ }
+}
+
static int getInternalFormat(SkColorType colorType)
{
switch(colorType) {
@@ -716,7 +730,7 @@
if (type < 0) {
type = getType(colorType);
}
- int err = checkFormat(colorType, internalformat, type);
+ int err = checkInternalFormat(colorType, internalformat, type);
if (err)
return err;
const int w = bitmap.width();
@@ -725,7 +739,8 @@
if (internalformat == GL_PALETTE8_RGBA8_OES) {
err = -1;
} else {
- glTexImage2D(target, level, internalformat, w, h, border, internalformat, type, p);
+ glTexImage2D(target, level, internalformat, w, h, border,
+ getPixelFormatFromInternalFormat(internalformat), type, p);
}
return err;
}
@@ -737,12 +752,13 @@
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
SkColorType colorType = bitmap.colorType();
+ int internalFormat = getInternalFormat(colorType);
if (format < 0) {
- format = getInternalFormat(colorType);
+ format = getPixelFormatFromInternalFormat(internalFormat);
if (format == GL_PALETTE8_RGBA8_OES)
return -1; // glCompressedTexSubImage2D() not supported
}
- int err = checkFormat(colorType, format, type);
+ int err = checkInternalFormat(colorType, internalFormat, type);
if (err)
return err;
const int w = bitmap.width();