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

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: fix 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
« include/gpu/GrGpuResource.h ('K') | « 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();
255 cache2->purgeAllUnlocked(); 264 cache2->purgeAllUnlocked();
256 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 265 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
257 REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrapped->gpuMemorySi ze() == 266 REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrapped->gpuMemorySi ze() ==
258 cache2->getResourceBytes()); 267 cache2->getResourceBytes());
259 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount()); 268 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount());
260 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes()); 269 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes());
261 270
262 wrapped->unref(); 271 wrapped->unref();
263 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); 272 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
264 REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() == cache2->getResource Bytes()); 273 REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() == cache2->getResource Bytes());
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());
282
robertphillips 2015/01/14 16:42:59 At some point this could be broken into a test_unb
bsalomon 2015/01/14 18:32:04 Done.
283 // A large uncached or wrapped resource shouldn't evict anything.
284 scratch = SkNEW_ARGS(TestResource, (context->getGpu(), scratchKey));
285 scratch->setSize(10);
286 scratch->unref();
287 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
288 REPORTER_ASSERT(reporter, 10 == cache2->getResourceBytes());
289 REPORTER_ASSERT(reporter, 1 == cache2->getBudgetedResourceCount());
290 REPORTER_ASSERT(reporter, 10 == cache2->getBudgetedResourceBytes());
291
292 content = SkNEW_ARGS(TestResource, (context->getGpu()));
293 content->setSize(11);
294 REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey));
295 content->unref();
296 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
297 REPORTER_ASSERT(reporter, 21 == cache2->getResourceBytes());
298 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
299 REPORTER_ASSERT(reporter, 21 == cache2->getBudgetedResourceBytes());
300
301 size_t large = 2 * cache2->getResourceBytes();
302 unbudgeted = SkNEW_ARGS(TestResource,
303 (context->getGpu(), large, GrGpuResource::kUncached_ LifeCycle));
304 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount());
305 REPORTER_ASSERT(reporter, 21 + large == cache2->getResourceBytes());
306 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
307 REPORTER_ASSERT(reporter, 21 == cache2->getBudgetedResourceBytes());
308
309 unbudgeted->unref();
310 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
311 REPORTER_ASSERT(reporter, 21 == cache2->getResourceBytes());
312 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
313 REPORTER_ASSERT(reporter, 21 == cache2->getBudgetedResourceBytes());
314
315 wrapped = SkNEW_ARGS(TestResource,
316 (context->getGpu(), large, GrGpuResource::kWrapped_Life Cycle));
317 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount());
318 REPORTER_ASSERT(reporter, 21 + large == cache2->getResourceBytes());
319 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
320 REPORTER_ASSERT(reporter, 21 == cache2->getBudgetedResourceBytes());
321
322 wrapped->unref();
323 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
324 REPORTER_ASSERT(reporter, 21 == cache2->getResourceBytes());
325 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
326 REPORTER_ASSERT(reporter, 21 == cache2->getBudgetedResourceBytes());
327
328 cache2->purgeAllUnlocked();
329 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
330 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
331 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount());
332 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes());
273 } 333 }
274 334
275 static void test_duplicate_scratch_key(skiatest::Reporter* reporter) { 335 static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
276 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); 336 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
277 REPORTER_ASSERT(reporter, SkToBool(context)); 337 REPORTER_ASSERT(reporter, SkToBool(context));
278 if (NULL == context) { 338 if (NULL == context) {
279 return; 339 return;
280 } 340 }
281 context->setResourceCacheLimits(5, 30000); 341 context->setResourceCacheLimits(5, 30000);
282 GrResourceCache2* cache2 = context->getResourceCache2(); 342 GrResourceCache2* cache2 = context->getResourceCache2();
283 cache2->purgeAllUnlocked(); 343 cache2->purgeAllUnlocked();
284 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 344 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
285 345
286 GrScratchKey scratchKey; 346 GrScratchKey scratchKey;
287 make_scratch_key(&scratchKey); 347 make_scratch_key(&scratchKey);
288 348
289 // Create two resources that have the same scratch key. 349 // Create two resources that have the same scratch key.
290 TestResource* a = new TestResource(context->getGpu(), scratchKey); 350 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu(), scratchKey));
291 TestResource* b = new TestResource(context->getGpu(), scratchKey); 351 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu(), scratchKey));
292 a->setSize(11); 352 a->setSize(11);
293 b->setSize(12); 353 b->setSize(12);
294 // Scratch resources are registered with GrResourceCache2 just by existing. There are 2. 354 // Scratch resources are registered with GrResourceCache2 just by existing. There are 2.
295 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 355 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
296 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey (scratchKey));) 356 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey (scratchKey));)
297 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 357 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
298 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == 358 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() ==
299 cache2->getResourceBytes()); 359 cache2->getResourceBytes());
300 360
301 // Our refs mean that the resources are non purgable. 361 // Our refs mean that the resources are non purgable.
(...skipping 22 matching lines...) Expand all
324 } 384 }
325 context->setResourceCacheLimits(5, 30000); 385 context->setResourceCacheLimits(5, 30000);
326 GrResourceCache2* cache2 = context->getResourceCache2(); 386 GrResourceCache2* cache2 = context->getResourceCache2();
327 cache2->purgeAllUnlocked(); 387 cache2->purgeAllUnlocked();
328 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 388 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
329 389
330 GrScratchKey scratchKey; 390 GrScratchKey scratchKey;
331 make_scratch_key(&scratchKey); 391 make_scratch_key(&scratchKey);
332 392
333 // Create two resources that have the same scratch key. 393 // Create two resources that have the same scratch key.
334 TestResource* a = new TestResource(context->getGpu(), scratchKey); 394 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu(), scratchKey));
335 TestResource* b = new TestResource(context->getGpu(), scratchKey); 395 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu(), scratchKey));
336 a->unref(); 396 a->unref();
337 b->unref(); 397 b->unref();
338 398
339 // Scratch resources are registered with GrResourceCache2 just by existing. There are 2. 399 // Scratch resources are registered with GrResourceCache2 just by existing. There are 2.
340 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 400 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
341 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey (scratchKey));) 401 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey (scratchKey));)
342 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 402 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
343 403
344 // Find the first resource and remove its scratch key 404 // Find the first resource and remove its scratch key
345 GrGpuResource* find; 405 GrGpuResource* find;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 GrResourceCache2* cache2 = context->getResourceCache2(); 445 GrResourceCache2* cache2 = context->getResourceCache2();
386 cache2->purgeAllUnlocked(); 446 cache2->purgeAllUnlocked();
387 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 447 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
388 448
389 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); 449 GrCacheID::Domain domain = GrCacheID::GenerateDomain();
390 GrCacheID::Key keyData; 450 GrCacheID::Key keyData;
391 memset(&keyData, 0, sizeof(keyData)); 451 memset(&keyData, 0, sizeof(keyData));
392 GrResourceKey key(GrCacheID(domain, keyData), 0); 452 GrResourceKey key(GrCacheID(domain, keyData), 0);
393 453
394 // Create two resources that we will attempt to register with the same conte nt key. 454 // Create two resources that we will attempt to register with the same conte nt key.
395 TestResource* a = new TestResource(context->getGpu()); 455 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
396 TestResource* b = new TestResource(context->getGpu()); 456 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
397 a->setSize(11); 457 a->setSize(11);
398 b->setSize(12); 458 b->setSize(12);
399 459
400 // Can't set the same content key on two resources. 460 // Can't set the same content key on two resources.
401 REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key)); 461 REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key));
402 REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key)); 462 REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key));
403 463
404 // Still have two resources because b is still reffed. 464 // Still have two resources because b is still reffed.
405 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 465 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
406 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == 466 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); 507 GrResourceKey key2(GrCacheID(domain, keyData), 0);
448 keyData.fData64[0] = 3; 508 keyData.fData64[0] = 3;
449 GrResourceKey key3(GrCacheID(domain, keyData), 0); 509 GrResourceKey key3(GrCacheID(domain, keyData), 0);
450 510
451 context->setResourceCacheLimits(5, 30000); 511 context->setResourceCacheLimits(5, 30000);
452 GrResourceCache2* cache2 = context->getResourceCache2(); 512 GrResourceCache2* cache2 = context->getResourceCache2();
453 cache2->purgeAllUnlocked(); 513 cache2->purgeAllUnlocked();
454 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 514 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
455 515
456 // Add three resources to the cache. 516 // Add three resources to the cache.
457 TestResource* a = new TestResource(context->getGpu()); 517 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
458 TestResource* b = new TestResource(context->getGpu()); 518 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
459 TestResource* c = new TestResource(context->getGpu()); 519 TestResource* c = SkNEW_ARGS(TestResource, (context->getGpu()));
460 a->cacheAccess().setContentKey(key1); 520 a->cacheAccess().setContentKey(key1);
461 b->cacheAccess().setContentKey(key2); 521 b->cacheAccess().setContentKey(key2);
462 c->cacheAccess().setContentKey(key3); 522 c->cacheAccess().setContentKey(key3);
463 a->unref(); 523 a->unref();
464 b->unref(); 524 b->unref();
465 c->unref(); 525 c->unref();
466 526
467 REPORTER_ASSERT(reporter, cache2->hasContentKey(key1)); 527 REPORTER_ASSERT(reporter, cache2->hasContentKey(key1));
468 REPORTER_ASSERT(reporter, cache2->hasContentKey(key2)); 528 REPORTER_ASSERT(reporter, cache2->hasContentKey(key2));
469 REPORTER_ASSERT(reporter, cache2->hasContentKey(key3)); 529 REPORTER_ASSERT(reporter, cache2->hasContentKey(key3));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 573
514 keyData.fData64[0] = 2; 574 keyData.fData64[0] = 2;
515 GrResourceKey key2(GrCacheID(domain, keyData), 0); 575 GrResourceKey key2(GrCacheID(domain, keyData), 0);
516 576
517 { 577 {
518 context->setResourceCacheLimits(3, 30000); 578 context->setResourceCacheLimits(3, 30000);
519 GrResourceCache2* cache2 = context->getResourceCache2(); 579 GrResourceCache2* cache2 = context->getResourceCache2();
520 cache2->purgeAllUnlocked(); 580 cache2->purgeAllUnlocked();
521 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s()); 581 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s());
522 582
523 TestResource* a = new TestResource(context->getGpu()); 583 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
524 TestResource* b = new TestResource(context->getGpu()); 584 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
525 a->cacheAccess().setContentKey(key1); 585 a->cacheAccess().setContentKey(key1);
526 b->cacheAccess().setContentKey(key2); 586 b->cacheAccess().setContentKey(key2);
527 587
528 // Make a cycle 588 // Make a cycle
529 a->setUnrefWhenDestroyed(b); 589 a->setUnrefWhenDestroyed(b);
530 b->setUnrefWhenDestroyed(a); 590 b->setUnrefWhenDestroyed(a);
531 591
532 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 592 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
533 593
534 a->unref(); 594 a->unref();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 key2Data.fData64[1] = 0; 627 key2Data.fData64[1] = 0;
568 GrResourceKey key2(GrCacheID(domain, key2Data), 0); 628 GrResourceKey key2(GrCacheID(domain, key2Data), 0);
569 629
570 // Test changing resources sizes (both increase & decrease). 630 // Test changing resources sizes (both increase & decrease).
571 { 631 {
572 context->setResourceCacheLimits(3, 30000); 632 context->setResourceCacheLimits(3, 30000);
573 GrResourceCache2* cache2 = context->getResourceCache2(); 633 GrResourceCache2* cache2 = context->getResourceCache2();
574 cache2->purgeAllUnlocked(); 634 cache2->purgeAllUnlocked();
575 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s()); 635 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s());
576 636
577 TestResource* a = new TestResource(context->getGpu()); 637 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
578 a->cacheAccess().setContentKey(key1); 638 a->cacheAccess().setContentKey(key1);
579 a->unref(); 639 a->unref();
580 640
581 TestResource* b = new TestResource(context->getGpu()); 641 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
582 b->cacheAccess().setContentKey(key2); 642 b->cacheAccess().setContentKey(key2);
583 b->unref(); 643 b->unref();
584 644
585 REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes()); 645 REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes());
586 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 646 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
587 { 647 {
588 SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2-> findAndRefContentResource(key2))); 648 SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2-> findAndRefContentResource(key2)));
589 find2->setSize(200); 649 find2->setSize(200);
590 SkAutoTUnref<TestResource> find1(static_cast<TestResource*>(cache2-> findAndRefContentResource(key1))); 650 SkAutoTUnref<TestResource> find1(static_cast<TestResource*>(cache2-> findAndRefContentResource(key1)));
591 find1->setSize(50); 651 find1->setSize(50);
592 } 652 }
593 653
594 REPORTER_ASSERT(reporter, 250 == cache2->getResourceBytes()); 654 REPORTER_ASSERT(reporter, 250 == cache2->getResourceBytes());
595 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 655 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
596 } 656 }
597 657
598 // Test increasing a resources size beyond the cache budget. 658 // Test increasing a resources size beyond the cache budget.
599 { 659 {
600 context->setResourceCacheLimits(2, 300); 660 context->setResourceCacheLimits(2, 300);
601 GrResourceCache2* cache2 = context->getResourceCache2(); 661 GrResourceCache2* cache2 = context->getResourceCache2();
602 cache2->purgeAllUnlocked(); 662 cache2->purgeAllUnlocked();
603 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s()); 663 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s());
604 664
605 TestResource* a = new TestResource(context->getGpu()); 665 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
606 a->setSize(100); 666 a->setSize(100);
607 a->cacheAccess().setContentKey(key1); 667 a->cacheAccess().setContentKey(key1);
608 a->unref(); 668 a->unref();
609 669
610 TestResource* b = new TestResource(context->getGpu()); 670 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
611 b->setSize(100); 671 b->setSize(100);
612 b->cacheAccess().setContentKey(key2); 672 b->cacheAccess().setContentKey(key2);
613 b->unref(); 673 b->unref();
614 674
615 REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes()); 675 REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes());
616 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 676 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
617 677
618 { 678 {
619 SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2-> findAndRefContentResource(key2))); 679 SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2-> findAndRefContentResource(key2)));
620 find2->setSize(201); 680 find2->setSize(201);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 test_duplicate_content_key(reporter); 782 test_duplicate_content_key(reporter);
723 test_duplicate_scratch_key(reporter); 783 test_duplicate_scratch_key(reporter);
724 test_remove_scratch_key(reporter); 784 test_remove_scratch_key(reporter);
725 test_purge_invalidated(reporter); 785 test_purge_invalidated(reporter);
726 test_cache_chained_purge(reporter); 786 test_cache_chained_purge(reporter);
727 test_resource_size_changed(reporter); 787 test_resource_size_changed(reporter);
728 test_large_resource_count(reporter); 788 test_large_resource_count(reporter);
729 } 789 }
730 790
731 #endif 791 #endif
OLDNEW
« include/gpu/GrGpuResource.h ('K') | « tests/GLProgramsTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698