aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar krajcevski <krajcevski@google.com>2014-06-12 09:20:38 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-06-12 09:20:38 -0700
commitfb4f5cb39e31b8544b526074683a65bb716b7acf (patch)
treec8418b5711e3b6b6d826d769d836813fe80b1b72 /src
parentda4ed3289ec05a7155d5669c90a743a829574ea6 (diff)
Use scratch with LATC data if possible
R=robertphillips@google.com Author: krajcevski@google.com Review URL: https://codereview.chromium.org/330593004
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrSWMaskHelper.cpp73
-rw-r--r--src/gpu/GrSWMaskHelper.h7
2 files changed, 44 insertions, 36 deletions
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index 697500f329..15b5457ccc 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -125,26 +125,35 @@ bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) {
GrTextureDesc desc;
desc.fWidth = fBM.width();
desc.fHeight = fBM.height();
- desc.fConfig = kAlpha_8_GrPixelConfig;
+
+#if GR_COMPRESS_ALPHA_MASK
+ static const int kLATCBlockSize = 4;
+ if (desc.fWidth % kLATCBlockSize == 0 && desc.fHeight % kLATCBlockSize == 0) {
+ desc.fConfig = kLATC_GrPixelConfig;
+ } else {
+#endif
+ desc.fConfig = kAlpha_8_GrPixelConfig;
+#if GR_COMPRESS_ALPHA_MASK
+ }
+#endif
texture->set(fContext, desc);
return NULL != texture->texture();
}
-GrTexture* GrSWMaskHelper::toLATCTexture(GrContext* ctx) {
- // 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;
- }
+void GrSWMaskHelper::sendTextureData(GrTexture *texture, const GrTextureDesc& desc,
+ const void *data, int rowbytes) {
+ // 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();
- GrTextureDesc desc;
- desc.fWidth = fBM.width();
- desc.fHeight = fBM.height();
- desc.fConfig = kLATC_GrPixelConfig;
- return ctx->getGpu()->createTexture(desc, latcData->bytes(), 0);
+ // 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, desc.fWidth, desc.fHeight,
+ desc.fConfig, data, rowbytes,
+ reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag);
}
/**
@@ -153,17 +162,22 @@ GrTexture* GrSWMaskHelper::toLATCTexture(GrContext* ctx) {
void GrSWMaskHelper::toTexture(GrTexture *texture) {
SkAutoLockPixels alp(fBM);
- // 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, 'texture' shouldn't have a render target.
- SkASSERT(NULL == texture->asRenderTarget());
-
- texture->writePixels(0, 0, fBM.width(), fBM.height(),
- kAlpha_8_GrPixelConfig,
- fBM.getPixels(), fBM.rowBytes(),
- reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag);
+ GrTextureDesc desc;
+ desc.fWidth = fBM.width();
+ desc.fHeight = fBM.height();
+ desc.fConfig = texture->config();
+
+ // First see if we should compress this texture before uploading.
+ if (texture->config() == kLATC_GrPixelConfig) {
+ SkTextureCompressor::Format format = SkTextureCompressor::kLATC_Format;
+ SkAutoDataUnref latcData(SkTextureCompressor::CompressBitmapToFormat(fBM, format));
+ SkASSERT(NULL != latcData);
+
+ this->sendTextureData(texture, desc, latcData->data(), 0);
+ } else {
+ // Looks like we have to send a full A8 texture.
+ this->sendTextureData(texture, desc, fBM.getPixels(), fBM.rowBytes());
+ }
}
////////////////////////////////////////////////////////////////////////////////
@@ -186,15 +200,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;
diff --git a/src/gpu/GrSWMaskHelper.h b/src/gpu/GrSWMaskHelper.h
index 894f49c9cd..0ffaa64982 100644
--- a/src/gpu/GrSWMaskHelper.h
+++ b/src/gpu/GrSWMaskHelper.h
@@ -65,8 +65,6 @@ public:
// Move the mask generation results from the internal bitmap to the gpu.
void toTexture(GrTexture* texture);
- GrTexture* toLATCTexture(GrContext* ctx);
-
// Reset the internal bitmap
void clear(uint8_t alpha) {
fBM.eraseColor(SkColorSetARGB(alpha, alpha, alpha, alpha));
@@ -103,6 +101,11 @@ private:
SkDraw fDraw;
SkRasterClip fRasterClip;
+ // Actually sends the texture data to the GPU. This is called from
+ // toTexture with the data filled in depending on the texture config.
+ void sendTextureData(GrTexture *texture, const GrTextureDesc& desc,
+ const void *data, int rowbytes);
+
typedef SkNoncopyable INHERITED;
};