aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/GrResourceCacheBench.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-02 21:38:22 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-02 21:38:22 +0000
commit089a780c3355129eefc942246534bc1f126b8ccb (patch)
tree717d71a73ad4ce8d8810cf8344d67c6ddb143507 /bench/GrResourceCacheBench.cpp
parent40f6e3a25c0d35b9416346b72f1b6ba07778d173 (diff)
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
Diffstat (limited to 'bench/GrResourceCacheBench.cpp')
-rw-r--r--bench/GrResourceCacheBench.cpp54
1 files changed, 27 insertions, 27 deletions
diff --git a/bench/GrResourceCacheBench.cpp b/bench/GrResourceCacheBench.cpp
index e808cd7836..6767ca1d49 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 @@ 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;