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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 846303002: Make uncached textures uncached from the get go. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add comment Created 5 years, 11 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 | « tests/GLProgramsTest.cpp ('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 "GrContext.h" 10 #include "GrContext.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 60
61 context->setResourceCacheLimits(oldMaxNum, oldMaxBytes); 61 context->setResourceCacheLimits(oldMaxNum, oldMaxBytes);
62 } 62 }
63 63
64 class TestResource : public GrGpuResource { 64 class TestResource : public GrGpuResource {
65 static const size_t kDefaultSize = 100; 65 static const size_t kDefaultSize = 100;
66 66
67 public: 67 public:
68 SK_DECLARE_INST_COUNT(TestResource); 68 SK_DECLARE_INST_COUNT(TestResource);
69 TestResource(GrGpu* gpu, bool isWrapped) 69 TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle)
70 : INHERITED(gpu, isWrapped) 70 : INHERITED(gpu, lifeCycle)
71 , fToDelete(NULL)
72 , fSize(size) {
73 ++fNumAlive;
74 this->registerWithCache();
75 }
76
77 TestResource(GrGpu* gpu, GrGpuResource::LifeCycle lifeCycle)
78 : INHERITED(gpu, lifeCycle)
71 , fToDelete(NULL) 79 , fToDelete(NULL)
72 , fSize(kDefaultSize) { 80 , fSize(kDefaultSize) {
73 ++fNumAlive; 81 ++fNumAlive;
74 this->registerWithCache(); 82 this->registerWithCache();
75 } 83 }
76 84
77 TestResource(GrGpu* gpu) 85 TestResource(GrGpu* gpu)
78 : INHERITED(gpu, false) 86 : INHERITED(gpu, kCached_LifeCycle)
79 , fToDelete(NULL) 87 , fToDelete(NULL)
80 , fSize(kDefaultSize) { 88 , fSize(kDefaultSize) {
81 ++fNumAlive; 89 ++fNumAlive;
82 this->registerWithCache(); 90 this->registerWithCache();
83 } 91 }
84 92
85 TestResource(GrGpu* gpu, const GrScratchKey& scratchKey) 93 TestResource(GrGpu* gpu, const GrScratchKey& scratchKey)
86 : INHERITED(gpu, false) 94 : INHERITED(gpu, kCached_LifeCycle)
87 , fToDelete(NULL) 95 , fToDelete(NULL)
88 , fSize(kDefaultSize) { 96 , fSize(kDefaultSize) {
89 this->setScratchKey(scratchKey); 97 this->setScratchKey(scratchKey);
90 ++fNumAlive; 98 ++fNumAlive;
91 this->registerWithCache(); 99 this->registerWithCache();
92 } 100 }
93 101
94 ~TestResource() { 102 ~TestResource() {
95 --fNumAlive; 103 --fNumAlive;
96 SkSafeUnref(fToDelete); 104 SkSafeUnref(fToDelete);
(...skipping 26 matching lines...) Expand all
123 REPORTER_ASSERT(reporter, SkToBool(context)); 131 REPORTER_ASSERT(reporter, SkToBool(context));
124 if (NULL == context) { 132 if (NULL == context) {
125 return; 133 return;
126 } 134 }
127 context->setResourceCacheLimits(10, 30000); 135 context->setResourceCacheLimits(10, 30000);
128 GrResourceCache2* cache2 = context->getResourceCache2(); 136 GrResourceCache2* cache2 = context->getResourceCache2();
129 cache2->purgeAllUnlocked(); 137 cache2->purgeAllUnlocked();
130 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 138 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
131 139
132 // Create a bunch of resources with no keys 140 // Create a bunch of resources with no keys
133 TestResource* a = new TestResource(context->getGpu()); 141 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
134 TestResource* b = new TestResource(context->getGpu()); 142 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
135 TestResource* c = new TestResource(context->getGpu()); 143 TestResource* c = SkNEW_ARGS(TestResource, (context->getGpu()));
136 TestResource* d = new TestResource(context->getGpu()); 144 TestResource* d = SkNEW_ARGS(TestResource, (context->getGpu()));
137 a->setSize(11); 145 a->setSize(11);
138 b->setSize(12); 146 b->setSize(12);
139 c->setSize(13); 147 c->setSize(13);
140 d->setSize(14); 148 d->setSize(14);
141 149
142 REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); 150 REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive());
143 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount()); 151 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount());
144 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMe morySize() + 152 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMe morySize() +
145 d->gpuMemorySize() == cache2->getResourceBytes()); 153 d->gpuMemorySize() == cache2->getResourceBytes());
146 154
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgeted ResourceBytes()); 199 SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgeted ResourceBytes());
192 200
193 GrScratchKey scratchKey; 201 GrScratchKey scratchKey;
194 make_scratch_key(&scratchKey); 202 make_scratch_key(&scratchKey);
195 203
196 GrCacheID::Key keyData; 204 GrCacheID::Key keyData;
197 memset(&keyData, 0, sizeof(keyData)); 205 memset(&keyData, 0, sizeof(keyData));
198 GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0) ; 206 GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0) ;
199 207
200 // Create a scratch, a content, and a wrapped resource 208 // Create a scratch, a content, and a wrapped resource
201 TestResource* scratch = new TestResource(context->getGpu(), scratchKey); 209 TestResource* scratch = SkNEW_ARGS(TestResource, (context->getGpu(), scratch Key));
202 scratch->setSize(10); 210 scratch->setSize(10);
203 TestResource* content = new TestResource(context->getGpu()); 211 TestResource* content = SkNEW_ARGS(TestResource, (context->getGpu()));
204 scratch->setSize(11); 212 content->setSize(11);
205 REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey)); 213 REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey));
206 TestResource* wrapped = new TestResource(context->getGpu(), true); 214 TestResource* wrapped = SkNEW_ARGS(TestResource,
207 scratch->setSize(12); 215 (context->getGpu(), GrGpuResource::kWrapp ed_LifeCycle));
208 TestResource* unbudgeted = new TestResource(context->getGpu()); 216 wrapped->setSize(12);
217 TestResource* unbudgeted = SkNEW_ARGS(TestResource,
218 (context->getGpu(), GrGpuResource::kUn cached_LifeCycle));
209 unbudgeted->setSize(13); 219 unbudgeted->setSize(13);
210 unbudgeted->cacheAccess().setBudgeted(false);
211 220
212 // Make sure we can't add a content key to the wrapped resource 221 // Make sure we can't add a content key to the wrapped resource
213 keyData.fData8[0] = 1; 222 keyData.fData8[0] = 1;
214 GrResourceKey contentKey2(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0 ); 223 GrResourceKey contentKey2(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0 );
215 REPORTER_ASSERT(reporter, !wrapped->cacheAccess().setContentKey(contentKey2) ); 224 REPORTER_ASSERT(reporter, !wrapped->cacheAccess().setContentKey(contentKey2) );
216 REPORTER_ASSERT(reporter, NULL == cache2->findAndRefContentResource(contentK ey2)); 225 REPORTER_ASSERT(reporter, NULL == cache2->findAndRefContentResource(contentK ey2));
217 226
218 // Make sure sizes are as we expect 227 // Make sure sizes are as we expect
219 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount()); 228 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount());
220 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) + 229 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) +
(...skipping 13 matching lines...) Expand all
234 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) == 243 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) ==
235 cache2->getBudgetedResourceBytes()); 244 cache2->getBudgetedResourceBytes());
236 245
237 // Unreffing the wrapped resource should free it right away. 246 // Unreffing the wrapped resource should free it right away.
238 wrapped->unref(); 247 wrapped->unref();
239 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount()); 248 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount());
240 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) + 249 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) +
241 unbudgeted->gpuMemorySize() == cache2->getResource Bytes()); 250 unbudgeted->gpuMemorySize() == cache2->getResource Bytes());
242 251
243 // Now try freeing the budgeted resources first 252 // Now try freeing the budgeted resources first
244 wrapped = new TestResource(context->getGpu(), true); 253 wrapped = SkNEW_ARGS(TestResource, (context->getGpu(), GrGpuResource::kWrapp ed_LifeCycle));
245 scratch->setSize(12); 254 scratch->setSize(12);
246 content->unref(); 255 content->unref();
247 cache2->purgeAllUnlocked(); 256 cache2->purgeAllUnlocked();
248 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount()); 257 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount());
249 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize( ) + 258 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize( ) +
250 unbudgeted->gpuMemorySize() == cache2->getResource Bytes()); 259 unbudgeted->gpuMemorySize() == cache2->getResource Bytes());
251 REPORTER_ASSERT(reporter, 1 == cache2->getBudgetedResourceCount()); 260 REPORTER_ASSERT(reporter, 1 == cache2->getBudgetedResourceCount());
252 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache2->getBudgetedRes ourceBytes()); 261 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache2->getBudgetedRes ourceBytes());
253 262
254 scratch->unref(); 263 scratch->unref();
(...skipping 10 matching lines...) Expand all
265 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount()); 274 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount());
266 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes()); 275 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes());
267 276
268 unbudgeted->unref(); 277 unbudgeted->unref();
269 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount()); 278 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
270 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes()); 279 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
271 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount()); 280 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount());
272 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes()); 281 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes());
273 } 282 }
274 283
284 static void test_unbudgeted(skiatest::Reporter* reporter) {
285 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
286 REPORTER_ASSERT(reporter, SkToBool(context));
287 if (NULL == context) {
288 return;
289 }
290 context->setResourceCacheLimits(10, 300);
291 GrResourceCache2* cache2 = context->getResourceCache2();
292 cache2->purgeAllUnlocked();
293 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
294 SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgeted ResourceBytes());
295
296 GrScratchKey scratchKey;
297 make_scratch_key(&scratchKey);
298
299 GrCacheID::Key keyData;
300 memset(&keyData, 0, sizeof(keyData));
301 GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0) ;
302
303 TestResource* scratch;
304 TestResource* content;
305 TestResource* wrapped;
306 TestResource* unbudgeted;
307
308 // A large uncached or wrapped resource shouldn't evict anything.
309 scratch = SkNEW_ARGS(TestResource, (context->getGpu(), scratchKey));
310 scratch->setSize(10);
311 scratch->unref();
312 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
313 REPORTER_ASSERT(reporter, 10 == cache2->getResourceBytes());
314 REPORTER_ASSERT(reporter, 1 == cache2->getBudgetedResourceCount());
315 REPORTER_ASSERT(reporter, 10 == cache2->getBudgetedResourceBytes());
316
317 content = SkNEW_ARGS(TestResource, (context->getGpu()));
318 content->setSize(11);
319 REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey));
320 content->unref();
321 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
322 REPORTER_ASSERT(reporter, 21 == cache2->getResourceBytes());
323 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
324 REPORTER_ASSERT(reporter, 21 == cache2->getBudgetedResourceBytes());
325
326 size_t large = 2 * cache2->getResourceBytes();
327 unbudgeted = SkNEW_ARGS(TestResource,
328 (context->getGpu(), large, GrGpuResource::kUncached_ LifeCycle));
329 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount());
330 REPORTER_ASSERT(reporter, 21 + large == cache2->getResourceBytes());
331 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
332 REPORTER_ASSERT(reporter, 21 == cache2->getBudgetedResourceBytes());
333
334 unbudgeted->unref();
335 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
336 REPORTER_ASSERT(reporter, 21 == cache2->getResourceBytes());
337 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
338 REPORTER_ASSERT(reporter, 21 == cache2->getBudgetedResourceBytes());
339
340 wrapped = SkNEW_ARGS(TestResource,
341 (context->getGpu(), large, GrGpuResource::kWrapped_Life Cycle));
342 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount());
343 REPORTER_ASSERT(reporter, 21 + large == cache2->getResourceBytes());
344 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
345 REPORTER_ASSERT(reporter, 21 == cache2->getBudgetedResourceBytes());
346
347 wrapped->unref();
348 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
349 REPORTER_ASSERT(reporter, 21 == cache2->getResourceBytes());
350 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
351 REPORTER_ASSERT(reporter, 21 == cache2->getBudgetedResourceBytes());
352
353 cache2->purgeAllUnlocked();
354 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
355 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
356 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount());
357 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes());
358 }
359
275 static void test_duplicate_scratch_key(skiatest::Reporter* reporter) { 360 static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
276 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); 361 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
277 REPORTER_ASSERT(reporter, SkToBool(context)); 362 REPORTER_ASSERT(reporter, SkToBool(context));
278 if (NULL == context) { 363 if (NULL == context) {
279 return; 364 return;
280 } 365 }
281 context->setResourceCacheLimits(5, 30000); 366 context->setResourceCacheLimits(5, 30000);
282 GrResourceCache2* cache2 = context->getResourceCache2(); 367 GrResourceCache2* cache2 = context->getResourceCache2();
283 cache2->purgeAllUnlocked(); 368 cache2->purgeAllUnlocked();
284 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 369 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
285 370
286 GrScratchKey scratchKey; 371 GrScratchKey scratchKey;
287 make_scratch_key(&scratchKey); 372 make_scratch_key(&scratchKey);
288 373
289 // Create two resources that have the same scratch key. 374 // Create two resources that have the same scratch key.
290 TestResource* a = new TestResource(context->getGpu(), scratchKey); 375 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu(), scratchKey));
291 TestResource* b = new TestResource(context->getGpu(), scratchKey); 376 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu(), scratchKey));
292 a->setSize(11); 377 a->setSize(11);
293 b->setSize(12); 378 b->setSize(12);
294 // Scratch resources are registered with GrResourceCache2 just by existing. There are 2. 379 // Scratch resources are registered with GrResourceCache2 just by existing. There are 2.
295 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 380 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
296 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey (scratchKey));) 381 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey (scratchKey));)
297 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 382 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
298 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == 383 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() ==
299 cache2->getResourceBytes()); 384 cache2->getResourceBytes());
300 385
301 // Our refs mean that the resources are non purgable. 386 // Our refs mean that the resources are non purgable.
(...skipping 22 matching lines...) Expand all
324 } 409 }
325 context->setResourceCacheLimits(5, 30000); 410 context->setResourceCacheLimits(5, 30000);
326 GrResourceCache2* cache2 = context->getResourceCache2(); 411 GrResourceCache2* cache2 = context->getResourceCache2();
327 cache2->purgeAllUnlocked(); 412 cache2->purgeAllUnlocked();
328 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 413 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
329 414
330 GrScratchKey scratchKey; 415 GrScratchKey scratchKey;
331 make_scratch_key(&scratchKey); 416 make_scratch_key(&scratchKey);
332 417
333 // Create two resources that have the same scratch key. 418 // Create two resources that have the same scratch key.
334 TestResource* a = new TestResource(context->getGpu(), scratchKey); 419 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu(), scratchKey));
335 TestResource* b = new TestResource(context->getGpu(), scratchKey); 420 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu(), scratchKey));
336 a->unref(); 421 a->unref();
337 b->unref(); 422 b->unref();
338 423
339 // Scratch resources are registered with GrResourceCache2 just by existing. There are 2. 424 // Scratch resources are registered with GrResourceCache2 just by existing. There are 2.
340 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 425 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
341 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey (scratchKey));) 426 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey (scratchKey));)
342 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 427 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
343 428
344 // Find the first resource and remove its scratch key 429 // Find the first resource and remove its scratch key
345 GrGpuResource* find; 430 GrGpuResource* find;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 GrResourceCache2* cache2 = context->getResourceCache2(); 470 GrResourceCache2* cache2 = context->getResourceCache2();
386 cache2->purgeAllUnlocked(); 471 cache2->purgeAllUnlocked();
387 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 472 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
388 473
389 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); 474 GrCacheID::Domain domain = GrCacheID::GenerateDomain();
390 GrCacheID::Key keyData; 475 GrCacheID::Key keyData;
391 memset(&keyData, 0, sizeof(keyData)); 476 memset(&keyData, 0, sizeof(keyData));
392 GrResourceKey key(GrCacheID(domain, keyData), 0); 477 GrResourceKey key(GrCacheID(domain, keyData), 0);
393 478
394 // Create two resources that we will attempt to register with the same conte nt key. 479 // Create two resources that we will attempt to register with the same conte nt key.
395 TestResource* a = new TestResource(context->getGpu()); 480 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
396 TestResource* b = new TestResource(context->getGpu()); 481 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
397 a->setSize(11); 482 a->setSize(11);
398 b->setSize(12); 483 b->setSize(12);
399 484
400 // Can't set the same content key on two resources. 485 // Can't set the same content key on two resources.
401 REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key)); 486 REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key));
402 REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key)); 487 REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key));
403 488
404 // Still have two resources because b is still reffed. 489 // Still have two resources because b is still reffed.
405 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 490 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
406 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == 491 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() ==
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 GrResourceKey key2(GrCacheID(domain, keyData), 0); 532 GrResourceKey key2(GrCacheID(domain, keyData), 0);
448 keyData.fData64[0] = 3; 533 keyData.fData64[0] = 3;
449 GrResourceKey key3(GrCacheID(domain, keyData), 0); 534 GrResourceKey key3(GrCacheID(domain, keyData), 0);
450 535
451 context->setResourceCacheLimits(5, 30000); 536 context->setResourceCacheLimits(5, 30000);
452 GrResourceCache2* cache2 = context->getResourceCache2(); 537 GrResourceCache2* cache2 = context->getResourceCache2();
453 cache2->purgeAllUnlocked(); 538 cache2->purgeAllUnlocked();
454 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 539 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
455 540
456 // Add three resources to the cache. 541 // Add three resources to the cache.
457 TestResource* a = new TestResource(context->getGpu()); 542 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
458 TestResource* b = new TestResource(context->getGpu()); 543 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
459 TestResource* c = new TestResource(context->getGpu()); 544 TestResource* c = SkNEW_ARGS(TestResource, (context->getGpu()));
460 a->cacheAccess().setContentKey(key1); 545 a->cacheAccess().setContentKey(key1);
461 b->cacheAccess().setContentKey(key2); 546 b->cacheAccess().setContentKey(key2);
462 c->cacheAccess().setContentKey(key3); 547 c->cacheAccess().setContentKey(key3);
463 a->unref(); 548 a->unref();
464 b->unref(); 549 b->unref();
465 c->unref(); 550 c->unref();
466 551
467 REPORTER_ASSERT(reporter, cache2->hasContentKey(key1)); 552 REPORTER_ASSERT(reporter, cache2->hasContentKey(key1));
468 REPORTER_ASSERT(reporter, cache2->hasContentKey(key2)); 553 REPORTER_ASSERT(reporter, cache2->hasContentKey(key2));
469 REPORTER_ASSERT(reporter, cache2->hasContentKey(key3)); 554 REPORTER_ASSERT(reporter, cache2->hasContentKey(key3));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 598
514 keyData.fData64[0] = 2; 599 keyData.fData64[0] = 2;
515 GrResourceKey key2(GrCacheID(domain, keyData), 0); 600 GrResourceKey key2(GrCacheID(domain, keyData), 0);
516 601
517 { 602 {
518 context->setResourceCacheLimits(3, 30000); 603 context->setResourceCacheLimits(3, 30000);
519 GrResourceCache2* cache2 = context->getResourceCache2(); 604 GrResourceCache2* cache2 = context->getResourceCache2();
520 cache2->purgeAllUnlocked(); 605 cache2->purgeAllUnlocked();
521 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s()); 606 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s());
522 607
523 TestResource* a = new TestResource(context->getGpu()); 608 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
524 TestResource* b = new TestResource(context->getGpu()); 609 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
525 a->cacheAccess().setContentKey(key1); 610 a->cacheAccess().setContentKey(key1);
526 b->cacheAccess().setContentKey(key2); 611 b->cacheAccess().setContentKey(key2);
527 612
528 // Make a cycle 613 // Make a cycle
529 a->setUnrefWhenDestroyed(b); 614 a->setUnrefWhenDestroyed(b);
530 b->setUnrefWhenDestroyed(a); 615 b->setUnrefWhenDestroyed(a);
531 616
532 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 617 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
533 618
534 a->unref(); 619 a->unref();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 key2Data.fData64[1] = 0; 652 key2Data.fData64[1] = 0;
568 GrResourceKey key2(GrCacheID(domain, key2Data), 0); 653 GrResourceKey key2(GrCacheID(domain, key2Data), 0);
569 654
570 // Test changing resources sizes (both increase & decrease). 655 // Test changing resources sizes (both increase & decrease).
571 { 656 {
572 context->setResourceCacheLimits(3, 30000); 657 context->setResourceCacheLimits(3, 30000);
573 GrResourceCache2* cache2 = context->getResourceCache2(); 658 GrResourceCache2* cache2 = context->getResourceCache2();
574 cache2->purgeAllUnlocked(); 659 cache2->purgeAllUnlocked();
575 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s()); 660 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s());
576 661
577 TestResource* a = new TestResource(context->getGpu()); 662 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
578 a->cacheAccess().setContentKey(key1); 663 a->cacheAccess().setContentKey(key1);
579 a->unref(); 664 a->unref();
580 665
581 TestResource* b = new TestResource(context->getGpu()); 666 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
582 b->cacheAccess().setContentKey(key2); 667 b->cacheAccess().setContentKey(key2);
583 b->unref(); 668 b->unref();
584 669
585 REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes()); 670 REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes());
586 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 671 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
587 { 672 {
588 SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2-> findAndRefContentResource(key2))); 673 SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2-> findAndRefContentResource(key2)));
589 find2->setSize(200); 674 find2->setSize(200);
590 SkAutoTUnref<TestResource> find1(static_cast<TestResource*>(cache2-> findAndRefContentResource(key1))); 675 SkAutoTUnref<TestResource> find1(static_cast<TestResource*>(cache2-> findAndRefContentResource(key1)));
591 find1->setSize(50); 676 find1->setSize(50);
592 } 677 }
593 678
594 REPORTER_ASSERT(reporter, 250 == cache2->getResourceBytes()); 679 REPORTER_ASSERT(reporter, 250 == cache2->getResourceBytes());
595 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 680 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
596 } 681 }
597 682
598 // Test increasing a resources size beyond the cache budget. 683 // Test increasing a resources size beyond the cache budget.
599 { 684 {
600 context->setResourceCacheLimits(2, 300); 685 context->setResourceCacheLimits(2, 300);
601 GrResourceCache2* cache2 = context->getResourceCache2(); 686 GrResourceCache2* cache2 = context->getResourceCache2();
602 cache2->purgeAllUnlocked(); 687 cache2->purgeAllUnlocked();
603 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s()); 688 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s());
604 689
605 TestResource* a = new TestResource(context->getGpu()); 690 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
606 a->setSize(100); 691 a->setSize(100);
607 a->cacheAccess().setContentKey(key1); 692 a->cacheAccess().setContentKey(key1);
608 a->unref(); 693 a->unref();
609 694
610 TestResource* b = new TestResource(context->getGpu()); 695 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
611 b->setSize(100); 696 b->setSize(100);
612 b->cacheAccess().setContentKey(key2); 697 b->cacheAccess().setContentKey(key2);
613 b->unref(); 698 b->unref();
614 699
615 REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes()); 700 REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes());
616 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 701 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
617 702
618 { 703 {
619 SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2-> findAndRefContentResource(key2))); 704 SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2-> findAndRefContentResource(key2)));
620 find2->setSize(201); 705 find2->setSize(201);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 desc.fWidth = gWidth; 797 desc.fWidth = gWidth;
713 desc.fHeight = gHeight; 798 desc.fHeight = gHeight;
714 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); 799 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight);
715 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info )); 800 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info ));
716 test_cache(reporter, context, surface->getCanvas()); 801 test_cache(reporter, context, surface->getCanvas());
717 } 802 }
718 803
719 // The below tests create their own mock contexts. 804 // The below tests create their own mock contexts.
720 test_no_key(reporter); 805 test_no_key(reporter);
721 test_budgeting(reporter); 806 test_budgeting(reporter);
807 test_unbudgeted(reporter);
722 test_duplicate_content_key(reporter); 808 test_duplicate_content_key(reporter);
723 test_duplicate_scratch_key(reporter); 809 test_duplicate_scratch_key(reporter);
724 test_remove_scratch_key(reporter); 810 test_remove_scratch_key(reporter);
725 test_purge_invalidated(reporter); 811 test_purge_invalidated(reporter);
726 test_cache_chained_purge(reporter); 812 test_cache_chained_purge(reporter);
727 test_resource_size_changed(reporter); 813 test_resource_size_changed(reporter);
728 test_large_resource_count(reporter); 814 test_large_resource_count(reporter);
729 } 815 }
730 816
731 #endif 817 #endif
OLDNEW
« no previous file with comments | « tests/GLProgramsTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698