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
This commit is contained in:
commit-bot@chromium.org 2014-05-02 21:38:22 +00:00
parent 40f6e3a25c
commit 089a780c33
35 changed files with 288 additions and 247 deletions

View File

@ -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 @@ enum {
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 @@ public:
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 @@ public:
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 @@ static void populate_cache(GrResourceCache* cache, GrGpu* gpu, int resourceCount
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 @@ static void populate_cache(GrResourceCache* cache, GrGpu* gpu, int resourceCount
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 @@ static void check_cache_contents_or_die(GrResourceCache* cache, int k) {
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 @@ static void check_cache_contents_or_die(GrResourceCache* cache, int k) {
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 @@ static void check_cache_contents_or_die(GrResourceCache* cache, int k) {
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 @@ static void check_cache_contents_or_die(GrResourceCache* cache, int k) {
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;

View File

@ -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',

55
include/gpu/GrCacheable.h Normal file
View File

@ -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

View File

@ -20,6 +20,7 @@
class GrAARectRenderer;
class GrAutoScratchTexture;
class GrCacheable;
class GrDrawState;
class GrDrawTarget;
class GrEffect;
@ -87,8 +88,8 @@ public:
* 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.
*/

View File

@ -5,26 +5,25 @@
* found in the LICENSE file.
*/
#ifndef GrResource_DEFINED
#define GrResource_DEFINED
#ifndef GrGpuObject_DEFINED
#define GrGpuObject_DEFINED
#include "SkRefCnt.h"
#include "GrCacheable.h"
#include "SkTInternalLList.h"
class GrGpu;
class GrContext;
class GrResourceEntry;
/**
* Base class for the GPU resources created by a GrContext.
* Base class for the GPU objects created by a GrContext.
*/
class GrResource : public SkRefCnt {
class GrGpuObject : public GrCacheable {
public:
SK_DECLARE_INST_COUNT(GrResource)
SK_DECLARE_INST_COUNT(GrGpuObject)
/**
* Frees the resource in the underlying 3D API. It must be safe to call this
* when the resource has been previously abandoned.
* Frees the object in the underlying 3D API. It must be safe to call this
* when the object has been previously abandoned.
*/
void release();
@ -35,37 +34,26 @@ public:
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
* 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 resource has been released or abandoned,
* @return true if the object has been released or abandoned,
* false otherwise.
*/
bool isValid() const { return NULL != fGpu; }
bool wasDestroyed() 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.
* 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 setCacheEntry(GrResourceEntry* cacheEntry) { fCacheEntry = cacheEntry; }
GrResourceEntry* getCacheEntry() { return fCacheEntry; }
void incDeferredRefCount() const {
SkASSERT(fDeferredRefCount >= 0);
++fDeferredRefCount;
@ -84,14 +72,16 @@ public:
void setNeedsDeferredUnref() { fFlags |= kDeferredUnref_FlagBit; }
virtual bool isValidOnGpu() const SK_OVERRIDE { return !this->wasDestroyed(); }
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.
* 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.
*/
GrResource(GrGpu* gpu, bool isWrapped);
virtual ~GrResource();
GrGpuObject(GrGpu* gpu, bool isWrapped);
virtual ~GrGpuObject();
GrGpu* getGpu() const { return fGpu; }
@ -100,7 +90,6 @@ protected:
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); }
@ -110,18 +99,16 @@ private:
#endif
// We're in an internal doubly linked list
SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResource);
SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuObject);
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
// 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 resource wraps a GPU resource given to us by the user.
* 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).
*/
@ -129,7 +116,7 @@ private:
/**
* This texture should be de-refed when the deferred ref count goes
* to zero. A resource gets into this state when the resource cache
* 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.
*/
@ -137,7 +124,7 @@ private:
};
uint32_t fFlags;
typedef SkRefCnt INHERITED;
typedef GrCacheable INHERITED;
};
#endif

View File

@ -26,7 +26,7 @@ public:
SK_DECLARE_INST_COUNT(GrRenderTarget)
// GrResource overrides
virtual size_t sizeInBytes() const SK_OVERRIDE;
virtual size_t gpuMemorySize() const SK_OVERRIDE;
// GrSurface overrides
/**

View File

@ -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 @@ protected:
GrTextureDesc fDesc;
private:
typedef GrResource INHERITED;
typedef GrGpuObject INHERITED;
};
#endif // GrSurface_DEFINED

View File

@ -55,7 +55,7 @@ public:
/**
* 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);

View File

@ -109,7 +109,7 @@ void GrBufferAllocPool::unlock() {
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 @@ void GrBufferAllocPool::validate(bool unusedBlockAllowed) const {
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 @@ void* GrBufferAllocPool::makeSpace(size_t size,
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 @@ int GrBufferAllocPool::currentBufferItems(size_t itemSize) const {
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 @@ void GrBufferAllocPool::putBack(size_t bytes) {
// 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 @@ bool GrBufferAllocPool::createBlock(size_t requestSize) {
prev.fBuffer->unlock();
} else {
flushCpuData(prev.fBuffer,
prev.fBuffer->sizeInBytes() - prev.fBytesFree);
prev.fBuffer->gpuMemorySize() - prev.fBytesFree);
}
fBufferPtr = NULL;
}
@ -348,7 +348,7 @@ void GrBufferAllocPool::flushCpuData(GrGeometryBuffer* buffer,
SkASSERT(NULL != buffer);
SkASSERT(!buffer->isLocked());
SkASSERT(fCpuData.get() == fBufferPtr);
SkASSERT(flushSize <= buffer->sizeInBytes());
SkASSERT(flushSize <= buffer->gpuMemorySize());
VALIDATE(true);
if (fGpu->caps()->bufferLockSupport() &&

View File

@ -238,7 +238,7 @@ GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc,
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 @@ GrStencilBuffer* GrContext::findStencilBuffer(int width, int height,
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 @@ GrTexture* GrContext::createTexture(const GrTextureParams* params,
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 @@ static GrTexture* create_scratch_texture(GrGpu* gpu,
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 @@ GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra
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 @@ GrPath* GrContext::createPath(const SkPath& inPath, const SkStrokeRec& stroke) {
path->ref();
} else {
path = fGpu->createPath(inPath, stroke);
fTextureCache->purgeAsNeeded(1, path->sizeInBytes());
fTextureCache->purgeAsNeeded(1, path->gpuMemorySize());
fTextureCache->addResource(resourceKey, path);
}
return path;

View File

@ -361,7 +361,7 @@ bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex,
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 @@ bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex,
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) {

View File

@ -742,7 +742,7 @@ protected:
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;

View File

@ -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 @@ public:
*/
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

View File

@ -57,11 +57,11 @@ void GrGpu::abandonResources() {
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 @@ void GrGpu::releaseResources() {
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 @@ void GrGpu::releaseResources() {
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);
}

View File

@ -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 @@ public:
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 @@ private:
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 @@ private:
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;
};

View File

@ -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 @@ const GrContext* GrResource::getContext() const {
}
}
GrContext* GrResource::getContext() {
GrContext* GrGpuObject::getContext() {
if (NULL != fGpu) {
return fGpu->getContext();
} else {

View File

@ -21,11 +21,11 @@ public:
* @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;
};

View File

@ -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 @@ protected:
SkRect fBounds;
private:
typedef GrResource INHERITED;
typedef GrGpuObject INHERITED;
};
#endif

View File

@ -63,7 +63,7 @@ void GrRenderTarget::discard() {
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

View File

@ -9,7 +9,7 @@
#include "GrResourceCache.h"
#include "GrResource.h"
#include "GrCacheable.h"
DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage);
@ -26,20 +26,20 @@ GrResourceKey::ResourceType GrResourceKey::GenerateResourceType() {
///////////////////////////////////////////////////////////////////////////////
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 @@ GrResourceCache::~GrResourceCache() {
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::setLimits(int maxResources, size_t maxResourceBytes) {
}
}
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 @@ void GrResourceCache::internalDetach(GrResourceEntry* entry,
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 @@ void GrResourceCache::attachToHead(GrResourceEntry* entry,
// 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 @@ GrResource* GrResourceCache::find(const GrResourceKey& key, uint32_t ownershipFl
}
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 @@ void GrResourceCache::addResource(const GrResourceKey& key,
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::addResource(const GrResourceKey& key,
}
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 @@ void GrResourceCache::makeExclusive(GrResourceEntry* entry) {
#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 @@ void GrResourceCache::removeInvalidResource(GrResourceEntry* entry) {
// 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 @@ void GrResourceCache::purgeInvalidated() {
//
// 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 @@ void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) {
// 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 @@ void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) {
break;
}
GrResourceEntry* prev = iter.prev();
GrResourceCacheEntry* prev = iter.prev();
if (entry->fResource->unique()) {
changed = true;
this->deleteResource(entry);
@ -371,7 +371,7 @@ void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) {
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 @@ size_t GrResourceCache::countBytes(const EntryList& list) {
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 @@ void GrResourceCache::validate() const {
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 @@ void GrResourceCache::printStats() {
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) {

View File

@ -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 @@ public:
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 @@ struct GrResourceInvalidatedMessage {
///////////////////////////////////////////////////////////////////////////////
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 @@ public:
#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 @@ private:
///////////////////////////////////////////////////////////////////////////////
/**
* 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 @@ private:
* 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 @@ public:
* 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 @@ public:
* is called.
*/
void addResource(const GrResourceKey& key,
GrResource* resource,
GrCacheable* resource,
uint32_t ownershipFlags = 0);
/**
@ -263,18 +263,18 @@ public:
* 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 @@ private:
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 @@ private:
void purgeInvalidated();
#ifdef SK_DEBUG
static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list);
static size_t countBytes(const SkTInternalLList<GrResourceCacheEntry>& list);
#endif
};

View File

@ -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 @@ public:
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 @@ private:
SkIRect fLastClipStackRect;
SkIPoint fLastClipSpaceOffset;
typedef GrResource INHERITED;
typedef GrGpuObject INHERITED;
};
#endif

View File

@ -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;
};

View File

@ -167,7 +167,7 @@ SkPixelRef* SkGrPixelRef::deepCopy(SkBitmap::Config dstConfig, const SkIRect* su
}
bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) {
if (NULL == fSurface || !fSurface->isValid()) {
if (NULL == fSurface || fSurface->wasDestroyed()) {
return false;
}

View File

@ -14,7 +14,7 @@ GrGLIndexBuffer::GrGLIndexBuffer(GrGpuGL* gpu, const Desc& desc)
}
void GrGLIndexBuffer::onRelease() {
if (this->isValid()) {
if (!this->wasDestroyed()) {
fImpl.release(this->getGpuGL());
}
@ -27,7 +27,7 @@ void GrGLIndexBuffer::onAbandon() {
}
void* GrGLIndexBuffer::lock() {
if (this->isValid()) {
if (!this->wasDestroyed()) {
return fImpl.lock(this->getGpuGL());
} else {
return NULL;
@ -39,7 +39,7 @@ void* GrGLIndexBuffer::lockPtr() const {
}
void GrGLIndexBuffer::unlock() {
if (this->isValid()) {
if (!this->wasDestroyed()) {
fImpl.unlock(this->getGpuGL());
}
}
@ -49,7 +49,7 @@ bool GrGLIndexBuffer::isLocked() const {
}
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;

View File

@ -26,7 +26,7 @@ public:
size_t baseOffset() const { return fImpl.baseOffset(); }
void bind() const {
if (this->isValid()) {
if (!this->wasDestroyed()) {
fImpl.bind(this->getGpuGL());
}
}
@ -45,7 +45,7 @@ protected:
private:
GrGpuGL* getGpuGL() const {
SkASSERT(this->isValid());
SkASSERT(!this->wasDestroyed());
return (GrGpuGL*)(this->getGpu());
}

View File

@ -27,7 +27,7 @@ public:
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;

View File

@ -13,7 +13,7 @@ GrGLStencilBuffer::~GrGLStencilBuffer() {
this->release();
}
size_t GrGLStencilBuffer::sizeInBytes() const {
size_t GrGLStencilBuffer::gpuMemorySize() const {
uint64_t size = this->width();
size *= this->height();
size *= fFormat.fTotalBits;

View File

@ -36,7 +36,7 @@ public:
virtual ~GrGLStencilBuffer();
virtual size_t sizeInBytes() const SK_OVERRIDE;
virtual size_t gpuMemorySize() const SK_OVERRIDE;
GrGLuint renderbufferID() const {
return fRenderbufferID;

View File

@ -69,7 +69,7 @@ void GrGLAttribArrayState::disableUnusedArrays(const GrGpuGL* gpu, uint64_t used
///////////////////////////////////////////////////////////////////////////////////////////////////
GrGLVertexArray::GrGLVertexArray(GrGpuGL* gpu, GrGLint id, int attribCount)
: GrResource(gpu, false)
: INHERITED(gpu, false)
, fID(id)
, fAttribArrays(attribCount)
, fIndexBufferIDIsValid(false) {

View File

@ -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 @@ private:
* 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 @@ public:
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 @@ private:
GrGLuint fIndexBufferID;
bool fIndexBufferIDIsValid;
typedef GrResource INHERITED;
typedef GrGpuObject INHERITED;
};
#endif

View File

@ -14,7 +14,7 @@ GrGLVertexBuffer::GrGLVertexBuffer(GrGpuGL* gpu, const Desc& desc)
}
void GrGLVertexBuffer::onRelease() {
if (this->isValid()) {
if (!this->wasDestroyed()) {
fImpl.release(this->getGpuGL());
}
@ -28,7 +28,7 @@ void GrGLVertexBuffer::onAbandon() {
}
void* GrGLVertexBuffer::lock() {
if (this->isValid()) {
if (!this->wasDestroyed()) {
return fImpl.lock(this->getGpuGL());
} else {
return NULL;
@ -40,7 +40,7 @@ void* GrGLVertexBuffer::lockPtr() const {
}
void GrGLVertexBuffer::unlock() {
if (this->isValid()) {
if (!this->wasDestroyed()) {
fImpl.unlock(this->getGpuGL());
}
}
@ -50,7 +50,7 @@ bool GrGLVertexBuffer::isLocked() const {
}
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;

View File

@ -26,7 +26,7 @@ public:
size_t baseOffset() const { return fImpl.baseOffset(); }
void bind() const {
if (this->isValid()) {
if (!this->wasDestroyed()) {
fImpl.bind(this->getGpuGL());
}
}
@ -45,7 +45,7 @@ protected:
private:
GrGpuGL* getGpuGL() const {
SkASSERT(this->isValid());
SkASSERT(!this->wasDestroyed());
return (GrGpuGL*)(this->getGpu());
}

View File

@ -2788,7 +2788,7 @@ GrGLAttribArrayState* GrGpuGL::HWGeometryState::bindArrayAndBuffersToDraw(
// 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));

View File

@ -56,12 +56,11 @@ static void test_cache(skiatest::Reporter* reporter,
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 @@ public:
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 @@ private:
TestResource* fToDelete;
static int fAlive;
typedef GrResource INHERITED;
typedef GrCacheable INHERITED;
};
int TestResource::fAlive = 0;
@ -105,8 +105,8 @@ static void test_purge_invalidated(skiatest::Reporter* reporter, GrContext* cont
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 @@ static void test_purge_invalidated(skiatest::Reporter* reporter, GrContext* cont
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 @@ static void test_cache_delete_on_destruction(skiatest::Reporter* reporter,
{
{
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 @@ static void test_cache_delete_on_destruction(skiatest::Reporter* reporter,
}
{
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);