Split GrResource into GrCacheable/GrGpuObject
Before this change, an object needed to inherit from GrResource (and
thus be a GPU object) in order to live in the GrResourceCache. That
was a problem for caching items that weren't GPU objects themselves,
but owned GPU objects.
This change splits GrResource into two classes:
1. GrCacheable: The base class for objects that can live in the
GrResourceCache.
2. GrGpuObject, which inherits from GrCacheable: The base class for
objects that get tracked by GrGpu.
This change is purely a refactor; there is no change in functionality.
Change-Id: I3e8daeb1f123041f414aa306c1366e959ae9e39e
BUG=skia:
R=bsalomon@google.com
Author: cdalton@nvidia.com
Review URL: https://codereview.chromium.org/251013002
git-svn-id: http://skia.googlecode.com/svn/trunk@14553 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/bench/GrResourceCacheBench.cpp b/bench/GrResourceCacheBench.cpp
index e808cd7..6767ca1 100644
--- a/bench/GrResourceCacheBench.cpp
+++ b/bench/GrResourceCacheBench.cpp
@@ -9,7 +9,7 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
-#include "GrResource.h"
+#include "GrCacheable.h"
#include "GrResourceCache.h"
#include "GrStencilBuffer.h"
#include "GrTexture.h"
@@ -21,21 +21,21 @@
CACHE_SIZE_BYTES = 2 * 1024 * 1024,
};
-class StencilResource : public GrResource {
+class StencilResource : public GrCacheable {
public:
SK_DECLARE_INST_COUNT(StencilResource);
- StencilResource(GrGpu* gpu, int id)
- : INHERITED(gpu, false),
- fID(id) {
- }
- ~StencilResource() {
- this->release();
+ StencilResource(int id)
+ : fID(id) {
}
- virtual size_t sizeInBytes() const SK_OVERRIDE {
+ virtual size_t gpuMemorySize() const SK_OVERRIDE {
return 100 + ((fID % 1 == 0) ? -5 : 6);
}
+ virtual bool isValidOnGpu() const SK_OVERRIDE {
+ return true;
+ }
+
static GrResourceKey ComputeKey(int width, int height, int sampleCnt) {
return GrStencilBuffer::ComputeKey(width, height, sampleCnt);
}
@@ -43,24 +43,24 @@
int fID;
private:
- typedef GrResource INHERITED;
+ typedef GrCacheable INHERITED;
};
-class TextureResource : public GrResource {
+class TextureResource : public GrCacheable {
public:
SK_DECLARE_INST_COUNT(TextureResource);
- TextureResource(GrGpu* gpu, int id)
- : INHERITED(gpu, false),
- fID(id) {
- }
- ~TextureResource() {
- this->release();
+ TextureResource(int id)
+ : fID(id) {
}
- virtual size_t sizeInBytes() const SK_OVERRIDE {
+ virtual size_t gpuMemorySize() const SK_OVERRIDE {
return 100 + ((fID % 1 == 0) ? -40 : 33);
}
+ virtual bool isValidOnGpu() const SK_OVERRIDE {
+ return true;
+ }
+
static GrResourceKey ComputeKey(const GrTextureDesc& desc) {
return GrTexture::ComputeScratchKey(desc);
}
@@ -68,7 +68,7 @@
int fID;
private:
- typedef GrResource INHERITED;
+ typedef GrCacheable INHERITED;
};
static void get_stencil(int i, int* w, int* h, int* s) {
@@ -91,8 +91,8 @@
int w, h, s;
get_stencil(i, &w, &h, &s);
GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s);
- GrResource* resource = SkNEW_ARGS(StencilResource, (gpu, i));
- cache->purgeAsNeeded(1, resource->sizeInBytes());
+ GrCacheable* resource = SkNEW_ARGS(StencilResource, (i));
+ cache->purgeAsNeeded(1, resource->gpuMemorySize());
cache->addResource(key, resource);
resource->unref();
}
@@ -101,8 +101,8 @@
GrTextureDesc desc;
get_texture_desc(i, &desc);
GrResourceKey key = TextureResource::ComputeKey(desc);
- GrResource* resource = SkNEW_ARGS(TextureResource, (gpu, i));
- cache->purgeAsNeeded(1, resource->sizeInBytes());
+ GrCacheable* resource = SkNEW_ARGS(TextureResource, (i));
+ cache->purgeAsNeeded(1, resource->gpuMemorySize());
cache->addResource(key, resource);
resource->unref();
}
@@ -114,7 +114,7 @@
GrTextureDesc desc;
get_texture_desc(k, &desc);
GrResourceKey key = TextureResource::ComputeKey(desc);
- GrResource* item = cache->find(key);
+ GrCacheable* item = cache->find(key);
if (NULL == item) {
SkFAIL("cache add does not work as expected");
return;
@@ -128,7 +128,7 @@
int w, h, s;
get_stencil(k, &w, &h, &s);
GrResourceKey key = StencilResource::ComputeKey(w, h, s);
- GrResource* item = cache->find(key);
+ GrCacheable* item = cache->find(key);
if (NULL == item) {
SkFAIL("cache add does not work as expected");
return;
@@ -145,7 +145,7 @@
get_texture_desc(k, &desc);
desc.fHeight |= 1;
GrResourceKey key = TextureResource::ComputeKey(desc);
- GrResource* item = cache->find(key);
+ GrCacheable* item = cache->find(key);
if (NULL != item) {
SkFAIL("cache add does not work as expected");
return;
@@ -156,7 +156,7 @@
get_stencil(k, &w, &h, &s);
h |= 1;
GrResourceKey key = StencilResource::ComputeKey(w, h, s);
- GrResource* item = cache->find(key);
+ GrCacheable* item = cache->find(key);
if (NULL != item) {
SkFAIL("cache add does not work as expected");
return;
diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi
index efeeb2d..258b532 100644
--- a/gyp/gpu.gypi
+++ b/gyp/gpu.gypi
@@ -9,6 +9,7 @@
'variables': {
'skgpu_sources': [
'<(skia_include_path)/gpu/GrBackendEffectFactory.h',
+ '<(skia_include_path)/gpu/GrCacheable.h',
'<(skia_include_path)/gpu/GrClipData.h',
'<(skia_include_path)/gpu/GrColor.h',
'<(skia_include_path)/gpu/GrConfig.h',
@@ -20,13 +21,13 @@
'<(skia_include_path)/gpu/GrEffectUnitTest.h',
'<(skia_include_path)/gpu/GrFontScaler.h',
'<(skia_include_path)/gpu/GrGlyph.h',
+ '<(skia_include_path)/gpu/GrGpuObject.h',
'<(skia_include_path)/gpu/GrKey.h',
'<(skia_include_path)/gpu/GrPaint.h',
'<(skia_include_path)/gpu/GrPathRendererChain.h',
'<(skia_include_path)/gpu/GrPoint.h',
'<(skia_include_path)/gpu/GrRect.h',
'<(skia_include_path)/gpu/GrRenderTarget.h',
- '<(skia_include_path)/gpu/GrResource.h',
'<(skia_include_path)/gpu/GrSurface.h',
'<(skia_include_path)/gpu/GrTBackendEffectFactory.h',
'<(skia_include_path)/gpu/GrTexture.h',
@@ -78,6 +79,7 @@
'<(skia_src_path)/gpu/GrClipMaskManager.cpp',
'<(skia_src_path)/gpu/GrGpu.cpp',
'<(skia_src_path)/gpu/GrGpu.h',
+ '<(skia_src_path)/gpu/GrGpuObject.cpp',
'<(skia_src_path)/gpu/GrGpuFactory.cpp',
'<(skia_src_path)/gpu/GrIndexBuffer.h',
'<(skia_src_path)/gpu/GrInOrderDrawBuffer.cpp',
@@ -107,7 +109,6 @@
'<(skia_src_path)/gpu/GrRenderTarget.cpp',
'<(skia_src_path)/gpu/GrReducedClip.cpp',
'<(skia_src_path)/gpu/GrReducedClip.h',
- '<(skia_src_path)/gpu/GrResource.cpp',
'<(skia_src_path)/gpu/GrResourceCache.cpp',
'<(skia_src_path)/gpu/GrResourceCache.h',
'<(skia_src_path)/gpu/GrStencil.cpp',
diff --git a/include/gpu/GrCacheable.h b/include/gpu/GrCacheable.h
new file mode 100644
index 0000000..75dec16
--- /dev/null
+++ b/include/gpu/GrCacheable.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrCacheable_DEFINED
+#define GrCacheable_DEFINED
+
+#include "SkRefCnt.h"
+
+class GrResourceCacheEntry;
+
+/**
+ * Base class for objects that can be kept in the GrResourceCache.
+ */
+class GrCacheable : public SkRefCnt {
+public:
+ SK_DECLARE_INST_COUNT(GrCacheable)
+
+ /**
+ * Retrieves the amount of GPU memory used by this resource in bytes. It is
+ * approximate since we aren't aware of additional padding or copies made
+ * by the driver.
+ *
+ * @return the amount of GPU memory used in bytes
+ */
+ virtual size_t gpuMemorySize() const = 0;
+
+ /**
+ * Checks whether the GPU memory allocated to this resource is still in effect.
+ * It can become invalid if its context is destroyed or lost, in which case it
+ * should no longer count against the GrResourceCache budget.
+ *
+ * @return true if this resource is still holding GPU memory
+ * false otherwise.
+ */
+ virtual bool isValidOnGpu() const = 0;
+
+ void setCacheEntry(GrResourceCacheEntry* cacheEntry) { fCacheEntry = cacheEntry; }
+ GrResourceCacheEntry* getCacheEntry() { return fCacheEntry; }
+
+protected:
+ GrCacheable() : fCacheEntry(NULL) {}
+
+ bool isInCache() const { return NULL != fCacheEntry; }
+
+private:
+ GrResourceCacheEntry* fCacheEntry; // NULL if not in cache
+
+ typedef SkRefCnt INHERITED;
+};
+
+#endif
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index c88f469..4d0a94e 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -20,6 +20,7 @@
class GrAARectRenderer;
class GrAutoScratchTexture;
+class GrCacheable;
class GrDrawState;
class GrDrawTarget;
class GrEffect;
@@ -87,8 +88,8 @@
* buffer, etc. references/IDs are now invalid. Should be called even when
* GrContext is no longer going to be used for two reasons:
* 1) ~GrContext will not try to free the objects in the 3D API.
- * 2) If you've created GrResources that outlive the GrContext they will
- * be marked as invalid (GrResource::isValid()) and won't attempt to
+ * 2) If you've created GrGpuObjects that outlive the GrContext they will
+ * be marked as invalid (GrGpuObjects::isValid()) and won't attempt to
* free their underlying resource in the 3D API.
* Content drawn since the last GrContext::flush() may be lost.
*/
diff --git a/include/gpu/GrGpuObject.h b/include/gpu/GrGpuObject.h
new file mode 100644
index 0000000..72d2f89
--- /dev/null
+++ b/include/gpu/GrGpuObject.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrGpuObject_DEFINED
+#define GrGpuObject_DEFINED
+
+#include "GrCacheable.h"
+#include "SkTInternalLList.h"
+
+class GrGpu;
+class GrContext;
+
+/**
+ * Base class for the GPU objects created by a GrContext.
+ */
+class GrGpuObject : public GrCacheable {
+public:
+ SK_DECLARE_INST_COUNT(GrGpuObject)
+
+ /**
+ * Frees the object in the underlying 3D API. It must be safe to call this
+ * when the object has been previously abandoned.
+ */
+ void release();
+
+ /**
+ * Removes references to objects in the underlying 3D API without freeing
+ * them. Used when the API context has been torn down before the GrContext.
+ */
+ void abandon();
+
+ /**
+ * Tests whether a object has been abandoned or released. All objects will
+ * be in this state after their creating GrContext is destroyed or has
+ * contextLost called. It's up to the client to test wasDestroyed() before
+ * attempting to use an object if it holds refs on objects across
+ * ~GrContext, freeResources with the force flag, or contextLost.
+ *
+ * @return true if the object has been released or abandoned,
+ * false otherwise.
+ */
+ bool wasDestroyed() const { return NULL == fGpu; }
+
+ /**
+ * Retrieves the context that owns the object. Note that it is possible for
+ * this to return NULL. When objects have been release()ed or abandon()ed
+ * they no longer have an owning context. Destroying a GrContext
+ * automatically releases all its resources.
+ */
+ const GrContext* getContext() const;
+ GrContext* getContext();
+
+ void incDeferredRefCount() const {
+ SkASSERT(fDeferredRefCount >= 0);
+ ++fDeferredRefCount;
+ }
+
+ void decDeferredRefCount() const {
+ SkASSERT(fDeferredRefCount > 0);
+ --fDeferredRefCount;
+ if (0 == fDeferredRefCount && this->needsDeferredUnref()) {
+ SkASSERT(this->getRefCnt() > 1);
+ this->unref();
+ }
+ }
+
+ int getDeferredRefCount() const { return fDeferredRefCount; }
+
+ void setNeedsDeferredUnref() { fFlags |= kDeferredUnref_FlagBit; }
+
+ virtual bool isValidOnGpu() const SK_OVERRIDE { return !this->wasDestroyed(); }
+
+protected:
+ /**
+ * isWrapped indicates we have wrapped a client-created backend object in a GrGpuObject. If it
+ * is true then the client is responsible for the lifetime of the underlying backend object.
+ * Otherwise, our onRelease() should free the object.
+ */
+ GrGpuObject(GrGpu* gpu, bool isWrapped);
+ virtual ~GrGpuObject();
+
+ GrGpu* getGpu() const { return fGpu; }
+
+ // Derived classes should always call their parent class' onRelease
+ // and onAbandon methods in their overrides.
+ virtual void onRelease() {};
+ virtual void onAbandon() {};
+
+ bool isWrapped() const { return kWrapped_FlagBit & fFlags; }
+ bool needsDeferredUnref() const { return SkToBool(kDeferredUnref_FlagBit & fFlags); }
+
+private:
+#ifdef SK_DEBUG
+ friend class GrGpu; // for assert in GrGpu to access getGpu
+#endif
+
+ // We're in an internal doubly linked list
+ SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuObject);
+
+ GrGpu* fGpu; // not reffed. The GrGpu can be deleted while there
+ // are still live GrGpuObjects. It will call
+ // release() on all such objects in its destructor.
+ mutable int fDeferredRefCount; // How many references in deferred drawing buffers.
+
+ enum Flags {
+ /**
+ * This object wraps a GPU object given to us by the user.
+ * Lifetime management is left up to the user (i.e., we will not
+ * free it).
+ */
+ kWrapped_FlagBit = 0x1,
+
+ /**
+ * This texture should be de-refed when the deferred ref count goes
+ * to zero. An object gets into this state when the resource cache
+ * is holding a ref-of-obligation (i.e., someone needs to own it but
+ * no one else wants to) but doesn't really want to keep it around.
+ */
+ kDeferredUnref_FlagBit = 0x2,
+ };
+ uint32_t fFlags;
+
+ typedef GrCacheable INHERITED;
+};
+
+#endif
diff --git a/include/gpu/GrRenderTarget.h b/include/gpu/GrRenderTarget.h
index ac3cbee..6a3f26f 100644
--- a/include/gpu/GrRenderTarget.h
+++ b/include/gpu/GrRenderTarget.h
@@ -26,7 +26,7 @@
SK_DECLARE_INST_COUNT(GrRenderTarget)
// GrResource overrides
- virtual size_t sizeInBytes() const SK_OVERRIDE;
+ virtual size_t gpuMemorySize() const SK_OVERRIDE;
// GrSurface overrides
/**
diff --git a/include/gpu/GrResource.h b/include/gpu/GrResource.h
deleted file mode 100644
index 93dec58..0000000
--- a/include/gpu/GrResource.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrResource_DEFINED
-#define GrResource_DEFINED
-
-#include "SkRefCnt.h"
-#include "SkTInternalLList.h"
-
-class GrGpu;
-class GrContext;
-class GrResourceEntry;
-
-/**
- * Base class for the GPU resources created by a GrContext.
- */
-class GrResource : public SkRefCnt {
-public:
- SK_DECLARE_INST_COUNT(GrResource)
-
- /**
- * Frees the resource in the underlying 3D API. It must be safe to call this
- * when the resource has been previously abandoned.
- */
- void release();
-
- /**
- * Removes references to objects in the underlying 3D API without freeing
- * them. Used when the API context has been torn down before the GrContext.
- */
- void abandon();
-
- /**
- * Tests whether a resource has been abandoned or released. All resources
- * will be in this state after their creating GrContext is destroyed or has
- * contextLost called. It's up to the client to test isValid() before
- * attempting to use a resource if it holds refs on resources across
- * ~GrContext, freeResources with the force flag, or contextLost.
- *
- * @return true if the resource has been released or abandoned,
- * false otherwise.
- */
- bool isValid() const { return NULL != fGpu; }
-
- /**
- * Retrieves the size of the object in GPU memory. This is approximate since
- * we aren't aware of additional padding or copies made by the driver.
- *
- * @return the size of the buffer in bytes
- */
- virtual size_t sizeInBytes() const = 0;
-
- /**
- * Retrieves the context that owns the resource. Note that it is possible
- * for this to return NULL. When resources have been release()ed or
- * abandon()ed they no longer have an owning context. Destroying a
- * GrContext automatically releases all its resources.
- */
- const GrContext* getContext() const;
- GrContext* getContext();
-
- void setCacheEntry(GrResourceEntry* cacheEntry) { fCacheEntry = cacheEntry; }
- GrResourceEntry* getCacheEntry() { return fCacheEntry; }
-
- void incDeferredRefCount() const {
- SkASSERT(fDeferredRefCount >= 0);
- ++fDeferredRefCount;
- }
-
- void decDeferredRefCount() const {
- SkASSERT(fDeferredRefCount > 0);
- --fDeferredRefCount;
- if (0 == fDeferredRefCount && this->needsDeferredUnref()) {
- SkASSERT(this->getRefCnt() > 1);
- this->unref();
- }
- }
-
- int getDeferredRefCount() const { return fDeferredRefCount; }
-
- void setNeedsDeferredUnref() { fFlags |= kDeferredUnref_FlagBit; }
-
-protected:
- /**
- * isWrapped indicates we have wrapped a client-created backend resource in a GrResource. If it
- * is true then the client is responsible for the lifetime of the underlying backend resource.
- * Otherwise, our onRelease() should free the resource.
- */
- GrResource(GrGpu* gpu, bool isWrapped);
- virtual ~GrResource();
-
- GrGpu* getGpu() const { return fGpu; }
-
- // Derived classes should always call their parent class' onRelease
- // and onAbandon methods in their overrides.
- virtual void onRelease() {};
- virtual void onAbandon() {};
-
- bool isInCache() const { return NULL != fCacheEntry; }
- bool isWrapped() const { return kWrapped_FlagBit & fFlags; }
- bool needsDeferredUnref() const { return SkToBool(kDeferredUnref_FlagBit & fFlags); }
-
-private:
-#ifdef SK_DEBUG
- friend class GrGpu; // for assert in GrGpu to access getGpu
-#endif
-
- // We're in an internal doubly linked list
- SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResource);
-
- GrGpu* fGpu; // not reffed. The GrGpu can be deleted while there
- // are still live GrResources. It will call
- // release() on all such resources in its
- // destructor.
- GrResourceEntry* fCacheEntry; // NULL if not in cache
- mutable int fDeferredRefCount; // How many references in deferred drawing buffers.
-
- enum Flags {
- /**
- * This resource wraps a GPU resource given to us by the user.
- * Lifetime management is left up to the user (i.e., we will not
- * free it).
- */
- kWrapped_FlagBit = 0x1,
-
- /**
- * This texture should be de-refed when the deferred ref count goes
- * to zero. A resource gets into this state when the resource cache
- * is holding a ref-of-obligation (i.e., someone needs to own it but
- * no one else wants to) but doesn't really want to keep it around.
- */
- kDeferredUnref_FlagBit = 0x2,
- };
- uint32_t fFlags;
-
- typedef SkRefCnt INHERITED;
-};
-
-#endif
diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h
index 15e44ab..f741c77 100644
--- a/include/gpu/GrSurface.h
+++ b/include/gpu/GrSurface.h
@@ -10,14 +10,14 @@
#define GrSurface_DEFINED
#include "GrTypes.h"
-#include "GrResource.h"
+#include "GrGpuObject.h"
#include "SkRect.h"
class GrTexture;
class GrRenderTarget;
struct SkImageInfo;
-class GrSurface : public GrResource {
+class GrSurface : public GrGpuObject {
public:
SK_DECLARE_INST_COUNT(GrSurface);
@@ -144,7 +144,7 @@
GrTextureDesc fDesc;
private:
- typedef GrResource INHERITED;
+ typedef GrGpuObject INHERITED;
};
#endif // GrSurface_DEFINED
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index 1df9dc6..1b9f7b7 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -55,7 +55,7 @@
/**
* Approximate number of bytes used by the texture
*/
- virtual size_t sizeInBytes() const SK_OVERRIDE {
+ virtual size_t gpuMemorySize() const SK_OVERRIDE {
return (size_t) fDesc.fWidth *
fDesc.fHeight *
GrBytesPerPixel(fDesc.fConfig);
diff --git a/src/gpu/GrBufferAllocPool.cpp b/src/gpu/GrBufferAllocPool.cpp
index 2dbf3eb..2f18e15 100644
--- a/src/gpu/GrBufferAllocPool.cpp
+++ b/src/gpu/GrBufferAllocPool.cpp
@@ -109,7 +109,7 @@
if (block.fBuffer->isLocked()) {
block.fBuffer->unlock();
} else {
- size_t flushSize = block.fBuffer->sizeInBytes() - block.fBytesFree;
+ size_t flushSize = block.fBuffer->gpuMemorySize() - block.fBytesFree;
flushCpuData(fBlocks.back().fBuffer, flushSize);
}
fBufferPtr = NULL;
@@ -135,7 +135,7 @@
SkASSERT(!fBlocks[i].fBuffer->isLocked());
}
for (int i = 0; i < fBlocks.count(); ++i) {
- size_t bytes = fBlocks[i].fBuffer->sizeInBytes() - fBlocks[i].fBytesFree;
+ size_t bytes = fBlocks[i].fBuffer->gpuMemorySize() - fBlocks[i].fBytesFree;
bytesInUse += bytes;
SkASSERT(bytes || unusedBlockAllowed);
}
@@ -161,7 +161,7 @@
if (NULL != fBufferPtr) {
BufferBlock& back = fBlocks.back();
- size_t usedBytes = back.fBuffer->sizeInBytes() - back.fBytesFree;
+ size_t usedBytes = back.fBuffer->gpuMemorySize() - back.fBytesFree;
size_t pad = GrSizeAlignUpPad(usedBytes,
alignment);
if ((size + pad) <= back.fBytesFree) {
@@ -201,7 +201,7 @@
VALIDATE();
if (NULL != fBufferPtr) {
const BufferBlock& back = fBlocks.back();
- size_t usedBytes = back.fBuffer->sizeInBytes() - back.fBytesFree;
+ size_t usedBytes = back.fBuffer->gpuMemorySize() - back.fBytesFree;
size_t pad = GrSizeAlignUpPad(usedBytes, itemSize);
return static_cast<int>((back.fBytesFree - pad) / itemSize);
} else if (fPreallocBuffersInUse < fPreallocBuffers.count()) {
@@ -231,7 +231,7 @@
// caller shouldnt try to put back more than they've taken
SkASSERT(!fBlocks.empty());
BufferBlock& block = fBlocks.back();
- size_t bytesUsed = block.fBuffer->sizeInBytes() - block.fBytesFree;
+ size_t bytesUsed = block.fBuffer->gpuMemorySize() - block.fBytesFree;
if (bytes >= bytesUsed) {
bytes -= bytesUsed;
fBytesInUse -= bytesUsed;
@@ -290,7 +290,7 @@
prev.fBuffer->unlock();
} else {
flushCpuData(prev.fBuffer,
- prev.fBuffer->sizeInBytes() - prev.fBytesFree);
+ prev.fBuffer->gpuMemorySize() - prev.fBytesFree);
}
fBufferPtr = NULL;
}
@@ -348,7 +348,7 @@
SkASSERT(NULL != buffer);
SkASSERT(!buffer->isLocked());
SkASSERT(fCpuData.get() == fBufferPtr);
- SkASSERT(flushSize <= buffer->sizeInBytes());
+ SkASSERT(flushSize <= buffer->gpuMemorySize());
VALIDATE(true);
if (fGpu->caps()->bufferLockSupport() &&
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 90bf8c0..c518a1c 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -238,7 +238,7 @@
const GrCacheID& cacheID,
const GrTextureParams* params) {
GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheID);
- GrResource* resource = fTextureCache->find(resourceKey);
+ GrCacheable* resource = fTextureCache->find(resourceKey);
SkSafeRef(resource);
return static_cast<GrTexture*>(resource);
}
@@ -264,7 +264,7 @@
GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width,
height,
sampleCnt);
- GrResource* resource = fTextureCache->find(resourceKey);
+ GrCacheable* resource = fTextureCache->find(resourceKey);
return static_cast<GrStencilBuffer*>(resource);
}
@@ -397,7 +397,7 @@
if (NULL != texture) {
// Adding a resource could put us overbudget. Try to free up the
// necessary space before adding it.
- fTextureCache->purgeAsNeeded(1, texture->sizeInBytes());
+ fTextureCache->purgeAsNeeded(1, texture->gpuMemorySize());
fTextureCache->addResource(resourceKey, texture);
if (NULL != cacheKey) {
@@ -416,7 +416,7 @@
GrResourceKey key = GrTexture::ComputeScratchKey(texture->desc());
// Adding a resource could put us overbudget. Try to free up the
// necessary space before adding it.
- textureCache->purgeAsNeeded(1, texture->sizeInBytes());
+ textureCache->purgeAsNeeded(1, texture->gpuMemorySize());
// Make the resource exclusive so future 'find' calls don't return it
textureCache->addResource(key, texture, GrResourceCache::kHide_OwnershipFlag);
}
@@ -448,7 +448,7 @@
desc.fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc.fHeight));
}
- GrResource* resource = NULL;
+ GrCacheable* resource = NULL;
int origWidth = desc.fWidth;
int origHeight = desc.fHeight;
@@ -1819,7 +1819,7 @@
path->ref();
} else {
path = fGpu->createPath(inPath, stroke);
- fTextureCache->purgeAsNeeded(1, path->sizeInBytes());
+ fTextureCache->purgeAsNeeded(1, path->gpuMemorySize());
fTextureCache->addResource(resourceKey, path);
}
return path;
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 5512f17..4847305 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -361,7 +361,7 @@
maxValidVertex = geoSrc.fVertexCount;
break;
case kBuffer_GeometrySrcType:
- maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->sizeInBytes() / geoSrc.fVertexSize);
+ maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySize() / geoSrc.fVertexSize);
break;
}
if (maxVertex > maxValidVertex) {
@@ -378,7 +378,7 @@
maxValidIndex = geoSrc.fIndexCount;
break;
case kBuffer_GeometrySrcType:
- maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->sizeInBytes() / sizeof(uint16_t));
+ maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t));
break;
}
if (maxIndex > maxValidIndex) {
diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h
index 46dd9d0..bbaf5a9 100644
--- a/src/gpu/GrDrawTarget.h
+++ b/src/gpu/GrDrawTarget.h
@@ -742,7 +742,7 @@
case kArray_GeometrySrcType:
return src.fIndexCount;
case kBuffer_GeometrySrcType:
- return static_cast<int>(src.fIndexBuffer->sizeInBytes() / sizeof(uint16_t));
+ return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t));
default:
SkFAIL("Unexpected Index Source.");
return 0;
diff --git a/src/gpu/GrGeometryBuffer.h b/src/gpu/GrGeometryBuffer.h
index 3bb7118..2a5aab7 100644
--- a/src/gpu/GrGeometryBuffer.h
+++ b/src/gpu/GrGeometryBuffer.h
@@ -10,14 +10,14 @@
#ifndef GrGeometryBuffer_DEFINED
#define GrGeometryBuffer_DEFINED
-#include "GrResource.h"
+#include "GrGpuObject.h"
class GrGpu;
/**
* Parent class for vertex and index buffers
*/
-class GrGeometryBuffer : public GrResource {
+class GrGeometryBuffer : public GrGpuObject {
public:
SK_DECLARE_INST_COUNT(GrGeometryBuffer);
@@ -82,22 +82,22 @@
*/
virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0;
- // GrResource overrides
- virtual size_t sizeInBytes() const { return fSizeInBytes; }
+ // GrGpuObject overrides
+ virtual size_t gpuMemorySize() const { return fGpuMemorySize; }
protected:
- GrGeometryBuffer(GrGpu* gpu, bool isWrapped, size_t sizeInBytes, bool dynamic, bool cpuBacked)
+ GrGeometryBuffer(GrGpu* gpu, bool isWrapped, size_t gpuMemorySize, bool dynamic, bool cpuBacked)
: INHERITED(gpu, isWrapped)
- , fSizeInBytes(sizeInBytes)
+ , fGpuMemorySize(gpuMemorySize)
, fDynamic(dynamic)
, fCPUBacked(cpuBacked) {}
private:
- size_t fSizeInBytes;
+ size_t fGpuMemorySize;
bool fDynamic;
bool fCPUBacked;
- typedef GrResource INHERITED;
+ typedef GrGpuObject INHERITED;
};
#endif
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 82da8c2..bc92952 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -57,11 +57,11 @@
fClipMaskManager.releaseResources();
- while (NULL != fResourceList.head()) {
- fResourceList.head()->abandon();
+ while (NULL != fObjectList.head()) {
+ fObjectList.head()->abandon();
}
- SkASSERT(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
+ SkASSERT(NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed());
SkSafeSetNull(fQuadIndexBuffer);
delete fVertexPool;
fVertexPool = NULL;
@@ -73,11 +73,11 @@
fClipMaskManager.releaseResources();
- while (NULL != fResourceList.head()) {
- fResourceList.head()->release();
+ while (NULL != fObjectList.head()) {
+ fObjectList.head()->release();
}
- SkASSERT(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
+ SkASSERT(NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed());
SkSafeSetNull(fQuadIndexBuffer);
delete fVertexPool;
fVertexPool = NULL;
@@ -85,18 +85,18 @@
fIndexPool = NULL;
}
-void GrGpu::insertResource(GrResource* resource) {
- SkASSERT(NULL != resource);
- SkASSERT(this == resource->getGpu());
+void GrGpu::insertObject(GrGpuObject* object) {
+ SkASSERT(NULL != object);
+ SkASSERT(this == object->getGpu());
- fResourceList.addToHead(resource);
+ fObjectList.addToHead(object);
}
-void GrGpu::removeResource(GrResource* resource) {
- SkASSERT(NULL != resource);
- SkASSERT(this == resource->getGpu());
+void GrGpu::removeObject(GrGpuObject* object) {
+ SkASSERT(NULL != object);
+ SkASSERT(this == object->getGpu());
- fResourceList.remove(resource);
+ fObjectList.remove(object);
}
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index dd5b2c8..fc16237 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -13,11 +13,11 @@
#include "SkPath.h"
class GrContext;
+class GrGpuObject;
class GrIndexBufferAllocPool;
class GrPath;
class GrPathRenderer;
class GrPathRendererChain;
-class GrResource;
class GrStencilBuffer;
class GrVertexBufferAllocPool;
@@ -231,29 +231,28 @@
size_t rowBytes);
/**
- * Called to tell Gpu object that all GrResources have been lost and should
+ * Called to tell GrGpu that all GrGpuObjects have been lost and should
* be abandoned. Overrides must call INHERITED::abandonResources().
*/
virtual void abandonResources();
/**
- * Called to tell Gpu object to release all GrResources. Overrides must call
+ * Called to tell GrGpu to release all GrGpuObjects. Overrides must call
* INHERITED::releaseResources().
*/
void releaseResources();
/**
- * Add resource to list of resources. Should only be called by GrResource.
+ * Add object to list of objects. Should only be called by GrGpuObject.
* @param resource the resource to add.
*/
- void insertResource(GrResource* resource);
+ void insertObject(GrGpuObject* object);
/**
- * Remove resource from list of resources. Should only be called by
- * GrResource.
+ * Remove object from list of objects. Should only be called by GrGpuObject.
* @param resource the resource to remove.
*/
- void removeResource(GrResource* resource);
+ void removeObject(GrGpuObject* object);
// GrDrawTarget overrides
virtual void clear(const SkIRect* rect,
@@ -503,7 +502,7 @@
enum {
kPreallocGeomPoolStateStackCnt = 4,
};
- typedef SkTInternalLList<GrResource> ResourceList;
+ typedef SkTInternalLList<GrGpuObject> ObjectList;
SkSTArray<kPreallocGeomPoolStateStackCnt, GeometryPoolState, true> fGeomPoolStateStack;
ResetTimestamp fResetTimestamp;
uint32_t fResetBits;
@@ -516,7 +515,7 @@
mutable GrIndexBuffer* fQuadIndexBuffer;
// Used to abandon/release all resources created by this GrGpu. TODO: Move this
// functionality to GrResourceCache.
- ResourceList fResourceList;
+ ObjectList fObjectList;
typedef GrDrawTarget INHERITED;
};
diff --git a/src/gpu/GrResource.cpp b/src/gpu/GrGpuObject.cpp
similarity index 64%
rename from src/gpu/GrResource.cpp
rename to src/gpu/GrGpuObject.cpp
index e20a30f..43a86f2 100644
--- a/src/gpu/GrResource.cpp
+++ b/src/gpu/GrGpuObject.cpp
@@ -7,44 +7,43 @@
*/
-#include "GrResource.h"
+#include "GrGpuObject.h"
#include "GrGpu.h"
-GrResource::GrResource(GrGpu* gpu, bool isWrapped) {
+GrGpuObject::GrGpuObject(GrGpu* gpu, bool isWrapped) {
fGpu = gpu;
- fCacheEntry = NULL;
fDeferredRefCount = 0;
if (isWrapped) {
fFlags = kWrapped_FlagBit;
} else {
fFlags = 0;
}
- fGpu->insertResource(this);
+ fGpu->insertObject(this);
}
-GrResource::~GrResource() {
+GrGpuObject::~GrGpuObject() {
// subclass should have released this.
SkASSERT(0 == fDeferredRefCount);
- SkASSERT(!this->isValid());
+ SkASSERT(this->wasDestroyed());
}
-void GrResource::release() {
+void GrGpuObject::release() {
if (NULL != fGpu) {
this->onRelease();
- fGpu->removeResource(this);
+ fGpu->removeObject(this);
fGpu = NULL;
}
}
-void GrResource::abandon() {
+void GrGpuObject::abandon() {
if (NULL != fGpu) {
this->onAbandon();
- fGpu->removeResource(this);
+ fGpu->removeObject(this);
fGpu = NULL;
}
}
-const GrContext* GrResource::getContext() const {
+const GrContext* GrGpuObject::getContext() const {
if (NULL != fGpu) {
return fGpu->getContext();
} else {
@@ -52,7 +51,7 @@
}
}
-GrContext* GrResource::getContext() {
+GrContext* GrGpuObject::getContext() {
if (NULL != fGpu) {
return fGpu->getContext();
} else {
diff --git a/src/gpu/GrIndexBuffer.h b/src/gpu/GrIndexBuffer.h
index e23bc9b..113b89d 100644
--- a/src/gpu/GrIndexBuffer.h
+++ b/src/gpu/GrIndexBuffer.h
@@ -21,11 +21,11 @@
* @return the maximum number of quads using full size of index buffer.
*/
int maxQuads() const {
- return static_cast<int>(this->sizeInBytes() / (sizeof(uint16_t) * 6));
+ return static_cast<int>(this->gpuMemorySize() / (sizeof(uint16_t) * 6));
}
protected:
- GrIndexBuffer(GrGpu* gpu, bool isWrapped, size_t sizeInBytes, bool dynamic, bool cpuBacked)
- : INHERITED(gpu, isWrapped, sizeInBytes, dynamic, cpuBacked) {}
+ GrIndexBuffer(GrGpu* gpu, bool isWrapped, size_t gpuMemorySize, bool dynamic, bool cpuBacked)
+ : INHERITED(gpu, isWrapped, gpuMemorySize, dynamic, cpuBacked) {}
private:
typedef GrGeometryBuffer INHERITED;
};
diff --git a/src/gpu/GrPath.h b/src/gpu/GrPath.h
index f481ea4..d324e6a 100644
--- a/src/gpu/GrPath.h
+++ b/src/gpu/GrPath.h
@@ -8,13 +8,13 @@
#ifndef GrPath_DEFINED
#define GrPath_DEFINED
-#include "GrResource.h"
+#include "GrGpuObject.h"
#include "GrResourceCache.h"
#include "SkPath.h"
#include "SkRect.h"
#include "SkStrokeRec.h"
-class GrPath : public GrResource {
+class GrPath : public GrGpuObject {
public:
SK_DECLARE_INST_COUNT(GrPath);
@@ -41,7 +41,7 @@
SkRect fBounds;
private:
- typedef GrResource INHERITED;
+ typedef GrGpuObject INHERITED;
};
#endif
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index 9348dc1..13fc229 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -63,7 +63,7 @@
context->discardRenderTarget(this);
}
-size_t GrRenderTarget::sizeInBytes() const {
+size_t GrRenderTarget::gpuMemorySize() const {
size_t colorBits;
if (kUnknown_GrPixelConfig == fDesc.fConfig) {
colorBits = 32; // don't know, make a guess
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index ba8b962..26f7592 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -9,7 +9,7 @@
#include "GrResourceCache.h"
-#include "GrResource.h"
+#include "GrCacheable.h"
DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage);
@@ -26,20 +26,20 @@
///////////////////////////////////////////////////////////////////////////////
-GrResourceEntry::GrResourceEntry(const GrResourceKey& key, GrResource* resource)
+GrResourceCacheEntry::GrResourceCacheEntry(const GrResourceKey& key, GrCacheable* resource)
: fKey(key), fResource(resource) {
// we assume ownership of the resource, and will unref it when we die
SkASSERT(resource);
resource->ref();
}
-GrResourceEntry::~GrResourceEntry() {
+GrResourceCacheEntry::~GrResourceCacheEntry() {
fResource->setCacheEntry(NULL);
fResource->unref();
}
#ifdef SK_DEBUG
-void GrResourceEntry::validate() const {
+void GrResourceCacheEntry::validate() const {
SkASSERT(fResource);
SkASSERT(fResource->getCacheEntry() == this);
fResource->validate();
@@ -75,7 +75,7 @@
EntryList::Iter iter;
// Unlike the removeAll, here we really remove everything, including locked resources.
- while (GrResourceEntry* entry = fList.head()) {
+ while (GrResourceCacheEntry* entry = fList.head()) {
GrAutoResourceCacheValidate atcv(this);
// remove from our cache
@@ -108,14 +108,14 @@
}
}
-void GrResourceCache::internalDetach(GrResourceEntry* entry,
+void GrResourceCache::internalDetach(GrResourceCacheEntry* entry,
BudgetBehaviors behavior) {
fList.remove(entry);
// update our stats
if (kIgnore_BudgetBehavior == behavior) {
fClientDetachedCount += 1;
- fClientDetachedBytes += entry->resource()->sizeInBytes();
+ fClientDetachedBytes += entry->resource()->gpuMemorySize();
#if GR_CACHE_STATS
if (fHighWaterClientDetachedCount < fClientDetachedCount) {
@@ -130,23 +130,23 @@
SkASSERT(kAccountFor_BudgetBehavior == behavior);
fEntryCount -= 1;
- fEntryBytes -= entry->resource()->sizeInBytes();
+ fEntryBytes -= entry->resource()->gpuMemorySize();
}
}
-void GrResourceCache::attachToHead(GrResourceEntry* entry,
+void GrResourceCache::attachToHead(GrResourceCacheEntry* entry,
BudgetBehaviors behavior) {
fList.addToHead(entry);
// update our stats
if (kIgnore_BudgetBehavior == behavior) {
fClientDetachedCount -= 1;
- fClientDetachedBytes -= entry->resource()->sizeInBytes();
+ fClientDetachedBytes -= entry->resource()->gpuMemorySize();
} else {
SkASSERT(kAccountFor_BudgetBehavior == behavior);
fEntryCount += 1;
- fEntryBytes += entry->resource()->sizeInBytes();
+ fEntryBytes += entry->resource()->gpuMemorySize();
#if GR_CACHE_STATS
if (fHighWaterEntryCount < fEntryCount) {
@@ -164,15 +164,15 @@
// is relying on the texture.
class GrTFindUnreffedFunctor {
public:
- bool operator()(const GrResourceEntry* entry) const {
+ bool operator()(const GrResourceCacheEntry* entry) const {
return entry->resource()->unique();
}
};
-GrResource* GrResourceCache::find(const GrResourceKey& key, uint32_t ownershipFlags) {
+GrCacheable* GrResourceCache::find(const GrResourceKey& key, uint32_t ownershipFlags) {
GrAutoResourceCacheValidate atcv(this);
- GrResourceEntry* entry = NULL;
+ GrResourceCacheEntry* entry = NULL;
if (ownershipFlags & kNoOtherOwners_OwnershipFlag) {
GrTFindUnreffedFunctor functor;
@@ -198,7 +198,7 @@
}
void GrResourceCache::addResource(const GrResourceKey& key,
- GrResource* resource,
+ GrCacheable* resource,
uint32_t ownershipFlags) {
SkASSERT(NULL == resource->getCacheEntry());
// we don't expect to create new resources during a purge. In theory
@@ -208,7 +208,7 @@
SkASSERT(!fPurging);
GrAutoResourceCacheValidate atcv(this);
- GrResourceEntry* entry = SkNEW_ARGS(GrResourceEntry, (key, resource));
+ GrResourceCacheEntry* entry = SkNEW_ARGS(GrResourceCacheEntry, (key, resource));
resource->setCacheEntry(entry);
this->attachToHead(entry);
@@ -220,7 +220,7 @@
}
-void GrResourceCache::makeExclusive(GrResourceEntry* entry) {
+void GrResourceCache::makeExclusive(GrResourceCacheEntry* entry) {
GrAutoResourceCacheValidate atcv(this);
// When scratch textures are detached (to hide them from future finds) they
@@ -233,7 +233,7 @@
#endif
}
-void GrResourceCache::removeInvalidResource(GrResourceEntry* entry) {
+void GrResourceCache::removeInvalidResource(GrResourceCacheEntry* entry) {
// If the resource went invalid while it was detached then purge it
// This can happen when a 3D context was lost,
// the client called GrContext::contextDestroyed() to notify Gr,
@@ -241,19 +241,19 @@
// texture (which was invalidated at contextDestroyed time).
fClientDetachedCount -= 1;
fEntryCount -= 1;
- size_t size = entry->resource()->sizeInBytes();
+ size_t size = entry->resource()->gpuMemorySize();
fClientDetachedBytes -= size;
fEntryBytes -= size;
}
-void GrResourceCache::makeNonExclusive(GrResourceEntry* entry) {
+void GrResourceCache::makeNonExclusive(GrResourceCacheEntry* entry) {
GrAutoResourceCacheValidate atcv(this);
#ifdef SK_DEBUG
fExclusiveList.remove(entry);
#endif
- if (entry->resource()->isValid()) {
+ if (entry->resource()->isValidOnGpu()) {
// Since scratch textures still count against the cache budget even
// when they have been removed from the cache, re-adding them doesn't
// alter the budget information.
@@ -313,13 +313,13 @@
//
// This is complicated and confusing. May try this in the future. For
// now, these resources are just LRU'd as if we never got the message.
- while (GrResourceEntry* entry = fCache.find(invalidated[i].key, GrTFindUnreffedFunctor())) {
+ while (GrResourceCacheEntry* entry = fCache.find(invalidated[i].key, GrTFindUnreffedFunctor())) {
this->deleteResource(entry);
}
}
}
-void GrResourceCache::deleteResource(GrResourceEntry* entry) {
+void GrResourceCache::deleteResource(GrResourceCacheEntry* entry) {
SkASSERT(1 == entry->fResource->getRefCnt());
// remove from our cache
@@ -347,7 +347,7 @@
// doubly linked list doesn't invalidate its data/pointers
// outside of the specific area where a deletion occurs (e.g.,
// in internalDetach)
- GrResourceEntry* entry = iter.init(fList, EntryList::Iter::kTail_IterStart);
+ GrResourceCacheEntry* entry = iter.init(fList, EntryList::Iter::kTail_IterStart);
while (NULL != entry) {
GrAutoResourceCacheValidate atcv(this);
@@ -358,7 +358,7 @@
break;
}
- GrResourceEntry* prev = iter.prev();
+ GrResourceCacheEntry* prev = iter.prev();
if (entry->fResource->unique()) {
changed = true;
this->deleteResource(entry);
@@ -371,7 +371,7 @@
void GrResourceCache::purgeAllUnlocked() {
GrAutoResourceCacheValidate atcv(this);
- // we can have one GrResource holding a lock on another
+ // we can have one GrCacheable holding a lock on another
// so we don't want to just do a simple loop kicking each
// entry out. Instead change the budget and purge.
@@ -406,11 +406,11 @@
EntryList::Iter iter;
- const GrResourceEntry* entry = iter.init(const_cast<EntryList&>(list),
- EntryList::Iter::kTail_IterStart);
+ const GrResourceCacheEntry* entry = iter.init(const_cast<EntryList&>(list),
+ EntryList::Iter::kTail_IterStart);
for ( ; NULL != entry; entry = iter.prev()) {
- bytes += entry->resource()->sizeInBytes();
+ bytes += entry->resource()->gpuMemorySize();
}
return bytes;
}
@@ -431,8 +431,8 @@
EntryList::Iter iter;
// check that the exclusively held entries are okay
- const GrResourceEntry* entry = iter.init(const_cast<EntryList&>(fExclusiveList),
- EntryList::Iter::kHead_IterStart);
+ const GrResourceCacheEntry* entry = iter.init(const_cast<EntryList&>(fExclusiveList),
+ EntryList::Iter::kHead_IterStart);
for ( ; NULL != entry; entry = iter.next()) {
entry->validate();
@@ -468,7 +468,7 @@
EntryList::Iter iter;
- GrResourceEntry* entry = iter.init(fList, EntryList::Iter::kTail_IterStart);
+ GrResourceCacheEntry* entry = iter.init(fList, EntryList::Iter::kTail_IterStart);
for ( ; NULL != entry; entry = iter.prev()) {
if (entry->fResource->getRefCnt() > 1) {
diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h
index a830918..b2f91cd 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -18,8 +18,8 @@
#include "SkMessageBus.h"
#include "SkTInternalLList.h"
-class GrResource;
-class GrResourceEntry;
+class GrCacheable;
+class GrResourceCacheEntry;
class GrResourceKey {
public:
@@ -28,11 +28,11 @@
return gDomain;
}
- /** Uniquely identifies the GrResource subclass in the key to avoid collisions
+ /** Uniquely identifies the GrCacheable subclass in the key to avoid collisions
across resource types. */
typedef uint8_t ResourceType;
- /** Flags set by the GrResource subclass. */
+ /** Flags set by the GrCacheable subclass. */
typedef uint8_t ResourceFlags;
/** Generate a unique ResourceType */
@@ -115,12 +115,12 @@
///////////////////////////////////////////////////////////////////////////////
-class GrResourceEntry {
+class GrResourceCacheEntry {
public:
- GrResource* resource() const { return fResource; }
+ GrCacheable* resource() const { return fResource; }
const GrResourceKey& key() const { return fKey; }
- static const GrResourceKey& GetKey(const GrResourceEntry& e) { return e.key(); }
+ static const GrResourceKey& GetKey(const GrResourceCacheEntry& e) { return e.key(); }
static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); }
#ifdef SK_DEBUG
void validate() const;
@@ -129,14 +129,14 @@
#endif
private:
- GrResourceEntry(const GrResourceKey& key, GrResource* resource);
- ~GrResourceEntry();
+ GrResourceCacheEntry(const GrResourceKey& key, GrCacheable* resource);
+ ~GrResourceCacheEntry();
GrResourceKey fKey;
- GrResource* fResource;
+ GrCacheable* fResource;
// Linked list for the LRU ordering.
- SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceEntry);
+ SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceCacheEntry);
friend class GrResourceCache;
};
@@ -144,7 +144,7 @@
///////////////////////////////////////////////////////////////////////////////
/**
- * Cache of GrResource objects.
+ * Cache of GrCacheable objects.
*
* These have a corresponding GrResourceKey, built from 128bits identifying the
* resource. Multiple resources can map to same GrResourceKey.
@@ -157,7 +157,7 @@
* For fast searches, we maintain a hash map based on the GrResourceKey.
*
* It is a goal to make the GrResourceCache the central repository and bookkeeper
- * of all resources. It should replace the linked list of GrResources that
+ * of all resources. It should replace the linked list of GrGpuObjects that
* GrGpu uses to call abandon/release.
*/
class GrResourceCache {
@@ -233,8 +233,8 @@
* For a resource to be completely exclusive to a caller both kNoOtherOwners
* and kHide must be specified.
*/
- GrResource* find(const GrResourceKey& key,
- uint32_t ownershipFlags = 0);
+ GrCacheable* find(const GrResourceKey& key,
+ uint32_t ownershipFlags = 0);
/**
* Add the new resource to the cache (by creating a new cache entry based
@@ -248,7 +248,7 @@
* is called.
*/
void addResource(const GrResourceKey& key,
- GrResource* resource,
+ GrCacheable* resource,
uint32_t ownershipFlags = 0);
/**
@@ -263,18 +263,18 @@
* the cache's budget and should be made non-exclusive when exclusive access
* is no longer needed.
*/
- void makeExclusive(GrResourceEntry* entry);
+ void makeExclusive(GrResourceCacheEntry* entry);
/**
* Restore 'entry' so that it can be found by future searches. 'entry'
* will also be purgeable (provided its lock count is now 0.)
*/
- void makeNonExclusive(GrResourceEntry* entry);
+ void makeNonExclusive(GrResourceCacheEntry* entry);
/**
* Remove a resource from the cache and delete it!
*/
- void deleteResource(GrResourceEntry* entry);
+ void deleteResource(GrResourceCacheEntry* entry);
/**
* Removes every resource in the cache that isn't locked.
@@ -310,15 +310,15 @@
kIgnore_BudgetBehavior
};
- void internalDetach(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior);
- void attachToHead(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior);
+ void internalDetach(GrResourceCacheEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior);
+ void attachToHead(GrResourceCacheEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior);
- void removeInvalidResource(GrResourceEntry* entry);
+ void removeInvalidResource(GrResourceCacheEntry* entry);
- GrTMultiMap<GrResourceEntry, GrResourceKey> fCache;
+ GrTMultiMap<GrResourceCacheEntry, GrResourceKey> fCache;
// We're an internal doubly linked list
- typedef SkTInternalLList<GrResourceEntry> EntryList;
+ typedef SkTInternalLList<GrResourceCacheEntry> EntryList;
EntryList fList;
#ifdef SK_DEBUG
@@ -356,7 +356,7 @@
void purgeInvalidated();
#ifdef SK_DEBUG
- static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list);
+ static size_t countBytes(const SkTInternalLList<GrResourceCacheEntry>& list);
#endif
};
diff --git a/src/gpu/GrStencilBuffer.h b/src/gpu/GrStencilBuffer.h
index 37d40f1..696ba83 100644
--- a/src/gpu/GrStencilBuffer.h
+++ b/src/gpu/GrStencilBuffer.h
@@ -11,13 +11,12 @@
#define GrStencilBuffer_DEFINED
#include "GrClipData.h"
-#include "GrResource.h"
+#include "GrGpuObject.h"
class GrRenderTarget;
-class GrResourceEntry;
class GrResourceKey;
-class GrStencilBuffer : public GrResource {
+class GrStencilBuffer : public GrGpuObject {
public:
SK_DECLARE_INST_COUNT(GrStencilBuffer);
@@ -55,7 +54,7 @@
protected:
GrStencilBuffer(GrGpu* gpu, bool isWrapped, int width, int height, int bits, int sampleCnt)
- : GrResource(gpu, isWrapped)
+ : GrGpuObject(gpu, isWrapped)
, fWidth(width)
, fHeight(height)
, fBits(bits)
@@ -75,7 +74,7 @@
SkIRect fLastClipStackRect;
SkIPoint fLastClipSpaceOffset;
- typedef GrResource INHERITED;
+ typedef GrGpuObject INHERITED;
};
#endif
diff --git a/src/gpu/GrVertexBuffer.h b/src/gpu/GrVertexBuffer.h
index a2bd5a1..c3cf534 100644
--- a/src/gpu/GrVertexBuffer.h
+++ b/src/gpu/GrVertexBuffer.h
@@ -15,8 +15,8 @@
class GrVertexBuffer : public GrGeometryBuffer {
protected:
- GrVertexBuffer(GrGpu* gpu, bool isWrapped, size_t sizeInBytes, bool dynamic, bool cpuBacked)
- : INHERITED(gpu, isWrapped, sizeInBytes, dynamic, cpuBacked) {}
+ GrVertexBuffer(GrGpu* gpu, bool isWrapped, size_t gpuMemorySize, bool dynamic, bool cpuBacked)
+ : INHERITED(gpu, isWrapped, gpuMemorySize, dynamic, cpuBacked) {}
private:
typedef GrGeometryBuffer INHERITED;
};
diff --git a/src/gpu/SkGrPixelRef.cpp b/src/gpu/SkGrPixelRef.cpp
index 18fefcc..fd21f10 100644
--- a/src/gpu/SkGrPixelRef.cpp
+++ b/src/gpu/SkGrPixelRef.cpp
@@ -167,7 +167,7 @@
}
bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) {
- if (NULL == fSurface || !fSurface->isValid()) {
+ if (NULL == fSurface || fSurface->wasDestroyed()) {
return false;
}
diff --git a/src/gpu/gl/GrGLIndexBuffer.cpp b/src/gpu/gl/GrGLIndexBuffer.cpp
index b6290b1..4e7f989 100644
--- a/src/gpu/gl/GrGLIndexBuffer.cpp
+++ b/src/gpu/gl/GrGLIndexBuffer.cpp
@@ -14,7 +14,7 @@
}
void GrGLIndexBuffer::onRelease() {
- if (this->isValid()) {
+ if (!this->wasDestroyed()) {
fImpl.release(this->getGpuGL());
}
@@ -27,7 +27,7 @@
}
void* GrGLIndexBuffer::lock() {
- if (this->isValid()) {
+ if (!this->wasDestroyed()) {
return fImpl.lock(this->getGpuGL());
} else {
return NULL;
@@ -39,7 +39,7 @@
}
void GrGLIndexBuffer::unlock() {
- if (this->isValid()) {
+ if (!this->wasDestroyed()) {
fImpl.unlock(this->getGpuGL());
}
}
@@ -49,7 +49,7 @@
}
bool GrGLIndexBuffer::updateData(const void* src, size_t srcSizeInBytes) {
- if (this->isValid()) {
+ if (!this->wasDestroyed()) {
return fImpl.updateData(this->getGpuGL(), src, srcSizeInBytes);
} else {
return false;
diff --git a/src/gpu/gl/GrGLIndexBuffer.h b/src/gpu/gl/GrGLIndexBuffer.h
index 32a8086..893e357 100644
--- a/src/gpu/gl/GrGLIndexBuffer.h
+++ b/src/gpu/gl/GrGLIndexBuffer.h
@@ -26,7 +26,7 @@
size_t baseOffset() const { return fImpl.baseOffset(); }
void bind() const {
- if (this->isValid()) {
+ if (!this->wasDestroyed()) {
fImpl.bind(this->getGpuGL());
}
}
@@ -45,7 +45,7 @@
private:
GrGpuGL* getGpuGL() const {
- SkASSERT(this->isValid());
+ SkASSERT(!this->wasDestroyed());
return (GrGpuGL*)(this->getGpu());
}
diff --git a/src/gpu/gl/GrGLPath.h b/src/gpu/gl/GrGLPath.h
index 3647d4d..3409547 100644
--- a/src/gpu/gl/GrGLPath.h
+++ b/src/gpu/gl/GrGLPath.h
@@ -27,7 +27,7 @@
GrGLuint pathID() const { return fPathID; }
// TODO: Figure out how to get an approximate size of the path in Gpu
// memory.
- virtual size_t sizeInBytes() const SK_OVERRIDE { return 100; }
+ virtual size_t gpuMemorySize() const SK_OVERRIDE { return 100; }
protected:
virtual void onRelease() SK_OVERRIDE;
diff --git a/src/gpu/gl/GrGLStencilBuffer.cpp b/src/gpu/gl/GrGLStencilBuffer.cpp
index 33e346c..abcb3c4 100644
--- a/src/gpu/gl/GrGLStencilBuffer.cpp
+++ b/src/gpu/gl/GrGLStencilBuffer.cpp
@@ -13,7 +13,7 @@
this->release();
}
-size_t GrGLStencilBuffer::sizeInBytes() const {
+size_t GrGLStencilBuffer::gpuMemorySize() 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 2bf33ef..1cb0a33 100644
--- a/src/gpu/gl/GrGLStencilBuffer.h
+++ b/src/gpu/gl/GrGLStencilBuffer.h
@@ -36,7 +36,7 @@
virtual ~GrGLStencilBuffer();
- virtual size_t sizeInBytes() const SK_OVERRIDE;
+ virtual size_t gpuMemorySize() const SK_OVERRIDE;
GrGLuint renderbufferID() const {
return fRenderbufferID;
diff --git a/src/gpu/gl/GrGLVertexArray.cpp b/src/gpu/gl/GrGLVertexArray.cpp
index abd337a..66feb82 100644
--- a/src/gpu/gl/GrGLVertexArray.cpp
+++ b/src/gpu/gl/GrGLVertexArray.cpp
@@ -69,7 +69,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
GrGLVertexArray::GrGLVertexArray(GrGpuGL* gpu, GrGLint id, int attribCount)
- : GrResource(gpu, false)
+ : INHERITED(gpu, false)
, fID(id)
, fAttribArrays(attribCount)
, fIndexBufferIDIsValid(false) {
diff --git a/src/gpu/gl/GrGLVertexArray.h b/src/gpu/gl/GrGLVertexArray.h
index 8a61f1a..0e5bffe 100644
--- a/src/gpu/gl/GrGLVertexArray.h
+++ b/src/gpu/gl/GrGLVertexArray.h
@@ -8,7 +8,7 @@
#ifndef GrGLVertexArray_DEFINED
#define GrGLVertexArray_DEFINED
-#include "GrResource.h"
+#include "GrGpuObject.h"
#include "GrTypesPriv.h"
#include "gl/GrGLDefines.h"
#include "gl/GrGLFunctions.h"
@@ -130,7 +130,7 @@
* This class represents an OpenGL vertex array object. It manages the lifetime of the vertex array
* and is used to track the state of the vertex array to avoid redundant GL calls.
*/
-class GrGLVertexArray : public GrResource {
+class GrGLVertexArray : public GrGpuObject {
public:
GrGLVertexArray(GrGpuGL* gpu, GrGLint id, int attribCount);
@@ -157,7 +157,7 @@
void invalidateCachedState();
- virtual size_t sizeInBytes() const SK_OVERRIDE { return 0; }
+ virtual size_t gpuMemorySize() const SK_OVERRIDE { return 0; }
protected:
virtual void onAbandon() SK_OVERRIDE;
@@ -170,7 +170,7 @@
GrGLuint fIndexBufferID;
bool fIndexBufferIDIsValid;
- typedef GrResource INHERITED;
+ typedef GrGpuObject INHERITED;
};
#endif
diff --git a/src/gpu/gl/GrGLVertexBuffer.cpp b/src/gpu/gl/GrGLVertexBuffer.cpp
index 685166c..8bfe1f0 100644
--- a/src/gpu/gl/GrGLVertexBuffer.cpp
+++ b/src/gpu/gl/GrGLVertexBuffer.cpp
@@ -14,7 +14,7 @@
}
void GrGLVertexBuffer::onRelease() {
- if (this->isValid()) {
+ if (!this->wasDestroyed()) {
fImpl.release(this->getGpuGL());
}
@@ -28,7 +28,7 @@
}
void* GrGLVertexBuffer::lock() {
- if (this->isValid()) {
+ if (!this->wasDestroyed()) {
return fImpl.lock(this->getGpuGL());
} else {
return NULL;
@@ -40,7 +40,7 @@
}
void GrGLVertexBuffer::unlock() {
- if (this->isValid()) {
+ if (!this->wasDestroyed()) {
fImpl.unlock(this->getGpuGL());
}
}
@@ -50,7 +50,7 @@
}
bool GrGLVertexBuffer::updateData(const void* src, size_t srcSizeInBytes) {
- if (this->isValid()) {
+ if (!this->wasDestroyed()) {
return fImpl.updateData(this->getGpuGL(), src, srcSizeInBytes);
} else {
return false;
diff --git a/src/gpu/gl/GrGLVertexBuffer.h b/src/gpu/gl/GrGLVertexBuffer.h
index 1741adc..1b9c4f1 100644
--- a/src/gpu/gl/GrGLVertexBuffer.h
+++ b/src/gpu/gl/GrGLVertexBuffer.h
@@ -26,7 +26,7 @@
size_t baseOffset() const { return fImpl.baseOffset(); }
void bind() const {
- if (this->isValid()) {
+ if (!this->wasDestroyed()) {
fImpl.bind(this->getGpuGL());
}
}
@@ -45,7 +45,7 @@
private:
GrGpuGL* getGpuGL() const {
- SkASSERT(this->isValid());
+ SkASSERT(!this->wasDestroyed());
return (GrGpuGL*)(this->getGpu());
}
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 9b92fe2..1a1bad7 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -2788,7 +2788,7 @@
// We use a vertex array if we're on a core profile and the verts are in a VBO.
if (gpu->glCaps().isCoreProfile() && !vbuffer->isCPUBacked()) {
- if (NULL == fVBOVertexArray || !fVBOVertexArray->isValid()) {
+ if (NULL == fVBOVertexArray || fVBOVertexArray->wasDestroyed()) {
SkSafeUnref(fVBOVertexArray);
GrGLuint arrayID;
GR_GL_CALL(gpu->glInterface(), GenVertexArrays(1, &arrayID));
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 6b324a7..7262b43 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -56,12 +56,11 @@
context->setTextureCacheLimits(oldMaxNum, oldMaxBytes);
}
-class TestResource : public GrResource {
+class TestResource : public GrCacheable {
public:
SK_DECLARE_INST_COUNT(TestResource);
- explicit TestResource(GrGpu* gpu)
- : INHERITED(gpu, false)
- , fCache(NULL)
+ TestResource()
+ : fCache(NULL)
, fToDelete(NULL) {
++fAlive;
}
@@ -73,10 +72,11 @@
fToDelete->setDeleteWhenDestroyed(NULL, NULL);
fCache->deleteResource(fToDelete->getCacheEntry());
}
- this->release();
}
- size_t sizeInBytes() const SK_OVERRIDE { return 100; }
+ size_t gpuMemorySize() const SK_OVERRIDE { return 100; }
+
+ bool isValidOnGpu() const SK_OVERRIDE { return true; }
static int alive() { return fAlive; }
@@ -90,7 +90,7 @@
TestResource* fToDelete;
static int fAlive;
- typedef GrResource INHERITED;
+ typedef GrCacheable INHERITED;
};
int TestResource::fAlive = 0;
@@ -105,8 +105,8 @@
GrResourceCache cache(5, 30000);
// Add two resources with the same key that delete each other from the cache when destroyed.
- TestResource* a = new TestResource(context->getGpu());
- TestResource* b = new TestResource(context->getGpu());
+ TestResource* a = new TestResource();
+ TestResource* b = new TestResource();
cache.addResource(key, a);
cache.addResource(key, b);
// Circle back.
@@ -116,7 +116,7 @@
b->unref();
// Add a third independent resource also with the same key.
- GrResource* r = new TestResource(context->getGpu());
+ GrCacheable* r = new TestResource();
cache.addResource(key, r);
r->unref();
@@ -141,8 +141,8 @@
{
{
GrResourceCache cache(3, 30000);
- TestResource* a = new TestResource(context->getGpu());
- TestResource* b = new TestResource(context->getGpu());
+ TestResource* a = new TestResource();
+ TestResource* b = new TestResource();
cache.addResource(key, a);
cache.addResource(key, b);
@@ -157,8 +157,8 @@
}
{
GrResourceCache cache(3, 30000);
- TestResource* a = new TestResource(context->getGpu());
- TestResource* b = new TestResource(context->getGpu());
+ TestResource* a = new TestResource();
+ TestResource* b = new TestResource();
cache.addResource(key, a);
cache.addResource(key, b);