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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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/RegionTest.cpp ('k') | tests/SVGDeviceTest.cpp » ('j') | 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 // Include here to ensure SK_SUPPORT_GPU is set correctly before it is examined. 8 // Include here to ensure SK_SUPPORT_GPU is set correctly before it is examined.
9 #include "SkTypes.h" 9 #include "SkTypes.h"
10 10
(...skipping 20 matching lines...) Expand all
31 //////////////////////////////////////////////////////////////////////////////// 31 ////////////////////////////////////////////////////////////////////////////////
32 static void test_cache(skiatest::Reporter* reporter, GrContext* context, SkCanva s* canvas) { 32 static void test_cache(skiatest::Reporter* reporter, GrContext* context, SkCanva s* canvas) {
33 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); 33 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight);
34 34
35 SkBitmap src; 35 SkBitmap src;
36 src.allocN32Pixels(size.width(), size.height()); 36 src.allocN32Pixels(size.width(), size.height());
37 src.eraseColor(SK_ColorBLACK); 37 src.eraseColor(SK_ColorBLACK);
38 size_t srcSize = src.getSize(); 38 size_t srcSize = src.getSize();
39 39
40 size_t initialCacheSize; 40 size_t initialCacheSize;
41 context->getResourceCacheUsage(NULL, &initialCacheSize); 41 context->getResourceCacheUsage(nullptr, &initialCacheSize);
42 42
43 int oldMaxNum; 43 int oldMaxNum;
44 size_t oldMaxBytes; 44 size_t oldMaxBytes;
45 context->getResourceCacheLimits(&oldMaxNum, &oldMaxBytes); 45 context->getResourceCacheLimits(&oldMaxNum, &oldMaxBytes);
46 46
47 // Set the cache limits so we can fit 10 "src" images and the 47 // Set the cache limits so we can fit 10 "src" images and the
48 // max number of textures doesn't matter 48 // max number of textures doesn't matter
49 size_t maxCacheSize = initialCacheSize + 10*srcSize; 49 size_t maxCacheSize = initialCacheSize + 10*srcSize;
50 context->setResourceCacheLimits(1000, maxCacheSize); 50 context->setResourceCacheLimits(1000, maxCacheSize);
51 51
52 SkBitmap readback; 52 SkBitmap readback;
53 readback.allocN32Pixels(size.width(), size.height()); 53 readback.allocN32Pixels(size.width(), size.height());
54 54
55 for (int i = 0; i < 100; ++i) { 55 for (int i = 0; i < 100; ++i) {
56 canvas->drawBitmap(src, 0, 0); 56 canvas->drawBitmap(src, 0, 0);
57 canvas->readPixels(size, &readback); 57 canvas->readPixels(size, &readback);
58 58
59 // "modify" the src texture 59 // "modify" the src texture
60 src.notifyPixelsChanged(); 60 src.notifyPixelsChanged();
61 61
62 size_t curCacheSize; 62 size_t curCacheSize;
63 context->getResourceCacheUsage(NULL, &curCacheSize); 63 context->getResourceCacheUsage(nullptr, &curCacheSize);
64 64
65 // we should never go over the size limit 65 // we should never go over the size limit
66 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); 66 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize);
67 } 67 }
68 68
69 context->setResourceCacheLimits(oldMaxNum, oldMaxBytes); 69 context->setResourceCacheLimits(oldMaxNum, oldMaxBytes);
70 } 70 }
71 71
72 static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex t) { 72 static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex t) {
73 GrSurfaceDesc smallDesc; 73 GrSurfaceDesc smallDesc;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 const GrGpu* gpu = context->getGpu(); 178 const GrGpu* gpu = context->getGpu();
179 // this test is only valid for GL 179 // this test is only valid for GL
180 if (!gpu || !gpu->glContextForTesting()) { 180 if (!gpu || !gpu->glContextForTesting()) {
181 return; 181 return;
182 } 182 }
183 183
184 GrBackendObject texIDs[2]; 184 GrBackendObject texIDs[2];
185 static const int kW = 100; 185 static const int kW = 100;
186 static const int kH = 100; 186 static const int kH = 100;
187 187
188 texIDs[0] = gpu->createTestingOnlyBackendTexture(NULL, kW, kH, kRGBA_8888_Gr PixelConfig); 188 texIDs[0] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888 _GrPixelConfig);
189 texIDs[1] = gpu->createTestingOnlyBackendTexture(NULL, kW, kH, kRGBA_8888_Gr PixelConfig); 189 texIDs[1] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888 _GrPixelConfig);
190 190
191 context->resetContext(); 191 context->resetContext();
192 192
193 GrBackendTextureDesc desc; 193 GrBackendTextureDesc desc;
194 desc.fConfig = kBGRA_8888_GrPixelConfig; 194 desc.fConfig = kBGRA_8888_GrPixelConfig;
195 desc.fWidth = kW; 195 desc.fWidth = kW;
196 desc.fHeight = kH; 196 desc.fHeight = kH;
197 197
198 desc.fTextureHandle = texIDs[0]; 198 desc.fTextureHandle = texIDs[0];
199 SkAutoTUnref<GrTexture> borrowed(context->textureProvider()->wrapBackendText ure( 199 SkAutoTUnref<GrTexture> borrowed(context->textureProvider()->wrapBackendText ure(
200 desc, kBorrow_GrWrapOwnership)); 200 desc, kBorrow_GrWrapOwnership));
201 201
202 desc.fTextureHandle = texIDs[1]; 202 desc.fTextureHandle = texIDs[1];
203 SkAutoTUnref<GrTexture> adopted(context->textureProvider()->wrapBackendTextu re( 203 SkAutoTUnref<GrTexture> adopted(context->textureProvider()->wrapBackendTextu re(
204 desc, kAdopt_GrWrapOwnership)); 204 desc, kAdopt_GrWrapOwnership));
205 205
206 REPORTER_ASSERT(reporter, SkToBool(borrowed) && SkToBool(adopted)); 206 REPORTER_ASSERT(reporter, SkToBool(borrowed) && SkToBool(adopted));
207 if (!SkToBool(borrowed) || !SkToBool(adopted)) { 207 if (!SkToBool(borrowed) || !SkToBool(adopted)) {
208 return; 208 return;
209 } 209 }
210 210
211 borrowed.reset(NULL); 211 borrowed.reset(nullptr);
212 adopted.reset(NULL); 212 adopted.reset(nullptr);
213 213
214 context->flush(); 214 context->flush();
215 215
216 bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(texIDs[0]); 216 bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(texIDs[0]);
217 bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(texIDs[1]); 217 bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(texIDs[1]);
218 218
219 REPORTER_ASSERT(reporter, borrowedIsAlive); 219 REPORTER_ASSERT(reporter, borrowedIsAlive);
220 REPORTER_ASSERT(reporter, !adoptedIsAlive); 220 REPORTER_ASSERT(reporter, !adoptedIsAlive);
221 221
222 gpu->deleteTestingOnlyBackendTexture(texIDs[0]); 222 gpu->deleteTestingOnlyBackendTexture(texIDs[0]);
223 223
224 context->resetContext(); 224 context->resetContext();
225 } 225 }
226 226
227 class TestResource : public GrGpuResource { 227 class TestResource : public GrGpuResource {
228 enum ScratchConstructor { kScratchConstructor }; 228 enum ScratchConstructor { kScratchConstructor };
229 public: 229 public:
230 static const size_t kDefaultSize = 100; 230 static const size_t kDefaultSize = 100;
231 231
232 /** Property that distinctly categorizes the resource. 232 /** Property that distinctly categorizes the resource.
233 * For example, textures have width, height, ... */ 233 * For example, textures have width, height, ... */
234 enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty }; 234 enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty };
235 235
236 TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle) 236 TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle)
237 : INHERITED(gpu, lifeCycle) 237 : INHERITED(gpu, lifeCycle)
238 , fToDelete(NULL) 238 , fToDelete(nullptr)
239 , fSize(size) 239 , fSize(size)
240 , fProperty(kA_SimulatedProperty) { 240 , fProperty(kA_SimulatedProperty) {
241 ++fNumAlive; 241 ++fNumAlive;
242 this->registerWithCache(); 242 this->registerWithCache();
243 } 243 }
244 244
245 TestResource(GrGpu* gpu, GrGpuResource::LifeCycle lifeCycle) 245 TestResource(GrGpu* gpu, GrGpuResource::LifeCycle lifeCycle)
246 : INHERITED(gpu, lifeCycle) 246 : INHERITED(gpu, lifeCycle)
247 , fToDelete(NULL) 247 , fToDelete(nullptr)
248 , fSize(kDefaultSize) 248 , fSize(kDefaultSize)
249 , fProperty(kA_SimulatedProperty) { 249 , fProperty(kA_SimulatedProperty) {
250 ++fNumAlive; 250 ++fNumAlive;
251 this->registerWithCache(); 251 this->registerWithCache();
252 } 252 }
253 253
254 TestResource(GrGpu* gpu) 254 TestResource(GrGpu* gpu)
255 : INHERITED(gpu, kCached_LifeCycle) 255 : INHERITED(gpu, kCached_LifeCycle)
256 , fToDelete(NULL) 256 , fToDelete(nullptr)
257 , fSize(kDefaultSize) 257 , fSize(kDefaultSize)
258 , fProperty(kA_SimulatedProperty) { 258 , fProperty(kA_SimulatedProperty) {
259 ++fNumAlive; 259 ++fNumAlive;
260 this->registerWithCache(); 260 this->registerWithCache();
261 } 261 }
262 262
263 static TestResource* CreateScratch(GrGpu* gpu, SimulatedProperty property, b ool cached = true) { 263 static TestResource* CreateScratch(GrGpu* gpu, SimulatedProperty property, b ool cached = true) {
264 return new TestResource(gpu, property, cached, kScratchConstructor); 264 return new TestResource(gpu, property, cached, kScratchConstructor);
265 } 265 }
266 266
(...skipping 23 matching lines...) Expand all
290 290
291 static size_t ExpectedScratchKeySize() { 291 static size_t ExpectedScratchKeySize() {
292 return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaData Cnt); 292 return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaData Cnt);
293 } 293 }
294 294
295 private: 295 private:
296 static const int kScratchKeyFieldCnt = 6; 296 static const int kScratchKeyFieldCnt = 6;
297 297
298 TestResource(GrGpu* gpu, SimulatedProperty property, bool cached, ScratchCon structor) 298 TestResource(GrGpu* gpu, SimulatedProperty property, bool cached, ScratchCon structor)
299 : INHERITED(gpu, cached ? kCached_LifeCycle : kUncached_LifeCycle) 299 : INHERITED(gpu, cached ? kCached_LifeCycle : kUncached_LifeCycle)
300 , fToDelete(NULL) 300 , fToDelete(nullptr)
301 , fSize(kDefaultSize) 301 , fSize(kDefaultSize)
302 , fProperty(property) { 302 , fProperty(property) {
303 GrScratchKey scratchKey; 303 GrScratchKey scratchKey;
304 ComputeScratchKey(fProperty, &scratchKey); 304 ComputeScratchKey(fProperty, &scratchKey);
305 this->setScratchKey(scratchKey); 305 this->setScratchKey(scratchKey);
306 ++fNumAlive; 306 ++fNumAlive;
307 this->registerWithCache(); 307 this->registerWithCache();
308 } 308 }
309 309
310 size_t onGpuMemorySize() const override { return fSize; } 310 size_t onGpuMemorySize() const override { return fSize; }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 TestResource* wrapped = new TestResource(context->getGpu(), GrGpuResource::k Borrowed_LifeCycle); 410 TestResource* wrapped = new TestResource(context->getGpu(), GrGpuResource::k Borrowed_LifeCycle);
411 wrapped->setSize(12); 411 wrapped->setSize(12);
412 TestResource* unbudgeted = 412 TestResource* unbudgeted =
413 new TestResource(context->getGpu(), GrGpuResource::kUncached_LifeCyc le); 413 new TestResource(context->getGpu(), GrGpuResource::kUncached_LifeCyc le);
414 unbudgeted->setSize(13); 414 unbudgeted->setSize(13);
415 415
416 // Make sure we can't add a unique key to the wrapped resource 416 // Make sure we can't add a unique key to the wrapped resource
417 GrUniqueKey uniqueKey2; 417 GrUniqueKey uniqueKey2;
418 make_unique_key<0>(&uniqueKey2, 1); 418 make_unique_key<0>(&uniqueKey2, 1);
419 wrapped->resourcePriv().setUniqueKey(uniqueKey2); 419 wrapped->resourcePriv().setUniqueKey(uniqueKey2);
420 REPORTER_ASSERT(reporter, NULL == cache->findAndRefUniqueResource(uniqueKey2 )); 420 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefUniqueResource(uniqueK ey2));
421 421
422 // Make sure sizes are as we expect 422 // Make sure sizes are as we expect
423 REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); 423 REPORTER_ASSERT(reporter, 4 == cache->getResourceCount());
424 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + 424 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() +
425 wrapped->gpuMemorySize() + unbudgeted->gpuMemorySi ze() == 425 wrapped->gpuMemorySize() + unbudgeted->gpuMemorySi ze() ==
426 cache->getResourceBytes()); 426 cache->getResourceBytes());
427 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); 427 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
428 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == 428 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() ==
429 cache->getBudgetedResourceBytes()); 429 cache->getBudgetedResourceBytes());
430 430
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 TestResource::CreateScratch(context->getGpu(), TestResource::kA_Simulate dProperty, false); 550 TestResource::CreateScratch(context->getGpu(), TestResource::kA_Simulate dProperty, false);
551 GrScratchKey key; 551 GrScratchKey key;
552 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key); 552 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key);
553 553
554 size_t size = resource->gpuMemorySize(); 554 size_t size = resource->gpuMemorySize();
555 for (int i = 0; i < 2; ++i) { 555 for (int i = 0; i < 2; ++i) {
556 // Since this resource is unbudgeted, it should not be reachable as scra tch. 556 // Since this resource is unbudgeted, it should not be reachable as scra tch.
557 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y); 557 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y);
558 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); 558 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
559 REPORTER_ASSERT(reporter, !resource->resourcePriv().isBudgeted()); 559 REPORTER_ASSERT(reporter, !resource->resourcePriv().isBudgeted());
560 REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(key, TestResource::kDefaultSize, 0)); 560 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(ke y, TestResource::kDefaultSize, 0));
561 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 561 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
562 REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); 562 REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
563 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); 563 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
564 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); 564 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
565 565
566 // Once it is unrefed, it should become available as scratch. 566 // Once it is unrefed, it should become available as scratch.
567 resource->unref(); 567 resource->unref();
568 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 568 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
569 REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); 569 REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
570 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); 570 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 // Create two resources that have the same scratch key. 608 // Create two resources that have the same scratch key.
609 TestResource* a = TestResource::CreateScratch(context->getGpu(), 609 TestResource* a = TestResource::CreateScratch(context->getGpu(),
610 TestResource::kB_SimulatedProp erty); 610 TestResource::kB_SimulatedProp erty);
611 TestResource* b = TestResource::CreateScratch(context->getGpu(), 611 TestResource* b = TestResource::CreateScratch(context->getGpu(),
612 TestResource::kB_SimulatedProp erty); 612 TestResource::kB_SimulatedProp erty);
613 a->setSize(11); 613 a->setSize(11);
614 b->setSize(12); 614 b->setSize(12);
615 GrScratchKey scratchKey1; 615 GrScratchKey scratchKey1;
616 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key1); 616 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key1);
617 // Check for negative case consistency. (leaks upon test failure.) 617 // Check for negative case consistency. (leaks upon test failure.)
618 REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(scratchKe y1, TestResource::kDefaultSize, 0)); 618 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(scratc hKey1, TestResource::kDefaultSize, 0));
619 619
620 GrScratchKey scratchKey; 620 GrScratchKey scratchKey;
621 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch Key); 621 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch Key);
622 622
623 // Scratch resources are registered with GrResourceCache just by existing. T here are 2. 623 // Scratch resources are registered with GrResourceCache just by existing. T here are 2.
624 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 624 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
625 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey( scratchKey));) 625 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey( scratchKey));)
626 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); 626 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
627 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == 627 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() ==
628 cache->getResourceBytes()); 628 cache->getResourceBytes());
(...skipping 26 matching lines...) Expand all
655 TestResource::kB_SimulatedProp erty); 655 TestResource::kB_SimulatedProp erty);
656 TestResource* b = TestResource::CreateScratch(context->getGpu(), 656 TestResource* b = TestResource::CreateScratch(context->getGpu(),
657 TestResource::kB_SimulatedProp erty); 657 TestResource::kB_SimulatedProp erty);
658 a->unref(); 658 a->unref();
659 b->unref(); 659 b->unref();
660 660
661 GrScratchKey scratchKey; 661 GrScratchKey scratchKey;
662 // Ensure that scratch key lookup is correct for negative case. 662 // Ensure that scratch key lookup is correct for negative case.
663 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key); 663 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key);
664 // (following leaks upon test failure). 664 // (following leaks upon test failure).
665 REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestR esource::kDefaultSize, 0) == NULL); 665 REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestR esource::kDefaultSize, 0) == nullptr);
666 666
667 // Scratch resources are registered with GrResourceCache just by existing. T here are 2. 667 // Scratch resources are registered with GrResourceCache just by existing. T here are 2.
668 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch Key); 668 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch Key);
669 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 669 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
670 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey( scratchKey));) 670 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey( scratchKey));)
671 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); 671 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
672 672
673 // Find the first resource and remove its scratch key 673 // Find the first resource and remove its scratch key
674 GrGpuResource* find; 674 GrGpuResource* find;
675 find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSi ze, 0); 675 find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSi ze, 0);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 scratchKey = scratchKey2; 735 scratchKey = scratchKey2;
736 REPORTER_ASSERT(reporter, scratchKey.size() == TestResource::ExpectedScratch KeySize()); 736 REPORTER_ASSERT(reporter, scratchKey.size() == TestResource::ExpectedScratch KeySize());
737 REPORTER_ASSERT(reporter, scratchKey1 != scratchKey); 737 REPORTER_ASSERT(reporter, scratchKey1 != scratchKey);
738 REPORTER_ASSERT(reporter, scratchKey != scratchKey1); 738 REPORTER_ASSERT(reporter, scratchKey != scratchKey1);
739 REPORTER_ASSERT(reporter, scratchKey2 == scratchKey); 739 REPORTER_ASSERT(reporter, scratchKey2 == scratchKey);
740 REPORTER_ASSERT(reporter, scratchKey == scratchKey2); 740 REPORTER_ASSERT(reporter, scratchKey == scratchKey2);
741 741
742 // Ensure that scratch key lookup is correct for negative case. 742 // Ensure that scratch key lookup is correct for negative case.
743 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key); 743 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key);
744 // (following leaks upon test failure). 744 // (following leaks upon test failure).
745 REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestR esource::kDefaultSize, 0) == NULL); 745 REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestR esource::kDefaultSize, 0) == nullptr);
746 746
747 // Find the first resource with a scratch key and a copy of a scratch key. 747 // Find the first resource with a scratch key and a copy of a scratch key.
748 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch Key); 748 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch Key);
749 GrGpuResource* find = cache->findAndRefScratchResource(scratchKey, TestResou rce::kDefaultSize, 0); 749 GrGpuResource* find = cache->findAndRefScratchResource(scratchKey, TestResou rce::kDefaultSize, 0);
750 REPORTER_ASSERT(reporter, find != NULL); 750 REPORTER_ASSERT(reporter, find != nullptr);
751 find->unref(); 751 find->unref();
752 752
753 scratchKey2 = scratchKey; 753 scratchKey2 = scratchKey;
754 find = cache->findAndRefScratchResource(scratchKey2, TestResource::kDefaultS ize, 0); 754 find = cache->findAndRefScratchResource(scratchKey2, TestResource::kDefaultS ize, 0);
755 REPORTER_ASSERT(reporter, find != NULL); 755 REPORTER_ASSERT(reporter, find != nullptr);
756 REPORTER_ASSERT(reporter, find == a || find == b); 756 REPORTER_ASSERT(reporter, find == a || find == b);
757 757
758 GrGpuResource* find2 = cache->findAndRefScratchResource(scratchKey2, TestRes ource::kDefaultSize, 0); 758 GrGpuResource* find2 = cache->findAndRefScratchResource(scratchKey2, TestRes ource::kDefaultSize, 0);
759 REPORTER_ASSERT(reporter, find2 != NULL); 759 REPORTER_ASSERT(reporter, find2 != nullptr);
760 REPORTER_ASSERT(reporter, find2 == a || find2 == b); 760 REPORTER_ASSERT(reporter, find2 == a || find2 == b);
761 REPORTER_ASSERT(reporter, find2 != find); 761 REPORTER_ASSERT(reporter, find2 != find);
762 find2->unref(); 762 find2->unref();
763 find->unref(); 763 find->unref();
764 } 764 }
765 765
766 static void test_duplicate_unique_key(skiatest::Reporter* reporter) { 766 static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
767 Mock mock(5, 30000); 767 Mock mock(5, 30000);
768 GrContext* context = mock.context(); 768 GrContext* context = mock.context();
769 GrResourceCache* cache = mock.cache(); 769 GrResourceCache* cache = mock.cache();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 949
950 a->unref(); 950 a->unref();
951 b->unref(); 951 b->unref();
952 952
953 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 953 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
954 954
955 cache->purgeAllUnlocked(); 955 cache->purgeAllUnlocked();
956 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 956 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
957 957
958 // Break the cycle 958 // Break the cycle
959 a->setUnrefWhenDestroyed(NULL); 959 a->setUnrefWhenDestroyed(nullptr);
960 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 960 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
961 961
962 cache->purgeAllUnlocked(); 962 cache->purgeAllUnlocked();
963 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); 963 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
964 } 964 }
965 965
966 static void test_resource_size_changed(skiatest::Reporter* reporter) { 966 static void test_resource_size_changed(skiatest::Reporter* reporter) {
967 GrUniqueKey key1, key2; 967 GrUniqueKey key1, key2;
968 make_unique_key<0>(&key1, 1); 968 make_unique_key<0>(&key1, 1);
969 make_unique_key<0>(&key2, 2); 969 make_unique_key<0>(&key2, 2);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 1073
1074 // Verify that the correct resources were purged. 1074 // Verify that the correct resources were purged.
1075 int currShouldPurgeIdx = 0; 1075 int currShouldPurgeIdx = 0;
1076 for (int j = 0; j < kCount; ++j) { 1076 for (int j = 0; j < kCount; ++j) {
1077 GrUniqueKey key; 1077 GrUniqueKey key;
1078 make_unique_key<0>(&key, j); 1078 make_unique_key<0>(&key, j);
1079 GrGpuResource* res = cache->findAndRefUniqueResource(key); 1079 GrGpuResource* res = cache->findAndRefUniqueResource(key);
1080 if (currShouldPurgeIdx < shouldPurgeIdxs.count() && 1080 if (currShouldPurgeIdx < shouldPurgeIdxs.count() &&
1081 shouldPurgeIdxs[currShouldPurgeIdx] == j) { 1081 shouldPurgeIdxs[currShouldPurgeIdx] == j) {
1082 ++currShouldPurgeIdx; 1082 ++currShouldPurgeIdx;
1083 REPORTER_ASSERT(reporter, NULL == res); 1083 REPORTER_ASSERT(reporter, nullptr == res);
1084 } else { 1084 } else {
1085 REPORTER_ASSERT(reporter, NULL != res); 1085 REPORTER_ASSERT(reporter, nullptr != res);
1086 } 1086 }
1087 SkSafeUnref(res); 1087 SkSafeUnref(res);
1088 } 1088 }
1089 1089
1090 for (int j = 0; j < resourcesToUnref.count(); ++j) { 1090 for (int j = 0; j < resourcesToUnref.count(); ++j) {
1091 resourcesToUnref[j]->unref(); 1091 resourcesToUnref[j]->unref();
1092 } 1092 }
1093 } 1093 }
1094 } 1094 }
1095 1095
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 } 1250 }
1251 1251
1252 //////////////////////////////////////////////////////////////////////////////// 1252 ////////////////////////////////////////////////////////////////////////////////
1253 DEF_GPUTEST(ResourceCache, reporter, factory) { 1253 DEF_GPUTEST(ResourceCache, reporter, factory) {
1254 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { 1254 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
1255 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type); 1255 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type);
1256 if (!GrContextFactory::IsRenderingGLContext(glType)) { 1256 if (!GrContextFactory::IsRenderingGLContext(glType)) {
1257 continue; 1257 continue;
1258 } 1258 }
1259 GrContext* context = factory->get(glType); 1259 GrContext* context = factory->get(glType);
1260 if (NULL == context) { 1260 if (nullptr == context) {
1261 continue; 1261 continue;
1262 } 1262 }
1263 GrSurfaceDesc desc; 1263 GrSurfaceDesc desc;
1264 desc.fConfig = kSkia8888_GrPixelConfig; 1264 desc.fConfig = kSkia8888_GrPixelConfig;
1265 desc.fFlags = kRenderTarget_GrSurfaceFlag; 1265 desc.fFlags = kRenderTarget_GrSurfaceFlag;
1266 desc.fWidth = gWidth; 1266 desc.fWidth = gWidth;
1267 desc.fHeight = gHeight; 1267 desc.fHeight = gHeight;
1268 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); 1268 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight);
1269 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, 1269 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context,
1270 SkSurface::kN o_Budgeted, info)); 1270 SkSurface::kN o_Budgeted, info));
(...skipping 14 matching lines...) Expand all
1285 test_purge_invalidated(reporter); 1285 test_purge_invalidated(reporter);
1286 test_cache_chained_purge(reporter); 1286 test_cache_chained_purge(reporter);
1287 test_resource_size_changed(reporter); 1287 test_resource_size_changed(reporter);
1288 test_timestamp_wrap(reporter); 1288 test_timestamp_wrap(reporter);
1289 test_flush(reporter); 1289 test_flush(reporter);
1290 test_large_resource_count(reporter); 1290 test_large_resource_count(reporter);
1291 test_custom_data(reporter); 1291 test_custom_data(reporter);
1292 } 1292 }
1293 1293
1294 #endif 1294 #endif
OLDNEW
« no previous file with comments | « tests/RegionTest.cpp ('k') | tests/SVGDeviceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698