blob: a1a594e1dd4bbd8dc57c4771c038c4b28c5b40ef [file] [log] [blame]
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +00008#if SK_SUPPORT_GPU
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +00009
bsalomonbcf0a522014-10-08 08:40:09 -070010#include "GrContext.h"
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +000011#include "GrContextFactory.h"
bsalomonbcf0a522014-10-08 08:40:09 -070012#include "GrGpu.h"
bsalomon33435572014-11-05 14:47:41 -080013#include "GrResourceCache2.h"
bsalomonbcf0a522014-10-08 08:40:09 -070014#include "SkCanvas.h"
bsalomon71cb0c22014-11-14 12:10:14 -080015#include "SkGr.h"
16#include "SkMessageBus.h"
reed69f6f002014-09-18 06:09:44 -070017#include "SkSurface.h"
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000018#include "Test.h"
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +000019
20static const int gWidth = 640;
21static const int gHeight = 480;
22
23////////////////////////////////////////////////////////////////////////////////
bsalomon33435572014-11-05 14:47:41 -080024static void test_cache(skiatest::Reporter* reporter, GrContext* context, SkCanvas* canvas) {
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +000025 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight);
26
27 SkBitmap src;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +000028 src.allocN32Pixels(size.width(), size.height());
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +000029 src.eraseColor(SK_ColorBLACK);
30 size_t srcSize = src.getSize();
31
commit-bot@chromium.org95c20032014-05-09 14:29:32 +000032 size_t initialCacheSize;
33 context->getResourceCacheUsage(NULL, &initialCacheSize);
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +000034
35 int oldMaxNum;
36 size_t oldMaxBytes;
commit-bot@chromium.org95c20032014-05-09 14:29:32 +000037 context->getResourceCacheLimits(&oldMaxNum, &oldMaxBytes);
skia.committer@gmail.com17f1ae62013-08-09 07:01:22 +000038
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +000039 // Set the cache limits so we can fit 10 "src" images and the
40 // max number of textures doesn't matter
41 size_t maxCacheSize = initialCacheSize + 10*srcSize;
commit-bot@chromium.org95c20032014-05-09 14:29:32 +000042 context->setResourceCacheLimits(1000, maxCacheSize);
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +000043
44 SkBitmap readback;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +000045 readback.allocN32Pixels(size.width(), size.height());
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +000046
47 for (int i = 0; i < 100; ++i) {
48 canvas->drawBitmap(src, 0, 0);
49 canvas->readPixels(size, &readback);
50
51 // "modify" the src texture
52 src.notifyPixelsChanged();
53
commit-bot@chromium.org95c20032014-05-09 14:29:32 +000054 size_t curCacheSize;
55 context->getResourceCacheUsage(NULL, &curCacheSize);
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +000056
57 // we should never go over the size limit
58 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize);
59 }
60
commit-bot@chromium.org95c20032014-05-09 14:29:32 +000061 context->setResourceCacheLimits(oldMaxNum, oldMaxBytes);
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +000062}
63
bsalomon6d3fe022014-07-25 08:35:45 -070064class TestResource : public GrGpuResource {
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000065 static const size_t kDefaultSize = 100;
66
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +000067public:
68 SK_DECLARE_INST_COUNT(TestResource);
bsalomondace19e2014-11-17 07:34:06 -080069 TestResource(GrGpu* gpu, bool isWrapped)
70 : INHERITED(gpu, isWrapped)
71 , fToDelete(NULL)
72 , fSize(kDefaultSize) {
73 ++fNumAlive;
74 this->registerWithCache();
75 }
76
bsalomon8b79d232014-11-10 10:19:06 -080077 TestResource(GrGpu* gpu)
bsalomonc44be0e2014-07-25 07:32:33 -070078 : INHERITED(gpu, false)
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000079 , fToDelete(NULL)
bsalomon8b79d232014-11-10 10:19:06 -080080 , fSize(kDefaultSize) {
81 ++fNumAlive;
82 this->registerWithCache();
83 }
84
bsalomon7775c852014-12-30 12:50:52 -080085 TestResource(GrGpu* gpu, const GrScratchKey& scratchKey)
bsalomon8b79d232014-11-10 10:19:06 -080086 : INHERITED(gpu, false)
bsalomon8b79d232014-11-10 10:19:06 -080087 , fToDelete(NULL)
88 , fSize(kDefaultSize) {
89 this->setScratchKey(scratchKey);
bsalomon33435572014-11-05 14:47:41 -080090 ++fNumAlive;
bsalomon16961262014-08-26 14:01:07 -070091 this->registerWithCache();
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +000092 }
93
94 ~TestResource() {
bsalomon33435572014-11-05 14:47:41 -080095 --fNumAlive;
bsalomon71cb0c22014-11-14 12:10:14 -080096 SkSafeUnref(fToDelete);
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +000097 }
98
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000099 void setSize(size_t size) {
100 fSize = size;
101 this->didChangeGpuMemorySize();
102 }
103
bsalomon33435572014-11-05 14:47:41 -0800104 static int NumAlive() { return fNumAlive; }
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +0000105
bsalomon71cb0c22014-11-14 12:10:14 -0800106 void setUnrefWhenDestroyed(TestResource* resource) {
107 SkRefCnt_SafeAssign(fToDelete, resource);
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +0000108 }
109
110private:
bsalomon69ed47f2014-11-12 11:13:39 -0800111 size_t onGpuMemorySize() const SK_OVERRIDE { return fSize; }
112
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +0000113 TestResource* fToDelete;
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000114 size_t fSize;
bsalomon33435572014-11-05 14:47:41 -0800115 static int fNumAlive;
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +0000116
bsalomon6d3fe022014-07-25 08:35:45 -0700117 typedef GrGpuResource INHERITED;
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +0000118};
bsalomon33435572014-11-05 14:47:41 -0800119int TestResource::fNumAlive = 0;
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +0000120
bsalomon71cb0c22014-11-14 12:10:14 -0800121static void test_no_key(skiatest::Reporter* reporter) {
122 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
123 REPORTER_ASSERT(reporter, SkToBool(context));
124 if (NULL == context) {
125 return;
126 }
127 context->setResourceCacheLimits(10, 30000);
128 GrResourceCache2* cache2 = context->getResourceCache2();
129 cache2->purgeAllUnlocked();
130 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
131
132 // Create a bunch of resources with no keys
133 TestResource* a = new TestResource(context->getGpu());
134 TestResource* b = new TestResource(context->getGpu());
135 TestResource* c = new TestResource(context->getGpu());
136 TestResource* d = new TestResource(context->getGpu());
137 a->setSize(11);
138 b->setSize(12);
139 c->setSize(13);
140 d->setSize(14);
141
142 REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive());
143 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount());
144 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMemorySize() +
145 d->gpuMemorySize() == cache2->getResourceBytes());
146
147 // Should be safe to purge without deleting the resources since we still have refs.
148 cache2->purgeAllUnlocked();
149 REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive());
150
151 // Since the resources have neither content nor scratch keys, delete immediately upon unref.
152
153 a->unref();
154 REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive());
155 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount());
156 REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() + d->gpuMemorySize() ==
157 cache2->getResourceBytes());
158
159 c->unref();
160 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
161 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
162 REPORTER_ASSERT(reporter, b->gpuMemorySize() + d->gpuMemorySize() ==
163 cache2->getResourceBytes());
164
165 d->unref();
166 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
167 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
168 REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache2->getResourceBytes());
169
170 b->unref();
171 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
172 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
173 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
174}
175
bsalomon7775c852014-12-30 12:50:52 -0800176static void make_scratch_key(GrScratchKey* key) {
177 static GrScratchKey::ResourceType t = GrScratchKey::GenerateResourceType();
178 GrScratchKey::Builder builder(key, t, 0);
179}
180
bsalomon84c8e622014-11-17 09:33:27 -0800181static void test_budgeting(skiatest::Reporter* reporter) {
bsalomondace19e2014-11-17 07:34:06 -0800182 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
183 REPORTER_ASSERT(reporter, SkToBool(context));
184 if (NULL == context) {
185 return;
186 }
187 context->setResourceCacheLimits(10, 300);
188 GrResourceCache2* cache2 = context->getResourceCache2();
189 cache2->purgeAllUnlocked();
190 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
191 SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgetedResourceBytes());
192
bsalomon7775c852014-12-30 12:50:52 -0800193 GrScratchKey scratchKey;
194 make_scratch_key(&scratchKey);
195
bsalomondace19e2014-11-17 07:34:06 -0800196 GrCacheID::Key keyData;
197 memset(&keyData, 0, sizeof(keyData));
bsalomon7775c852014-12-30 12:50:52 -0800198 GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0);
bsalomondace19e2014-11-17 07:34:06 -0800199
200 // Create a scratch, a content, and a wrapped resource
201 TestResource* scratch = new TestResource(context->getGpu(), scratchKey);
202 scratch->setSize(10);
203 TestResource* content = new TestResource(context->getGpu());
204 scratch->setSize(11);
205 REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey));
206 TestResource* wrapped = new TestResource(context->getGpu(), true);
207 scratch->setSize(12);
bsalomon84c8e622014-11-17 09:33:27 -0800208 TestResource* unbudgeted = new TestResource(context->getGpu());
209 unbudgeted->setSize(13);
210 unbudgeted->cacheAccess().setBudgeted(false);
bsalomondace19e2014-11-17 07:34:06 -0800211
212 // Make sure we can't add a content key to the wrapped resource
213 keyData.fData8[0] = 1;
bsalomon7775c852014-12-30 12:50:52 -0800214 GrResourceKey contentKey2(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0);
bsalomondace19e2014-11-17 07:34:06 -0800215 REPORTER_ASSERT(reporter, !wrapped->cacheAccess().setContentKey(contentKey2));
216 REPORTER_ASSERT(reporter, NULL == cache2->findAndRefContentResource(contentKey2));
217
218 // Make sure sizes are as we expect
bsalomon84c8e622014-11-17 09:33:27 -0800219 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount());
bsalomondace19e2014-11-17 07:34:06 -0800220 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() +
bsalomon84c8e622014-11-17 09:33:27 -0800221 wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() ==
222 cache2->getResourceBytes());
bsalomondace19e2014-11-17 07:34:06 -0800223 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
224 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() ==
225 cache2->getBudgetedResourceBytes());
226
227 // Our refs mean that the resources are non purgable.
228 cache2->purgeAllUnlocked();
bsalomon84c8e622014-11-17 09:33:27 -0800229 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount());
bsalomondace19e2014-11-17 07:34:06 -0800230 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() +
bsalomon84c8e622014-11-17 09:33:27 -0800231 wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() ==
232 cache2->getResourceBytes());
bsalomondace19e2014-11-17 07:34:06 -0800233 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
234 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() ==
235 cache2->getBudgetedResourceBytes());
236
237 // Unreffing the wrapped resource should free it right away.
238 wrapped->unref();
bsalomon84c8e622014-11-17 09:33:27 -0800239 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount());
240 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() +
241 unbudgeted->gpuMemorySize() == cache2->getResourceBytes());
bsalomondace19e2014-11-17 07:34:06 -0800242
bsalomon84c8e622014-11-17 09:33:27 -0800243 // Now try freeing the budgeted resources first
bsalomondace19e2014-11-17 07:34:06 -0800244 wrapped = new TestResource(context->getGpu(), true);
245 scratch->setSize(12);
246 content->unref();
247 cache2->purgeAllUnlocked();
bsalomon84c8e622014-11-17 09:33:27 -0800248 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount());
249 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize() +
250 unbudgeted->gpuMemorySize() == cache2->getResourceBytes());
bsalomondace19e2014-11-17 07:34:06 -0800251 REPORTER_ASSERT(reporter, 1 == cache2->getBudgetedResourceCount());
252 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache2->getBudgetedResourceBytes());
253
254 scratch->unref();
255 cache2->purgeAllUnlocked();
bsalomon84c8e622014-11-17 09:33:27 -0800256 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
257 REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrapped->gpuMemorySize() ==
258 cache2->getResourceBytes());
bsalomondace19e2014-11-17 07:34:06 -0800259 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount());
260 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes());
261
262 wrapped->unref();
bsalomon84c8e622014-11-17 09:33:27 -0800263 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
264 REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() == cache2->getResourceBytes());
265 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount());
266 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes());
267
268 unbudgeted->unref();
bsalomondace19e2014-11-17 07:34:06 -0800269 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
270 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
bsalomon84c8e622014-11-17 09:33:27 -0800271 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount());
272 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes());
bsalomondace19e2014-11-17 07:34:06 -0800273}
274
bsalomon8b79d232014-11-10 10:19:06 -0800275static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
276 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
277 REPORTER_ASSERT(reporter, SkToBool(context));
278 if (NULL == context) {
279 return;
280 }
281 context->setResourceCacheLimits(5, 30000);
bsalomon71cb0c22014-11-14 12:10:14 -0800282 GrResourceCache2* cache2 = context->getResourceCache2();
283 cache2->purgeAllUnlocked();
284 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
bsalomon8b79d232014-11-10 10:19:06 -0800285
bsalomon7775c852014-12-30 12:50:52 -0800286 GrScratchKey scratchKey;
287 make_scratch_key(&scratchKey);
bsalomon8b79d232014-11-10 10:19:06 -0800288
289 // Create two resources that have the same scratch key.
290 TestResource* a = new TestResource(context->getGpu(), scratchKey);
291 TestResource* b = new TestResource(context->getGpu(), scratchKey);
292 a->setSize(11);
293 b->setSize(12);
294 // Scratch resources are registered with GrResourceCache2 just by existing. There are 2.
bsalomon8b79d232014-11-10 10:19:06 -0800295 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
296 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey(scratchKey));)
bsalomon71cb0c22014-11-14 12:10:14 -0800297 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
298 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() ==
299 cache2->getResourceBytes());
bsalomon8b79d232014-11-10 10:19:06 -0800300
301 // Our refs mean that the resources are non purgable.
bsalomon71cb0c22014-11-14 12:10:14 -0800302 cache2->purgeAllUnlocked();
bsalomon8b79d232014-11-10 10:19:06 -0800303 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
bsalomon71cb0c22014-11-14 12:10:14 -0800304 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
bsalomon8b79d232014-11-10 10:19:06 -0800305
306 // Unref but don't purge
307 a->unref();
308 b->unref();
309 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
310 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey(scratchKey));)
311
312 // Purge again. This time resources should be purgable.
bsalomon71cb0c22014-11-14 12:10:14 -0800313 cache2->purgeAllUnlocked();
bsalomon8b79d232014-11-10 10:19:06 -0800314 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
bsalomon71cb0c22014-11-14 12:10:14 -0800315 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
bsalomon8b79d232014-11-10 10:19:06 -0800316 SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache2->countScratchEntriesForKey(scratchKey));)
317}
318
bsalomon10e23ca2014-11-25 05:52:06 -0800319static void test_remove_scratch_key(skiatest::Reporter* reporter) {
320 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
321 REPORTER_ASSERT(reporter, SkToBool(context));
322 if (NULL == context) {
323 return;
324 }
325 context->setResourceCacheLimits(5, 30000);
326 GrResourceCache2* cache2 = context->getResourceCache2();
327 cache2->purgeAllUnlocked();
328 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
329
bsalomon7775c852014-12-30 12:50:52 -0800330 GrScratchKey scratchKey;
331 make_scratch_key(&scratchKey);
bsalomon10e23ca2014-11-25 05:52:06 -0800332
333 // Create two resources that have the same scratch key.
334 TestResource* a = new TestResource(context->getGpu(), scratchKey);
335 TestResource* b = new TestResource(context->getGpu(), scratchKey);
336 a->unref();
337 b->unref();
338
339 // Scratch resources are registered with GrResourceCache2 just by existing. There are 2.
340 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
341 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey(scratchKey));)
342 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
343
344 // Find the first resource and remove its scratch key
345 GrGpuResource* find;
346 find = cache2->findAndRefScratchResource(scratchKey);
347 find->cacheAccess().removeScratchKey();
348 // It's still alive, but not cached by scratch key anymore
349 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
350 SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache2->countScratchEntriesForKey(scratchKey));)
351 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
352
353 // The cache should immediately delete it when it's unrefed since it isn't accessible.
354 find->unref();
355 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
356 SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache2->countScratchEntriesForKey(scratchKey));)
357 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
358
359 // Repeat for the second resource.
360 find = cache2->findAndRefScratchResource(scratchKey);
361 find->cacheAccess().removeScratchKey();
362 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
363 SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache2->countScratchEntriesForKey(scratchKey));)
364 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
365
366 // Should be able to call this multiple times with no problem.
367 find->cacheAccess().removeScratchKey();
368 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
369 SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache2->countScratchEntriesForKey(scratchKey));)
370 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
371
372 find->unref();
373 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
374 SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache2->countScratchEntriesForKey(scratchKey));)
375 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
376}
377
bsalomon8b79d232014-11-10 10:19:06 -0800378static void test_duplicate_content_key(skiatest::Reporter* reporter) {
379 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
380 REPORTER_ASSERT(reporter, SkToBool(context));
381 if (NULL == context) {
382 return;
383 }
bsalomon33435572014-11-05 14:47:41 -0800384 context->setResourceCacheLimits(5, 30000);
bsalomon71cb0c22014-11-14 12:10:14 -0800385 GrResourceCache2* cache2 = context->getResourceCache2();
386 cache2->purgeAllUnlocked();
387 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +0000388
bsalomon8b79d232014-11-10 10:19:06 -0800389 GrCacheID::Domain domain = GrCacheID::GenerateDomain();
390 GrCacheID::Key keyData;
391 memset(&keyData, 0, sizeof(keyData));
bsalomon7775c852014-12-30 12:50:52 -0800392 GrResourceKey key(GrCacheID(domain, keyData), 0);
bsalomon8b79d232014-11-10 10:19:06 -0800393
bsalomon8b79d232014-11-10 10:19:06 -0800394 // Create two resources that we will attempt to register with the same content key.
bsalomonc44be0e2014-07-25 07:32:33 -0700395 TestResource* a = new TestResource(context->getGpu());
396 TestResource* b = new TestResource(context->getGpu());
bsalomon8b79d232014-11-10 10:19:06 -0800397 a->setSize(11);
398 b->setSize(12);
bsalomon71cb0c22014-11-14 12:10:14 -0800399
400 // Can't set the same content key on two resources.
401 REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key));
402 REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key));
403
404 // Still have two resources because b is still reffed.
405 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
406 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() ==
407 cache2->getResourceBytes());
bsalomon8b79d232014-11-10 10:19:06 -0800408 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
409
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +0000410 b->unref();
bsalomon71cb0c22014-11-14 12:10:14 -0800411 // Now b should be gone.
412 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
413 REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache2->getResourceBytes());
bsalomon8b79d232014-11-10 10:19:06 -0800414 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +0000415
bsalomon71cb0c22014-11-14 12:10:14 -0800416 cache2->purgeAllUnlocked();
417 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
418 REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache2->getResourceBytes());
419 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
420
421 // Drop the ref on a but it isn't immediately purged as it still has a valid scratch key.
bsalomon8b79d232014-11-10 10:19:06 -0800422 a->unref();
bsalomon71cb0c22014-11-14 12:10:14 -0800423 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
424 REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache2->getResourceBytes());
425 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
426
427 cache2->purgeAllUnlocked();
428 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
429 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
bsalomon33435572014-11-05 14:47:41 -0800430 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +0000431}
432
bsalomon8b79d232014-11-10 10:19:06 -0800433static void test_purge_invalidated(skiatest::Reporter* reporter) {
434 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
435 REPORTER_ASSERT(reporter, SkToBool(context));
436 if (NULL == context) {
437 return;
438 }
439
commit-bot@chromium.orgbd58feb2014-01-17 17:56:21 +0000440 GrCacheID::Domain domain = GrCacheID::GenerateDomain();
441 GrCacheID::Key keyData;
bsalomon8b79d232014-11-10 10:19:06 -0800442 memset(&keyData, 0, sizeof(keyData));
443
bsalomon8b79d232014-11-10 10:19:06 -0800444 keyData.fData64[0] = 1;
bsalomon7775c852014-12-30 12:50:52 -0800445 GrResourceKey key1(GrCacheID(domain, keyData), 0);
bsalomon8b79d232014-11-10 10:19:06 -0800446 keyData.fData64[0] = 2;
bsalomon7775c852014-12-30 12:50:52 -0800447 GrResourceKey key2(GrCacheID(domain, keyData), 0);
bsalomon8b79d232014-11-10 10:19:06 -0800448 keyData.fData64[0] = 3;
bsalomon7775c852014-12-30 12:50:52 -0800449 GrResourceKey key3(GrCacheID(domain, keyData), 0);
bsalomon8b79d232014-11-10 10:19:06 -0800450
451 context->setResourceCacheLimits(5, 30000);
bsalomon8b79d232014-11-10 10:19:06 -0800452 GrResourceCache2* cache2 = context->getResourceCache2();
bsalomon71cb0c22014-11-14 12:10:14 -0800453 cache2->purgeAllUnlocked();
454 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
bsalomon8b79d232014-11-10 10:19:06 -0800455
456 // Add three resources to the cache.
457 TestResource* a = new TestResource(context->getGpu());
458 TestResource* b = new TestResource(context->getGpu());
459 TestResource* c = new TestResource(context->getGpu());
bsalomon71cb0c22014-11-14 12:10:14 -0800460 a->cacheAccess().setContentKey(key1);
461 b->cacheAccess().setContentKey(key2);
462 c->cacheAccess().setContentKey(key3);
bsalomon8b79d232014-11-10 10:19:06 -0800463 a->unref();
464 b->unref();
465 c->unref();
466
467 REPORTER_ASSERT(reporter, cache2->hasContentKey(key1));
468 REPORTER_ASSERT(reporter, cache2->hasContentKey(key2));
469 REPORTER_ASSERT(reporter, cache2->hasContentKey(key3));
470
471 // Invalidate two of the three, they should be purged and destroyed.
472 REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive());
473 const GrResourceInvalidatedMessage msg1 = { key1 };
474 SkMessageBus<GrResourceInvalidatedMessage>::Post(msg1);
475 const GrResourceInvalidatedMessage msg2 = { key2 };
476 SkMessageBus<GrResourceInvalidatedMessage>::Post(msg2);
bsalomon6d4488c2014-11-11 07:27:16 -0800477#if 0 // Disabled until reimplemented in GrResourceCache2.
bsalomon71cb0c22014-11-14 12:10:14 -0800478 cache2->purgeAsNeeded();
bsalomon8b79d232014-11-10 10:19:06 -0800479 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
480 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1));
481 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key2));
482 REPORTER_ASSERT(reporter, cache2->hasContentKey(key3));
bsalomon6d4488c2014-11-11 07:27:16 -0800483#endif
bsalomon8b79d232014-11-10 10:19:06 -0800484
485 // Invalidate the third.
486 const GrResourceInvalidatedMessage msg3 = { key3 };
487 SkMessageBus<GrResourceInvalidatedMessage>::Post(msg3);
bsalomon6d4488c2014-11-11 07:27:16 -0800488#if 0 // Disabled until reimplemented in GrResourceCache2.
bsalomon71cb0c22014-11-14 12:10:14 -0800489 cache2->purgeAsNeeded();
bsalomon8b79d232014-11-10 10:19:06 -0800490 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
491 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key3));
bsalomon6d4488c2014-11-11 07:27:16 -0800492#endif
bsalomon71cb0c22014-11-14 12:10:14 -0800493
494 cache2->purgeAllUnlocked();
495 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
496 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
497 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
bsalomon8b79d232014-11-10 10:19:06 -0800498}
499
bsalomon71cb0c22014-11-14 12:10:14 -0800500static void test_cache_chained_purge(skiatest::Reporter* reporter) {
bsalomon8b79d232014-11-10 10:19:06 -0800501 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
502 REPORTER_ASSERT(reporter, SkToBool(context));
503 if (NULL == context) {
504 return;
505 }
506
507 GrCacheID::Domain domain = GrCacheID::GenerateDomain();
508 GrCacheID::Key keyData;
509 memset(&keyData, 0, sizeof(keyData));
bsalomon8b79d232014-11-10 10:19:06 -0800510
511 keyData.fData64[0] = 1;
bsalomon7775c852014-12-30 12:50:52 -0800512 GrResourceKey key1(GrCacheID(domain, keyData), 0);
bsalomon8b79d232014-11-10 10:19:06 -0800513
514 keyData.fData64[0] = 2;
bsalomon7775c852014-12-30 12:50:52 -0800515 GrResourceKey key2(GrCacheID(domain, keyData), 0);
commit-bot@chromium.orgbd58feb2014-01-17 17:56:21 +0000516
517 {
bsalomon33435572014-11-05 14:47:41 -0800518 context->setResourceCacheLimits(3, 30000);
bsalomon71cb0c22014-11-14 12:10:14 -0800519 GrResourceCache2* cache2 = context->getResourceCache2();
520 cache2->purgeAllUnlocked();
521 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
commit-bot@chromium.orgbd58feb2014-01-17 17:56:21 +0000522
bsalomon820dd6c2014-11-05 12:09:45 -0800523 TestResource* a = new TestResource(context->getGpu());
524 TestResource* b = new TestResource(context->getGpu());
bsalomon71cb0c22014-11-14 12:10:14 -0800525 a->cacheAccess().setContentKey(key1);
526 b->cacheAccess().setContentKey(key2);
bsalomon820dd6c2014-11-05 12:09:45 -0800527
bsalomon71cb0c22014-11-14 12:10:14 -0800528 // Make a cycle
529 a->setUnrefWhenDestroyed(b);
530 b->setUnrefWhenDestroyed(a);
531
532 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
bsalomon33435572014-11-05 14:47:41 -0800533
534 a->unref();
535 b->unref();
bsalomon8b79d232014-11-10 10:19:06 -0800536
bsalomon33435572014-11-05 14:47:41 -0800537 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
bsalomon8b79d232014-11-10 10:19:06 -0800538
bsalomon71cb0c22014-11-14 12:10:14 -0800539 cache2->purgeAllUnlocked();
540 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
bsalomon8b79d232014-11-10 10:19:06 -0800541
bsalomon71cb0c22014-11-14 12:10:14 -0800542 // Break the cycle
543 a->setUnrefWhenDestroyed(NULL);
544 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
bsalomon33435572014-11-05 14:47:41 -0800545
bsalomon71cb0c22014-11-14 12:10:14 -0800546 cache2->purgeAllUnlocked();
bsalomon33435572014-11-05 14:47:41 -0800547 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
commit-bot@chromium.orgbd58feb2014-01-17 17:56:21 +0000548 }
549}
550
bsalomon8b79d232014-11-10 10:19:06 -0800551static void test_resource_size_changed(skiatest::Reporter* reporter) {
552 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
553 REPORTER_ASSERT(reporter, SkToBool(context));
554 if (NULL == context) {
555 return;
556 }
557
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000558 GrCacheID::Domain domain = GrCacheID::GenerateDomain();
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000559
560 GrCacheID::Key key1Data;
561 key1Data.fData64[0] = 0;
562 key1Data.fData64[1] = 0;
bsalomon7775c852014-12-30 12:50:52 -0800563 GrResourceKey key1(GrCacheID(domain, key1Data), 0);
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000564
565 GrCacheID::Key key2Data;
566 key2Data.fData64[0] = 1;
567 key2Data.fData64[1] = 0;
bsalomon7775c852014-12-30 12:50:52 -0800568 GrResourceKey key2(GrCacheID(domain, key2Data), 0);
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000569
570 // Test changing resources sizes (both increase & decrease).
571 {
bsalomon33435572014-11-05 14:47:41 -0800572 context->setResourceCacheLimits(3, 30000);
bsalomon8b79d232014-11-10 10:19:06 -0800573 GrResourceCache2* cache2 = context->getResourceCache2();
bsalomon71cb0c22014-11-14 12:10:14 -0800574 cache2->purgeAllUnlocked();
575 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000576
bsalomonc44be0e2014-07-25 07:32:33 -0700577 TestResource* a = new TestResource(context->getGpu());
bsalomon71cb0c22014-11-14 12:10:14 -0800578 a->cacheAccess().setContentKey(key1);
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000579 a->unref();
580
bsalomonc44be0e2014-07-25 07:32:33 -0700581 TestResource* b = new TestResource(context->getGpu());
bsalomon71cb0c22014-11-14 12:10:14 -0800582 b->cacheAccess().setContentKey(key2);
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000583 b->unref();
584
bsalomon71cb0c22014-11-14 12:10:14 -0800585 REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes());
586 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
bsalomon8b79d232014-11-10 10:19:06 -0800587 {
588 SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2->findAndRefContentResource(key2)));
589 find2->setSize(200);
590 SkAutoTUnref<TestResource> find1(static_cast<TestResource*>(cache2->findAndRefContentResource(key1)));
591 find1->setSize(50);
592 }
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000593
bsalomon71cb0c22014-11-14 12:10:14 -0800594 REPORTER_ASSERT(reporter, 250 == cache2->getResourceBytes());
595 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000596 }
597
598 // Test increasing a resources size beyond the cache budget.
599 {
bsalomon33435572014-11-05 14:47:41 -0800600 context->setResourceCacheLimits(2, 300);
bsalomon8b79d232014-11-10 10:19:06 -0800601 GrResourceCache2* cache2 = context->getResourceCache2();
bsalomon71cb0c22014-11-14 12:10:14 -0800602 cache2->purgeAllUnlocked();
603 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000604
bsalomon8b79d232014-11-10 10:19:06 -0800605 TestResource* a = new TestResource(context->getGpu());
606 a->setSize(100);
bsalomon71cb0c22014-11-14 12:10:14 -0800607 a->cacheAccess().setContentKey(key1);
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000608 a->unref();
609
bsalomon8b79d232014-11-10 10:19:06 -0800610 TestResource* b = new TestResource(context->getGpu());
611 b->setSize(100);
bsalomon71cb0c22014-11-14 12:10:14 -0800612 b->cacheAccess().setContentKey(key2);
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000613 b->unref();
614
bsalomon71cb0c22014-11-14 12:10:14 -0800615 REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes());
616 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000617
bsalomon8b79d232014-11-10 10:19:06 -0800618 {
619 SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2->findAndRefContentResource(key2)));
620 find2->setSize(201);
621 }
622 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1));
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000623
bsalomon71cb0c22014-11-14 12:10:14 -0800624 REPORTER_ASSERT(reporter, 201 == cache2->getResourceBytes());
625 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000626 }
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000627}
628
bsalomon10e23ca2014-11-25 05:52:06 -0800629static void test_large_resource_count(skiatest::Reporter* reporter) {
630 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
631 REPORTER_ASSERT(reporter, SkToBool(context));
632 if (NULL == context) {
633 return;
634 }
635
636 static const int kResourceCnt = 2000;
637 // Set the cache size to double the resource count because we're going to create 2x that number
638 // resources, using two different key domains. Add a little slop to the bytes because we resize
639 // down to 1 byte after creating the resource.
640 context->setResourceCacheLimits(2 * kResourceCnt, 2 * kResourceCnt + 1000);
641 GrResourceCache2* cache2 = context->getResourceCache2();
642 cache2->purgeAllUnlocked();
643 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
644
645 GrCacheID::Domain domain0 = GrCacheID::GenerateDomain();
646 GrCacheID::Domain domain1 = GrCacheID::GenerateDomain();
bsalomon10e23ca2014-11-25 05:52:06 -0800647
648 GrCacheID::Key keyData;
649 memset(&keyData, 0, sizeof(keyData));
650
651 for (int i = 0; i < kResourceCnt; ++i) {
652 TestResource* resource;
653 keyData.fData32[0] = i;
654
bsalomon7775c852014-12-30 12:50:52 -0800655 GrResourceKey key0(GrCacheID(domain0, keyData), 0);
bsalomon10e23ca2014-11-25 05:52:06 -0800656 resource = SkNEW_ARGS(TestResource, (context->getGpu()));
657 resource->cacheAccess().setContentKey(key0);
658 resource->setSize(1);
659 resource->unref();
660
bsalomon7775c852014-12-30 12:50:52 -0800661 GrResourceKey key1(GrCacheID(domain1, keyData), 0);
bsalomon10e23ca2014-11-25 05:52:06 -0800662 resource = SkNEW_ARGS(TestResource, (context->getGpu()));
663 resource->cacheAccess().setContentKey(key1);
664 resource->setSize(1);
665 resource->unref();
666 }
667
668 REPORTER_ASSERT(reporter, TestResource::NumAlive() == 2 * kResourceCnt);
669 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 2 * kResourceCnt);
670 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 2 * kResourceCnt);
671 REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 2 * kResourceCnt);
672 REPORTER_ASSERT(reporter, cache2->getResourceCount() == 2 * kResourceCnt);
673 for (int i = 0; i < kResourceCnt; ++i) {
674 keyData.fData32[0] = i;
bsalomon7775c852014-12-30 12:50:52 -0800675 GrResourceKey key0(GrCacheID(domain0, keyData), 0);
bsalomon10e23ca2014-11-25 05:52:06 -0800676 REPORTER_ASSERT(reporter, cache2->hasContentKey(key0));
bsalomon7775c852014-12-30 12:50:52 -0800677 GrResourceKey key1(GrCacheID(domain0, keyData), 0);
bsalomon10e23ca2014-11-25 05:52:06 -0800678 REPORTER_ASSERT(reporter, cache2->hasContentKey(key1));
679 }
680
681 cache2->purgeAllUnlocked();
682 REPORTER_ASSERT(reporter, TestResource::NumAlive() == 0);
683 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 0);
684 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 0);
685 REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 0);
686 REPORTER_ASSERT(reporter, cache2->getResourceCount() == 0);
687
688 for (int i = 0; i < kResourceCnt; ++i) {
689 keyData.fData32[0] = i;
bsalomon7775c852014-12-30 12:50:52 -0800690 GrResourceKey key0(GrCacheID(domain0, keyData), 0);
bsalomon10e23ca2014-11-25 05:52:06 -0800691 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key0));
bsalomon7775c852014-12-30 12:50:52 -0800692 GrResourceKey key1(GrCacheID(domain0, keyData), 0);
bsalomon10e23ca2014-11-25 05:52:06 -0800693 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1));
694 }
695}
696
697
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +0000698////////////////////////////////////////////////////////////////////////////////
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +0000699DEF_GPUTEST(ResourceCache, reporter, factory) {
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +0000700 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
701 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
702 if (!GrContextFactory::IsRenderingGLContext(glType)) {
703 continue;
704 }
705 GrContext* context = factory->get(glType);
bsalomonfdcf2c02014-11-05 12:30:32 -0800706 if (NULL == context) {
707 continue;
708 }
bsalomonf2703d82014-10-28 14:33:06 -0700709 GrSurfaceDesc desc;
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +0000710 desc.fConfig = kSkia8888_GrPixelConfig;
bsalomonf2703d82014-10-28 14:33:06 -0700711 desc.fFlags = kRenderTarget_GrSurfaceFlag;
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +0000712 desc.fWidth = gWidth;
713 desc.fHeight = gHeight;
reed69f6f002014-09-18 06:09:44 -0700714 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight);
reed4a8126e2014-09-22 07:29:03 -0700715 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info));
reed69f6f002014-09-18 06:09:44 -0700716 test_cache(reporter, context, surface->getCanvas());
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +0000717 }
bsalomon33435572014-11-05 14:47:41 -0800718
bsalomon8b79d232014-11-10 10:19:06 -0800719 // The below tests create their own mock contexts.
bsalomon71cb0c22014-11-14 12:10:14 -0800720 test_no_key(reporter);
bsalomon84c8e622014-11-17 09:33:27 -0800721 test_budgeting(reporter);
bsalomon8b79d232014-11-10 10:19:06 -0800722 test_duplicate_content_key(reporter);
723 test_duplicate_scratch_key(reporter);
bsalomon10e23ca2014-11-25 05:52:06 -0800724 test_remove_scratch_key(reporter);
bsalomon8b79d232014-11-10 10:19:06 -0800725 test_purge_invalidated(reporter);
bsalomon71cb0c22014-11-14 12:10:14 -0800726 test_cache_chained_purge(reporter);
bsalomon8b79d232014-11-10 10:19:06 -0800727 test_resource_size_changed(reporter);
bsalomon10e23ca2014-11-25 05:52:06 -0800728 test_large_resource_count(reporter);
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +0000729}
730
commit-bot@chromium.orgc28f5552013-08-08 22:55:21 +0000731#endif