#if SK_SUPPORT_GPU
#include "Benchmark.h"
-#include "GrCacheable.h"
+#include "GrGpuResource.h"
#include "GrContext.h"
#include "GrResourceCache.h"
#include "GrStencilBuffer.h"
CACHE_SIZE_BYTES = 2 * 1024 * 1024,
};
-class StencilResource : public GrCacheable {
+class StencilResource : public GrGpuResource {
public:
SK_DECLARE_INST_COUNT(StencilResource);
- StencilResource(int id)
- : fID(id) {
+ StencilResource(GrGpu* gpu, int id)
+ : INHERITED(gpu, false)
+ , fID(id) {
}
+ virtual ~StencilResource() { this->release(); }
+
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);
}
int fID;
private:
- typedef GrCacheable INHERITED;
+ typedef GrGpuResource INHERITED;
};
-class TextureResource : public GrCacheable {
+class TextureResource : public GrGpuResource {
public:
SK_DECLARE_INST_COUNT(TextureResource);
- TextureResource(int id)
- : fID(id) {
+ TextureResource(GrGpu* gpu, int id)
+ : INHERITED(gpu, false)
+ , fID(id) {
}
+ virtual ~TextureResource() { this->release(); }
+
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 GrTextureImpl::ComputeScratchKey(desc);
}
int fID;
private:
- typedef GrCacheable INHERITED;
+ typedef GrGpuResource INHERITED;
};
static void get_stencil(int i, int* w, int* h, int* s) {
int w, h, s;
get_stencil(i, &w, &h, &s);
GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s);
- GrCacheable* resource = SkNEW_ARGS(StencilResource, (i));
+ GrGpuResource* resource = SkNEW_ARGS(StencilResource, (gpu, i));
cache->purgeAsNeeded(1, resource->gpuMemorySize());
cache->addResource(key, resource);
resource->unref();
GrTextureDesc desc;
get_texture_desc(i, &desc);
GrResourceKey key = TextureResource::ComputeKey(desc);
- GrCacheable* resource = SkNEW_ARGS(TextureResource, (i));
+ GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i));
cache->purgeAsNeeded(1, resource->gpuMemorySize());
cache->addResource(key, resource);
resource->unref();
GrTextureDesc desc;
get_texture_desc(k, &desc);
GrResourceKey key = TextureResource::ComputeKey(desc);
- GrCacheable* item = cache->find(key);
+ GrGpuResource* item = cache->find(key);
if (NULL == item) {
SkFAIL("cache add does not work as expected");
return;
int w, h, s;
get_stencil(k, &w, &h, &s);
GrResourceKey key = StencilResource::ComputeKey(w, h, s);
- GrCacheable* item = cache->find(key);
+ GrGpuResource* item = cache->find(key);
if (NULL == item) {
SkFAIL("cache add does not work as expected");
return;
get_texture_desc(k, &desc);
desc.fHeight |= 1;
GrResourceKey key = TextureResource::ComputeKey(desc);
- GrCacheable* item = cache->find(key);
+ GrGpuResource* item = cache->find(key);
if (NULL != item) {
SkFAIL("cache add does not work as expected");
return;
get_stencil(k, &w, &h, &s);
h |= 1;
GrResourceKey key = StencilResource::ComputeKey(w, h, s);
- GrCacheable* item = cache->find(key);
+ GrGpuResource* item = cache->find(key);
if (NULL != item) {
SkFAIL("cache add does not work as expected");
return;