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:
parent
6806bdaca8
commit
b24b4fa12b
@ -951,12 +951,15 @@ private:
|
|||||||
void (*proc)(const SkDescriptor*, void*),
|
void (*proc)(const SkDescriptor*, void*),
|
||||||
void* context, bool ignoreGamma = false) const;
|
void* context, bool ignoreGamma = false) const;
|
||||||
|
|
||||||
|
static void Term();
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
kCanonicalTextSizeForPaths = 64
|
kCanonicalTextSizeForPaths = 64
|
||||||
};
|
};
|
||||||
friend class SkAutoGlyphCache;
|
friend class SkAutoGlyphCache;
|
||||||
friend class SkCanvas;
|
friend class SkCanvas;
|
||||||
friend class SkDraw;
|
friend class SkDraw;
|
||||||
|
friend class SkGraphics; // So Term() can be called.
|
||||||
friend class SkPDFDevice;
|
friend class SkPDFDevice;
|
||||||
friend class SkTextToPathIter;
|
friend class SkTextToPathIter;
|
||||||
|
|
||||||
|
@ -122,6 +122,7 @@ void SkGraphics::Init() {
|
|||||||
|
|
||||||
void SkGraphics::Term() {
|
void SkGraphics::Term() {
|
||||||
PurgeFontCache();
|
PurgeFontCache();
|
||||||
|
SkPaint::Term();
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1621,51 +1621,53 @@ void SkScalerContext::MakeRec(const SkPaint& paint,
|
|||||||
*/
|
*/
|
||||||
SK_DECLARE_STATIC_MUTEX(gMaskGammaCacheMutex);
|
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 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* cachedDeviceLuminance(SkScalar gammaExponent) {
|
||||||
static SkColorSpaceLuminance* gDeviceLuminance = NULL;
|
if (gDeviceGammaExponent != gammaExponent) {
|
||||||
static SkScalar gGammaExponent = SK_ScalarMin;
|
SkDELETE(gDeviceLuminance);
|
||||||
if (gGammaExponent != gammaExponent) {
|
|
||||||
if (0 == gammaExponent) {
|
if (0 == gammaExponent) {
|
||||||
gDeviceLuminance = SkNEW(SkSRGBLuminance);
|
gDeviceLuminance = SkNEW(SkSRGBLuminance);
|
||||||
} else {
|
} else {
|
||||||
gDeviceLuminance = SkNEW_ARGS(SkGammaLuminance, (gammaExponent));
|
gDeviceLuminance = SkNEW_ARGS(SkGammaLuminance, (gammaExponent));
|
||||||
}
|
}
|
||||||
gGammaExponent = gammaExponent;
|
gDeviceGammaExponent = gammaExponent;
|
||||||
}
|
}
|
||||||
return gDeviceLuminance;
|
return gDeviceLuminance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SkColorSpaceLuminance* gPaintLuminance = NULL;
|
||||||
|
static SkScalar gPaintGammaExponent = SK_ScalarMin;
|
||||||
/**
|
/**
|
||||||
* The caller must hold the gMaskGammaCacheMutex and continue to hold it until
|
* 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* cachedPaintLuminance(SkScalar gammaExponent) {
|
||||||
static SkColorSpaceLuminance* gPaintLuminance = NULL;
|
if (gPaintGammaExponent != gammaExponent) {
|
||||||
static SkScalar gGammaExponent = SK_ScalarMin;
|
SkDELETE(gPaintLuminance);
|
||||||
if (gGammaExponent != gammaExponent) {
|
|
||||||
if (0 == gammaExponent) {
|
if (0 == gammaExponent) {
|
||||||
gPaintLuminance = SkNEW(SkSRGBLuminance);
|
gPaintLuminance = SkNEW(SkSRGBLuminance);
|
||||||
} else {
|
} else {
|
||||||
gPaintLuminance = SkNEW_ARGS(SkGammaLuminance, (gammaExponent));
|
gPaintLuminance = SkNEW_ARGS(SkGammaLuminance, (gammaExponent));
|
||||||
}
|
}
|
||||||
gGammaExponent = gammaExponent;
|
gPaintGammaExponent = gammaExponent;
|
||||||
}
|
}
|
||||||
return gPaintLuminance;
|
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 caller must hold the gMaskGammaCacheMutex and continue to hold it until
|
||||||
* the returned SkMaskGamma pointer is refed or forgotten.
|
* the returned SkMaskGamma pointer is refed or forgotten.
|
||||||
*/
|
*/
|
||||||
static SkMaskGamma* cachedMaskGamma(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma) {
|
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) {
|
if (gContrast != contrast || gPaintGamma != paintGamma || gDeviceGamma != deviceGamma) {
|
||||||
SkSafeUnref(gMaskGamma);
|
SkSafeUnref(gMaskGamma);
|
||||||
SkColorSpaceLuminance* paintLuminance = cachedPaintLuminance(paintGamma);
|
SkColorSpaceLuminance* paintLuminance = cachedPaintLuminance(paintGamma);
|
||||||
@ -1678,6 +1680,23 @@ static SkMaskGamma* cachedMaskGamma(SkScalar contrast, SkScalar paintGamma, SkSc
|
|||||||
return gMaskGamma;
|
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)
|
* We ensure that the rec is self-consistent and efficient (where possible)
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user