Add new ASTC pixel config
R=bsalomon@google.com, robertphillips@google.com
Author: krajcevski@google.com
Review URL: https://codereview.chromium.org/399623004
diff --git a/include/gpu/GrColor.h b/include/gpu/GrColor.h
index af394d7..c53e4b2 100644
--- a/include/gpu/GrColor.h
+++ b/include/gpu/GrColor.h
@@ -135,21 +135,23 @@
kRGB_GrColorComponentFlags, // kETC1_GrPixelConfig
kA_GrColorComponentFlag, // kLATC_GrPixelConfig
kA_GrColorComponentFlag, // kR11_EAC_GrPixelConfig
+ kRGBA_GrColorComponentFlags, // kASTC_12x12_GrPixelConfig
kRGBA_GrColorComponentFlags, // kRGBA_float_GrPixelConfig
};
return kFlags[config];
- GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
- GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
- GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
- GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
- GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
- GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
- GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
- GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
- GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
- GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
- GR_STATIC_ASSERT(10 == kRGBA_float_GrPixelConfig);
+ GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
+ GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
+ GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
+ GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
+ GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
+ GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
+ GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
+ GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
+ GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
+ GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
+ GR_STATIC_ASSERT(10 == kASTC_12x12_GrPixelConfig);
+ GR_STATIC_ASSERT(11 == kRGBA_float_GrPixelConfig);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt);
}
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index db013e3..0a73be9 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -287,6 +287,19 @@
* (Corresponds to section C.3.5 of the OpenGL 4.4 core profile spec)
*/
kR11_EAC_GrPixelConfig,
+
+ /**
+ * 12x12 ASTC Compressed Data
+ * ASTC stands for Adaptive Scalable Texture Compression. It is a technique
+ * that allows for a lot of customization in the compressed representataion
+ * of a block. The only thing fixed in the representation is the block size,
+ * which means that a texture that contains ASTC data must be treated as
+ * having RGBA values. However, there are single-channel encodings which set
+ * the alpha to opaque and all three RGB channels equal effectively making the
+ * compression format a single channel such as R11 EAC and LATC.
+ */
+ kASTC_12x12_GrPixelConfig,
+
/**
* Byte order is r, g, b, a. This color format is 32 bits per channel
*/
@@ -314,6 +327,7 @@
case kETC1_GrPixelConfig:
case kLATC_GrPixelConfig:
case kR11_EAC_GrPixelConfig:
+ case kASTC_12x12_GrPixelConfig:
return true;
default:
return false;
@@ -678,6 +692,11 @@
SkASSERT((height & 3) == 0);
return (width >> 2) * (height >> 2) * 8;
+ case kASTC_12x12_GrPixelConfig:
+ SkASSERT((width % 12) == 0);
+ SkASSERT((height % 12) == 0);
+ return (width / 12) * (height / 12) * 16;
+
default:
SkFAIL("Unknown compressed pixel config");
return 4 * width * height;
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 221f571..483a9a5 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -1135,19 +1135,21 @@
"ETC1", // kETC1_GrPixelConfig,
"LATC", // kLATC_GrPixelConfig,
"R11EAC", // kR11_EAC_GrPixelConfig,
+ "ASTC12x12",// kASTC_12x12_GrPixelConfig,
"RGBAFloat", // kRGBA_float_GrPixelConfig
};
- GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
- GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
- GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
- GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
- GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
- GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
- GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
- GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
- GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
- GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
- GR_STATIC_ASSERT(10 == kRGBA_float_GrPixelConfig);
+ GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
+ GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
+ GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
+ GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
+ GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
+ GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
+ GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
+ GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
+ GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
+ GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
+ GR_STATIC_ASSERT(10 == kASTC_12x12_GrPixelConfig);
+ GR_STATIC_ASSERT(11 == kRGBA_float_GrPixelConfig);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
index 984a9cf..fb5a8d3 100644
--- a/src/gpu/GrTexture.cpp
+++ b/src/gpu/GrTexture.cpp
@@ -64,22 +64,7 @@
GrBytesPerPixel(fDesc.fConfig);
if (GrPixelConfigIsCompressed(fDesc.fConfig)) {
- // Figure out the width and height corresponding to the data...
-
- // Both of the available formats (ETC1 and LATC) have 4x4
- // blocks that compress down to 8 bytes.
- switch(fDesc.fConfig) {
- case kETC1_GrPixelConfig:
- case kLATC_GrPixelConfig:
- case kR11_EAC_GrPixelConfig:
- SkASSERT((fDesc.fWidth & 3) == 0);
- SkASSERT((fDesc.fHeight & 3) == 0);
- textureSize = (fDesc.fWidth >> 2) * (fDesc.fHeight >> 2) * 8;
- break;
-
- default:
- SkFAIL("Unknown compressed config");
- }
+ textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fDesc.fHeight);
}
if (this->impl()->hasMipMaps()) {
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 178550b..8474873 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -563,6 +563,12 @@
fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
}
+ // Check for ASTC
+ fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
+ ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
+ ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
+ ctxInfo.hasExtension("GL_OES_texture_compression_astc");
+
// Check for floating point texture support
// NOTE: We disallow floating point textures on ES devices if linear
// filtering modes are not supported. This is for simplicity, but a more
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index b66feb2..3a2be13 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -2698,11 +2698,17 @@
case kR11_EAC_GrPixelConfig:
*internalFormat = GR_GL_COMPRESSED_R11;
break;
+
+ case kASTC_12x12_GrPixelConfig:
+ *internalFormat = GR_GL_COMPRESSED_RGBA_ASTC_12x12;
+ break;
+
case kRGBA_float_GrPixelConfig:
*internalFormat = GR_GL_RGBA32F;
*externalFormat = GR_GL_RGBA;
*externalType = GR_GL_FLOAT;
break;
+
default:
return false;
}