From c5fd5c41abd1e50293643c40e11e1f62cd22d3e9 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Tue, 17 May 2016 11:58:24 -0700 Subject: 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 --- src/gpu/text/GrBatchFontCache.cpp | 18 ++++++++---------- src/gpu/text/GrBatchFontCache.h | 27 ++++++++++++++------------- src/gpu/text/GrFontScaler.cpp | 29 +---------------------------- src/gpu/text/GrFontScaler.h | 26 +------------------------- 4 files changed, 24 insertions(+), 76 deletions(-) (limited to 'src/gpu/text') 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::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::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(ptr); - SkTDynamicHash::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::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 { 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 fCache; - SkAutoTUnref 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; GrContext* fContext; - SkTDynamicHash 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(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 @@ -16,27 +16,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. * @@ -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; }; -- cgit v1.2.3