diff options
author | 2013-03-19 14:44:54 +0000 | |
---|---|---|
committer | 2013-03-19 14:44:54 +0000 | |
commit | 90808e87c21e93b8e670360655e0b0eb12cb2f87 (patch) | |
tree | 0219fa6397867b6bfd18120d733dad498e1a338a | |
parent | 14687813ea0174dc165961ebca8df4153c3dde59 (diff) |
Add SkTypeface* parameter to SkScalerContext (and its callers)
Use SkTypeface to create scalercontext instead of SkFontHost
Review URL: https://codereview.chromium.org/12706010
git-svn-id: http://skia.googlecode.com/svn/trunk@8223 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkPaint.h | 2 | ||||
-rw-r--r-- | include/core/SkTypeface.h | 2 | ||||
-rw-r--r-- | src/core/SkGlyphCache.cpp | 18 | ||||
-rw-r--r-- | src/core/SkGlyphCache.h | 13 | ||||
-rw-r--r-- | src/core/SkPaint.cpp | 14 | ||||
-rw-r--r-- | src/core/SkScalerContext.cpp | 6 | ||||
-rw-r--r-- | src/core/SkScalerContext.h | 1 |
7 files changed, 35 insertions, 21 deletions
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index 36fb737d04..a73a46a2c6 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -974,7 +974,7 @@ private: SkGlyphCache* detachCache(const SkDeviceProperties* deviceProperties, const SkMatrix*) const; void descriptorProc(const SkDeviceProperties* deviceProperties, const SkMatrix* deviceMatrix, - void (*proc)(const SkDescriptor*, void*), + void (*proc)(SkTypeface*, const SkDescriptor*, void*), void* context, bool ignoreGamma = false) const; static void Term(); diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index a531cf2c84..45779dcf1a 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -194,6 +194,7 @@ public: int getUnitsPerEm() const; SkStream* openStream(int* ttcIndex) const; + SkScalerContext* createScalerContext(const SkDescriptor*) const; protected: /** uniqueID must be unique and non-zero @@ -218,6 +219,7 @@ private: bool fIsFixedWidth; friend class SkPaint; + friend class SkGlyphCache; // GetDefaultTypeface // just so deprecated fonthost can call protected methods friend class SkFontHost; diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp index 2673aba8a5..d33a13f4bc 100644 --- a/src/core/SkGlyphCache.cpp +++ b/src/core/SkGlyphCache.cpp @@ -13,6 +13,7 @@ #include "SkPath.h" #include "SkTemplates.h" #include "SkTLS.h" +#include "SkTypeface.h" //#define SPEW_PURGE_STATUS //#define USE_CACHE_HASH @@ -52,12 +53,15 @@ bool gSkSuppressFontCachePurgeSpew; #define METRICS_RESERVE_COUNT 128 // so we don't grow this array a lot -SkGlyphCache::SkGlyphCache(const SkDescriptor* desc) - : fGlyphAlloc(kMinGlphAlloc), fImageAlloc(kMinImageAlloc) { +SkGlyphCache::SkGlyphCache(SkTypeface* typeface, const SkDescriptor* desc) + : fGlyphAlloc(kMinGlphAlloc) + , fImageAlloc(kMinImageAlloc) { + SkASSERT(typeface); + fPrev = fNext = NULL; fDesc = desc->copy(); - fScalerContext = SkScalerContext::Create(desc); + fScalerContext = typeface->createScalerContext(desc); fScalerContext->getFontMetrics(NULL, &fFontMetricsY); // init to 0 so that all of the pointers will be null @@ -523,9 +527,13 @@ void SkGlyphCache::VisitAllCaches(bool (*proc)(SkGlyphCache*, void*), - try to acquire the mutext again - call a fontscaler (which might call into the cache) */ -SkGlyphCache* SkGlyphCache::VisitCache(const SkDescriptor* desc, +SkGlyphCache* SkGlyphCache::VisitCache(SkTypeface* typeface, + const SkDescriptor* desc, bool (*proc)(const SkGlyphCache*, void*), void* context) { + if (!typeface) { + typeface = SkTypeface::GetDefaultTypeface(); + } SkASSERT(desc); SkGlyphCache_Globals& globals = getGlobals(); @@ -558,7 +566,7 @@ SkGlyphCache* SkGlyphCache::VisitCache(const SkDescriptor* desc, ac.release(); // release the mutex now insideMutex = false; // can't use globals anymore - cache = SkNEW_ARGS(SkGlyphCache, (desc)); + cache = SkNEW_ARGS(SkGlyphCache, (typeface, desc)); FOUND_IT: diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h index 537b44784a..39a1c389c2 100644 --- a/src/core/SkGlyphCache.h +++ b/src/core/SkGlyphCache.h @@ -135,7 +135,7 @@ public: create a new one. If the proc() returns true, detach the cache and return it, otherwise leave it and return NULL. */ - static SkGlyphCache* VisitCache(const SkDescriptor* desc, + static SkGlyphCache* VisitCache(SkTypeface*, const SkDescriptor* desc, bool (*proc)(const SkGlyphCache*, void*), void* context); @@ -154,8 +154,9 @@ public: eventually get purged, and the win is that different thread will never block each other while a strike is being used. */ - static SkGlyphCache* DetachCache(const SkDescriptor* desc) { - return VisitCache(desc, DetachProc, NULL); + static SkGlyphCache* DetachCache(SkTypeface* typeface, + const SkDescriptor* desc) { + return VisitCache(typeface, desc, DetachProc, NULL); } #ifdef SK_DEBUG @@ -184,7 +185,7 @@ public: }; private: - SkGlyphCache(const SkDescriptor*); + SkGlyphCache(SkTypeface*, const SkDescriptor*); ~SkGlyphCache(); enum MetricsType { @@ -273,8 +274,8 @@ private: class SkAutoGlyphCache { public: SkAutoGlyphCache(SkGlyphCache* cache) : fCache(cache) {} - SkAutoGlyphCache(const SkDescriptor* desc) { - fCache = SkGlyphCache::DetachCache(desc); + SkAutoGlyphCache(SkTypeface* typeface, const SkDescriptor* desc) { + fCache = SkGlyphCache::DetachCache(typeface, desc); } SkAutoGlyphCache(const SkPaint& paint, const SkDeviceProperties* deviceProperties, diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index c7ad933dd1..aa1b8e4803 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -414,8 +414,9 @@ SkAnnotation* SkPaint::setAnnotation(SkAnnotation* annotation) { #include "SkGlyphCache.h" #include "SkUtils.h" -static void DetachDescProc(const SkDescriptor* desc, void* context) { - *((SkGlyphCache**)context) = SkGlyphCache::DetachCache(desc); +static void DetachDescProc(SkTypeface* typeface, const SkDescriptor* desc, + void* context) { + *((SkGlyphCache**)context) = SkGlyphCache::DetachCache(typeface, desc); } #ifdef SK_BUILD_FOR_ANDROID @@ -1206,8 +1207,9 @@ static bool FontMetricsCacheProc(const SkGlyphCache* cache, void* context) { return false; // don't detach the cache } -static void FontMetricsDescProc(const SkDescriptor* desc, void* context) { - SkGlyphCache::VisitCache(desc, FontMetricsCacheProc, context); +static void FontMetricsDescProc(SkTypeface* typeface, const SkDescriptor* desc, + void* context) { + SkGlyphCache::VisitCache(typeface, desc, FontMetricsCacheProc, context); } SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const { @@ -1761,7 +1763,7 @@ void SkScalerContext::PostMakeRec(const SkPaint&, SkScalerContext::Rec* rec) { */ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties, const SkMatrix* deviceMatrix, - void (*proc)(const SkDescriptor*, void*), + void (*proc)(SkTypeface*, const SkDescriptor*, void*), void* context, bool ignoreGamma) const { SkScalerContext::Rec rec; @@ -1873,7 +1875,7 @@ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties, } #endif - proc(desc, context); + proc(fTypeface, desc, context); } SkGlyphCache* SkPaint::detachCache(const SkDeviceProperties* deviceProperties, diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp index 9d13a6c120..56dcb9b7cc 100644 --- a/src/core/SkScalerContext.cpp +++ b/src/core/SkScalerContext.cpp @@ -770,13 +770,15 @@ protected: extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc); -SkScalerContext* SkScalerContext::Create(const SkDescriptor* desc) { +SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc) const { SkScalerContext* c = NULL; //SkCreateColorScalerContext(desc); if (NULL == c) { - c = SkFontHost::CreateScalerContext(desc); + c = this->onCreateScalerContext(desc); } if (NULL == c) { c = SkNEW_ARGS(SkScalerContext_Empty, (desc)); } return c; } + + diff --git a/src/core/SkScalerContext.h b/src/core/SkScalerContext.h index f2e00a691f..a4f2ea681e 100644 --- a/src/core/SkScalerContext.h +++ b/src/core/SkScalerContext.h @@ -197,7 +197,6 @@ public: const SkMatrix*, Rec* rec); static inline void PostMakeRec(const SkPaint&, Rec*); - static SkScalerContext* Create(const SkDescriptor*); static SkMaskGamma::PreBlend GetMaskPreBlend(const Rec& rec); protected: |