Rename GrContext::uniqueID to contextID and hide it
The GrContext's ID isn't really unique any more (since it can be shared among a family of contexts). Change its name to reflect the new reality.
Additionally, no client seems to be using it so make it private.
Change-Id: Ibb9004d699fe6ca7876b3be94142e612b5b9efbd
Reviewed-on: https://skia-review.googlesource.com/c/188308
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index 9d22f6e..a2032c6 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -192,7 +192,7 @@
#if SK_SUPPORT_GPU
if (sk_sp<GrTextureProxy> proxy = as_IB(image)->asTextureProxyRef()) {
- if (as_IB(image)->contextID() != context->uniqueID()) {
+ if (as_IB(image)->contextID() != context->contextPriv().contextID()) {
return nullptr;
}
diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp
index 8f2dcd6..7926956 100644
--- a/src/gpu/GrBackendTextureImageGenerator.cpp
+++ b/src/gpu/GrBackendTextureImageGenerator.cpp
@@ -56,7 +56,8 @@
SkImageInfo info = SkImageInfo::Make(texture->width(), texture->height(), colorType, alphaType,
std::move(colorSpace));
return std::unique_ptr<SkImageGenerator>(new GrBackendTextureImageGenerator(
- info, texture.get(), origin, context->uniqueID(), std::move(semaphore), backendTexture));
+ info, texture.get(), origin, context->contextPriv().contextID(),
+ std::move(semaphore), backendTexture));
}
GrBackendTextureImageGenerator::GrBackendTextureImageGenerator(const SkImageInfo& info,
@@ -104,7 +105,7 @@
fBorrowingMutex.acquire();
sk_sp<GrReleaseProcHelper> releaseProcHelper;
if (SK_InvalidGenID != fRefHelper->fBorrowingContextID) {
- if (fRefHelper->fBorrowingContextID != context->uniqueID()) {
+ if (fRefHelper->fBorrowingContextID != context->contextPriv().contextID()) {
fBorrowingMutex.release();
return nullptr;
} else {
@@ -121,10 +122,10 @@
fRefHelper));
fRefHelper->fBorrowingContextReleaseProc = releaseProcHelper.get();
}
- fRefHelper->fBorrowingContextID = context->uniqueID();
+ fRefHelper->fBorrowingContextID = context->contextPriv().contextID();
fBorrowingMutex.release();
- SkASSERT(fRefHelper->fBorrowingContextID == context->uniqueID());
+ SkASSERT(fRefHelper->fBorrowingContextID == context->contextPriv().contextID());
GrSurfaceDesc desc;
desc.fWidth = fBackendTexture.width();
diff --git a/src/gpu/GrBaseContextPriv.h b/src/gpu/GrBaseContextPriv.h
index c706082..cea4436 100644
--- a/src/gpu/GrBaseContextPriv.h
+++ b/src/gpu/GrBaseContextPriv.h
@@ -16,6 +16,7 @@
class GrBaseContextPriv {
public:
// from GrContext_Base
+ uint32_t contextID() const { return fContext->contextID(); }
private:
explicit GrBaseContextPriv(GrContext_Base* context) : fContext(context) {}
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index b6c8b93..57103af 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -74,13 +74,13 @@
if (fGpu) {
fCaps = fGpu->refCaps();
- fResourceCache = new GrResourceCache(fCaps.get(), &fSingleOwner, this->uniqueID());
+ fResourceCache = new GrResourceCache(fCaps.get(), &fSingleOwner, this->contextID());
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(this->contextID(), fCaps, &fSingleOwner);
}
if (fResourceCache) {
@@ -131,8 +131,7 @@
fGlyphCache = new GrStrikeCache(fCaps.get(), options.fGlyphCacheTextureMaximumBytes);
- fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB,
- this, this->uniqueID()));
+ fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this, this->contextID()));
// DDL TODO: we need to think through how the task group & persistent cache
// get passed on to/shared between all the DDLRecorders created with this context.
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 3ae9a9c..65054bb 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -30,6 +30,7 @@
public:
// from GrContext_Base
+ uint32_t contextID() const { return fContext->contextID(); }
// from GrImageContext
diff --git a/src/gpu/GrContextThreadSafeProxy.cpp b/src/gpu/GrContextThreadSafeProxy.cpp
index c9ba5c4..b3754e4 100644
--- a/src/gpu/GrContextThreadSafeProxy.cpp
+++ b/src/gpu/GrContextThreadSafeProxy.cpp
@@ -8,26 +8,27 @@
#include "GrContextThreadSafeProxy.h"
#include "GrContextThreadSafeProxyPriv.h"
+#include "GrBaseContextPriv.h"
#include "GrCaps.h"
#include "GrContext.h"
#include "GrSkSLFPFactoryCache.h"
#include "SkSurface_Gpu.h"
#include "SkSurfaceCharacterization.h"
-GrContextThreadSafeProxy::GrContextThreadSafeProxy(sk_sp<const GrCaps> caps, uint32_t uniqueID,
+GrContextThreadSafeProxy::GrContextThreadSafeProxy(sk_sp<const GrCaps> caps, uint32_t contextID,
GrBackendApi backend,
const GrContextOptions& options,
sk_sp<GrSkSLFPFactoryCache> cache)
: fCaps(std::move(caps))
- , fContextUniqueID(uniqueID)
+ , fContextID(contextID)
, fBackend(backend)
, fOptions(options)
, fFPFactoryCache(std::move(cache)) {}
GrContextThreadSafeProxy::~GrContextThreadSafeProxy() = default;
-bool GrContextThreadSafeProxy::matches(GrContext* context) const {
- return context->uniqueID() == fContextUniqueID;
+bool GrContextThreadSafeProxy::matches(GrContext_Base* context) const {
+ return context->priv().contextID() == fContextID;
}
SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization(
diff --git a/src/gpu/GrContextThreadSafeProxyPriv.h b/src/gpu/GrContextThreadSafeProxyPriv.h
index 298ad78..16132b5 100644
--- a/src/gpu/GrContextThreadSafeProxyPriv.h
+++ b/src/gpu/GrContextThreadSafeProxyPriv.h
@@ -21,7 +21,7 @@
const GrCaps* caps() const { return fProxy->fCaps.get(); }
sk_sp<const GrCaps> refCaps() const { return fProxy->fCaps; }
- uint32_t contextUniqueID() const { return fProxy->fContextUniqueID; }
+ uint32_t contextID() const { return fProxy->fContextID; }
GrBackendApi backend() const { return fProxy->fBackend; }
sk_sp<GrSkSLFPFactoryCache> fpFactoryCache() const;
diff --git a/src/gpu/GrContext_Base.cpp b/src/gpu/GrContext_Base.cpp
index 80e7a80..582f89a 100644
--- a/src/gpu/GrContext_Base.cpp
+++ b/src/gpu/GrContext_Base.cpp
@@ -17,9 +17,9 @@
}
GrContext_Base::GrContext_Base(GrBackendApi backend,
- uint32_t uniqueID)
+ uint32_t contextID)
: fBackend(backend)
- , fUniqueID(SK_InvalidGenID == uniqueID ? next_id() : uniqueID) {
+ , fContextID(SK_InvalidGenID == contextID ? next_id() : contextID) {
}
GrContext_Base::~GrContext_Base() {
diff --git a/src/gpu/GrDDLContext.cpp b/src/gpu/GrDDLContext.cpp
index 5461bd9..c590f79 100644
--- a/src/gpu/GrDDLContext.cpp
+++ b/src/gpu/GrDDLContext.cpp
@@ -18,7 +18,7 @@
class SK_API GrDDLContext : public GrContext {
public:
GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy)
- : INHERITED(proxy->priv().backend(), proxy->priv().contextUniqueID()) {
+ : INHERITED(proxy->priv().backend(), proxy->priv().contextID()) {
fCaps = proxy->priv().refCaps();
fFPFactoryCache = proxy->priv().fpFactoryCache();
SkASSERT(fFPFactoryCache);
diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp
index 688278d..af0f1b9 100644
--- a/src/gpu/GrDirectContext.cpp
+++ b/src/gpu/GrDirectContext.cpp
@@ -63,7 +63,7 @@
SkASSERT(!fThreadSafeProxy);
SkASSERT(!fFPFactoryCache);
fFPFactoryCache.reset(new GrSkSLFPFactoryCache());
- fThreadSafeProxy.reset(new GrContextThreadSafeProxy(fCaps, this->uniqueID(),
+ fThreadSafeProxy.reset(new GrContextThreadSafeProxy(fCaps, this->contextID(),
this->backend(),
options, fFPFactoryCache));
diff --git a/src/gpu/GrImageContextPriv.h b/src/gpu/GrImageContextPriv.h
index 2a49de9..c00f6df 100644
--- a/src/gpu/GrImageContextPriv.h
+++ b/src/gpu/GrImageContextPriv.h
@@ -16,6 +16,7 @@
class GrImageContextPriv {
public:
// from GrContext_Base
+ uint32_t contextID() const { return fContext->contextID(); }
// from GrImageContext
diff --git a/src/gpu/GrOnFlushResourceProvider.cpp b/src/gpu/GrOnFlushResourceProvider.cpp
index aadd353..9ca39a3 100644
--- a/src/gpu/GrOnFlushResourceProvider.cpp
+++ b/src/gpu/GrOnFlushResourceProvider.cpp
@@ -94,8 +94,8 @@
return buffer;
}
-uint32_t GrOnFlushResourceProvider::contextUniqueID() const {
- return fDrawingMgr->getContext()->uniqueID();
+uint32_t GrOnFlushResourceProvider::contextID() const {
+ return fDrawingMgr->getContext()->contextPriv().contextID();
}
const GrCaps* GrOnFlushResourceProvider::caps() const {
diff --git a/src/gpu/GrOnFlushResourceProvider.h b/src/gpu/GrOnFlushResourceProvider.h
index 9cbcddc..f2ce74f 100644
--- a/src/gpu/GrOnFlushResourceProvider.h
+++ b/src/gpu/GrOnFlushResourceProvider.h
@@ -92,7 +92,7 @@
sk_sp<const GrBuffer> findOrMakeStaticBuffer(GrBufferType, size_t, const void* data,
const GrUniqueKey&);
- uint32_t contextUniqueID() const;
+ uint32_t contextID() const;
const GrCaps* caps() const;
private:
diff --git a/src/gpu/GrPathRendererChain.cpp b/src/gpu/GrPathRendererChain.cpp
index 6e28c5d..dd3b0c2 100644
--- a/src/gpu/GrPathRendererChain.cpp
+++ b/src/gpu/GrPathRendererChain.cpp
@@ -41,7 +41,7 @@
using AllowCaching = GrCoverageCountingPathRenderer::AllowCaching;
if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(
caps, AllowCaching(options.fAllowPathMaskCaching),
- context->uniqueID())) {
+ context->contextPriv().contextID())) {
fCoverageCountingPathRenderer = ccpr.get();
context->contextPriv().addOnFlushCallbackObject(fCoverageCountingPathRenderer);
fChain.push_back(std::move(ccpr));
diff --git a/src/gpu/GrRecordingContextPriv.h b/src/gpu/GrRecordingContextPriv.h
index 0002b27..1990594 100644
--- a/src/gpu/GrRecordingContextPriv.h
+++ b/src/gpu/GrRecordingContextPriv.h
@@ -16,6 +16,7 @@
class GrRecordingContextPriv {
public:
// from GrContext_Base
+ uint32_t contextID() const { return fContext->contextID(); }
// from GrImageContext
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp
index e7b070e..5220394 100644
--- a/src/gpu/GrSoftwarePathRenderer.cpp
+++ b/src/gpu/GrSoftwarePathRenderer.cpp
@@ -374,7 +374,7 @@
SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
fProxyProvider->assignUniqueKeyToProxy(maskKey, proxy.get());
args.fShape->addGenIDChangeListener(
- sk_make_sp<PathInvalidator>(maskKey, args.fContext->uniqueID()));
+ sk_make_sp<PathInvalidator>(maskKey, args.fContext->contextPriv().contextID()));
}
}
if (inverseFilled) {
diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp
index c1c92f3..3eb884b 100644
--- a/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -960,8 +960,8 @@
using PathTestStruct = GrSmallPathRenderer::PathTestStruct;
static PathTestStruct gTestStruct;
- if (context->uniqueID() != gTestStruct.fContextID) {
- gTestStruct.fContextID = context->uniqueID();
+ if (context->contextPriv().contextID() != gTestStruct.fContextID) {
+ gTestStruct.fContextID = context->contextPriv().contextID();
gTestStruct.reset();
const GrBackendFormat format =
context->contextPriv().caps()->getBackendFormatFromColorType(kAlpha_8_SkColorType);
diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp
index 01a4a4f..ccdca2b 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -9,7 +9,7 @@
#include "GrCaps.h"
#include "GrContext.h"
-#include "GrContextPriv.h"
+#include "GrRecordingContextPriv.h"
#include "GrSDFMaskFilter.h"
#include "GrTextBlobCache.h"
#include "SkDistanceFieldGen.h"
@@ -210,8 +210,8 @@
static std::unique_ptr<GrTextContext> gTextContext;
static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
- if (context->uniqueID() != gContextID) {
- gContextID = context->uniqueID();
+ if (context->priv().contextID() != gContextID) {
+ gContextID = context->priv().contextID();
gTextContext = GrTextContext::Make(GrTextContext::Options());
}
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index e6736eb..50c6ac9 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -50,6 +50,7 @@
int srcX, int srcY, CachingHint) const = 0;
virtual GrContext* context() const { return nullptr; }
+ // TODO: remove this contextID and use GrContext_Base::matches
virtual uint32_t contextID() const { return 0; }
#if SK_SUPPORT_GPU
virtual GrTextureProxy* peekProxy() const { return nullptr; }
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index cb036ef..ba8a132 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -351,7 +351,7 @@
return nullptr;
}
if (uint32_t incumbentID = as_IB(this)->contextID()) {
- if (incumbentID != context->uniqueID()) {
+ if (incumbentID != context->contextPriv().contextID()) {
return nullptr;
}
sk_sp<GrTextureProxy> proxy = as_IB(this)->asTextureProxyRef();
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index e4aabb7..54ef66a 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -31,6 +31,13 @@
//////////////////////////////////////////////////////////////////////////////////////////////////
+#if GR_TEST_UTILS
+void SkImage_GpuBase::resetContext(sk_sp<GrContext> newContext) {
+ SkASSERT(fContext->contextPriv().contextID() == newContext->contextPriv().contextID());
+ fContext = newContext;
+}
+#endif
+
bool SkImage_GpuBase::ValidateBackendTexture(GrContext* ctx, const GrBackendTexture& tex,
GrPixelConfig* config, SkColorType ct, SkAlphaType at,
sk_sp<SkColorSpace> cs) {
@@ -53,6 +60,10 @@
//////////////////////////////////////////////////////////////////////////////////////////////////
+uint32_t SkImage_GpuBase::contextID() const {
+ return fContext->contextPriv().contextID();
+}
+
bool SkImage_GpuBase::getROPixels(SkBitmap* dst, CachingHint chint) const {
if (!fContext->contextPriv().resourceProvider()) {
// DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
@@ -200,7 +211,7 @@
sk_sp<GrTextureProxy> SkImage_GpuBase::asTextureProxyRef(GrContext* context,
const GrSamplerState& params,
SkScalar scaleAdjust[2]) const {
- if (context->uniqueID() != fContext->uniqueID()) {
+ if (context->contextPriv().contextID() != fContext->contextPriv().contextID()) {
SkASSERT(0);
return nullptr;
}
@@ -498,8 +509,8 @@
}
tex->resourcePriv().setUniqueKey(fLastFulfilledKey);
SkASSERT(fContextID == SK_InvalidUniqueID ||
- fContextID == tex->getContext()->uniqueID());
- fContextID = tex->getContext()->uniqueID();
+ fContextID == tex->getContext()->contextPriv().contextID());
+ fContextID = tex->getContext()->contextPriv().contextID();
promiseTexture->addKeyToInvalidate(fContextID, fLastFulfilledKey);
return std::move(tex);
}
diff --git a/src/image/SkImage_GpuBase.h b/src/image/SkImage_GpuBase.h
index cc6d354..e9501ac 100644
--- a/src/image/SkImage_GpuBase.h
+++ b/src/image/SkImage_GpuBase.h
@@ -24,7 +24,7 @@
~SkImage_GpuBase() override;
GrContext* context() const final { return fContext.get(); }
- uint32_t contextID() const final { return fContext->uniqueID(); }
+ uint32_t contextID() const final;
bool getROPixels(SkBitmap*, CachingHint) const final;
sk_sp<SkImage> onMakeSubset(const SkIRect& subset) const final;
@@ -53,10 +53,7 @@
bool onIsValid(GrContext*) const final;
#if GR_TEST_UTILS
- void resetContext(sk_sp<GrContext> newContext) {
- SkASSERT(fContext->uniqueID() == newContext->uniqueID());
- fContext = newContext;
- }
+ void resetContext(sk_sp<GrContext> newContext);
#endif
static bool ValidateBackendTexture(GrContext* ctx, const GrBackendTexture& tex,
diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp
index 3782974..0788d21 100644
--- a/src/image/SkImage_Lazy.cpp
+++ b/src/image/SkImage_Lazy.cpp
@@ -417,7 +417,7 @@
set_key_on_proxy(proxyProvider, proxy.get(), nullptr, key);
if (!willBeMipped || GrMipMapped::kYes == proxy->mipMapped()) {
*fUniqueKeyInvalidatedMessages.append() =
- new GrUniqueKeyInvalidatedMessage(key, ctx->uniqueID());
+ new GrUniqueKeyInvalidatedMessage(key, ctx->contextPriv().contextID());
return proxy;
}
}
@@ -450,7 +450,7 @@
kLockTexturePathCount);
set_key_on_proxy(proxyProvider, proxy.get(), nullptr, key);
*fUniqueKeyInvalidatedMessages.append() =
- new GrUniqueKeyInvalidatedMessage(key, ctx->uniqueID());
+ new GrUniqueKeyInvalidatedMessage(key, ctx->contextPriv().contextID());
return proxy;
}
}
@@ -469,7 +469,7 @@
kLockTexturePathCount);
set_key_on_proxy(proxyProvider, proxy.get(), nullptr, key);
*fUniqueKeyInvalidatedMessages.append() =
- new GrUniqueKeyInvalidatedMessage(key, ctx->uniqueID());
+ new GrUniqueKeyInvalidatedMessage(key, ctx->contextPriv().contextID());
return proxy;
}
}
@@ -482,7 +482,7 @@
SkASSERT(willBeMipped);
SkASSERT(GrMipMapped::kNo == proxy->mipMapped());
*fUniqueKeyInvalidatedMessages.append() =
- new GrUniqueKeyInvalidatedMessage(key, ctx->uniqueID());
+ new GrUniqueKeyInvalidatedMessage(key, ctx->contextPriv().contextID());
if (auto mippedProxy = GrCopyBaseMipMapToTextureProxy(ctx, proxy.get())) {
set_key_on_proxy(proxyProvider, mippedProxy.get(), proxy.get(), key);
return mippedProxy;