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:
parent
14687813ea
commit
90808e87c2
@ -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();
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user