Have GrSurfaceProxys and GrGpuResources draw from the same pool of unique ids
The idea here is that, for wrapped Proxy objects, we want the uniqueID to reflect that of the wrapped object. For this to work the IDs for the non-wrapped versions can't conflict with GrGpuResource's pool of IDs.
Split off of: https://codereview.chromium.org/2215323003/ (Start using RenderTargetProxy (omnibus))
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2301523003
Review-Url: https://codereview.chromium.org/2301523003
diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h
index fb7cb8c..9305c16 100644
--- a/include/gpu/GrGpuResource.h
+++ b/include/gpu/GrGpuResource.h
@@ -180,7 +180,7 @@
* not change when the content of the GrGpuResource object changes. This will never return
* 0.
*/
- uint32_t getUniqueID() const { return fUniqueID; }
+ uint32_t uniqueID() const { return fUniqueID; }
/** Returns the current unique key for the resource. It will be invalid if the resource has no
associated unique key. */
@@ -217,6 +217,8 @@
**/
virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
+ static uint32_t CreateUniqueID();
+
protected:
// This must be called by every non-wrapped GrGpuObject. It should be called once the object is
// fully initialized (i.e. only from the constructors of the final class).
@@ -279,9 +281,6 @@
#ifdef SK_DEBUG
friend class GrGpu; // for assert in GrGpu to access getGpu
#endif
-
- static uint32_t CreateUniqueID();
-
// An index into a heap when this resource is purgeable or an array when not. This is maintained
// by the cache.
int fCacheArrayIndex;
diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h
index 01c5267..ad2ea91 100644
--- a/include/private/GrSurfaceProxy.h
+++ b/include/private/GrSurfaceProxy.h
@@ -41,11 +41,21 @@
virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; }
protected:
+ // Deferred version
GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted)
: fDesc(desc)
, fFit(fit)
, fBudgeted(budgeted)
- , fUniqueID(CreateUniqueID()) {
+ , fUniqueID(GrGpuResource::CreateUniqueID()) {
+ }
+
+ // Wrapped version
+ GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit,
+ SkBudgeted budgeted, uint32_t uniqueID)
+ : fDesc(desc)
+ , fFit(fit)
+ , fBudgeted(budgeted)
+ , fUniqueID(uniqueID) {
}
virtual ~GrSurfaceProxy() {}
@@ -54,10 +64,9 @@
const GrSurfaceDesc fDesc;
const SkBackingFit fFit; // always exact for wrapped resources
const SkBudgeted fBudgeted; // set from the backing resource for wrapped resources
- const uint32_t fUniqueID;
+ const uint32_t fUniqueID; // set from the backing resource for wrapped resources
private:
- static uint32_t CreateUniqueID();
// See comment in GrGpuResource.h.
void notifyAllCntsAreZero(CntType) const { delete this; }
diff --git a/include/private/GrTextureProxy.h b/include/private/GrTextureProxy.h
index eb82ca7..63cb3c8 100644
--- a/include/private/GrTextureProxy.h
+++ b/include/private/GrTextureProxy.h
@@ -30,12 +30,9 @@
GrTexture* instantiate(GrTextureProvider* texProvider);
private:
- GrTextureProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted,
- const void* /*srcData*/, size_t /*rowBytes*/)
- : INHERITED(desc, fit, budgeted) {
- // TODO: Handle 'srcData' here
- }
-
+ // Deferred version
+ GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit, SkBudgeted,
+ const void* srcData, size_t srcRowBytes);
// Wrapped version
GrTextureProxy(sk_sp<GrTexture> tex);