Make GrSurfaceProxy derive from GrNonAtomicRef and remove GrIORefProxy.

Also, expose GrNonAtomicRef's ref count. Since it's non-atomic and not
thread-safe it seems fine.

Change-Id: I5cf48e60d32094354955b2614cfeebbb4c1ecf2a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/238059
Auto-Submit: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2019-08-29 11:16:04 -04:00 committed by Skia Commit-Bot
parent a58bbee8f7
commit a036f0d54e
11 changed files with 13 additions and 55 deletions

View File

@ -392,7 +392,6 @@ private:
friend class GrGpuResource;
friend class GrSurfaceProxy;
friend class GrIORefProxy;
};
inline GrGpuResource::ProxyAccess GrGpuResource::proxyAccess() { return ProxyAccess(this); }

View File

@ -31,6 +31,10 @@ public:
bool unique() const { return 1 == fRefCnt; }
// We allow this getter because this type is not thread-safe, meaning only one thread should
// have ownership and be manipulating the ref count or querying this.
int refCnt() const { return fRefCnt; }
void ref() const {
// Once the ref cnt reaches zero it should never be ref'ed again.
SkASSERT(fRefCnt > 0);

View File

@ -104,7 +104,7 @@ sk_sp<GrTextureProxy> GrProxyProvider::findProxyByUniqueKey(const GrUniqueKey& k
GrTextureProxy* proxy = fUniquelyKeyedProxies.find(key);
if (proxy) {
SkASSERT(proxy->getProxyRefCnt() >= 1);
SkASSERT(proxy->refCnt() >= 1);
SkASSERT(proxy->origin() == origin);
return sk_ref_sp(proxy);
}

View File

@ -135,10 +135,6 @@ private:
// about what we're doing).
char fDummyPadding[10];
// For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class.
// For deferred proxies that pointer is filled in when we need to instantiate the
// deferred resource.
typedef GrSurfaceProxy INHERITED;
};

View File

@ -44,10 +44,10 @@ void GrResourceAllocator::determineRecyclability() {
continue;
}
if (cur->uses() >= cur->proxy()->priv().getProxyRefCnt()) {
if (cur->uses() >= cur->proxy()->refCnt()) {
// All the refs on the proxy are known to the resource allocator thus no one
// should be holding onto it outside of Ganesh.
SkASSERT(cur->uses() == cur->proxy()->priv().getProxyRefCnt());
SkASSERT(cur->uses() == cur->proxy()->refCnt());
cur->markAsRecyclable();
}
}

View File

@ -14,6 +14,7 @@
#include "include/gpu/GrSurface.h"
#include "include/gpu/GrTexture.h"
#include "include/private/SkNoncopyable.h"
#include "src/gpu/GrNonAtomicRef.h"
#include "src/gpu/GrSwizzle.h"
class GrCaps;
@ -27,40 +28,10 @@ class GrSurfaceContext;
class GrSurfaceProxyPriv;
class GrTextureProxy;
// This is basically SkRefCntBase except Ganesh uses internalGetProxyRefCnt for more than asserts.
class GrIORefProxy : public SkNoncopyable {
class GrSurfaceProxy : public GrNonAtomicRef<GrSurfaceProxy> {
public:
GrIORefProxy() : fRefCnt(1) {}
virtual ~GrSurfaceProxy();
virtual ~GrIORefProxy() {}
bool unique() const {
SkASSERT(fRefCnt > 0);
return 1 == fRefCnt;
}
void ref() const {
SkASSERT(fRefCnt > 0);
++fRefCnt;
}
void unref() const {
SkASSERT(fRefCnt > 0);
--fRefCnt;
if (0 == fRefCnt) {
delete this;
}
}
protected:
int32_t internalGetProxyRefCnt() const { return fRefCnt; }
private:
mutable int32_t fRefCnt;
};
class GrSurfaceProxy : public GrIORefProxy {
public:
/**
* Some lazy proxy callbacks want to set their own (or no key) on the GrSurfaces they return.
* Others want the GrSurface's key to be kept in sync with the proxy's key. This enum controls
@ -352,16 +323,12 @@ protected:
GrSurfaceProxy(sk_sp<GrSurface>, GrSurfaceOrigin, const GrSwizzle& textureSwizzle,
SkBackingFit);
~GrSurfaceProxy() override;
friend class GrSurfaceProxyPriv;
// Methods made available via GrSurfaceProxyPriv
bool ignoredByResourceAllocator() const { return fIgnoredByResourceAllocator; }
void setIgnoredByResourceAllocator() { fIgnoredByResourceAllocator = true; }
int32_t getProxyRefCnt() const { return this->internalGetProxyRefCnt(); }
void computeScratchKey(GrScratchKey*) const;
virtual sk_sp<GrSurface> createSurface(GrResourceProvider*) const = 0;
@ -447,8 +414,6 @@ private:
// and the GrRenderTask of a destination surface to which this one is being drawn or copied.
// This pointer is unreffed. GrRenderTasks own a ref on their surface proxies.
GrRenderTask* fLastRenderTask;
typedef GrIORefProxy INHERITED;
};
#endif

View File

@ -17,8 +17,6 @@
data members or virtual methods. */
class GrSurfaceProxyPriv {
public:
int32_t getProxyRefCnt() const { return fProxy->getProxyRefCnt(); }
void computeScratchKey(GrScratchKey* key) const { return fProxy->computeScratchKey(key); }
// Create a GrSurface-derived class that meets the requirements (i.e, desc, renderability)

View File

@ -173,10 +173,6 @@ private:
SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
// For wrapped proxies the GrTexture pointer is stored in GrIORefProxy.
// For deferred proxies that pointer will be filled in when we need to instantiate
// the deferred resource
typedef GrSurfaceProxy INHERITED;
};

View File

@ -355,7 +355,7 @@ public:
// At this point 'fAtlasProxy' should be instantiated and have:
// 1 ref from the 'fAtlasProxy' sk_sp
// 9 refs from the 9 AtlasedRectOps
SkASSERT(10 == fAtlasProxy->priv().getProxyRefCnt());
SkASSERT(10 == fAtlasProxy->refCnt());
// The backing GrSurface should have only 1 though bc there is only one proxy
SkASSERT(1 == fAtlasProxy->testingOnly_getBackingRefCnt());
auto rtc = resourceProvider->makeRenderTargetContext(fAtlasProxy, GrColorType::kRGBA_8888,

View File

@ -147,7 +147,7 @@ static void check_refs(skiatest::Reporter* reporter,
GrTextureProxy* proxy,
int32_t expectedProxyRefs,
int32_t expectedBackingRefs) {
int32_t actualProxyRefs = proxy->priv().getProxyRefCnt();
int32_t actualProxyRefs = proxy->refCnt();
int32_t actualBackingRefs = proxy->testingOnly_getBackingRefCnt();
SkASSERT(actualProxyRefs == expectedProxyRefs);

View File

@ -23,7 +23,7 @@ static void check_refs(skiatest::Reporter* reporter,
GrTextureProxy* proxy,
int32_t expectedProxyRefs,
int32_t expectedBackingRefs) {
int32_t actualProxyRefs = proxy->priv().getProxyRefCnt();
int32_t actualProxyRefs = proxy->refCnt();
int32_t actualBackingRefs = proxy->testingOnly_getBackingRefCnt();
SkASSERT(actualProxyRefs == expectedProxyRefs);