diff options
Diffstat (limited to 'src')
29 files changed, 139 insertions, 68 deletions
diff --git a/src/core/SkResourceCache.h b/src/core/SkResourceCache.h index 6087be7824..4794669492 100644 --- a/src/core/SkResourceCache.h +++ b/src/core/SkResourceCache.h @@ -112,7 +112,9 @@ public: // Used with SkMessageBus struct PurgeSharedIDMessage { PurgeSharedIDMessage(uint64_t sharedID) : fSharedID(sharedID) {} - + // SkResourceCache is typically used as a singleton and we don't label Inboxes so all + // messages go to all inboxes. + bool shouldSend(uint32_t inboxID) const { return true; } uint64_t fSharedID; }; diff --git a/src/gpu/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp index d2a1fbe3e9..7a70587619 100644 --- a/src/gpu/GrBitmapTextureMaker.cpp +++ b/src/gpu/GrBitmapTextureMaker.cpp @@ -61,7 +61,8 @@ sk_sp<GrTextureProxy> GrBitmapTextureMaker::refOriginalTextureProxy(bool willBeM if (!willBeMipped || GrMipMapped::kYes == proxy->mipMapped()) { SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin); if (fOriginalKey.isValid()) { - GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, fBitmap.pixelRef()); + GrInstallBitmapUniqueKeyInvalidator( + fOriginalKey, proxyProvider->contextUniqueID(), fBitmap.pixelRef()); } return proxy; } @@ -85,7 +86,8 @@ sk_sp<GrTextureProxy> GrBitmapTextureMaker::refOriginalTextureProxy(bool willBeM // time it too will be deleted or recycled. proxyProvider->removeUniqueKeyFromProxy(fOriginalKey, proxy.get()); proxyProvider->assignUniqueKeyToProxy(fOriginalKey, mippedProxy.get()); - GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, fBitmap.pixelRef()); + GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, proxyProvider->contextUniqueID(), + fBitmap.pixelRef()); } return mippedProxy; } @@ -105,8 +107,8 @@ void GrBitmapTextureMaker::makeCopyKey(const CopyParams& copyParams, GrUniqueKey } } -void GrBitmapTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { - GrInstallBitmapUniqueKeyInvalidator(copyKey, fBitmap.pixelRef()); +void GrBitmapTextureMaker::didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) { + GrInstallBitmapUniqueKeyInvalidator(copyKey, contextUniqueID, fBitmap.pixelRef()); } SkAlphaType GrBitmapTextureMaker::alphaType() const { diff --git a/src/gpu/GrBitmapTextureMaker.h b/src/gpu/GrBitmapTextureMaker.h index f945cbc4c6..22d8ca37ed 100644 --- a/src/gpu/GrBitmapTextureMaker.h +++ b/src/gpu/GrBitmapTextureMaker.h @@ -26,7 +26,7 @@ protected: void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey, SkColorSpace* dstColorSpace) override; - void didCacheCopy(const GrUniqueKey& copyKey) override; + void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override; SkAlphaType alphaType() const override; sk_sp<SkColorSpace> getColorSpace(SkColorSpace* dstColorSpace) override; diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp index 8095286329..7704d929f9 100644 --- a/src/gpu/GrClipStackClip.cpp +++ b/src/gpu/GrClipStackClip.cpp @@ -313,12 +313,13 @@ static void create_clip_mask_key(uint32_t clipGenID, const SkIRect& bounds, int } static void add_invalidate_on_pop_message(const SkClipStack& stack, uint32_t clipGenID, - const GrUniqueKey& clipMaskKey) { + const GrUniqueKey& clipMaskKey, + uint32_t contextUniqueID) { SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); while (const Element* element = iter.prev()) { if (element->getGenID() == clipGenID) { std::unique_ptr<GrUniqueKeyInvalidatedMessage> msg( - new GrUniqueKeyInvalidatedMessage(clipMaskKey)); + new GrUniqueKeyInvalidatedMessage(clipMaskKey, contextUniqueID)); element->addResourceInvalidationMessage(std::move(msg)); return; } @@ -363,7 +364,7 @@ sk_sp<GrTextureProxy> GrClipStackClip::createAlphaClipMask(GrContext* context, SkASSERT(result->origin() == kTopLeft_GrSurfaceOrigin); proxyProvider->assignUniqueKeyToProxy(key, result.get()); - add_invalidate_on_pop_message(*fStack, reducedClip.maskGenID(), key); + add_invalidate_on_pop_message(*fStack, reducedClip.maskGenID(), key, context->uniqueID()); return result; } @@ -504,6 +505,6 @@ sk_sp<GrTextureProxy> GrClipStackClip::createSoftwareClipMask( SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin); proxyProvider->assignUniqueKeyToProxy(key, proxy.get()); - add_invalidate_on_pop_message(*fStack, reducedClip.maskGenID(), key); + add_invalidate_on_pop_message(*fStack, reducedClip.maskGenID(), key, context->uniqueID()); return proxy; } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 6cf5d050a8..dd4f3218fa 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -85,10 +85,12 @@ bool GrContext::initCommon(const GrContextOptions& options) { fResourceCache = new GrResourceCache(fCaps.get(), fUniqueID); fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, &fSingleOwner, options.fExplicitlyAllocateGPUResources); + fProxyProvider = + new GrProxyProvider(fResourceProvider, fResourceCache, fCaps, &fSingleOwner); + } else { + fProxyProvider = new GrProxyProvider(this->uniqueID(), fCaps, &fSingleOwner); } - fProxyProvider = new GrProxyProvider(fResourceProvider, fResourceCache, fCaps, &fSingleOwner); - if (fResourceCache) { fResourceCache->setProxyProvider(fProxyProvider); } diff --git a/src/gpu/GrImageTextureMaker.cpp b/src/gpu/GrImageTextureMaker.cpp index 732811615f..a8e62162a6 100644 --- a/src/gpu/GrImageTextureMaker.cpp +++ b/src/gpu/GrImageTextureMaker.cpp @@ -42,7 +42,7 @@ void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* pa } } -void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { +void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) { as_IB(fClient)->notifyAddedToCache(); } diff --git a/src/gpu/GrImageTextureMaker.h b/src/gpu/GrImageTextureMaker.h index 1a72f68e1b..1fe882a4f3 100644 --- a/src/gpu/GrImageTextureMaker.h +++ b/src/gpu/GrImageTextureMaker.h @@ -29,7 +29,7 @@ protected: void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey, SkColorSpace* dstColorSpace) override; - void didCacheCopy(const GrUniqueKey& copyKey) override; + void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override; SkAlphaType alphaType() const override; sk_sp<SkColorSpace> getColorSpace(SkColorSpace* dstColorSpace) override; diff --git a/src/gpu/GrOnFlushResourceProvider.cpp b/src/gpu/GrOnFlushResourceProvider.cpp index ddf66020d2..26b59f93b9 100644 --- a/src/gpu/GrOnFlushResourceProvider.cpp +++ b/src/gpu/GrOnFlushResourceProvider.cpp @@ -6,6 +6,7 @@ */ #include "GrOnFlushResourceProvider.h" +#include "GrContext.h" #include "GrContextPriv.h" #include "GrDrawingManager.h" #include "GrProxyProvider.h" @@ -130,6 +131,10 @@ sk_sp<const GrBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(GrBuffer return buffer; } +uint32_t GrOnFlushResourceProvider::contextUniqueID() const { + return fDrawingMgr->getContext()->uniqueID(); +} + const GrCaps* GrOnFlushResourceProvider::caps() const { return fDrawingMgr->getContext()->contextPriv().caps(); } diff --git a/src/gpu/GrOnFlushResourceProvider.h b/src/gpu/GrOnFlushResourceProvider.h index d01f1342ea..c30ec61daa 100644 --- a/src/gpu/GrOnFlushResourceProvider.h +++ b/src/gpu/GrOnFlushResourceProvider.h @@ -8,7 +8,6 @@ #ifndef GrOnFlushResourceProvider_DEFINED #define GrOnFlushResourceProvider_DEFINED -#include "GrTypes.h" #include "GrDeferredUpload.h" #include "GrOpFlushState.h" #include "GrResourceProvider.h" @@ -21,7 +20,6 @@ class GrOnFlushResourceProvider; class GrRenderTargetOpList; class GrRenderTargetContext; class GrSurfaceProxy; - class SkColorSpace; class SkSurfaceProps; @@ -31,7 +29,7 @@ class SkSurfaceProps; */ class GrOnFlushCallbackObject { public: - virtual ~GrOnFlushCallbackObject() { } + virtual ~GrOnFlushCallbackObject() {} /* * The onFlush callback allows subsystems (e.g., text, path renderers) to create atlases @@ -91,6 +89,7 @@ public: sk_sp<const GrBuffer> findOrMakeStaticBuffer(GrBufferType, size_t, const void* data, const GrUniqueKey&); + uint32_t contextUniqueID() const; const GrCaps* caps() const; private: diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp index e259e34e28..df7b61e700 100644 --- a/src/gpu/GrProxyProvider.cpp +++ b/src/gpu/GrProxyProvider.cpp @@ -37,11 +37,32 @@ GrProxyProvider::GrProxyProvider(GrResourceProvider* resourceProvider, , fResourceCache(resourceCache) , fAbandoned(false) , fCaps(caps) + , fContextUniqueID(resourceCache->contextUniqueID()) #ifdef SK_DEBUG , fSingleOwner(owner) #endif { + SkASSERT(fResourceProvider); + SkASSERT(fResourceCache); + SkASSERT(fCaps); + SkASSERT(fSingleOwner); +} +GrProxyProvider::GrProxyProvider(uint32_t contextUniqueID, + sk_sp<const GrCaps> caps, + GrSingleOwner* owner) + : fResourceProvider(nullptr) + , fResourceCache(nullptr) + , fAbandoned(false) + , fCaps(caps) + , fContextUniqueID(contextUniqueID) +#ifdef SK_DEBUG + , fSingleOwner(owner) +#endif +{ + SkASSERT(fContextUniqueID != SK_InvalidUniqueID); + SkASSERT(fCaps); + SkASSERT(fSingleOwner); } GrProxyProvider::~GrProxyProvider() { diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h index 64b9ac4355..89f9518e46 100644 --- a/src/gpu/GrProxyProvider.h +++ b/src/gpu/GrProxyProvider.h @@ -27,6 +27,7 @@ class SkImage; class GrProxyProvider { public: GrProxyProvider(GrResourceProvider*, GrResourceCache*, sk_sp<const GrCaps>, GrSingleOwner*); + GrProxyProvider(uint32_t contextUniqueID, sk_sp<const GrCaps>, GrSingleOwner*); ~GrProxyProvider(); @@ -211,6 +212,7 @@ public: */ void processInvalidProxyUniqueKey(const GrUniqueKey&, GrTextureProxy*, bool invalidateSurface); + uint32_t contextUniqueID() const { return fContextUniqueID; } const GrCaps* caps() const { return fCaps.get(); } sk_sp<const GrCaps> refCaps() const { return fCaps; } @@ -258,6 +260,8 @@ private: GrResourceCache* fResourceCache; bool fAbandoned; sk_sp<const GrCaps> fCaps; + // If this provider is owned by a DDLContext then this is the DirectContext's ID. + uint32_t fContextUniqueID; // In debug builds we guard against improper thread handling SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;) diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h index ee0d183981..376fe10735 100644 --- a/src/gpu/GrRenderTargetContext.h +++ b/src/gpu/GrRenderTargetContext.h @@ -16,6 +16,7 @@ #include "GrSurfaceContext.h" #include "GrTypesPriv.h" #include "GrXferProcessor.h" +#include "SkCanvas.h" #include "SkRefCnt.h" #include "SkSurfaceProps.h" #include "text/GrTextUtils.h" diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index c4e940980e..23c8e7c996 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -63,27 +63,29 @@ private: ////////////////////////////////////////////////////////////////////////////// - GrResourceCache::GrResourceCache(const GrCaps* caps, uint32_t contextUniqueID) - : fProxyProvider(nullptr) - , fTimestamp(0) - , fMaxCount(kDefaultMaxCount) - , fMaxBytes(kDefaultMaxSize) - , fMaxUnusedFlushes(kDefaultMaxUnusedFlushes) + : fProxyProvider(nullptr) + , fTimestamp(0) + , fMaxCount(kDefaultMaxCount) + , fMaxBytes(kDefaultMaxSize) + , fMaxUnusedFlushes(kDefaultMaxUnusedFlushes) #if GR_CACHE_STATS - , fHighWaterCount(0) - , fHighWaterBytes(0) - , fBudgetedHighWaterCount(0) - , fBudgetedHighWaterBytes(0) + , fHighWaterCount(0) + , fHighWaterBytes(0) + , fBudgetedHighWaterCount(0) + , fBudgetedHighWaterBytes(0) #endif - , fBytes(0) - , fBudgetedCount(0) - , fBudgetedBytes(0) - , fPurgeableBytes(0) - , fRequestFlush(false) - , fExternalFlushCnt(0) - , fContextUniqueID(contextUniqueID) - , fPreferVRAMUseOverFlushes(caps->preferVRAMUseOverFlushes()) { + , fBytes(0) + , fBudgetedCount(0) + , fBudgetedBytes(0) + , fPurgeableBytes(0) + , fRequestFlush(false) + , fExternalFlushCnt(0) + , fInvalidUniqueKeyInbox(contextUniqueID) + , fFreedGpuResourceInbox(contextUniqueID) + , fContextUniqueID(contextUniqueID) + , fPreferVRAMUseOverFlushes(caps->preferVRAMUseOverFlushes()) { + SkASSERT(contextUniqueID != SK_InvalidUniqueID); SkDEBUGCODE(fCount = 0;) SkDEBUGCODE(fNewlyPurgeableResourceForValidation = nullptr;) } @@ -604,9 +606,8 @@ void GrResourceCache::processFreedGpuResources() { SkTArray<GrGpuResourceFreedMessage> msgs; fFreedGpuResourceInbox.poll(&msgs); for (int i = 0; i < msgs.count(); ++i) { - if (msgs[i].fOwningUniqueID == fContextUniqueID) { - msgs[i].fResource->unref(); - } + SkASSERT(msgs[i].fOwningUniqueID == fContextUniqueID); + msgs[i].fResource->unref(); } } diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h index 771b13fb26..507c192f43 100644 --- a/src/gpu/GrResourceCache.h +++ b/src/gpu/GrResourceCache.h @@ -27,6 +27,10 @@ class SkTraceMemoryDump; struct GrGpuResourceFreedMessage { GrGpuResource* fResource; uint32_t fOwningUniqueID; + bool shouldSend(uint32_t inboxID) const { + // The inbox's ID is the unique ID of the owning GrContext. + return inboxID == fOwningUniqueID; + } }; /** @@ -67,6 +71,9 @@ public: class ResourceAccess; ResourceAccess resourceAccess(); + /** Unique ID of the owning GrContext. */ + uint32_t contextUniqueID() const { return fContextUniqueID; } + /** * Sets the cache limits in terms of number of resources, max gpu memory byte size, and number * of external GrContext flushes that a resource can be unused before it is evicted. The latter diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h index 35c36826af..347a5de2cd 100644 --- a/src/gpu/GrResourceProvider.h +++ b/src/gpu/GrResourceProvider.h @@ -251,6 +251,7 @@ public: fGpu = nullptr; } + uint32_t contextUniqueID() const { return fCache->contextUniqueID(); } const GrCaps* caps() const { return fCaps.get(); } bool overBudget() const { return fCache->overBudget(); } diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp index ee52122840..213dbdb025 100644 --- a/src/gpu/GrSoftwarePathRenderer.cpp +++ b/src/gpu/GrSoftwarePathRenderer.cpp @@ -216,7 +216,9 @@ private: // When the SkPathRef genID changes, invalidate a corresponding GrResource described by key. class PathInvalidator : public SkPathRef::GenIDChangeListener { public: - explicit PathInvalidator(const GrUniqueKey& key) : fMsg(key) {} + PathInvalidator(const GrUniqueKey& key, uint32_t contextUniqueID) + : fMsg(key, contextUniqueID) {} + private: GrUniqueKeyInvalidatedMessage fMsg; @@ -366,7 +368,8 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) { if (useCache) { SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin); fProxyProvider->assignUniqueKeyToProxy(maskKey, proxy.get()); - args.fShape->addGenIDChangeListener(sk_make_sp<PathInvalidator>(maskKey)); + args.fShape->addGenIDChangeListener( + sk_make_sp<PathInvalidator>(maskKey, args.fContext->uniqueID())); } } if (inverseFilled) { diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp index 4b21bac9d0..d016896c3f 100644 --- a/src/gpu/GrTextureAdjuster.cpp +++ b/src/gpu/GrTextureAdjuster.cpp @@ -33,7 +33,7 @@ void GrTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* copyK MakeCopyKeyFromOrigKey(baseKey, params, copyKey); } -void GrTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) { +void GrTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) { // We don't currently have a mechanism for notifications on Images! } @@ -67,7 +67,7 @@ sk_sp<GrTextureProxy> GrTextureAdjuster::refTextureProxyCopy(const CopyParams& c proxyProvider->removeUniqueKeyFromProxy(key, cachedCopy.get()); } proxyProvider->assignUniqueKeyToProxy(key, copy.get()); - this->didCacheCopy(key); + this->didCacheCopy(key, proxyProvider->contextUniqueID()); } } return copy; diff --git a/src/gpu/GrTextureAdjuster.h b/src/gpu/GrTextureAdjuster.h index 885e39059d..e43e87b1dc 100644 --- a/src/gpu/GrTextureAdjuster.h +++ b/src/gpu/GrTextureAdjuster.h @@ -37,7 +37,7 @@ protected: SkAlphaType alphaType() const override { return fAlphaType; } void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey, SkColorSpace* dstColorSpace) override; - void didCacheCopy(const GrUniqueKey& copyKey) override; + void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override; GrTextureProxy* originalProxy() const { return fOriginal.get(); } sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; } diff --git a/src/gpu/GrTextureMaker.cpp b/src/gpu/GrTextureMaker.cpp index f9ee7585d2..22870cc7c8 100644 --- a/src/gpu/GrTextureMaker.cpp +++ b/src/gpu/GrTextureMaker.cpp @@ -109,7 +109,7 @@ sk_sp<GrTextureProxy> GrTextureMaker::onRefTextureProxyForParams(const GrSampler proxyProvider->removeUniqueKeyFromProxy(copyKey, cachedProxy.get()); } proxyProvider->assignUniqueKeyToProxy(copyKey, result.get()); - this->didCacheCopy(copyKey); + this->didCacheCopy(copyKey, proxyProvider->contextUniqueID()); } return result; } diff --git a/src/gpu/GrTextureProducer.h b/src/gpu/GrTextureProducer.h index c458d4fbe6..176247b67e 100644 --- a/src/gpu/GrTextureProducer.h +++ b/src/gpu/GrTextureProducer.h @@ -158,8 +158,7 @@ protected: * makeCopyKey() returns true). In that case, the maker is notified in case it * wants to note that for when the maker is destroyed. */ - virtual void didCacheCopy(const GrUniqueKey& copyKey) = 0; - + virtual void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) = 0; enum DomainMode { kNoDomain_DomainMode, diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index ff2b9843e8..5baf0d4017 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -88,17 +88,20 @@ sk_sp<GrTextureProxy> GrUploadBitmapToTextureProxy(GrProxyProvider* proxyProvide //////////////////////////////////////////////////////////////////////////////// -void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pixelRef) { +void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, uint32_t contextUniqueID, + SkPixelRef* pixelRef) { class Invalidator : public SkPixelRef::GenIDChangeListener { public: - explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} + explicit Invalidator(const GrUniqueKey& key, uint32_t contextUniqueID) + : fMsg(key, contextUniqueID) {} + private: GrUniqueKeyInvalidatedMessage fMsg; void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg); } }; - pixelRef->addGenIDChangeListener(new Invalidator(key)); + pixelRef->addGenIDChangeListener(new Invalidator(key, contextUniqueID)); } sk_sp<GrTextureProxy> GrCopyBaseMipMapToTextureProxy(GrContext* ctx, GrTextureProxy* baseProxy) { @@ -199,7 +202,8 @@ sk_sp<GrTextureProxy> GrMakeCachedImageProxy(GrProxyProvider* proxyProvider, // When recording DDLs we do not want to install change listeners because doing // so isn't threadsafe. if (bm && !proxyProvider->recordingDDL()) { - GrInstallBitmapUniqueKeyInvalidator(originalKey, bm->pixelRef()); + GrInstallBitmapUniqueKeyInvalidator(originalKey, proxyProvider->contextUniqueID(), + bm->pixelRef()); } } } diff --git a/src/gpu/SkGr.h b/src/gpu/SkGr.h index a2ac670712..ec9f30a3bf 100644 --- a/src/gpu/SkGr.h +++ b/src/gpu/SkGr.h @@ -243,6 +243,7 @@ void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& ima /** Call this after installing a GrUniqueKey on texture. It will cause the texture's key to be removed should the bitmap's contents change or be destroyed. */ -void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pixelRef); +void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, uint32_t contextUniqueID, + SkPixelRef* pixelRef); #endif diff --git a/src/gpu/ccpr/GrCCDrawPathsOp.cpp b/src/gpu/ccpr/GrCCDrawPathsOp.cpp index 2d250deb00..016756a7f6 100644 --- a/src/gpu/ccpr/GrCCDrawPathsOp.cpp +++ b/src/gpu/ccpr/GrCCDrawPathsOp.cpp @@ -251,7 +251,8 @@ void GrCCDrawPathsOp::setupResources(GrOnFlushResourceProvider* onFlushRP, GrCCAtlas* atlas = resources->copyPathToCachedAtlas(*cacheEntry, doEvenOddFill, &newOffset); cacheEntry->updateToCachedAtlas(atlas->getOrAssignUniqueKey(onFlushRP), - newOffset, atlas->refOrMakeCachedAtlasInfo()); + onFlushRP->contextUniqueID(), newOffset, + atlas->refOrMakeCachedAtlasInfo()); this->recordInstance(atlas->textureProxy(), resources->nextPathInstanceIdx()); resources->appendDrawPathInstance().set(*cacheEntry, draw.fCachedMaskShift, draw.fColor); @@ -296,8 +297,9 @@ void GrCCDrawPathsOp::setupResources(GrOnFlushResourceProvider* onFlushRP, const GrUniqueKey& atlasKey = resources->nextAtlasToStash()->getOrAssignUniqueKey(onFlushRP); - cacheEntry->initAsStashedAtlas(atlasKey, devToAtlasOffset, devBounds, devBounds45, - devIBounds, draw.fCachedMaskShift); + cacheEntry->initAsStashedAtlas(atlasKey, onFlushRP->contextUniqueID(), + devToAtlasOffset, devBounds, devBounds45, devIBounds, + draw.fCachedMaskShift); // Remember this atlas in case we encounter the path again during the same flush. cacheEntry->setCurrFlushAtlas(atlas); } diff --git a/src/gpu/ccpr/GrCCPathCache.cpp b/src/gpu/ccpr/GrCCPathCache.cpp index b22b1dd726..d7dc714c82 100644 --- a/src/gpu/ccpr/GrCCPathCache.cpp +++ b/src/gpu/ccpr/GrCCPathCache.cpp @@ -149,13 +149,16 @@ GrCCPathCacheEntry::~GrCCPathCacheEntry() { this->invalidateAtlas(); } -void GrCCPathCacheEntry::initAsStashedAtlas(const GrUniqueKey& atlasKey, +void GrCCPathCacheEntry::initAsStashedAtlas(const GrUniqueKey& atlasKey, uint32_t contextUniqueID, const SkIVector& atlasOffset, const SkRect& devBounds, const SkRect& devBounds45, const SkIRect& devIBounds, const SkIVector& maskShift) { + SkASSERT(contextUniqueID != SK_InvalidUniqueID); SkASSERT(atlasKey.isValid()); SkASSERT(!fCurrFlushAtlas); // Otherwise we should reuse the atlas from last time. + fContextUniqueID = contextUniqueID; + fAtlasKey = atlasKey; fAtlasOffset = atlasOffset + maskShift; SkASSERT(!fCachedAtlasInfo); // Otherwise they should have reused the cached atlas instead. @@ -166,12 +169,15 @@ void GrCCPathCacheEntry::initAsStashedAtlas(const GrUniqueKey& atlasKey, fDevIBounds = devIBounds.makeOffset(-maskShift.fX, -maskShift.fY); } -void GrCCPathCacheEntry::updateToCachedAtlas(const GrUniqueKey& atlasKey, +void GrCCPathCacheEntry::updateToCachedAtlas(const GrUniqueKey& atlasKey, uint32_t contextUniqueID, const SkIVector& newAtlasOffset, sk_sp<GrCCAtlas::CachedAtlasInfo> info) { + SkASSERT(contextUniqueID != SK_InvalidUniqueID); SkASSERT(atlasKey.isValid()); SkASSERT(!fCurrFlushAtlas); // Otherwise we should reuse the atlas from last time. + fContextUniqueID = contextUniqueID; + fAtlasKey = atlasKey; fAtlasOffset = newAtlasOffset; @@ -188,7 +194,7 @@ void GrCCPathCacheEntry::invalidateAtlas() { fCachedAtlasInfo->fNumInvalidatedPathPixels >= fCachedAtlasInfo->fNumPathPixels / 2) { // Too many invalidated pixels: purge the atlas texture from the resource cache. SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post( - GrUniqueKeyInvalidatedMessage(fAtlasKey)); + GrUniqueKeyInvalidatedMessage(fAtlasKey, fContextUniqueID)); fCachedAtlasInfo->fIsPurgedFromResourceCache = true; } } diff --git a/src/gpu/ccpr/GrCCPathCache.h b/src/gpu/ccpr/GrCCPathCache.h index 67e7d9f571..7a552bbc2a 100644 --- a/src/gpu/ccpr/GrCCPathCache.h +++ b/src/gpu/ccpr/GrCCPathCache.h @@ -121,14 +121,15 @@ public: // Called once our path has been rendered into the mainline CCPR (fp16, coverage count) atlas. // The caller will stash this atlas texture away after drawing, and during the next flush, // recover it and attempt to copy any paths that got reused into permanent 8-bit atlases. - void initAsStashedAtlas(const GrUniqueKey& atlasKey, const SkIVector& atlasOffset, - const SkRect& devBounds, const SkRect& devBounds45, - const SkIRect& devIBounds, const SkIVector& maskShift); + void initAsStashedAtlas(const GrUniqueKey& atlasKey, uint32_t contextUniqueID, + const SkIVector& atlasOffset, const SkRect& devBounds, + const SkRect& devBounds45, const SkIRect& devIBounds, + const SkIVector& maskShift); // Called once our path mask has been copied into a permanent, 8-bit atlas. This method points // the entry at the new atlas and updates the CachedAtlasInfo data. - void updateToCachedAtlas(const GrUniqueKey& atlasKey, const SkIVector& newAtlasOffset, - sk_sp<GrCCAtlas::CachedAtlasInfo>); + void updateToCachedAtlas(const GrUniqueKey& atlasKey, uint32_t contextUniqueID, + const SkIVector& newAtlasOffset, sk_sp<GrCCAtlas::CachedAtlasInfo>); const GrUniqueKey& atlasKey() const { return fAtlasKey; } @@ -162,6 +163,7 @@ private: // Called when our corresponding path is modified or deleted. void onChange() override; + uint32_t fContextUniqueID; GrCCPathCache* fCacheWeakPtr; // Gets manually reset to null by the path cache upon eviction. MaskTransform fMaskTransform; int fHitCount = 1; diff --git a/src/gpu/ops/GrMeshDrawOp.h b/src/gpu/ops/GrMeshDrawOp.h index ddc29f1dab..449fd53807 100644 --- a/src/gpu/ops/GrMeshDrawOp.h +++ b/src/gpu/ops/GrMeshDrawOp.h @@ -170,6 +170,7 @@ public: virtual const GrXferProcessor::DstProxy& dstProxy() const = 0; virtual GrResourceProvider* resourceProvider() const = 0; + uint32_t contextUniqueID() const { return this->resourceProvider()->contextUniqueID(); } virtual GrGlyphCache* glyphCache() const = 0; virtual GrAtlasManager* atlasManager() const = 0; diff --git a/src/gpu/ops/GrTessellatingPathRenderer.cpp b/src/gpu/ops/GrTessellatingPathRenderer.cpp index 1c0a7f5551..475197e197 100644 --- a/src/gpu/ops/GrTessellatingPathRenderer.cpp +++ b/src/gpu/ops/GrTessellatingPathRenderer.cpp @@ -42,7 +42,9 @@ struct TessInfo { // When the SkPathRef genID changes, invalidate a corresponding GrResource described by key. class PathInvalidator : public SkPathRef::GenIDChangeListener { public: - explicit PathInvalidator(const GrUniqueKey& key) : fMsg(key) {} + PathInvalidator(const GrUniqueKey& key, uint32_t contextUniqueID) + : fMsg(key, contextUniqueID) {} + private: GrUniqueKeyInvalidatedMessage fMsg; @@ -284,7 +286,7 @@ private: info.fCount = count; key.setCustomData(SkData::MakeWithCopy(&info, sizeof(info))); rp->assignUniqueKeyToResource(key, allocator.vertexBuffer()); - fShape.addGenIDChangeListener(sk_make_sp<PathInvalidator>(key)); + fShape.addGenIDChangeListener(sk_make_sp<PathInvalidator>(key, target->contextUniqueID())); } void drawAA(Target* target, const GrGeometryProcessor* gp, size_t vertexStride) { diff --git a/src/gpu/text/GrTextBlobCache.cpp b/src/gpu/text/GrTextBlobCache.cpp index 71d9052ade..a60903fca3 100644 --- a/src/gpu/text/GrTextBlobCache.cpp +++ b/src/gpu/text/GrTextBlobCache.cpp @@ -30,7 +30,7 @@ void GrTextBlobCache::freeAll() { void GrTextBlobCache::PostPurgeBlobMessage(uint32_t blobID, uint32_t cacheID) { SkASSERT(blobID != SK_InvalidGenID); - SkMessageBus<PurgeBlobMessage>::Post(PurgeBlobMessage({blobID}), cacheID); + SkMessageBus<PurgeBlobMessage>::Post(PurgeBlobMessage(blobID, cacheID)); } void GrTextBlobCache::purgeStaleBlobs() { @@ -38,7 +38,7 @@ void GrTextBlobCache::purgeStaleBlobs() { fPurgeBlobInbox.poll(&msgs); for (const auto& msg : msgs) { - auto* idEntry = fBlobIDCache.find(msg.fID); + auto* idEntry = fBlobIDCache.find(msg.fBlobID); if (!idEntry) { // no cache entries for id continue; @@ -51,7 +51,7 @@ void GrTextBlobCache::purgeStaleBlobs() { } // drop the idEntry itself (unrefs all blobs) - fBlobIDCache.remove(msg.fID); + fBlobIDCache.remove(msg.fBlobID); } } diff --git a/src/gpu/text/GrTextBlobCache.h b/src/gpu/text/GrTextBlobCache.h index b41d401aee..a174c9cf90 100644 --- a/src/gpu/text/GrTextBlobCache.h +++ b/src/gpu/text/GrTextBlobCache.h @@ -99,7 +99,12 @@ public: } struct PurgeBlobMessage { - uint32_t fID; + PurgeBlobMessage(uint32_t blobID, uint32_t contextUniqueID) + : fBlobID(blobID), fContextID(contextUniqueID) {} + bool shouldSend(uint32_t inboxID) const { return fContextID == inboxID; } + + uint32_t fBlobID; + uint32_t fContextID; }; static void PostPurgeBlobMessage(uint32_t blobID, uint32_t cacheID); |