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

Unified Diff: src/gpu/GrSWMaskHelper.cpp

Issue 398603004: Generalize mask helper a bit for compression (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clarity in organization Created 6 years, 5 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 15b5457cccc28e35f91a0a6dac6ab23bc22d7d15..547a05e79be8388df9d3811a470b01b3faa4de40 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -102,10 +102,20 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds,
-resultBounds.fTop * SK_Scalar1);
SkIRect bounds = SkIRect::MakeWH(resultBounds.width(),
resultBounds.height());
+#if GR_COMPRESS_ALPHA_MASK
+ // 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.
+ const int cmpWidth = (bounds.fRight + 15) & ~15;
+ const int cmpHeight = (bounds.fBottom + 3) & ~3;
+#else
+ const int cmpWidth = bounds.fRight;
+ const int cmpHeight = bounds.fBottom;
+#endif
- if (!fBM.allocPixels(SkImageInfo::MakeA8(bounds.fRight, bounds.fBottom))) {
+ if (!fBM.allocPixels(SkImageInfo::MakeA8(cmpWidth, cmpHeight))) {
return false;
}
+
sk_bzero(fBM.getPixels(), fBM.getSafeSize());
sk_bzero(&fDraw, sizeof(fDraw));
@@ -125,15 +135,20 @@ 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
+ static const int kCompressedBlockSize = 4;
+ static const GrPixelConfig kCompressedConfig = kR11_EAC_GrPixelConfig;
+
+ if (desc.fWidth % kCompressedBlockSize == 0 &&
+ desc.fHeight % kCompressedBlockSize == 0) {
+ desc.fConfig = kCompressedConfig;
+ }
+
+ // If this config isn't supported then we should fall back to A8
+ if (!(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig))) {
desc.fConfig = kAlpha_8_GrPixelConfig;
-#if GR_COMPRESS_ALPHA_MASK
}
#endif
@@ -156,6 +171,31 @@ void GrSWMaskHelper::sendTextureData(GrTexture *texture, const GrTextureDesc& de
reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag);
}
+void GrSWMaskHelper::compressTextureData(GrTexture *texture, const GrTextureDesc& desc) {
+
+ SkASSERT(GrPixelConfigIsCompressed(desc.fConfig));
+
+ SkTextureCompressor::Format format = SkTextureCompressor::kLATC_Format;
+
+ // 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);
+
+ this->sendTextureData(texture, desc, cmpData->data(), 0);
+}
+
/**
* Move the result of the software mask generation back to the gpu
*/
@@ -168,12 +208,8 @@ void GrSWMaskHelper::toTexture(GrTexture *texture) {
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);
+ if (GrPixelConfigIsCompressed(texture->config())) {
+ this->compressTextureData(texture, desc);
} else {
// Looks like we have to send a full A8 texture.
this->sendTextureData(texture, desc, fBM.getPixels(), fBM.rowBytes());
« 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