Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 418143004: Rename GrGpuObject to GrGpuResource (Closed) Base URL: https://skia.googlesource.com/skia.git@compact
Patch Set: Fix indents Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGLVertexArray.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #if SK_SUPPORT_GPU 8 #if SK_SUPPORT_GPU
9 9
10 #include "GrContextFactory.h" 10 #include "GrContextFactory.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 size_t curCacheSize; 51 size_t curCacheSize;
52 context->getResourceCacheUsage(NULL, &curCacheSize); 52 context->getResourceCacheUsage(NULL, &curCacheSize);
53 53
54 // we should never go over the size limit 54 // we should never go over the size limit
55 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); 55 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize);
56 } 56 }
57 57
58 context->setResourceCacheLimits(oldMaxNum, oldMaxBytes); 58 context->setResourceCacheLimits(oldMaxNum, oldMaxBytes);
59 } 59 }
60 60
61 class TestResource : public GrGpuObject { 61 class TestResource : public GrGpuResource {
62 static const size_t kDefaultSize = 100; 62 static const size_t kDefaultSize = 100;
63 63
64 public: 64 public:
65 SK_DECLARE_INST_COUNT(TestResource); 65 SK_DECLARE_INST_COUNT(TestResource);
66 TestResource(GrGpu* gpu, size_t size = kDefaultSize) 66 TestResource(GrGpu* gpu, size_t size = kDefaultSize)
67 : INHERITED(gpu, false) 67 : INHERITED(gpu, false)
68 , fCache(NULL) 68 , fCache(NULL)
69 , fToDelete(NULL) 69 , fToDelete(NULL)
70 , fSize(size) { 70 , fSize(size) {
71 ++fAlive; 71 ++fAlive;
(...skipping 22 matching lines...) Expand all
94 fCache = cache; 94 fCache = cache;
95 fToDelete = resource; 95 fToDelete = resource;
96 } 96 }
97 97
98 private: 98 private:
99 GrResourceCache* fCache; 99 GrResourceCache* fCache;
100 TestResource* fToDelete; 100 TestResource* fToDelete;
101 size_t fSize; 101 size_t fSize;
102 static int fAlive; 102 static int fAlive;
103 103
104 typedef GrGpuObject INHERITED; 104 typedef GrGpuResource INHERITED;
105 }; 105 };
106 int TestResource::fAlive = 0; 106 int TestResource::fAlive = 0;
107 107
108 static void test_purge_invalidated(skiatest::Reporter* reporter, GrContext* cont ext) { 108 static void test_purge_invalidated(skiatest::Reporter* reporter, GrContext* cont ext) {
109 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); 109 GrCacheID::Domain domain = GrCacheID::GenerateDomain();
110 GrCacheID::Key keyData; 110 GrCacheID::Key keyData;
111 keyData.fData64[0] = 5; 111 keyData.fData64[0] = 5;
112 keyData.fData64[1] = 18; 112 keyData.fData64[1] = 18;
113 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); 113 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
114 GrResourceKey key(GrCacheID(domain, keyData), t, 0); 114 GrResourceKey key(GrCacheID(domain, keyData), t, 0);
115 115
116 GrResourceCache cache(5, 30000); 116 GrResourceCache cache(5, 30000);
117 117
118 // Add two resources with the same key that delete each other from the cache when destroyed. 118 // Add two resources with the same key that delete each other from the cache when destroyed.
119 TestResource* a = new TestResource(context->getGpu()); 119 TestResource* a = new TestResource(context->getGpu());
120 TestResource* b = new TestResource(context->getGpu()); 120 TestResource* b = new TestResource(context->getGpu());
121 cache.addResource(key, a); 121 cache.addResource(key, a);
122 cache.addResource(key, b); 122 cache.addResource(key, b);
123 // Circle back. 123 // Circle back.
124 a->setDeleteWhenDestroyed(&cache, b); 124 a->setDeleteWhenDestroyed(&cache, b);
125 b->setDeleteWhenDestroyed(&cache, a); 125 b->setDeleteWhenDestroyed(&cache, a);
126 a->unref(); 126 a->unref();
127 b->unref(); 127 b->unref();
128 128
129 // Add a third independent resource also with the same key. 129 // Add a third independent resource also with the same key.
130 GrGpuObject* r = new TestResource(context->getGpu()); 130 GrGpuResource* r = new TestResource(context->getGpu());
131 cache.addResource(key, r); 131 cache.addResource(key, r);
132 r->unref(); 132 r->unref();
133 133
134 // Invalidate all three, all three should be purged and destroyed. 134 // Invalidate all three, all three should be purged and destroyed.
135 REPORTER_ASSERT(reporter, 3 == TestResource::alive()); 135 REPORTER_ASSERT(reporter, 3 == TestResource::alive());
136 const GrResourceInvalidatedMessage msg = { key }; 136 const GrResourceInvalidatedMessage msg = { key };
137 SkMessageBus<GrResourceInvalidatedMessage>::Post(msg); 137 SkMessageBus<GrResourceInvalidatedMessage>::Post(msg);
138 cache.purgeAsNeeded(); 138 cache.purgeAsNeeded();
139 REPORTER_ASSERT(reporter, 0 == TestResource::alive()); 139 REPORTER_ASSERT(reporter, 0 == TestResource::alive());
140 } 140 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 SkCanvas canvas(device.get()); 301 SkCanvas canvas(device.get());
302 302
303 test_cache(reporter, context, &canvas); 303 test_cache(reporter, context, &canvas);
304 test_purge_invalidated(reporter, context); 304 test_purge_invalidated(reporter, context);
305 test_cache_delete_on_destruction(reporter, context); 305 test_cache_delete_on_destruction(reporter, context);
306 test_resource_size_changed(reporter, context); 306 test_resource_size_changed(reporter, context);
307 } 307 }
308 } 308 }
309 309
310 #endif 310 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLVertexArray.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698