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>
This commit is contained in:
parent
96ee11959c
commit
caf1ebb95f
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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(); }
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
class GrAtlasTextBlob;
|
||||
class GrAtlasTextOp;
|
||||
class GrAtlasTextStrike;
|
||||
class GrTextStrike;
|
||||
class GrClip;
|
||||
class GrColorSpaceXform;
|
||||
class GrContext;
|
||||
|
Loading…
Reference in New Issue
Block a user