Skip to content

Commit 8429c79

Browse files
csmartdalton86Skia Commit-Bot
authored andcommitted
ccpr: Don't use the GrContext id for the path cache id
Currently this is probably safe, but somebody could easily make a change in the future that adds another path cache to the context and accidentally introduces tricky bugs. TBR=brianosman@google.com Bug: chromium:897510 Bug: chromium:897413 Bug: chromium:897245 Bug: chromium:897507 Change-Id: I6bc40ac671058f78eb290dd775612d99008d32e7 Reviewed-on: https://skia-review.googlesource.com/c/164700 Reviewed-by: Chris Dalton <csmartdalton@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
1 parent c967407 commit 8429c79

9 files changed

Lines changed: 35 additions & 19 deletions

src/gpu/GrPathRendererChain.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ GrPathRendererChain::GrPathRendererChain(GrContext* context, const Options& opti
3737
if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) {
3838
using AllowCaching = GrCoverageCountingPathRenderer::AllowCaching;
3939
if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(
40-
caps, AllowCaching(options.fAllowPathMaskCaching),
41-
context->uniqueID())) {
40+
caps, AllowCaching(options.fAllowPathMaskCaching))) {
4241
fCoverageCountingPathRenderer = ccpr.get();
4342
context->contextPriv().addOnFlushCallbackObject(fCoverageCountingPathRenderer);
4443
fChain.push_back(std::move(ccpr));

src/gpu/ccpr/GrCCAtlas.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@ const GrUniqueKey& GrCCAtlas::getOrAssignUniqueKey(GrOnFlushResourceProvider* on
166166
return fUniqueKey;
167167
}
168168

169-
sk_sp<GrCCAtlas::CachedAtlasInfo> GrCCAtlas::refOrMakeCachedAtlasInfo() {
169+
sk_sp<GrCCAtlas::CachedAtlasInfo> GrCCAtlas::refOrMakeCachedAtlasInfo(uint32_t contextUniqueID) {
170170
if (!fCachedAtlasInfo) {
171-
fCachedAtlasInfo = sk_make_sp<CachedAtlasInfo>();
171+
fCachedAtlasInfo = sk_make_sp<CachedAtlasInfo>(contextUniqueID);
172172
}
173+
SkASSERT(fCachedAtlasInfo->fContextUniqueID == contextUniqueID);
173174
return fCachedAtlasInfo;
174175
}
175176

src/gpu/ccpr/GrCCAtlas.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ class GrCCAtlas {
7474
// potentially be reused (i.e., those which still represent an extant path). When the percentage
7575
// of useful pixels drops below 50%, the entire texture is purged from the resource cache.
7676
struct CachedAtlasInfo : public GrNonAtomicRef<CachedAtlasInfo> {
77+
CachedAtlasInfo(uint32_t contextUniqueID) : fContextUniqueID(contextUniqueID) {}
78+
const uint32_t fContextUniqueID;
7779
int fNumPathPixels = 0;
7880
int fNumInvalidatedPathPixels = 0;
7981
bool fIsPurgedFromResourceCache = false;
8082
};
81-
sk_sp<CachedAtlasInfo> refOrMakeCachedAtlasInfo();
83+
sk_sp<CachedAtlasInfo> refOrMakeCachedAtlasInfo(uint32_t contextUniqueID);
8284

8385
// Instantiates our texture proxy for the atlas and returns a pre-cleared GrRenderTargetContext
8486
// that the caller may use to render the content. After this call, it is no longer valid to call

src/gpu/ccpr/GrCCDrawPathsOp.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,9 @@ void GrCCDrawPathsOp::setupResources(GrOnFlushResourceProvider* onFlushRP,
345345
SkIVector newOffset;
346346
GrCCAtlas* atlas =
347347
resources->copyPathToCachedAtlas(*cacheEntry, doEvenOddFill, &newOffset);
348-
cacheEntry->updateToCachedAtlas(atlas->getOrAssignUniqueKey(onFlushRP), newOffset,
349-
atlas->refOrMakeCachedAtlasInfo());
348+
cacheEntry->updateToCachedAtlas(
349+
atlas->getOrAssignUniqueKey(onFlushRP), newOffset,
350+
atlas->refOrMakeCachedAtlasInfo(onFlushRP->contextUniqueID()));
350351
this->recordInstance(atlas->textureProxy(), resources->nextPathInstanceIdx());
351352
resources->appendDrawPathInstance().set(*cacheEntry, draw.fCachedMaskShift,
352353
draw.fColor);

src/gpu/ccpr/GrCCPathCache.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212

1313
DECLARE_SKMESSAGEBUS_MESSAGE(sk_sp<GrCCPathCacheEntry>);
1414

15+
static inline uint32_t next_path_cache_id() {
16+
static std::atomic<uint32_t> gNextID(1);
17+
for (;;) {
18+
uint32_t id = gNextID.fetch_add(+1, std::memory_order_acquire);
19+
if (SK_InvalidUniqueID != id) {
20+
return id;
21+
}
22+
}
23+
}
24+
1525
static inline bool SkShouldPostMessageToBus(
1626
const sk_sp<GrCCPathCacheEntry>& entry, uint32_t msgBusUniqueID) {
1727
return entry->pathCacheUniqueID() == msgBusUniqueID;
@@ -20,6 +30,7 @@ static inline bool SkShouldPostMessageToBus(
2030
// The maximum number of cache entries we allow in our own cache.
2131
static constexpr int kMaxCacheCount = 1 << 16;
2232

33+
2334
GrCCPathCache::MaskTransform::MaskTransform(const SkMatrix& m, SkIVector* shift)
2435
: fMatrix2x2{m.getScaleX(), m.getSkewX(), m.getSkewY(), m.getScaleY()} {
2536
SkASSERT(!m.hasPerspective());
@@ -128,6 +139,11 @@ inline uint32_t GrCCPathCache::HashNode::Hash(HashKey key) {
128139
return GrResourceKeyHash(&key.fData[1], key.fData[0]);
129140
}
130141

142+
143+
GrCCPathCache::GrCCPathCache()
144+
: fInvalidatedEntriesInbox(next_path_cache_id()) {
145+
}
146+
131147
#ifdef SK_DEBUG
132148
GrCCPathCache::~GrCCPathCache() {
133149
// Ensure the hash table and LRU list are still coherent.
@@ -248,9 +264,8 @@ void GrCCPathCacheEntry::invalidateAtlas() {
248264
fCachedAtlasInfo->fNumInvalidatedPathPixels >= fCachedAtlasInfo->fNumPathPixels / 2) {
249265
// Too many invalidated pixels: purge the atlas texture from the resource cache.
250266
// The GrContext and CCPR path cache both share the same unique ID.
251-
uint32_t contextUniqueID = fPathCacheUniqueID;
252267
SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(
253-
GrUniqueKeyInvalidatedMessage(fAtlasKey, contextUniqueID));
268+
GrUniqueKeyInvalidatedMessage(fAtlasKey, fCachedAtlasInfo->fContextUniqueID));
254269
fCachedAtlasInfo->fIsPurgedFromResourceCache = true;
255270
}
256271
}

src/gpu/ccpr/GrCCPathCache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GrShape;
2424
*/
2525
class GrCCPathCache {
2626
public:
27-
GrCCPathCache(uint32_t contextUniqueID) : fInvalidatedEntriesInbox(contextUniqueID) {}
27+
GrCCPathCache();
2828
SkDEBUGCODE(~GrCCPathCache();)
2929

3030
// Stores the components of a transformation that affect a path mask (i.e. everything but

src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,15 @@ bool GrCoverageCountingPathRenderer::IsSupported(const GrCaps& caps) {
3030
}
3131

3232
sk_sp<GrCoverageCountingPathRenderer> GrCoverageCountingPathRenderer::CreateIfSupported(
33-
const GrCaps& caps, AllowCaching allowCaching, uint32_t contextUniqueID) {
33+
const GrCaps& caps, AllowCaching allowCaching) {
3434
return sk_sp<GrCoverageCountingPathRenderer>((IsSupported(caps))
35-
? new GrCoverageCountingPathRenderer(allowCaching, contextUniqueID)
35+
? new GrCoverageCountingPathRenderer(allowCaching)
3636
: nullptr);
3737
}
3838

39-
GrCoverageCountingPathRenderer::GrCoverageCountingPathRenderer(AllowCaching allowCaching,
40-
uint32_t contextUniqueID) {
39+
GrCoverageCountingPathRenderer::GrCoverageCountingPathRenderer(AllowCaching allowCaching) {
4140
if (AllowCaching::kYes == allowCaching) {
42-
fPathCache = skstd::make_unique<GrCCPathCache>(contextUniqueID);
41+
fPathCache = skstd::make_unique<GrCCPathCache>();
4342
}
4443
}
4544

src/gpu/ccpr/GrCoverageCountingPathRenderer.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class GrCoverageCountingPathRenderer : public GrPathRenderer, public GrOnFlushCa
3434
kYes = true
3535
};
3636

37-
static sk_sp<GrCoverageCountingPathRenderer> CreateIfSupported(const GrCaps&, AllowCaching,
38-
uint32_t contextUniqueID);
37+
static sk_sp<GrCoverageCountingPathRenderer> CreateIfSupported(const GrCaps&, AllowCaching);
3938

4039
using PendingPathsMap = std::map<uint32_t, sk_sp<GrCCPerOpListPaths>>;
4140

@@ -83,7 +82,7 @@ class GrCoverageCountingPathRenderer : public GrPathRenderer, public GrOnFlushCa
8382
float* inflationRadius = nullptr);
8483

8584
private:
86-
GrCoverageCountingPathRenderer(AllowCaching, uint32_t contextUniqueID);
85+
GrCoverageCountingPathRenderer(AllowCaching);
8786

8887
// GrPathRenderer overrides.
8988
StencilSupport onGetStencilSupport(const GrShape&) const override {

src/gpu/ccpr/GrCoverageCountingPathRenderer_none.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ bool GrCoverageCountingPathRenderer::IsSupported(const GrCaps& caps) {
1212
}
1313

1414
sk_sp<GrCoverageCountingPathRenderer> GrCoverageCountingPathRenderer::CreateIfSupported(
15-
const GrCaps& caps, AllowCaching allowCaching, uint32_t contextUniqueID) {
15+
const GrCaps& caps, AllowCaching allowCaching) {
1616
return nullptr;
1717
}
1818

0 commit comments

Comments
 (0)