aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/GrResourceCacheBench.cpp16
-rw-r--r--include/gpu/GrGpuResource.h19
-rw-r--r--include/gpu/GrTexture.h6
-rw-r--r--src/gpu/GrGeometryBuffer.h5
-rw-r--r--src/gpu/GrGpuResource.cpp1
-rw-r--r--src/gpu/GrResourceCache.cpp1
-rw-r--r--src/gpu/GrTexture.cpp2
-rw-r--r--src/gpu/gl/GrGLPath.h6
-rw-r--r--src/gpu/gl/GrGLPathRange.h4
-rw-r--r--src/gpu/gl/GrGLRenderTarget.cpp2
-rw-r--r--src/gpu/gl/GrGLRenderTarget.h7
-rw-r--r--src/gpu/gl/GrGLStencilBuffer.cpp2
-rw-r--r--src/gpu/gl/GrGLStencilBuffer.h4
-rw-r--r--src/gpu/gl/GrGLTextureRenderTarget.h12
-rw-r--r--src/gpu/gl/GrGLVertexArray.h4
-rw-r--r--tests/ResourceCacheTest.cpp4
16 files changed, 53 insertions, 42 deletions
diff --git a/bench/GrResourceCacheBench.cpp b/bench/GrResourceCacheBench.cpp
index 91c77fb589..6d631ddb2c 100644
--- a/bench/GrResourceCacheBench.cpp
+++ b/bench/GrResourceCacheBench.cpp
@@ -36,10 +36,6 @@ public:
virtual ~StencilResource() { this->release(); }
- virtual size_t gpuMemorySize() const SK_OVERRIDE {
- return 100 + ((fID % 1 == 0) ? -5 : 6);
- }
-
static GrResourceKey ComputeKey(int width, int height, int sampleCnt) {
return GrStencilBuffer::ComputeKey(width, height, sampleCnt);
}
@@ -47,6 +43,10 @@ public:
int fID;
private:
+ virtual size_t onGpuMemorySize() const SK_OVERRIDE {
+ return 100 + ((fID % 1 == 0) ? -5 : 6);
+ }
+
typedef GrGpuResource INHERITED;
};
@@ -61,10 +61,6 @@ public:
virtual ~TextureResource() { this->release(); }
- virtual size_t gpuMemorySize() const SK_OVERRIDE {
- return 100 + ((fID % 1 == 0) ? -40 : 33);
- }
-
static GrResourceKey ComputeKey(const GrSurfaceDesc& desc) {
GrCacheID::Key key;
memset(&key, 0, sizeof(key));
@@ -79,6 +75,10 @@ public:
int fID;
private:
+ virtual size_t onGpuMemorySize() const SK_OVERRIDE {
+ return 100 + ((fID % 1 == 0) ? -40 : 33);
+ }
+
typedef GrGpuResource INHERITED;
};
diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h
index 3d6701a702..5231b15f89 100644
--- a/include/gpu/GrGpuResource.h
+++ b/include/gpu/GrGpuResource.h
@@ -172,7 +172,13 @@ public:
*
* @return the amount of GPU memory used in bytes
*/
- virtual size_t gpuMemorySize() const = 0;
+ size_t gpuMemorySize() const {
+ if (kInvalidGpuMemorySize == fGpuMemorySize) {
+ fGpuMemorySize = this->onGpuMemorySize();
+ SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
+ }
+ return fGpuMemorySize;
+ }
/**
* Gets an id that is unique for this GrGpuResource object. It is static in that it does
@@ -206,10 +212,8 @@ protected:
bool isWrapped() const { return kWrapped_FlagBit & fFlags; }
/**
- * This entry point should be called whenever gpuMemorySize() begins
- * reporting a different size. If the object is in the cache, it will call
- * gpuMemorySize() immediately and pass the new size on to the resource
- * cache.
+ * This entry point should be called whenever gpuMemorySize() should report a different size.
+ * The cache will call gpuMemorySize() to update the current size of the resource.
*/
void didChangeGpuMemorySize() const;
@@ -220,6 +224,8 @@ protected:
void setScratchKey(const GrResourceKey& scratchKey);
private:
+ virtual size_t onGpuMemorySize() const = 0;
+
// See comments in CacheAccess.
bool setContentKey(const GrResourceKey& contentKey);
@@ -247,9 +253,12 @@ private:
kWrapped_FlagBit = 0x1,
};
+ static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
+
uint32_t fFlags;
GrResourceCacheEntry* fCacheEntry; // NULL if not in cache
+ mutable size_t fGpuMemorySize;
const uint32_t fUniqueID;
// TODO(bsalomon): Remove GrResourceKey and use different simpler types for content and scratch
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index 87f0d5ab0a..4989a5e8a0 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -19,11 +19,6 @@ class GrTexturePriv;
class GrTexture : virtual public GrSurface {
public:
- /**
- * Approximate number of bytes used by the texture
- */
- virtual size_t gpuMemorySize() const SK_OVERRIDE;
-
virtual GrTexture* asTexture() SK_OVERRIDE { return this; }
virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; }
@@ -56,6 +51,7 @@ protected:
void validateDesc() const;
private:
+ virtual size_t onGpuMemorySize() const SK_OVERRIDE;
void dirtyMipMaps(bool mipMapsDirty);
enum MipMapsStatus {
diff --git a/src/gpu/GrGeometryBuffer.h b/src/gpu/GrGeometryBuffer.h
index c3e1c65252..d6761831b1 100644
--- a/src/gpu/GrGeometryBuffer.h
+++ b/src/gpu/GrGeometryBuffer.h
@@ -98,9 +98,6 @@ public:
return this->onUpdateData(src, srcSizeInBytes);
}
- // GrGpuResource overrides
- virtual size_t gpuMemorySize() const { return fGpuMemorySize; }
-
protected:
GrGeometryBuffer(GrGpu* gpu, bool isWrapped, size_t gpuMemorySize, bool dynamic, bool cpuBacked)
: INHERITED(gpu, isWrapped)
@@ -110,6 +107,8 @@ protected:
, fCPUBacked(cpuBacked) {}
private:
+ virtual size_t onGpuMemorySize() const { return fGpuMemorySize; }
+
virtual void* onMap() = 0;
virtual void onUnmap() = 0;
virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0;
diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp
index 79ea52f3bc..f6f7282700 100644
--- a/src/gpu/GrGpuResource.cpp
+++ b/src/gpu/GrGpuResource.cpp
@@ -28,6 +28,7 @@ static inline GrResourceCache* get_resource_cache(GrGpu* gpu) {
GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped)
: fGpu(gpu)
, fCacheEntry(NULL)
+ , fGpuMemorySize(kInvalidGpuMemorySize)
, fUniqueID(CreateUniqueID())
, fScratchKey(GrResourceKey::NullScratchKey())
, fContentKeySet(false) {
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index 7083cf374b..a73d11703d 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -16,6 +16,7 @@ DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage);
///////////////////////////////////////////////////////////////////////////////
void GrGpuResource::didChangeGpuMemorySize() const {
+ fGpuMemorySize = kInvalidGpuMemorySize;
if (this->cacheAccess().isInCache()) {
fCacheEntry->didChangeResourceSize();
}
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
index 72e82252dc..58bbeaae42 100644
--- a/src/gpu/GrTexture.cpp
+++ b/src/gpu/GrTexture.cpp
@@ -28,7 +28,7 @@ void GrTexture::dirtyMipMaps(bool mipMapsDirty) {
}
}
-size_t GrTexture::gpuMemorySize() const {
+size_t GrTexture::onGpuMemorySize() const {
size_t textureSize;
if (GrPixelConfigIsCompressed(fDesc.fConfig)) {
diff --git a/src/gpu/gl/GrGLPath.h b/src/gpu/gl/GrGLPath.h
index 935a2e24ad..b8bd8ad1a4 100644
--- a/src/gpu/gl/GrGLPath.h
+++ b/src/gpu/gl/GrGLPath.h
@@ -30,15 +30,15 @@ public:
GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke);
virtual ~GrGLPath();
GrGLuint pathID() const { return fPathID; }
- // TODO: Figure out how to get an approximate size of the path in Gpu
- // memory.
- virtual size_t gpuMemorySize() const SK_OVERRIDE { return 100; }
protected:
virtual void onRelease() SK_OVERRIDE;
virtual void onAbandon() SK_OVERRIDE;
private:
+ // TODO: Figure out how to get an approximate size of the path in Gpu memory.
+ virtual size_t onGpuMemorySize() const SK_OVERRIDE { return 100; }
+
GrGLuint fPathID;
typedef GrPath INHERITED;
diff --git a/src/gpu/gl/GrGLPathRange.h b/src/gpu/gl/GrGLPathRange.h
index f21ce3a7c9..440ffbc0c9 100644
--- a/src/gpu/gl/GrGLPathRange.h
+++ b/src/gpu/gl/GrGLPathRange.h
@@ -43,8 +43,6 @@ public:
GrGLuint basePathID() const { return fBasePathID; }
- virtual size_t gpuMemorySize() const SK_OVERRIDE { return fGpuMemorySize; }
-
protected:
virtual void onInitPath(int index, const SkPath&) const;
@@ -52,6 +50,8 @@ protected:
virtual void onAbandon() SK_OVERRIDE;
private:
+ virtual size_t onGpuMemorySize() const SK_OVERRIDE { return fGpuMemorySize; }
+
GrGLuint fBasePathID;
mutable size_t fGpuMemorySize;
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 8482ecdc6c..98813beb2c 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -45,7 +45,7 @@ void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
}
}
-size_t GrGLRenderTarget::gpuMemorySize() const {
+size_t GrGLRenderTarget::onGpuMemorySize() const {
SkASSERT(kUnknown_GrPixelConfig != fDesc.fConfig);
SkASSERT(!GrPixelConfigIsCompressed(fDesc.fConfig));
size_t colorBytes = GrBytesPerPixel(fDesc.fConfig);
diff --git a/src/gpu/gl/GrGLRenderTarget.h b/src/gpu/gl/GrGLRenderTarget.h
index 0f041600ee..b81bbed4b2 100644
--- a/src/gpu/gl/GrGLRenderTarget.h
+++ b/src/gpu/gl/GrGLRenderTarget.h
@@ -58,8 +58,6 @@ public:
}
}
- virtual size_t gpuMemorySize() const SK_OVERRIDE;
-
protected:
// The public constructor registers this object with the cache. However, only the most derived
// class should register with the cache. This constructor does not do the registration and
@@ -72,6 +70,9 @@ protected:
virtual void onAbandon() SK_OVERRIDE;
virtual void onRelease() SK_OVERRIDE;
+ // In protected because subclass GrGLTextureRenderTarget calls this version.
+ virtual size_t onGpuMemorySize() const SK_OVERRIDE;
+
private:
GrGLuint fRTFBOID;
GrGLuint fTexFBOID;
@@ -82,7 +83,7 @@ private:
// we want the rendering to be at top left (GL has origin in bottom left)
GrGLIRect fViewport;
- // gpuMemorySize() needs to know what how many color values are owned per pixel. However,
+ // onGpuMemorySize() needs to know what how many color values are owned per pixel. However,
// abandon and release zero out the IDs and the cache needs to know the size even after those
// actions.
uint8_t fColorValuesPerPixel;
diff --git a/src/gpu/gl/GrGLStencilBuffer.cpp b/src/gpu/gl/GrGLStencilBuffer.cpp
index abcb3c4ba0..fd14ea01f2 100644
--- a/src/gpu/gl/GrGLStencilBuffer.cpp
+++ b/src/gpu/gl/GrGLStencilBuffer.cpp
@@ -13,7 +13,7 @@ GrGLStencilBuffer::~GrGLStencilBuffer() {
this->release();
}
-size_t GrGLStencilBuffer::gpuMemorySize() const {
+size_t GrGLStencilBuffer::onGpuMemorySize() const {
uint64_t size = this->width();
size *= this->height();
size *= fFormat.fTotalBits;
diff --git a/src/gpu/gl/GrGLStencilBuffer.h b/src/gpu/gl/GrGLStencilBuffer.h
index 024890ddd7..53777e40c7 100644
--- a/src/gpu/gl/GrGLStencilBuffer.h
+++ b/src/gpu/gl/GrGLStencilBuffer.h
@@ -37,8 +37,6 @@ public:
virtual ~GrGLStencilBuffer();
- virtual size_t gpuMemorySize() const SK_OVERRIDE;
-
GrGLuint renderbufferID() const {
return fRenderbufferID;
}
@@ -51,6 +49,8 @@ protected:
virtual void onAbandon() SK_OVERRIDE;
private:
+ virtual size_t onGpuMemorySize() const SK_OVERRIDE;
+
Format fFormat;
// may be zero for external SBs associated with external RTs
// (we don't require the client to give us the id, just tell
diff --git a/src/gpu/gl/GrGLTextureRenderTarget.h b/src/gpu/gl/GrGLTextureRenderTarget.h
index 55da28f6b8..06080a8a36 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.h
+++ b/src/gpu/gl/GrGLTextureRenderTarget.h
@@ -31,14 +31,11 @@ public:
: GrSurface(gpu, texIDDesc.fIsWrapped, desc)
, GrGLTexture(gpu, desc, texIDDesc, GrGLTexture::kDerived)
, GrGLRenderTarget(gpu, desc, rtIDDesc, GrGLRenderTarget::kDerived) {
- this->registerWithCache();
+ this->registerWithCache();
}
virtual ~GrGLTextureRenderTarget() { this->release(); }
- // GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
- virtual size_t gpuMemorySize() const SK_OVERRIDE { return GrGLRenderTarget::gpuMemorySize(); }
-
protected:
virtual void onAbandon() SK_OVERRIDE {
GrGLRenderTarget::onAbandon();
@@ -49,6 +46,13 @@ protected:
GrGLRenderTarget::onRelease();
GrGLTexture::onRelease();
}
+
+private:
+ // GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
+ virtual size_t onGpuMemorySize() const SK_OVERRIDE {
+ return GrGLRenderTarget::onGpuMemorySize();
+ }
+
};
#ifdef SK_BUILD_FOR_WIN
diff --git a/src/gpu/gl/GrGLVertexArray.h b/src/gpu/gl/GrGLVertexArray.h
index 96e90bc81f..e5032a9ea0 100644
--- a/src/gpu/gl/GrGLVertexArray.h
+++ b/src/gpu/gl/GrGLVertexArray.h
@@ -159,9 +159,9 @@ public:
void invalidateCachedState();
- virtual size_t gpuMemorySize() const SK_OVERRIDE { return 0; }
-
protected:
+ virtual size_t onGpuMemorySize() const SK_OVERRIDE { return 0; }
+
virtual void onAbandon() SK_OVERRIDE;
virtual void onRelease() SK_OVERRIDE;
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index fb1711372c..7cebddb0cc 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -99,8 +99,6 @@ public:
this->didChangeGpuMemorySize();
}
- size_t gpuMemorySize() const SK_OVERRIDE { return fSize; }
-
static int NumAlive() { return fNumAlive; }
void setDeleteWhenDestroyed(GrResourceCache* cache, TestResource* resource) {
@@ -109,6 +107,8 @@ public:
}
private:
+ size_t onGpuMemorySize() const SK_OVERRIDE { return fSize; }
+
GrResourceCache* fCache;
TestResource* fToDelete;
size_t fSize;