Future proof luminance caches.

https://codereview.appspot.com/6495071/


git-svn-id: http://skia.googlecode.com/svn/trunk@5382 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bungeman@google.com 2012-09-04 13:49:59 +00:00
parent 6806bdaca8
commit b24b4fa12b
3 changed files with 37 additions and 14 deletions

View File

@ -951,12 +951,15 @@ private:
void (*proc)(const SkDescriptor*, void*),
void* context, bool ignoreGamma = false) const;
static void Term();
enum {
kCanonicalTextSizeForPaths = 64
};
friend class SkAutoGlyphCache;
friend class SkCanvas;
friend class SkDraw;
friend class SkGraphics; // So Term() can be called.
friend class SkPDFDevice;
friend class SkTextToPathIter;

View File

@ -122,6 +122,7 @@ void SkGraphics::Init() {
void SkGraphics::Term() {
PurgeFontCache();
SkPaint::Term();
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -1621,51 +1621,53 @@ void SkScalerContext::MakeRec(const SkPaint& paint,
*/
SK_DECLARE_STATIC_MUTEX(gMaskGammaCacheMutex);
static SkColorSpaceLuminance* gDeviceLuminance = NULL;
static SkScalar gDeviceGammaExponent = SK_ScalarMin;
/**
* The caller must hold the gMaskGammaCacheMutex and continue to hold it until
* the returned SkColorSpaceLuminance pointer is refed or forgotten.
* the returned SkColorSpaceLuminance pointer is forgotten.
*/
static SkColorSpaceLuminance* cachedDeviceLuminance(SkScalar gammaExponent) {
static SkColorSpaceLuminance* gDeviceLuminance = NULL;
static SkScalar gGammaExponent = SK_ScalarMin;
if (gGammaExponent != gammaExponent) {
if (gDeviceGammaExponent != gammaExponent) {
SkDELETE(gDeviceLuminance);
if (0 == gammaExponent) {
gDeviceLuminance = SkNEW(SkSRGBLuminance);
} else {
gDeviceLuminance = SkNEW_ARGS(SkGammaLuminance, (gammaExponent));
}
gGammaExponent = gammaExponent;
gDeviceGammaExponent = gammaExponent;
}
return gDeviceLuminance;
}
static SkColorSpaceLuminance* gPaintLuminance = NULL;
static SkScalar gPaintGammaExponent = SK_ScalarMin;
/**
* The caller must hold the gMaskGammaCacheMutex and continue to hold it until
* the returned SkColorSpaceLuminance pointer is refed or forgotten.
* the returned SkColorSpaceLuminance pointer is forgotten.
*/
static SkColorSpaceLuminance* cachedPaintLuminance(SkScalar gammaExponent) {
static SkColorSpaceLuminance* gPaintLuminance = NULL;
static SkScalar gGammaExponent = SK_ScalarMin;
if (gGammaExponent != gammaExponent) {
if (gPaintGammaExponent != gammaExponent) {
SkDELETE(gPaintLuminance);
if (0 == gammaExponent) {
gPaintLuminance = SkNEW(SkSRGBLuminance);
} else {
gPaintLuminance = SkNEW_ARGS(SkGammaLuminance, (gammaExponent));
}
gGammaExponent = gammaExponent;
gPaintGammaExponent = gammaExponent;
}
return gPaintLuminance;
}
static SkMaskGamma* gMaskGamma = NULL;
static SkScalar gContrast = SK_ScalarMin;
static SkScalar gPaintGamma = SK_ScalarMin;
static SkScalar gDeviceGamma = SK_ScalarMin;
/**
* The caller must hold the gMaskGammaCacheMutex and continue to hold it until
* the returned SkMaskGamma pointer is refed or forgotten.
*/
static SkMaskGamma* cachedMaskGamma(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma) {
static SkMaskGamma* gMaskGamma = NULL;
static SkScalar gContrast = SK_ScalarMin;
static SkScalar gPaintGamma = SK_ScalarMin;
static SkScalar gDeviceGamma = SK_ScalarMin;
if (gContrast != contrast || gPaintGamma != paintGamma || gDeviceGamma != deviceGamma) {
SkSafeUnref(gMaskGamma);
SkColorSpaceLuminance* paintLuminance = cachedPaintLuminance(paintGamma);
@ -1678,6 +1680,23 @@ static SkMaskGamma* cachedMaskGamma(SkScalar contrast, SkScalar paintGamma, SkSc
return gMaskGamma;
}
/*static*/ void SkPaint::Term() {
SkAutoMutexAcquire ama(gMaskGammaCacheMutex);
SkSafeUnref(gMaskGamma);
SkDEBUGCODE(gContrast = SK_ScalarMin;)
SkDEBUGCODE(gPaintGamma = SK_ScalarMin;)
SkDEBUGCODE(gDeviceGamma = SK_ScalarMin;)
SkDELETE(gPaintLuminance);
SkDEBUGCODE(gPaintLuminance = NULL;)
SkDEBUGCODE(gPaintGammaExponent = SK_ScalarMin;)
SkDELETE(gDeviceLuminance);
SkDEBUGCODE(gDeviceLuminance = NULL;)
SkDEBUGCODE(gDeviceGammaExponent = SK_ScalarMin;)
}
/**
* We ensure that the rec is self-consistent and efficient (where possible)
*/