diff options
author | Robert Phillips <robertphillips@google.com> | 2018-03-01 14:28:44 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-01 19:57:34 +0000 |
commit | caf1ebb95f7fea81d416b81beb4b46c25643c714 (patch) | |
tree | 2dbdba2fdb7011deb68c7b22465aa02f911cdb5f | |
parent | 96ee11959c580f62078db2a3b6dc779da6c3f6c0 (diff) |
sk_sp-ify GrGlyphCache
Hopefully, this makes it clearer that the subRuns of the GrAtlasTextBlobs carry a ref on the GrAtlasTextStrikes
Change-Id: I3d612074d98bc26240465f717711b7a2bcecb6ed
Reviewed-on: https://skia-review.googlesource.com/110981
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
-rw-r--r-- | src/gpu/text/GrAtlasManager.cpp | 2 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasManager.h | 4 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasTextBlob.cpp | 10 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasTextBlob.h | 9 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasTextBlobVertexRegenerator.cpp | 6 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasTextContext.cpp | 15 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasTextContext.h | 4 | ||||
-rw-r--r-- | src/gpu/text/GrGlyphCache.cpp | 28 | ||||
-rw-r--r-- | src/gpu/text/GrGlyphCache.h | 41 | ||||
-rw-r--r-- | src/gpu/text/GrTextUtils.h | 2 |
10 files changed, 62 insertions, 59 deletions
diff --git a/src/gpu/text/GrAtlasManager.cpp b/src/gpu/text/GrAtlasManager.cpp index 6e227a94a2..c6a60567e6 100644 --- a/src/gpu/text/GrAtlasManager.cpp +++ b/src/gpu/text/GrAtlasManager.cpp @@ -96,7 +96,7 @@ bool GrAtlasManager::hasGlyph(GrGlyph* glyph) { // add to texture atlas that matches this format bool GrAtlasManager::addToAtlas(GrResourceProvider* resourceProvider, GrGlyphCache* glyphCache, - GrAtlasTextStrike* strike, GrDrawOpAtlas::AtlasID* id, + GrTextStrike* strike, GrDrawOpAtlas::AtlasID* id, GrDeferredUploadTarget* target, GrMaskFormat format, int width, int height, const void* image, SkIPoint16* loc) { glyphCache->setStrikeToPreserve(strike); diff --git a/src/gpu/text/GrAtlasManager.h b/src/gpu/text/GrAtlasManager.h index 4629cb173b..eb9c113b7e 100644 --- a/src/gpu/text/GrAtlasManager.h +++ b/src/gpu/text/GrAtlasManager.h @@ -12,7 +12,7 @@ #include "GrOnFlushResourceProvider.h" class GrAtlasGlypCache; -class GrAtlasTextStrike; +class GrTextStrike; struct GrGlyph; /** The GrAtlasManager classes manage the lifetime of and access to GrDrawOpAtlases. @@ -100,7 +100,7 @@ public: } // add to texture atlas that matches this format - bool addToAtlas(GrResourceProvider*, GrGlyphCache*, GrAtlasTextStrike*, + bool addToAtlas(GrResourceProvider*, GrGlyphCache*, GrTextStrike*, GrDrawOpAtlas::AtlasID*, GrDeferredUploadTarget*, GrMaskFormat, int width, int height, const void* image, SkIPoint16* loc); diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp index 35e783019f..8470370e1d 100644 --- a/src/gpu/text/GrAtlasTextBlob.cpp +++ b/src/gpu/text/GrAtlasTextBlob.cpp @@ -76,7 +76,7 @@ SkGlyphCache* GrAtlasTextBlob::setupCache(int runIndex, void GrAtlasTextBlob::appendGlyph(int runIndex, const SkRect& positions, GrColor color, - GrAtlasTextStrike* strike, + sk_sp<GrTextStrike> strike, GrGlyph* glyph, SkGlyphCache* cache, const SkGlyph& skGlyph, SkScalar x, SkScalar y, SkScalar scale, bool preTransformed) { @@ -104,9 +104,9 @@ void GrAtlasTextBlob::appendGlyph(int runIndex, Run::SubRunInfo* subRun = &run.fSubRunInfo.back(); if (run.fInitialized && subRun->maskFormat() != format) { subRun = &run.push_back(); - subRun->setStrike(strike); + subRun->setStrike(std::move(strike)); } else if (!run.fInitialized) { - subRun->setStrike(strike); + subRun->setStrike(std::move(strike)); } run.fInitialized = true; @@ -461,8 +461,8 @@ void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlo if (lSubRun.strike()) { SkASSERT_RELEASE(rSubRun.strike()); - SkASSERT_RELEASE(GrAtlasTextStrike::GetKey(*lSubRun.strike()) == - GrAtlasTextStrike::GetKey(*rSubRun.strike())); + SkASSERT_RELEASE(GrTextStrike::GetKey(*lSubRun.strike()) == + GrTextStrike::GetKey(*rSubRun.strike())); } else { SkASSERT_RELEASE(!rSubRun.strike()); diff --git a/src/gpu/text/GrAtlasTextBlob.h b/src/gpu/text/GrAtlasTextBlob.h index 9f91cae957..52771c7de1 100644 --- a/src/gpu/text/GrAtlasTextBlob.h +++ b/src/gpu/text/GrAtlasTextBlob.h @@ -181,7 +181,7 @@ public: void appendGlyph(int runIndex, const SkRect& positions, GrColor color, - GrAtlasTextStrike* strike, + sk_sp<GrTextStrike> strike, GrGlyph* glyph, SkGlyphCache*, const SkGlyph& skGlyph, SkScalar x, SkScalar y, SkScalar scale, bool preTransformed); @@ -371,8 +371,9 @@ private: // TODO when this object is more internal, drop the privacy void resetBulkUseToken() { fBulkUseToken.reset(); } GrDrawOpAtlas::BulkUseTokenUpdater* bulkUseToken() { return &fBulkUseToken; } - void setStrike(GrAtlasTextStrike* strike) { fStrike.reset(SkRef(strike)); } - GrAtlasTextStrike* strike() const { return fStrike.get(); } + void setStrike(sk_sp<GrTextStrike> strike) { fStrike = std::move(strike); } + GrTextStrike* strike() const { return fStrike.get(); } + sk_sp<GrTextStrike> refStrike() const { return fStrike; } void setAtlasGeneration(uint64_t atlasGeneration) { fAtlasGeneration = atlasGeneration;} uint64_t atlasGeneration() const { return fAtlasGeneration; } @@ -444,7 +445,7 @@ private: }; GrDrawOpAtlas::BulkUseTokenUpdater fBulkUseToken; - sk_sp<GrAtlasTextStrike> fStrike; + sk_sp<GrTextStrike> fStrike; SkMatrix fCurrentViewMatrix; SkRect fVertexBounds; uint64_t fAtlasGeneration; diff --git a/src/gpu/text/GrAtlasTextBlobVertexRegenerator.cpp b/src/gpu/text/GrAtlasTextBlobVertexRegenerator.cpp index 54001c2628..f574d6f046 100644 --- a/src/gpu/text/GrAtlasTextBlobVertexRegenerator.cpp +++ b/src/gpu/text/GrAtlasTextBlobVertexRegenerator.cpp @@ -232,7 +232,7 @@ Regenerator::VertexRegenerator(GrResourceProvider* resourceProvider, GrAtlasText template <bool regenPos, bool regenCol, bool regenTexCoords, bool regenGlyphs> Regenerator::Result Regenerator::doRegen() { static_assert(!regenGlyphs || regenTexCoords, "must regenTexCoords along regenGlyphs"); - GrAtlasTextStrike* strike = nullptr; + sk_sp<GrTextStrike> strike; if (regenTexCoords) { fSubRun->resetBulkUseToken(); @@ -250,7 +250,7 @@ Regenerator::Result Regenerator::doRegen() { if (regenGlyphs) { strike = fGlyphCache->getStrike(fLazyCache->get()); } else { - strike = fSubRun->strike(); + strike = fSubRun->refStrike(); } } @@ -302,7 +302,7 @@ Regenerator::Result Regenerator::doRegen() { fSubRun->setColor(fColor); if (regenTexCoords) { if (regenGlyphs) { - fSubRun->setStrike(strike); + fSubRun->setStrike(std::move(strike)); } fSubRun->setAtlasGeneration(fBrokenRun ? GrDrawOpAtlas::kInvalidAtlasGeneration diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp index aadc2dc0c1..ce1b52e0cd 100644 --- a/src/gpu/text/GrAtlasTextContext.cpp +++ b/src/gpu/text/GrAtlasTextContext.cpp @@ -384,7 +384,8 @@ void GrAtlasTextContext::DrawBmpText(GrAtlasTextBlob* blob, int runIndex, text, byteLength, x, y); return; } - GrAtlasTextStrike* currStrike = nullptr; + + sk_sp<GrTextStrike> currStrike; SkGlyphCache* cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix); SkFindAndPlaceGlyph::ProcessText(paint.skPaint().getTextEncoding(), text, byteLength, {x, y}, viewMatrix, paint.skPaint().getTextAlign(), cache, @@ -424,8 +425,7 @@ void GrAtlasTextContext::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex, return; } - GrAtlasTextStrike* currStrike = nullptr; - + sk_sp<GrTextStrike> currStrike; SkGlyphCache* cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix); SkFindAndPlaceGlyph::ProcessPosText( paint.skPaint().getTextEncoding(), text, byteLength, offset, viewMatrix, pos, @@ -541,7 +541,8 @@ void GrAtlasTextContext::DrawBmpPosTextAsPaths(GrAtlasTextBlob* blob, int runInd } void GrAtlasTextContext::BmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, - GrGlyphCache* grGlyphCache, GrAtlasTextStrike** strike, + GrGlyphCache* grGlyphCache, + sk_sp<GrTextStrike>* strike, const SkGlyph& skGlyph, SkScalar sx, SkScalar sy, GrColor color, SkGlyphCache* skGlyphCache, SkScalar textRatio) { @@ -777,7 +778,7 @@ void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex, glyphCache->getGlyphSizeLimit(), textRatio); - GrAtlasTextStrike* currStrike = nullptr; + sk_sp<GrTextStrike> currStrike; // We apply the fake-gamma by altering the distance in the shader, so we ignore the // passed-in scaler context flags. (It's only used when we fall-back to bitmap text). @@ -820,7 +821,7 @@ void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex, // TODO: merge with BmpAppendGlyph void GrAtlasTextContext::DfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, - GrGlyphCache* grGlyphCache, GrAtlasTextStrike** strike, + GrGlyphCache* grGlyphCache, sk_sp<GrTextStrike>* strike, const SkGlyph& skGlyph, SkScalar sx, SkScalar sy, GrColor color, SkGlyphCache* skGlyphCache, SkScalar textRatio) { @@ -905,7 +906,7 @@ void GrAtlasTextContext::FallbackTextHelper::drawText(GrAtlasTextBlob* blob, int &fViewMatrix); } - GrAtlasTextStrike* currStrike = nullptr; + sk_sp<GrTextStrike> currStrike; const char* text = fFallbackTxt.begin(); const char* stop = text + fFallbackTxt.count(); SkPoint* glyphPos = fFallbackPos.begin(); diff --git a/src/gpu/text/GrAtlasTextContext.h b/src/gpu/text/GrAtlasTextContext.h index 37b7de5357..bcdc9fdd02 100644 --- a/src/gpu/text/GrAtlasTextContext.h +++ b/src/gpu/text/GrAtlasTextContext.h @@ -174,11 +174,11 @@ private: const SkMatrix& viewMatrix) const; static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrGlyphCache*, - GrAtlasTextStrike**, const SkGlyph&, SkScalar sx, SkScalar sy, + sk_sp<GrTextStrike>*, const SkGlyph&, SkScalar sx, SkScalar sy, GrColor color, SkGlyphCache*, SkScalar textRatio); static void DfAppendGlyph(GrAtlasTextBlob*, int runIndex, GrGlyphCache*, - GrAtlasTextStrike**, const SkGlyph&, SkScalar sx, SkScalar sy, + sk_sp<GrTextStrike>*, const SkGlyph&, SkScalar sx, SkScalar sy, GrColor color, SkGlyphCache* cache, SkScalar textRatio); const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable.get(); } diff --git a/src/gpu/text/GrGlyphCache.cpp b/src/gpu/text/GrGlyphCache.cpp index d4440897bc..7d899076b2 100644 --- a/src/gpu/text/GrGlyphCache.cpp +++ b/src/gpu/text/GrGlyphCache.cpp @@ -41,13 +41,13 @@ void GrGlyphCache::HandleEviction(GrDrawOpAtlas::AtlasID id, void* ptr) { StrikeHash::Iter iter(&glyphCache->fCache); for (; !iter.done(); ++iter) { - GrAtlasTextStrike* strike = &*iter; + GrTextStrike* strike = &*iter; strike->removeID(id); // clear out any empty strikes. We will preserve the strike whose call to addToAtlas // triggered the eviction if (strike != glyphCache->fPreserveStrike && 0 == strike->fAtlasedGlyphs) { - glyphCache->fCache.remove(GrAtlasTextStrike::GetKey(*strike)); + glyphCache->fCache.remove(GrTextStrike::GetKey(*strike)); strike->fIsAbandoned = true; strike->unref(); } @@ -246,13 +246,13 @@ static bool get_packed_glyph_df_image(SkGlyphCache* cache, const SkGlyph& glyph, atlas and a position within that texture. */ -GrAtlasTextStrike::GrAtlasTextStrike(const SkDescriptor& key) +GrTextStrike::GrTextStrike(const SkDescriptor& key) : fFontScalerKey(key) , fPool(9/*start allocations at 512 bytes*/) , fAtlasedGlyphs(0) , fIsAbandoned(false) {} -GrAtlasTextStrike::~GrAtlasTextStrike() { +GrTextStrike::~GrTextStrike() { SkTDynamicHash<GrGlyph, GrGlyph::PackedID>::Iter iter(&fCache); while (!iter.done()) { (*iter).reset(); @@ -260,8 +260,8 @@ GrAtlasTextStrike::~GrAtlasTextStrike() { } } -GrGlyph* GrAtlasTextStrike::generateGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed, - SkGlyphCache* cache) { +GrGlyph* GrTextStrike::generateGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed, + SkGlyphCache* cache) { SkIRect bounds; if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(packed)) { if (!get_packed_glyph_df_bounds(cache, skGlyph, &bounds)) { @@ -280,7 +280,7 @@ GrGlyph* GrAtlasTextStrike::generateGlyph(const SkGlyph& skGlyph, GrGlyph::Packe return glyph; } -void GrAtlasTextStrike::removeID(GrDrawOpAtlas::AtlasID id) { +void GrTextStrike::removeID(GrDrawOpAtlas::AtlasID id) { SkTDynamicHash<GrGlyph, GrGlyph::PackedID>::Iter iter(&fCache); while (!iter.done()) { if (id == (*iter).fID) { @@ -292,13 +292,13 @@ void GrAtlasTextStrike::removeID(GrDrawOpAtlas::AtlasID id) { } } -bool GrAtlasTextStrike::addGlyphToAtlas(GrResourceProvider* resourceProvider, - GrDeferredUploadTarget* target, - GrGlyphCache* glyphCache, - GrAtlasManager* fullAtlasManager, - GrGlyph* glyph, - SkGlyphCache* cache, - GrMaskFormat expectedMaskFormat) { +bool GrTextStrike::addGlyphToAtlas(GrResourceProvider* resourceProvider, + GrDeferredUploadTarget* target, + GrGlyphCache* glyphCache, + GrAtlasManager* fullAtlasManager, + GrGlyph* glyph, + SkGlyphCache* cache, + GrMaskFormat expectedMaskFormat) { SkASSERT(glyph); SkASSERT(cache); SkASSERT(fCache.find(glyph->fPackedID)); diff --git a/src/gpu/text/GrGlyphCache.h b/src/gpu/text/GrGlyphCache.h index 169e4b30a5..8279814241 100644 --- a/src/gpu/text/GrGlyphCache.h +++ b/src/gpu/text/GrGlyphCache.h @@ -19,21 +19,21 @@ class GrAtlasManager; class GrGpu; /** - * The GrAtlasTextStrike manages a pool of CPU backing memory for GrGlyphs. This backing memory + * The GrTextStrike manages a pool of CPU backing memory for GrGlyphs. This backing memory * is indexed by a PackedID and SkGlyphCache. The SkGlyphCache is what actually creates the mask. - * The GrAtlasTextStrike may outlive the generating SkGlyphCache. However, it retains a copy - * of it's SkDescriptor as a key to access (or regenerate) the SkGlyphCache. GrAtlasTextStrike are + * The GrTextStrike may outlive the generating SkGlyphCache. However, it retains a copy + * of it's SkDescriptor as a key to access (or regenerate) the SkGlyphCache. GrTextStrikes are * created by and owned by a GrGlyphCache. */ -class GrAtlasTextStrike : public SkNVRefCnt<GrAtlasTextStrike> { +class GrTextStrike : public SkNVRefCnt<GrTextStrike> { public: - GrAtlasTextStrike(const SkDescriptor& fontScalerKey); - ~GrAtlasTextStrike(); + GrTextStrike(const SkDescriptor& fontScalerKey); + ~GrTextStrike(); inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed, SkGlyphCache* cache) { GrGlyph* glyph = fCache.find(packed); - if (nullptr == glyph) { + if (!glyph) { glyph = this->generateGlyph(skGlyph, packed, cache); } return glyph; @@ -47,7 +47,7 @@ public: GrMaskFormat expectedMaskFormat, SkGlyphCache* cache) { GrGlyph* glyph = fCache.find(packed); - if (nullptr == glyph) { + if (!glyph) { // We could return this to the caller, but in practice it adds code complexity for // potentially little benefit(ie, if the glyph is not in our font cache, then its not // in the atlas and we're going to be doing a texture upload anyways). @@ -76,8 +76,8 @@ public: // If a TextStrike is abandoned by the cache, then the caller must get a new strike bool isAbandoned() const { return fIsAbandoned; } - static const SkDescriptor& GetKey(const GrAtlasTextStrike& ts) { - return *ts.fFontScalerKey.getDesc(); + static const SkDescriptor& GetKey(const GrTextStrike& strike) { + return *strike.fFontScalerKey.getDesc(); } static uint32_t Hash(const SkDescriptor& desc) { return desc.getChecksum(); } @@ -113,15 +113,15 @@ public: void setGlyphSizeLimit(SkScalar sizeLimit) { fGlyphSizeLimit = sizeLimit; } SkScalar getGlyphSizeLimit() const { return fGlyphSizeLimit; } - void setStrikeToPreserve(GrAtlasTextStrike* strike) { fPreserveStrike = strike; } + void setStrikeToPreserve(GrTextStrike* strike) { fPreserveStrike = strike; } // The user of the cache may hold a long-lived ref to the returned strike. However, actions by // another client of the cache may cause the strike to be purged while it is still reffed. - // Therefore, the caller must check GrAtlasTextStrike::isAbandoned() if there are other + // Therefore, the caller must check GrTextStrike::isAbandoned() if there are other // interactions with the cache since the strike was received. - inline GrAtlasTextStrike* getStrike(const SkGlyphCache* cache) { - GrAtlasTextStrike* strike = fCache.find(cache->getDescriptor()); - if (nullptr == strike) { + inline sk_sp<GrTextStrike> getStrike(const SkGlyphCache* cache) { + sk_sp<GrTextStrike> strike = sk_ref_sp(fCache.find(cache->getDescriptor())); + if (!strike) { strike = this->generateStrike(cache); } return strike; @@ -132,16 +132,17 @@ public: static void HandleEviction(GrDrawOpAtlas::AtlasID, void*); private: - GrAtlasTextStrike* generateStrike(const SkGlyphCache* cache) { - GrAtlasTextStrike* strike = new GrAtlasTextStrike(cache->getDescriptor()); - fCache.add(strike); + sk_sp<GrTextStrike> generateStrike(const SkGlyphCache* cache) { + // 'fCache' get the construction ref + sk_sp<GrTextStrike> strike = sk_ref_sp(new GrTextStrike(cache->getDescriptor())); + fCache.add(strike.get()); return strike; } - using StrikeHash = SkTDynamicHash<GrAtlasTextStrike, SkDescriptor>; + using StrikeHash = SkTDynamicHash<GrTextStrike, SkDescriptor>; StrikeHash fCache; - GrAtlasTextStrike* fPreserveStrike; + GrTextStrike* fPreserveStrike; SkScalar fGlyphSizeLimit; }; diff --git a/src/gpu/text/GrTextUtils.h b/src/gpu/text/GrTextUtils.h index 69421c2474..ec26a86018 100644 --- a/src/gpu/text/GrTextUtils.h +++ b/src/gpu/text/GrTextUtils.h @@ -18,7 +18,7 @@ class GrAtlasTextBlob; class GrAtlasTextOp; -class GrAtlasTextStrike; +class GrTextStrike; class GrClip; class GrColorSpaceXform; class GrContext; |