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
This commit is contained in:
reed@google.com 2013-03-19 14:44:54 +00:00
parent 14687813ea
commit 90808e87c2
7 changed files with 35 additions and 21 deletions

View File

@ -974,7 +974,7 @@ private:
SkGlyphCache* detachCache(const SkDeviceProperties* deviceProperties, const SkMatrix*) const; SkGlyphCache* detachCache(const SkDeviceProperties* deviceProperties, const SkMatrix*) const;
void descriptorProc(const SkDeviceProperties* deviceProperties, const SkMatrix* deviceMatrix, 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; void* context, bool ignoreGamma = false) const;
static void Term(); static void Term();

View File

@ -194,6 +194,7 @@ public:
int getUnitsPerEm() const; int getUnitsPerEm() const;
SkStream* openStream(int* ttcIndex) const; SkStream* openStream(int* ttcIndex) const;
SkScalerContext* createScalerContext(const SkDescriptor*) const;
protected: protected:
/** uniqueID must be unique and non-zero /** uniqueID must be unique and non-zero
@ -218,6 +219,7 @@ private:
bool fIsFixedWidth; bool fIsFixedWidth;
friend class SkPaint; friend class SkPaint;
friend class SkGlyphCache; // GetDefaultTypeface
// just so deprecated fonthost can call protected methods // just so deprecated fonthost can call protected methods
friend class SkFontHost; friend class SkFontHost;

View File

@ -13,6 +13,7 @@
#include "SkPath.h" #include "SkPath.h"
#include "SkTemplates.h" #include "SkTemplates.h"
#include "SkTLS.h" #include "SkTLS.h"
#include "SkTypeface.h"
//#define SPEW_PURGE_STATUS //#define SPEW_PURGE_STATUS
//#define USE_CACHE_HASH //#define USE_CACHE_HASH
@ -52,12 +53,15 @@ bool gSkSuppressFontCachePurgeSpew;
#define METRICS_RESERVE_COUNT 128 // so we don't grow this array a lot #define METRICS_RESERVE_COUNT 128 // so we don't grow this array a lot
SkGlyphCache::SkGlyphCache(const SkDescriptor* desc) SkGlyphCache::SkGlyphCache(SkTypeface* typeface, const SkDescriptor* desc)
: fGlyphAlloc(kMinGlphAlloc), fImageAlloc(kMinImageAlloc) { : fGlyphAlloc(kMinGlphAlloc)
, fImageAlloc(kMinImageAlloc) {
SkASSERT(typeface);
fPrev = fNext = NULL; fPrev = fNext = NULL;
fDesc = desc->copy(); fDesc = desc->copy();
fScalerContext = SkScalerContext::Create(desc); fScalerContext = typeface->createScalerContext(desc);
fScalerContext->getFontMetrics(NULL, &fFontMetricsY); fScalerContext->getFontMetrics(NULL, &fFontMetricsY);
// init to 0 so that all of the pointers will be null // 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 - try to acquire the mutext again
- call a fontscaler (which might call into the cache) - 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*), bool (*proc)(const SkGlyphCache*, void*),
void* context) { void* context) {
if (!typeface) {
typeface = SkTypeface::GetDefaultTypeface();
}
SkASSERT(desc); SkASSERT(desc);
SkGlyphCache_Globals& globals = getGlobals(); SkGlyphCache_Globals& globals = getGlobals();
@ -558,7 +566,7 @@ SkGlyphCache* SkGlyphCache::VisitCache(const SkDescriptor* desc,
ac.release(); // release the mutex now ac.release(); // release the mutex now
insideMutex = false; // can't use globals anymore insideMutex = false; // can't use globals anymore
cache = SkNEW_ARGS(SkGlyphCache, (desc)); cache = SkNEW_ARGS(SkGlyphCache, (typeface, desc));
FOUND_IT: FOUND_IT:

View File

@ -135,7 +135,7 @@ public:
create a new one. If the proc() returns true, detach the cache and create a new one. If the proc() returns true, detach the cache and
return it, otherwise leave it and return NULL. 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*), bool (*proc)(const SkGlyphCache*, void*),
void* context); void* context);
@ -154,8 +154,9 @@ public:
eventually get purged, and the win is that different thread will never eventually get purged, and the win is that different thread will never
block each other while a strike is being used. block each other while a strike is being used.
*/ */
static SkGlyphCache* DetachCache(const SkDescriptor* desc) { static SkGlyphCache* DetachCache(SkTypeface* typeface,
return VisitCache(desc, DetachProc, NULL); const SkDescriptor* desc) {
return VisitCache(typeface, desc, DetachProc, NULL);
} }
#ifdef SK_DEBUG #ifdef SK_DEBUG
@ -184,7 +185,7 @@ public:
}; };
private: private:
SkGlyphCache(const SkDescriptor*); SkGlyphCache(SkTypeface*, const SkDescriptor*);
~SkGlyphCache(); ~SkGlyphCache();
enum MetricsType { enum MetricsType {
@ -273,8 +274,8 @@ private:
class SkAutoGlyphCache { class SkAutoGlyphCache {
public: public:
SkAutoGlyphCache(SkGlyphCache* cache) : fCache(cache) {} SkAutoGlyphCache(SkGlyphCache* cache) : fCache(cache) {}
SkAutoGlyphCache(const SkDescriptor* desc) { SkAutoGlyphCache(SkTypeface* typeface, const SkDescriptor* desc) {
fCache = SkGlyphCache::DetachCache(desc); fCache = SkGlyphCache::DetachCache(typeface, desc);
} }
SkAutoGlyphCache(const SkPaint& paint, SkAutoGlyphCache(const SkPaint& paint,
const SkDeviceProperties* deviceProperties, const SkDeviceProperties* deviceProperties,

View File

@ -414,8 +414,9 @@ SkAnnotation* SkPaint::setAnnotation(SkAnnotation* annotation) {
#include "SkGlyphCache.h" #include "SkGlyphCache.h"
#include "SkUtils.h" #include "SkUtils.h"
static void DetachDescProc(const SkDescriptor* desc, void* context) { static void DetachDescProc(SkTypeface* typeface, const SkDescriptor* desc,
*((SkGlyphCache**)context) = SkGlyphCache::DetachCache(desc); void* context) {
*((SkGlyphCache**)context) = SkGlyphCache::DetachCache(typeface, desc);
} }
#ifdef SK_BUILD_FOR_ANDROID #ifdef SK_BUILD_FOR_ANDROID
@ -1206,8 +1207,9 @@ static bool FontMetricsCacheProc(const SkGlyphCache* cache, void* context) {
return false; // don't detach the cache return false; // don't detach the cache
} }
static void FontMetricsDescProc(const SkDescriptor* desc, void* context) { static void FontMetricsDescProc(SkTypeface* typeface, const SkDescriptor* desc,
SkGlyphCache::VisitCache(desc, FontMetricsCacheProc, context); void* context) {
SkGlyphCache::VisitCache(typeface, desc, FontMetricsCacheProc, context);
} }
SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const { 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, void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties,
const SkMatrix* deviceMatrix, const SkMatrix* deviceMatrix,
void (*proc)(const SkDescriptor*, void*), void (*proc)(SkTypeface*, const SkDescriptor*, void*),
void* context, bool ignoreGamma) const { void* context, bool ignoreGamma) const {
SkScalerContext::Rec rec; SkScalerContext::Rec rec;
@ -1873,7 +1875,7 @@ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties,
} }
#endif #endif
proc(desc, context); proc(fTypeface, desc, context);
} }
SkGlyphCache* SkPaint::detachCache(const SkDeviceProperties* deviceProperties, SkGlyphCache* SkPaint::detachCache(const SkDeviceProperties* deviceProperties,

View File

@ -770,13 +770,15 @@ protected:
extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc); extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc);
SkScalerContext* SkScalerContext::Create(const SkDescriptor* desc) { SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc) const {
SkScalerContext* c = NULL; //SkCreateColorScalerContext(desc); SkScalerContext* c = NULL; //SkCreateColorScalerContext(desc);
if (NULL == c) { if (NULL == c) {
c = SkFontHost::CreateScalerContext(desc); c = this->onCreateScalerContext(desc);
} }
if (NULL == c) { if (NULL == c) {
c = SkNEW_ARGS(SkScalerContext_Empty, (desc)); c = SkNEW_ARGS(SkScalerContext_Empty, (desc));
} }
return c; return c;
} }

View File

@ -197,7 +197,6 @@ public:
const SkMatrix*, Rec* rec); const SkMatrix*, Rec* rec);
static inline void PostMakeRec(const SkPaint&, Rec*); static inline void PostMakeRec(const SkPaint&, Rec*);
static SkScalerContext* Create(const SkDescriptor*);
static SkMaskGamma::PreBlend GetMaskPreBlend(const Rec& rec); static SkMaskGamma::PreBlend GetMaskPreBlend(const Rec& rec);
protected: protected: