Add new ASTC pixel config
authorkrajcevski <krajcevski@google.com>
Wed, 16 Jul 2014 22:21:13 +0000 (15:21 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 16 Jul 2014 22:21:14 +0000 (15:21 -0700)
R=bsalomon@google.com, robertphillips@google.com

Author: krajcevski@google.com

Review URL: https://codereview.chromium.org/399623004

include/gpu/GrColor.h
include/gpu/GrTypes.h
src/gpu/GrDrawTarget.cpp
src/gpu/GrTexture.cpp
src/gpu/gl/GrGLCaps.cpp
src/gpu/gl/GrGpuGL.cpp

index af394d7..c53e4b2 100644 (file)
@@ -135,21 +135,23 @@ static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) {
         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);
 }
 
index db013e3..0a73be9 100644 (file)
@@ -287,6 +287,19 @@ enum GrPixelConfig {
      * (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 @@ static inline bool GrPixelConfigIsCompressed(GrPixelConfig config) {
         case kETC1_GrPixelConfig:
         case kLATC_GrPixelConfig:
         case kR11_EAC_GrPixelConfig:
+        case kASTC_12x12_GrPixelConfig:
             return true;
         default:
             return false;
@@ -678,6 +692,11 @@ static inline size_t GrCompressedFormatDataSize(GrPixelConfig config,
             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;
index 221f571..483a9a5 100644 (file)
@@ -1135,19 +1135,21 @@ SkString GrDrawTargetCaps::dump() const {
         "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]);
index 984a9cf..fb5a8d3 100644 (file)
@@ -64,22 +64,7 @@ size_t GrTexture::gpuMemorySize() const {
                                    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()) {
index 178550b..8474873 100644 (file)
@@ -563,6 +563,12 @@ void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const G
         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
index b66feb2..3a2be13 100644 (file)
@@ -2698,11 +2698,17 @@ bool GrGpuGL::configToGLFormats(GrPixelConfig config,
         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;
     }