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

Unified Diff: src/core/SkPaint.cpp

Issue 258883002: Gamma correction for distance field text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Don't use SkPaint distance field flag for filtering the ScalarContext::Rec; add getGammaLUT* commen… 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
Index: src/core/SkPaint.cpp
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index f3bf01bfafc5ca30e0507190a8ffee37f8a5efaa..1e68e96f8e13bb92f974a94c7db225d82aa0a7bf 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -1819,10 +1819,8 @@ void SkScalerContext::PostMakeRec(const SkPaint&, SkScalerContext::Rec* rec) {
/*
* ignoreGamma tells us that the caller just wants metrics that are unaffected
- * by gamma correction, so we jam the luminance field to 0 (most common value
- * for black text) in hopes that we get a cache hit easier. A better solution
- * would be for the fontcache lookup to know to ignore the luminance field
- * entirely, but not sure how to do that and keep it fast.
+ * by gamma correction, so we set the rec to ignore preblend: i.e. gamma = 1,
+ * contrast = 0, luminanceColor = transparent black.
*/
void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties,
const SkMatrix* deviceMatrix,
@@ -1832,7 +1830,7 @@ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties,
SkScalerContext::MakeRec(*this, deviceProperties, deviceMatrix, &rec);
if (ignoreGamma) {
- rec.setLuminanceColor(0);
+ rec.ignorePreBlend();
}
size_t descSize = sizeof(rec);
@@ -1956,9 +1954,10 @@ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties,
}
SkGlyphCache* SkPaint::detachCache(const SkDeviceProperties* deviceProperties,
- const SkMatrix* deviceMatrix) const {
+ const SkMatrix* deviceMatrix,
+ bool ignoreGamma) const {
SkGlyphCache* cache;
- this->descriptorProc(deviceProperties, deviceMatrix, DetachDescProc, &cache, false);
+ this->descriptorProc(deviceProperties, deviceMatrix, DetachDescProc, &cache, ignoreGamma);
return cache;
}
@@ -1974,6 +1973,33 @@ SkMaskGamma::PreBlend SkScalerContext::GetMaskPreBlend(const SkScalerContext::Re
return maskGamma.preBlend(rec.getLuminanceColor());
}
+size_t SkScalerContext::getGammaLUTSize(SkScalar contrast, SkScalar paintGamma,
+ SkScalar deviceGamma, int* width, int* height) {
+ SkAutoMutexAcquire ama(gMaskGammaCacheMutex);
+ const SkMaskGamma& maskGamma = cachedMaskGamma(contrast,
+ paintGamma,
+ deviceGamma);
+
+ maskGamma.getGammaTableDimensions(width, height);
+ size_t size = (*width)*(*height)*sizeof(uint8_t);
+
+ return size;
+}
+
+void SkScalerContext::getGammaLUTData(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma,
+ void* data) {
+ SkAutoMutexAcquire ama(gMaskGammaCacheMutex);
+ const SkMaskGamma& maskGamma = cachedMaskGamma(contrast,
+ paintGamma,
+ deviceGamma);
+ int width, height;
+ maskGamma.getGammaTableDimensions(&width, &height);
+ size_t size = width*height*sizeof(uint8_t);
+ const uint8_t* gammaTables = maskGamma.getGammaTables();
+ memcpy(data, gammaTables, size);
+}
+
+
///////////////////////////////////////////////////////////////////////////////
#include "SkStream.h"
@@ -2562,7 +2588,7 @@ SkTextToPathIter::SkTextToPathIter( const char text[], size_t length,
fPaint.setPathEffect(NULL);
}
- fCache = fPaint.detachCache(NULL, NULL);
+ fCache = fPaint.detachCache(NULL, NULL, false);
SkPaint::Style style = SkPaint::kFill_Style;
SkPathEffect* pe = NULL;
« no previous file with comments | « src/core/SkMaskGamma.h ('k') | src/core/SkScalerContext.h » ('j') | src/core/SkScalerContext.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698