Chromium Code Reviews| Index: src/gpu/GrSWMaskHelper.cpp |
| diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp |
| index 697500f329dda0b641a300c7e46213bc50a57288..0ae63d85277c9aa98f65936a5a81a460ab1b6a46 100644 |
| --- a/src/gpu/GrSWMaskHelper.cpp |
| +++ b/src/gpu/GrSWMaskHelper.cpp |
| @@ -125,26 +125,37 @@ bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) { |
| GrTextureDesc desc; |
| desc.fWidth = fBM.width(); |
| desc.fHeight = fBM.height(); |
| - desc.fConfig = kAlpha_8_GrPixelConfig; |
| + |
| + static const int kLATCBlockSize = 4; |
|
robertphillips
2014/06/12 14:43:33
1 line for this?
Don't we also need to guard this
krajcevski
2014/06/12 15:13:32
Done.
|
| + if (desc.fWidth % kLATCBlockSize == 0 && |
| + desc.fHeight % kLATCBlockSize == 0) { |
| + desc.fConfig = kLATC_GrPixelConfig; |
| + } else { |
| + desc.fConfig = kAlpha_8_GrPixelConfig; |
| + } |
| texture->set(fContext, desc); |
| return NULL != texture->texture(); |
| } |
|
robertphillips
2014/06/12 14:43:33
I don't know if it would be worth it but it looks
krajcevski
2014/06/12 15:13:32
Done.
|
| -GrTexture* GrSWMaskHelper::toLATCTexture(GrContext* ctx) { |
| +void GrSWMaskHelper::toLATCTexture(GrTexture* texture) { |
| // Encode the BM into LATC data: |
| SkAutoLockPixels alp(fBM); |
| SkTextureCompressor::Format format = SkTextureCompressor::kLATC_Format; |
| SkAutoDataUnref latcData(SkTextureCompressor::CompressBitmapToFormat(fBM, format)); |
| - if (NULL == latcData) { |
| - return NULL; |
| - } |
| + SkASSERT(NULL != latcData); |
| - GrTextureDesc desc; |
| - desc.fWidth = fBM.width(); |
| - desc.fHeight = fBM.height(); |
| - desc.fConfig = kLATC_GrPixelConfig; |
| - return ctx->getGpu()->createTexture(desc, latcData->bytes(), 0); |
| + // If we aren't reusing scratch textures we don't need to flush before |
| + // writing since no one else will be using 'texture' |
| + bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures(); |
| + |
| + // Since we're uploading to it, and it's compressed, 'texture' shouldn't |
| + // have a render target. |
| + SkASSERT(NULL == texture->asRenderTarget()); |
| + |
| + texture->writePixels(0, 0, fBM.width(), fBM.height(), |
| + kLATC_GrPixelConfig, latcData->bytes(), 0, |
| + reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag); |
| } |
| /** |
| @@ -153,6 +164,16 @@ GrTexture* GrSWMaskHelper::toLATCTexture(GrContext* ctx) { |
| void GrSWMaskHelper::toTexture(GrTexture *texture) { |
|
robertphillips
2014/06/12 14:43:33
toLATCTexture has its own alp - move this one down
krajcevski
2014/06/12 15:13:32
Done.
|
| SkAutoLockPixels alp(fBM); |
| +#if GR_COMPRESS_ALPHA_MASK |
| + // First see if we should compress this texture before uploading. |
| + if (texture->config() == kLATC_GrPixelConfig) { |
| + this->toLATCTexture(texture); |
| + return; |
| + } |
| +#endif |
| + |
| + // Looks like we have to send a full A8 texture. |
| + |
| // If we aren't reusing scratch textures we don't need to flush before |
| // writing since no one else will be using 'texture' |
| bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures(); |
| @@ -186,15 +207,6 @@ GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, |
| helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); |
| -#if GR_COMPRESS_ALPHA_MASK |
| - // Can we create an LATC texture? |
| - GrTexture *latc = helper.toLATCTexture(context); |
| - if (NULL != latc) { |
| - return latc; |
| - } |
| -#endif |
| - |
| - // Looks like we have to send a full A8 texture. |
| GrAutoScratchTexture ast; |
| if (!helper.getTexture(&ast)) { |
| return NULL; |