1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/GrTextStrike_impl.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2010 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 + 1.14 +#ifndef GrTextStrike_impl_DEFINED 1.15 +#define GrTextStrike_impl_DEFINED 1.16 + 1.17 +class GrFontCache::Key { 1.18 +public: 1.19 + explicit Key(const GrKey* fontScalarKey) { 1.20 + fFontScalerKey = fontScalarKey; 1.21 + } 1.22 + 1.23 + intptr_t getHash() const { return fFontScalerKey->getHash(); } 1.24 + 1.25 + static bool LessThan(const GrTextStrike& strike, const Key& key) { 1.26 + return *strike.getFontScalerKey() < *key.fFontScalerKey; 1.27 + } 1.28 + static bool Equals(const GrTextStrike& strike, const Key& key) { 1.29 + return *strike.getFontScalerKey() == *key.fFontScalerKey; 1.30 + } 1.31 + 1.32 +private: 1.33 + const GrKey* fFontScalerKey; 1.34 +}; 1.35 + 1.36 +void GrFontCache::detachStrikeFromList(GrTextStrike* strike) { 1.37 + if (strike->fPrev) { 1.38 + SkASSERT(fHead != strike); 1.39 + strike->fPrev->fNext = strike->fNext; 1.40 + } else { 1.41 + SkASSERT(fHead == strike); 1.42 + fHead = strike->fNext; 1.43 + } 1.44 + 1.45 + if (strike->fNext) { 1.46 + SkASSERT(fTail != strike); 1.47 + strike->fNext->fPrev = strike->fPrev; 1.48 + } else { 1.49 + SkASSERT(fTail == strike); 1.50 + fTail = strike->fPrev; 1.51 + } 1.52 +} 1.53 + 1.54 +GrTextStrike* GrFontCache::getStrike(GrFontScaler* scaler, bool useDistanceField) { 1.55 + this->validate(); 1.56 + 1.57 + const Key key(scaler->getKey()); 1.58 + GrTextStrike* strike = fCache.find(key); 1.59 + if (NULL == strike) { 1.60 + strike = this->generateStrike(scaler, key); 1.61 + } else if (strike->fPrev) { 1.62 + // Need to put the strike at the head of its dllist, since that is how 1.63 + // we age the strikes for purging (we purge from the back of the list 1.64 + this->detachStrikeFromList(strike); 1.65 + // attach at the head 1.66 + fHead->fPrev = strike; 1.67 + strike->fNext = fHead; 1.68 + strike->fPrev = NULL; 1.69 + fHead = strike; 1.70 + } 1.71 + strike->fUseDistanceField = useDistanceField; 1.72 + this->validate(); 1.73 + return strike; 1.74 +} 1.75 + 1.76 +/////////////////////////////////////////////////////////////////////////////// 1.77 + 1.78 +/** 1.79 + * This Key just wraps a glyphID, and matches the protocol need for 1.80 + * GrTHashTable 1.81 + */ 1.82 +class GrTextStrike::Key { 1.83 +public: 1.84 + Key(GrGlyph::PackedID id) : fPackedID(id) {} 1.85 + 1.86 + uint32_t getHash() const { return fPackedID; } 1.87 + 1.88 + static bool LessThan(const GrGlyph& glyph, const Key& key) { 1.89 + return glyph.fPackedID < key.fPackedID; 1.90 + } 1.91 + static bool Equals(const GrGlyph& glyph, const Key& key) { 1.92 + return glyph.fPackedID == key.fPackedID; 1.93 + } 1.94 + 1.95 +private: 1.96 + GrGlyph::PackedID fPackedID; 1.97 +}; 1.98 + 1.99 +GrGlyph* GrTextStrike::getGlyph(GrGlyph::PackedID packed, 1.100 + GrFontScaler* scaler) { 1.101 + GrGlyph* glyph = fCache.find(packed); 1.102 + if (NULL == glyph) { 1.103 + glyph = this->generateGlyph(packed, scaler); 1.104 + } 1.105 + return glyph; 1.106 +} 1.107 + 1.108 +#endif