diff options
-rw-r--r-- | include/gpu/GrTypes.h | 13 | ||||
-rw-r--r-- | src/gpu/GrDrawTarget.cpp | 16 | ||||
-rw-r--r-- | src/gpu/GrDrawTargetCaps.h | 7 | ||||
-rw-r--r-- | src/gpu/gl/GrGLCaps.cpp | 31 | ||||
-rw-r--r-- | src/gpu/gl/GrGLCaps.h | 2 |
5 files changed, 69 insertions, 0 deletions
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h index c1b3554c6e..67c8f87e76 100644 --- a/include/gpu/GrTypes.h +++ b/include/gpu/GrTypes.h @@ -620,6 +620,19 @@ enum GrGLBackendState { }; /** + * The compressed texture formats that may be supported by the renderer. + * Make sure to check for the required capabilities using + * GrDrawTargetCaps::compressedTextureSupport + */ +enum GrCompressedFormat { + kUncompressed_GrCompressedFormat = -1, + kETC1_GrCompressedFormat = 0, + + kLast_GrCompressedFormat = kETC1_GrCompressedFormat +}; +static const size_t kCompressedFormatCount = kLast_GrCompressedFormat + 1; + +/** * This value translates to reseting all the context state for any backend. */ static const uint32_t kAll_GrBackendState = 0xffffffff; diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp index 6d8d18463a..b97aa8901a 100644 --- a/src/gpu/GrDrawTarget.cpp +++ b/src/gpu/GrDrawTarget.cpp @@ -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,18 @@ SkString GrDrawTargetCaps::dump() const { gNY[fConfigRenderSupport[i][1]]); } } + + static const char* kCompressedFormatNames[] = { + "ETC1", // kETC1_GrCompressedFormat + }; + GR_STATIC_ASSERT(0 == kETC1_GrCompressedFormat); + GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCompressedFormatNames) == kCompressedFormatCount); + + for (size_t i = 0; i < kCompressedFormatCount; ++i) { + r.appendf("%s Compressed Texture Support: %s\n", + kCompressedFormatNames[i], + gNY[fCompressedFormatSupport[i]]); + } + return r; } diff --git a/src/gpu/GrDrawTargetCaps.h b/src/gpu/GrDrawTargetCaps.h index 648b5c36be..681327cdc7 100644 --- a/src/gpu/GrDrawTargetCaps.h +++ b/src/gpu/GrDrawTargetCaps.h @@ -72,6 +72,11 @@ public: return fConfigRenderSupport[config][withMSAA]; } + bool compressedTextureSupport(GrCompressedFormat format) const { + SkASSERT(format < kCompressedFormatCount); + 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[kCompressedFormatCount]; + typedef SkRefCnt INHERITED; }; diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index f577e9d740..0117a3a83f 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -369,6 +369,8 @@ bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { this->initConfigRenderableTable(ctxInfo); + this->initCompressedTextureSupport(ctxInfo); + return true; } @@ -458,6 +460,35 @@ 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; +} + bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf, GrGLenum format, GrGLenum type) const { diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h index ea0f41245d..c2d808e4a5 100644 --- a/src/gpu/gl/GrGLCaps.h +++ b/src/gpu/gl/GrGLCaps.h @@ -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; |