Index: src/gpu/GrSWMaskHelper.cpp |
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp |
index 744fa1db8ffff2b192d63a2134927630cbed18a0..5a025959841f25ea71c3c3057cab33dd98114bca 100644 |
--- a/src/gpu/GrSWMaskHelper.cpp |
+++ b/src/gpu/GrSWMaskHelper.cpp |
@@ -85,6 +85,13 @@ static bool choose_compressed_fmt(const GrDrawTargetCaps* caps, |
} |
+GrSWMaskHelper::~GrSWMaskHelper() { |
+ if (NULL != fCompressedBuffer) { |
reed1
2014/08/06 20:56:03
1. can just call sk_free() w/o checking
2. don't n
krajcevski
2014/08/06 22:42:00
Done.
|
+ sk_free(fCompressedBuffer); |
+ fCompressedBuffer = NULL; |
+ } |
+} |
+ |
/** |
* Draw a single rect element of the clip stack into the accumulation bitmap |
*/ |
@@ -125,13 +132,20 @@ void GrSWMaskHelper::draw(const SkPath& path, const SkStrokeRec& stroke, SkRegio |
} |
paint.setAntiAlias(antiAlias); |
+ SkTBlitterAllocator allocator; |
+ SkBlitter* blitter = NULL; |
+ if (kBlitter_CompressionMode == fCompressionMode) { |
+ blitter = SkTextureCompressor::CreateBlitterForFormat( |
+ fBM.width(), fBM.height(), fCompressedBuffer, &allocator, fCompressedFormat); |
+ } |
+ |
if (SkRegion::kReplace_Op == op && 0xFF == alpha) { |
SkASSERT(0xFF == paint.getAlpha()); |
- fDraw.drawPathCoverage(path, paint); |
+ fDraw.drawPathCoverage(path, paint, blitter); |
} else { |
paint.setXfermodeMode(op_to_mode(op)); |
paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); |
- fDraw.drawPath(path, paint); |
+ fDraw.drawPath(path, paint, blitter); |
} |
} |
@@ -150,31 +164,48 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds, |
resultBounds.height()); |
#if GR_COMPRESS_ALPHA_MASK |
- fCompressMask = choose_compressed_fmt(fContext->getGpu()->caps(), &fCompressedFormat); |
-#else |
- fCompressMask = false; |
+ if (choose_compressed_fmt(fContext->getGpu()->caps(), &fCompressedFormat)) { |
+ fCompressionMode = kCompress_CompressionMode; |
+ } |
#endif |
// 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. |
- int cmpWidth, cmpHeight; |
- if (fCompressMask) { |
+ int cmpWidth = bounds.fRight; |
+ int cmpHeight = bounds.fBottom; |
+ if (kCompress_CompressionMode == fCompressionMode) { |
int dimX, dimY; |
SkTextureCompressor::GetBlockDimensions(fCompressedFormat, &dimX, &dimY); |
- cmpWidth = dimX * ((bounds.fRight + (dimX - 1)) / dimX); |
- cmpHeight = dimY * ((bounds.fBottom + (dimY - 1)) / dimY); |
- } else { |
- cmpWidth = bounds.fRight; |
- cmpHeight = bounds.fBottom; |
- } |
+ cmpWidth = dimX * ((cmpWidth + (dimX - 1)) / dimX); |
+ cmpHeight = dimY * ((cmpHeight + (dimY - 1)) / dimY); |
- if (!fBM.allocPixels(SkImageInfo::MakeA8(cmpWidth, cmpHeight))) { |
- return false; |
- } |
+ // Can we create a blitter? |
+ if (SkTextureCompressor::ExistsBlitterForFormat(fCompressedFormat)) { |
+ int cmpSz = SkTextureCompressor::GetCompressedDataSize( |
+ fCompressedFormat, cmpWidth, cmpHeight); |
- sk_bzero(fBM.getPixels(), fBM.getSafeSize()); |
+ SkASSERT(cmpSz > 0); |
+ fCompressedBuffer = sk_malloc_throw(cmpSz); |
+ fCompressionMode = kBlitter_CompressionMode; |
+ } |
+ } |
+ |
+ // If we don't have a custom blitter, then we need a bitmap |
+ // to compress into. |
+ const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(cmpWidth, cmpHeight); |
+ if (kBlitter_CompressionMode != fCompressionMode) { |
+ if (!fBM.allocPixels(bmImageInfo)) { |
+ return false; |
+ } |
+ |
+ sk_bzero(fBM.getPixels(), fBM.getSafeSize()); |
+ } else { |
+ // Otherwise, we just need to remember how big the buffer is... |
+ fBM.setInfo(bmImageInfo); |
+ } |
sk_bzero(&fDraw, sizeof(fDraw)); |
+ |
fRasterClip.setRect(bounds); |
fDraw.fRC = &fRasterClip; |
fDraw.fClip = &fRasterClip.bwRgn(); |
@@ -193,7 +224,7 @@ bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) { |
desc.fHeight = fBM.height(); |
desc.fConfig = kAlpha_8_GrPixelConfig; |
- if (fCompressMask) { |
+ if (kNone_CompressionMode != fCompressionMode) { |
#ifdef SK_DEBUG |
int dimX, dimY; |
@@ -203,12 +234,7 @@ bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) { |
#endif |
desc.fConfig = fmt_to_config(fCompressedFormat); |
- |
- // If this config isn't supported then we should fall back to A8 |
- if (!(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig))) { |
- SkDEBUGFAIL("Determining compression should be set from choose_compressed_fmt"); |
- desc.fConfig = kAlpha_8_GrPixelConfig; |
- } |
+ SkASSERT(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig)); |
} |
texture->set(fContext, desc); |
@@ -253,11 +279,18 @@ void GrSWMaskHelper::toTexture(GrTexture *texture) { |
desc.fConfig = texture->config(); |
// First see if we should compress this texture before uploading. |
- if (fCompressMask) { |
- this->compressTextureData(texture, desc); |
- } else { |
- // Looks like we have to send a full A8 texture. |
- this->sendTextureData(texture, desc, fBM.getPixels(), fBM.rowBytes()); |
+ switch (fCompressionMode) { |
+ case kNone_CompressionMode: |
+ this->sendTextureData(texture, desc, fBM.getPixels(), fBM.rowBytes()); |
+ break; |
+ |
+ case kCompress_CompressionMode: |
+ this->compressTextureData(texture, desc); |
+ break; |
+ |
+ case kBlitter_CompressionMode: |
+ SkASSERT(NULL != fCompressedBuffer); |
+ this->sendTextureData(texture, desc, fCompressedBuffer, 0); |
} |
} |