aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/text
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-05-17 11:58:24 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-17 11:58:24 -0700
commitc5fd5c41abd1e50293643c40e11e1f62cd22d3e9 (patch)
tree58b69e15beda6c3054edc7da554e09ca2f61bb2d /src/gpu/text
parent7888f780d85ced5c572f0227c16b88ed59bcffe5 (diff)
Remove GrFontDescKey.
This was a reference counted wrapper of SkDescriptor. It doesn't seem like the copies are performance critical. This gets us closer to removing GrFontScaler. Also removes some unused member functions on GrBatchTextStrike and GrFontScaler. BUG=chromium:608566 GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1988833003 Review-Url: https://codereview.chromium.org/1988833003
Diffstat (limited to 'src/gpu/text')
-rw-r--r--src/gpu/text/GrBatchFontCache.cpp18
-rw-r--r--src/gpu/text/GrBatchFontCache.h27
-rw-r--r--src/gpu/text/GrFontScaler.cpp29
-rw-r--r--src/gpu/text/GrFontScaler.h26
4 files changed, 24 insertions, 76 deletions
diff --git a/src/gpu/text/GrBatchFontCache.cpp b/src/gpu/text/GrBatchFontCache.cpp
index 8345b5cf4b..06e199418b 100644
--- a/src/gpu/text/GrBatchFontCache.cpp
+++ b/src/gpu/text/GrBatchFontCache.cpp
@@ -69,7 +69,7 @@ GrBatchFontCache::GrBatchFontCache(GrContext* context)
}
GrBatchFontCache::~GrBatchFontCache() {
- SkTDynamicHash<GrBatchTextStrike, GrFontDescKey>::Iter iter(&fCache);
+ StrikeHash::Iter iter(&fCache);
while (!iter.done()) {
(*iter).fIsAbandoned = true;
(*iter).unref();
@@ -81,7 +81,7 @@ GrBatchFontCache::~GrBatchFontCache() {
}
void GrBatchFontCache::freeAll() {
- SkTDynamicHash<GrBatchTextStrike, GrFontDescKey>::Iter iter(&fCache);
+ StrikeHash::Iter iter(&fCache);
while (!iter.done()) {
(*iter).fIsAbandoned = true;
(*iter).unref();
@@ -97,7 +97,7 @@ void GrBatchFontCache::freeAll() {
void GrBatchFontCache::HandleEviction(GrBatchAtlas::AtlasID id, void* ptr) {
GrBatchFontCache* fontCache = reinterpret_cast<GrBatchFontCache*>(ptr);
- SkTDynamicHash<GrBatchTextStrike, GrFontDescKey>::Iter iter(&fontCache->fCache);
+ StrikeHash::Iter iter(&fontCache->fCache);
for (; !iter.done(); ++iter) {
GrBatchTextStrike* strike = &*iter;
strike->removeID(id);
@@ -105,7 +105,7 @@ void GrBatchFontCache::HandleEviction(GrBatchAtlas::AtlasID id, void* ptr) {
// clear out any empty strikes. We will preserve the strike whose call to addToAtlas
// triggered the eviction
if (strike != fontCache->fPreserveStrike && 0 == strike->fAtlasedGlyphs) {
- fontCache->fCache.remove(*(strike->fFontScalerKey));
+ fontCache->fCache.remove(GrBatchTextStrike::GetKey(*strike));
strike->fIsAbandoned = true;
strike->unref();
}
@@ -153,14 +153,12 @@ void GrBatchFontCache::setAtlasSizes_ForTesting(const GrBatchAtlasConfig configs
atlas and a position within that texture.
*/
-GrBatchTextStrike::GrBatchTextStrike(GrBatchFontCache* cache, const GrFontDescKey* key)
- : fFontScalerKey(SkRef(key))
+GrBatchTextStrike::GrBatchTextStrike(GrBatchFontCache* owner, const SkDescriptor& key)
+ : fFontScalerKey(key)
, fPool(9/*start allocations at 512 bytes*/)
+ , fBatchFontCache(owner) // no need to ref, it won't go away before we do
, fAtlasedGlyphs(0)
- , fIsAbandoned(false) {
-
- fBatchFontCache = cache; // no need to ref, it won't go away before we do
-}
+ , fIsAbandoned(false) {}
GrBatchTextStrike::~GrBatchTextStrike() {
SkTDynamicHash<GrGlyph, GrGlyph::PackedID>::Iter iter(&fCache);
diff --git a/src/gpu/text/GrBatchFontCache.h b/src/gpu/text/GrBatchFontCache.h
index 8e420cd146..4429885193 100644
--- a/src/gpu/text/GrBatchFontCache.h
+++ b/src/gpu/text/GrBatchFontCache.h
@@ -20,16 +20,17 @@ class GrGpu;
/**
* The GrBatchTextStrike manages a pool of CPU backing memory for GrGlyphs. This backing memory
- * is indexed by a PackedID and GrFontScaler. The GrFontScaler is what actually creates the mask.
+ * is indexed by a PackedID and GrFontScaler. The GrFontScaler is what actually creates the mask.
+ * The GrBatchTextStrike may outlive the generating GrFontScaler. However, it retains a copy
+ * of it's SkDescriptor as a key to access (or regenerate) the GrFontScaler. GrBatchTextStrikes are
+ * created by and owned by a GrBatchFontCache.
*/
class GrBatchTextStrike : public SkNVRefCnt<GrBatchTextStrike> {
public:
- GrBatchTextStrike(GrBatchFontCache*, const GrFontDescKey* fontScalerKey);
+ /** Owner is the cache that owns this strike. */
+ GrBatchTextStrike(GrBatchFontCache* owner, const SkDescriptor& fontScalerKey);
~GrBatchTextStrike();
- const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; }
- GrBatchFontCache* getBatchFontCache() const { return fBatchFontCache; }
-
inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed,
GrFontScaler* scaler) {
GrGlyph* glyph = fCache.find(packed);
@@ -75,16 +76,15 @@ public:
// If a TextStrike is abandoned by the cache, then the caller must get a new strike
bool isAbandoned() const { return fIsAbandoned; }
- static const GrFontDescKey& GetKey(const GrBatchTextStrike& ts) {
- return *(ts.fFontScalerKey);
- }
- static uint32_t Hash(const GrFontDescKey& key) {
- return key.getHash();
+ static const SkDescriptor& GetKey(const GrBatchTextStrike& ts) {
+ return *ts.fFontScalerKey.getDesc();
}
+ static uint32_t Hash(const SkDescriptor& desc) { return desc.getChecksum(); }
+
private:
SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache;
- SkAutoTUnref<const GrFontDescKey> fFontScalerKey;
+ SkAutoDescriptor fFontScalerKey;
SkVarAlloc fPool;
GrBatchFontCache* fBatchFontCache;
@@ -113,7 +113,7 @@ public:
// Therefore, the caller must check GrBatchTextStrike::isAbandoned() if there are other
// interactions with the cache since the strike was received.
inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) {
- GrBatchTextStrike* strike = fCache.find(*(scaler->getKey()));
+ GrBatchTextStrike* strike = fCache.find(scaler->getKey());
if (nullptr == strike) {
strike = this->generateStrike(scaler);
}
@@ -221,8 +221,9 @@ private:
static void HandleEviction(GrBatchAtlas::AtlasID, void*);
+ using StrikeHash = SkTDynamicHash<GrBatchTextStrike, SkDescriptor>;
GrContext* fContext;
- SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache;
+ StrikeHash fCache;
GrBatchAtlas* fAtlases[kMaskFormatCount];
GrBatchTextStrike* fPreserveStrike;
GrBatchAtlasConfig fAtlasConfigs[kMaskFormatCount];
diff --git a/src/gpu/text/GrFontScaler.cpp b/src/gpu/text/GrFontScaler.cpp
index 0fb768e1db..796f4d46c0 100644
--- a/src/gpu/text/GrFontScaler.cpp
+++ b/src/gpu/text/GrFontScaler.cpp
@@ -14,36 +14,9 @@
GrFontScaler::GrFontScaler(SkGlyphCache* strike) {
fStrike = strike;
- fKey = nullptr;
}
-GrFontScaler::~GrFontScaler() {
- SkSafeUnref(fKey);
-}
-
-GrMaskFormat GrFontScaler::getMaskFormat() const {
- SkMask::Format format = fStrike->getMaskFormat();
- switch (format) {
- case SkMask::kBW_Format:
- // fall through to kA8 -- we store BW glyphs in our 8-bit cache
- case SkMask::kA8_Format:
- return kA8_GrMaskFormat;
- case SkMask::kLCD16_Format:
- return kA565_GrMaskFormat;
- case SkMask::kARGB32_Format:
- return kARGB_GrMaskFormat;
- default:
- SkDEBUGFAIL("unsupported SkMask::Format");
- return kA8_GrMaskFormat;
- }
-}
-
-const GrFontDescKey* GrFontScaler::getKey() {
- if (nullptr == fKey) {
- fKey = new GrFontDescKey(fStrike->getDescriptor());
- }
- return fKey;
-}
+const SkDescriptor& GrFontScaler::getKey() { return fStrike->getDescriptor(); }
GrMaskFormat GrFontScaler::getPackedGlyphMaskFormat(const SkGlyph& glyph) const {
SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat);
diff --git a/src/gpu/text/GrFontScaler.h b/src/gpu/text/GrFontScaler.h
index 313d485d39..41cce99fa5 100644
--- a/src/gpu/text/GrFontScaler.h
+++ b/src/gpu/text/GrFontScaler.h
@@ -17,27 +17,6 @@ class SkGlyph;
class SkPath;
/*
- * Wrapper class to turn a font cache descriptor into a key
- * for GrFontScaler-related lookups
- */
-class GrFontDescKey : public SkRefCnt {
-public:
- explicit GrFontDescKey(const SkDescriptor& desc) : fDesc(desc), fHash(desc.getChecksum()) {}
-
- uint32_t getHash() const { return fHash; }
-
- bool operator==(const GrFontDescKey& rh) const {
- return fHash == rh.fHash && *fDesc.getDesc() == *rh.fDesc.getDesc();
- }
-
-private:
- SkAutoDescriptor fDesc;
- uint32_t fHash;
-
- typedef SkRefCnt INHERITED;
-};
-
-/*
* This is Gr's interface to the host platform's font scaler.
*
* The client is responsible for instantiating this. The instance is created
@@ -46,10 +25,8 @@ private:
class GrFontScaler final : public SkNoncopyable {
public:
explicit GrFontScaler(SkGlyphCache* strike);
- ~GrFontScaler();
- const GrFontDescKey* getKey();
- GrMaskFormat getMaskFormat() const;
+ const SkDescriptor& getKey();
GrMaskFormat getPackedGlyphMaskFormat(const SkGlyph&) const;
bool getPackedGlyphBounds(const SkGlyph&, SkIRect* bounds);
bool getPackedGlyphImage(const SkGlyph&, int width, int height, int rowBytes,
@@ -63,7 +40,6 @@ private:
// The SkGlyphCache actually owns this GrFontScaler. The GrFontScaler is deleted when the
// SkGlyphCache is deleted.
SkGlyphCache* fStrike;
- GrFontDescKey* fKey;
typedef SkNoncopyable INHERITED;
};