Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Unified Diff: src/gpu/GrSWMaskHelper.cpp

Issue 330593004: Use scratch with LATC data if possible (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrSWMaskHelper.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « src/gpu/GrSWMaskHelper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698