Add compressed texture capabilities for GPU devices
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 27 May 2014 18:52:24 +0000 (18:52 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 27 May 2014 18:52:24 +0000 (18:52 +0000)
BUG=skia:

Committed: http://code.google.com/p/skia/source/detail?r=14880

R=bsalomon@google.com, robertphillips@google.com

Author: krajcevski@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@14901 2bbb7eff-a529-9590-31e7-b0007b416f81

include/gpu/GrTypes.h
src/gpu/GrDrawTarget.cpp
src/gpu/GrDrawTargetCaps.h
src/gpu/gl/GrGLCaps.cpp
src/gpu/gl/GrGLCaps.h

index c1b3554c6e008eb322d18838618a53cbeeb54495..5868a39e7d22add6a914351a166d6d28e0d08188 100644 (file)
@@ -619,6 +619,20 @@ enum GrGLBackendState {
     kALL_GrGLBackendState              = 0xffff
 };
 
+/**
+ * The compressed texture formats that may be supported by the renderer.
+ * Make sure to check for the required capabilities using
+ * GrDrawTargetCaps::compressedTextureSupport
+ */
+enum GrCompressedFormat {
+    kETC1_GrCompressedFormat,
+    kETC2_GrCompressedFormat,
+    kDXT1_GrCompressedFormat,
+
+    kLast_GrCompressedFormat = kDXT1_GrCompressedFormat
+};
+static const int kGrCompressedFormatCount = kLast_GrCompressedFormat + 1;
+
 /**
  * This value translates to reseting all the context state for any backend.
  */
index 6d8d18463aec37f28bc34c18d7ea59b578462f04..a5b6ac6f038f0db5d5c1cde39ef066ee1f80a65d 100644 (file)
@@ -1029,6 +1029,7 @@ void GrDrawTargetCaps::reset() {
     fMaxSampleCount = 0;
 
     memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
+    memset(fCompressedFormatSupport, 0, sizeof(fCompressedFormatSupport));
 }
 
 GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
@@ -1054,6 +1055,8 @@ GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
     fMaxSampleCount = other.fMaxSampleCount;
 
     memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
+    memcpy(fCompressedFormatSupport, other.fCompressedFormatSupport,
+          sizeof(fCompressedFormatSupport));
 
     return *this;
 }
@@ -1129,5 +1132,22 @@ SkString GrDrawTargetCaps::dump() const {
                      gNY[fConfigRenderSupport[i][1]]);
         }
     }
+
+    static const char* kCompressedFormatNames[] = {
+        "ETC1",  // kETC1_GrCompressedFormat
+        "ETC2",  // kETC2_GrCompressedFormat,
+        "DXT1",  // kDXT1_GrCompressedFormat,
+    };
+    GR_STATIC_ASSERT(0 == kETC1_GrCompressedFormat);
+    GR_STATIC_ASSERT(1 == kETC2_GrCompressedFormat);
+    GR_STATIC_ASSERT(2 == kDXT1_GrCompressedFormat);
+    GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCompressedFormatNames) == kGrCompressedFormatCount);
+
+    for (size_t i = 0; i < SK_ARRAY_COUNT(kCompressedFormatNames); ++i) {
+        r.appendf("%s Compressed Texture Support: %s\n",
+                 kCompressedFormatNames[i],
+                 gNY[fCompressedFormatSupport[i]]);
+    }
+
     return r;
 }
index 648b5c36be15a523b96e47fc7c18d487715fb0c8..db2b090512c4cd2b3ad4f57619e6967e973126f5 100644 (file)
@@ -72,6 +72,11 @@ public:
         return fConfigRenderSupport[config][withMSAA];
     }
 
+    bool compressedTextureSupport(GrCompressedFormat format) const {
+        SkASSERT(kGrCompressedFormatCount > format);
+        return fCompressedFormatSupport[format];
+    }
+
 protected:
     bool f8BitPaletteSupport        : 1;
     bool fNPOTTextureTileSupport    : 1;
@@ -97,6 +102,8 @@ protected:
     // The first entry for each config is without msaa and the second is with.
     bool fConfigRenderSupport[kGrPixelConfigCnt][2];
 
+    bool fCompressedFormatSupport[kGrCompressedFormatCount];
+
     typedef SkRefCnt INHERITED;
 };
 
index f577e9d740398dc5ca53fec9379b2e7266f544db..6523e032335f30925587a34e51a6cbe868283f50 100644 (file)
@@ -369,6 +369,8 @@ bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
 
     this->initConfigRenderableTable(ctxInfo);
 
+    this->initCompressedTextureSupport(ctxInfo);
+
     return true;
 }
 
@@ -458,6 +460,38 @@ void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
     }
 }
 
+void GrGLCaps::initCompressedTextureSupport(const GrGLContextInfo &ctxInfo) {
+    GrGLStandard standard = ctxInfo.standard();
+    GrGLVersion version = ctxInfo.version();
+
+    // glCompressedTexImage2D is available on all OpenGL ES devices...
+    // however, it is only available on standard OpenGL after version 1.3
+    if (kGL_GrGLStandard == standard && version < GR_GL_VER(1, 3)) {
+        return;
+    }
+
+    // Check for ETC1
+    bool hasETC1 = false;
+
+    // First check version for support
+    if (kGL_GrGLStandard == standard) {
+        hasETC1 =
+            version >= GR_GL_VER(4, 3) ||
+            ctxInfo.hasExtension("GL_ARB_ES3_compatibility");
+    } else {
+        hasETC1 =
+            version >= GR_GL_VER(3, 0) ||
+            ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
+            // ETC2 is a superset of ETC1, so we can just check for that, too.
+            (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
+             ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"));
+    }
+    fCompressedFormatSupport[kETC1_GrCompressedFormat] = hasETC1;
+
+    fCompressedFormatSupport[kETC2_GrCompressedFormat] = false;
+    fCompressedFormatSupport[kDXT1_GrCompressedFormat] = false;
+}
+
 bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
                                    GrGLenum format,
                                    GrGLenum type) const {
index ea0f41245d20bedea2d4a0fa76f95510a09a024e..c2d808e4a54bdb63ba5544cdc6a5f2f481f60b1a 100644 (file)
@@ -313,6 +313,8 @@ private:
     // This must be called after initFSAASupport().
     void initConfigRenderableTable(const GrGLContextInfo&);
 
+    void initCompressedTextureSupport(const GrGLContextInfo &);
+
     // tracks configs that have been verified to pass the FBO completeness when
     // used as a color attachment
     VerifiedColorConfigs fVerifiedColorConfigs;