Start the process of choosing the correct compression format

R=robertphillips@google.com

Author: krajcevski@google.com

Review URL: https://codereview.chromium.org/427093004
This commit is contained in:
krajcevski 2014-07-30 13:08:11 -07:00 committed by Commit bot
parent e83909f76c
commit b3abe90145
3 changed files with 71 additions and 46 deletions

View File

@ -50,6 +50,37 @@ static inline GrPixelConfig fmt_to_config(SkTextureCompressor::Format fmt) {
return configMap[fmt]; return configMap[fmt];
} }
#if GR_COMPRESS_ALPHA_MASK
static bool choose_compressed_fmt(const GrDrawTargetCaps* caps,
SkTextureCompressor::Format *fmt) {
if (NULL == fmt) {
return false;
}
// We can't use scratch textures without the ability to update
// compressed textures...
if (!(caps->compressedTexSubImageSupport())) {
return false;
}
// Figure out what our preferred texture type is. If ASTC is available, that always
// gives the biggest win. Otherwise, in terms of compression speed and accuracy,
// LATC has a slight edge over R11 EAC.
if (caps->isConfigTexturable(kASTC_12x12_GrPixelConfig)) {
*fmt = SkTextureCompressor::kASTC_12x12_Format;
return true;
} else if (caps->isConfigTexturable(kLATC_GrPixelConfig)) {
*fmt = SkTextureCompressor::kLATC_Format;
return true;
} else if (caps->isConfigTexturable(kR11_EAC_GrPixelConfig)) {
*fmt = SkTextureCompressor::kR11_EAC_Format;
return true;
}
return false;
}
#endif
} }
/** /**
@ -117,18 +148,23 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds,
resultBounds.height()); resultBounds.height());
#if GR_COMPRESS_ALPHA_MASK #if GR_COMPRESS_ALPHA_MASK
fCompressedFormat = SkTextureCompressor::kR11_EAC_Format; fCompressMask = choose_compressed_fmt(fContext->getGpu()->caps(), &fCompressedFormat);
#else
fCompressMask = false;
#endif
// Make sure that the width is a multiple of 16 so that we can use // Make sure that the width is a multiple of 16 so that we can use
// specialized SIMD instructions that compress 4 blocks at a time. // specialized SIMD instructions that compress 4 blocks at a time.
int cmpWidth, cmpHeight;
if (fCompressMask) {
int dimX, dimY; int dimX, dimY;
SkTextureCompressor::GetBlockDimensions(fCompressedFormat, &dimX, &dimY); SkTextureCompressor::GetBlockDimensions(fCompressedFormat, &dimX, &dimY);
const int cmpWidth = dimX * ((bounds.fRight + (dimX - 1)) / dimX); cmpWidth = dimX * ((bounds.fRight + (dimX - 1)) / dimX);
const int cmpHeight = dimY * ((bounds.fBottom + (dimY - 1)) / dimY); cmpHeight = dimY * ((bounds.fBottom + (dimY - 1)) / dimY);
#else } else {
const int cmpWidth = bounds.fRight; cmpWidth = bounds.fRight;
const int cmpHeight = bounds.fBottom; cmpHeight = bounds.fBottom;
#endif }
if (!fBM.allocPixels(SkImageInfo::MakeA8(cmpWidth, cmpHeight))) { if (!fBM.allocPixels(SkImageInfo::MakeA8(cmpWidth, cmpHeight))) {
return false; return false;
@ -153,8 +189,9 @@ bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) {
GrTextureDesc desc; GrTextureDesc desc;
desc.fWidth = fBM.width(); desc.fWidth = fBM.width();
desc.fHeight = fBM.height(); desc.fHeight = fBM.height();
desc.fConfig = kAlpha_8_GrPixelConfig;
#if GR_COMPRESS_ALPHA_MASK if (fCompressMask) {
#ifdef SK_DEBUG #ifdef SK_DEBUG
int dimX, dimY; int dimX, dimY;
@ -167,11 +204,10 @@ bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) {
// If this config isn't supported then we should fall back to A8 // If this config isn't supported then we should fall back to A8
if (!(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig))) { if (!(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig))) {
SkDEBUGFAIL("Determining compression should be set from choose_compressed_fmt");
desc.fConfig = kAlpha_8_GrPixelConfig; desc.fConfig = kAlpha_8_GrPixelConfig;
} }
#else }
desc.fConfig = kAlpha_8_GrPixelConfig;
#endif
texture->set(fContext, desc); texture->set(fContext, desc);
return NULL != texture->texture(); return NULL != texture->texture();
@ -195,23 +231,9 @@ void GrSWMaskHelper::sendTextureData(GrTexture *texture, const GrTextureDesc& de
void GrSWMaskHelper::compressTextureData(GrTexture *texture, const GrTextureDesc& desc) { void GrSWMaskHelper::compressTextureData(GrTexture *texture, const GrTextureDesc& desc) {
SkASSERT(GrPixelConfigIsCompressed(desc.fConfig)); SkASSERT(GrPixelConfigIsCompressed(desc.fConfig));
SkASSERT(fmt_to_config(fCompressedFormat) == desc.fConfig);
SkTextureCompressor::Format format = SkTextureCompressor::kLATC_Format; SkAutoDataUnref cmpData(SkTextureCompressor::CompressBitmapToFormat(fBM, fCompressedFormat));
// Choose the format required by the texture descriptor.
switch(desc.fConfig) {
case kLATC_GrPixelConfig:
format = SkTextureCompressor::kLATC_Format;
break;
case kR11_EAC_GrPixelConfig:
format = SkTextureCompressor::kR11_EAC_Format;
break;
default:
SkFAIL("Unrecognized texture compression format.");
break;
}
SkAutoDataUnref cmpData(SkTextureCompressor::CompressBitmapToFormat(fBM, format));
SkASSERT(NULL != cmpData); SkASSERT(NULL != cmpData);
this->sendTextureData(texture, desc, cmpData->data(), 0); this->sendTextureData(texture, desc, cmpData->data(), 0);
@ -229,7 +251,7 @@ void GrSWMaskHelper::toTexture(GrTexture *texture) {
desc.fConfig = texture->config(); desc.fConfig = texture->config();
// First see if we should compress this texture before uploading. // First see if we should compress this texture before uploading.
if (GrPixelConfigIsCompressed(texture->config())) { if (fCompressMask) {
this->compressTextureData(texture, desc); this->compressTextureData(texture, desc);
} else { } else {
// Looks like we have to send a full A8 texture. // Looks like we have to send a full A8 texture.

View File

@ -42,7 +42,7 @@ class GrDrawTarget;
class GrSWMaskHelper : SkNoncopyable { class GrSWMaskHelper : SkNoncopyable {
public: public:
GrSWMaskHelper(GrContext* context) GrSWMaskHelper(GrContext* context)
: fContext(context) { : fContext(context), fCompressMask(false) {
} }
// set up the internal state in preparation for draws. Since many masks // set up the internal state in preparation for draws. Since many masks
@ -102,9 +102,13 @@ private:
SkDraw fDraw; SkDraw fDraw;
SkRasterClip fRasterClip; SkRasterClip fRasterClip;
#if GR_COMPRESS_ALPHA_MASK // This flag says whether or not we should compress the mask. If
// it is true, then fCompressedFormat is always valid.
bool fCompressMask;
// This is the desired format within which to compress the
// texture. This value is only valid if fCompressMask is true.
SkTextureCompressor::Format fCompressedFormat; SkTextureCompressor::Format fCompressedFormat;
#endif
// Actually sends the texture data to the GPU. This is called from // Actually sends the texture data to the GPU. This is called from
// toTexture with the data filled in depending on the texture config. // toTexture with the data filled in depending on the texture config.

View File

@ -558,11 +558,10 @@ void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const G
fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC; fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
fLATCAlias = alias; fLATCAlias = alias;
// Check for R11_EAC // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
if (kGL_GrGLStandard == standard) { // cards default to decompressing the textures in the driver, and is
fConfigTextureSupport[kR11_EAC_GrPixelConfig] = // generally slower.
version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility"); if (kGL_GrGLStandard != standard) {
} else {
fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0); fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
} }