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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 1286203002: Defer flushes if kPreferNoIO is specified (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use explicit size in test Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGLRenderTarget.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 // 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 static const size_t kDefaultSize = 100;
229 enum ScratchConstructor { kScratchConstructor }; 228 enum ScratchConstructor { kScratchConstructor };
230 public: 229 public:
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(NULL)
239 , fSize(size) 239 , fSize(size)
240 , fProperty(kA_SimulatedProperty) { 240 , fProperty(kA_SimulatedProperty) {
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 TestResource::CreateScratch(context->getGpu(), TestResource::kA_Simulate dProperty, false); 553 TestResource::CreateScratch(context->getGpu(), TestResource::kA_Simulate dProperty, false);
554 GrScratchKey key; 554 GrScratchKey key;
555 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key); 555 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key);
556 556
557 size_t size = resource->gpuMemorySize(); 557 size_t size = resource->gpuMemorySize();
558 for (int i = 0; i < 2; ++i) { 558 for (int i = 0; i < 2; ++i) {
559 // Since this resource is unbudgeted, it should not be reachable as scra tch. 559 // Since this resource is unbudgeted, it should not be reachable as scra tch.
560 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y); 560 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y);
561 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); 561 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
562 REPORTER_ASSERT(reporter, !resource->resourcePriv().isBudgeted()); 562 REPORTER_ASSERT(reporter, !resource->resourcePriv().isBudgeted());
563 REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(key)) ; 563 REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(key, TestResource::kDefaultSize, 0));
564 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 564 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
565 REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); 565 REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
566 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); 566 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
567 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); 567 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
568 568
569 // Once it is unrefed, it should become available as scratch. 569 // Once it is unrefed, it should become available as scratch.
570 resource->unref(); 570 resource->unref();
571 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 571 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
572 REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); 572 REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
573 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); 573 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
574 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()); 574 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes());
575 resource = static_cast<TestResource*>(cache->findAndRefScratchResource(k ey)); 575 resource = static_cast<TestResource*>(cache->findAndRefScratchResource(k ey, TestResource::kDefaultSize, 0));
576 REPORTER_ASSERT(reporter, resource); 576 REPORTER_ASSERT(reporter, resource);
577 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y); 577 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y);
578 REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch()); 578 REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch());
579 REPORTER_ASSERT(reporter, resource->resourcePriv().isBudgeted()); 579 REPORTER_ASSERT(reporter, resource->resourcePriv().isBudgeted());
580 580
581 if (0 == i) { 581 if (0 == i) {
582 // If made unbudgeted, it should return to original state: ref'ed an d unbudgeted. Try 582 // If made unbudgeted, it should return to original state: ref'ed an d unbudgeted. Try
583 // the above tests again. 583 // the above tests again.
584 resource->resourcePriv().makeUnbudgeted(); 584 resource->resourcePriv().makeUnbudgeted();
585 } else { 585 } else {
(...skipping 25 matching lines...) Expand all
611 // Create two resources that have the same scratch key. 611 // Create two resources that have the same scratch key.
612 TestResource* a = TestResource::CreateScratch(context->getGpu(), 612 TestResource* a = TestResource::CreateScratch(context->getGpu(),
613 TestResource::kB_SimulatedProp erty); 613 TestResource::kB_SimulatedProp erty);
614 TestResource* b = TestResource::CreateScratch(context->getGpu(), 614 TestResource* b = TestResource::CreateScratch(context->getGpu(),
615 TestResource::kB_SimulatedProp erty); 615 TestResource::kB_SimulatedProp erty);
616 a->setSize(11); 616 a->setSize(11);
617 b->setSize(12); 617 b->setSize(12);
618 GrScratchKey scratchKey1; 618 GrScratchKey scratchKey1;
619 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key1); 619 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key1);
620 // Check for negative case consistency. (leaks upon test failure.) 620 // Check for negative case consistency. (leaks upon test failure.)
621 REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(scratchKe y1)); 621 REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(scratchKe y1, TestResource::kDefaultSize, 0));
622 622
623 GrScratchKey scratchKey; 623 GrScratchKey scratchKey;
624 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch Key); 624 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch Key);
625 625
626 // Scratch resources are registered with GrResourceCache just by existing. T here are 2. 626 // Scratch resources are registered with GrResourceCache just by existing. T here are 2.
627 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 627 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
628 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey( scratchKey));) 628 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey( scratchKey));)
629 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); 629 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
630 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == 630 REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() ==
631 cache->getResourceBytes()); 631 cache->getResourceBytes());
(...skipping 26 matching lines...) Expand all
658 TestResource::kB_SimulatedProp erty); 658 TestResource::kB_SimulatedProp erty);
659 TestResource* b = TestResource::CreateScratch(context->getGpu(), 659 TestResource* b = TestResource::CreateScratch(context->getGpu(),
660 TestResource::kB_SimulatedProp erty); 660 TestResource::kB_SimulatedProp erty);
661 a->unref(); 661 a->unref();
662 b->unref(); 662 b->unref();
663 663
664 GrScratchKey scratchKey; 664 GrScratchKey scratchKey;
665 // Ensure that scratch key lookup is correct for negative case. 665 // Ensure that scratch key lookup is correct for negative case.
666 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key); 666 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key);
667 // (following leaks upon test failure). 667 // (following leaks upon test failure).
668 REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey) == NU LL); 668 REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestR esource::kDefaultSize, 0) == NULL);
669 669
670 // Scratch resources are registered with GrResourceCache just by existing. T here are 2. 670 // Scratch resources are registered with GrResourceCache just by existing. T here are 2.
671 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch Key); 671 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch Key);
672 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 672 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
673 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey( scratchKey));) 673 SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey( scratchKey));)
674 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); 674 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
675 675
676 // Find the first resource and remove its scratch key 676 // Find the first resource and remove its scratch key
677 GrGpuResource* find; 677 GrGpuResource* find;
678 find = cache->findAndRefScratchResource(scratchKey); 678 find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSi ze, 0);
679 find->resourcePriv().removeScratchKey(); 679 find->resourcePriv().removeScratchKey();
680 // It's still alive, but not cached by scratch key anymore 680 // It's still alive, but not cached by scratch key anymore
681 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 681 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
682 SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey( scratchKey));) 682 SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey( scratchKey));)
683 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); 683 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
684 684
685 // The cache should immediately delete it when it's unrefed since it isn't a ccessible. 685 // The cache should immediately delete it when it's unrefed since it isn't a ccessible.
686 find->unref(); 686 find->unref();
687 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); 687 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
688 SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey( scratchKey));) 688 SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey( scratchKey));)
689 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 689 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
690 690
691 // Repeat for the second resource. 691 // Repeat for the second resource.
692 find = cache->findAndRefScratchResource(scratchKey); 692 find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSi ze, 0);
693 find->resourcePriv().removeScratchKey(); 693 find->resourcePriv().removeScratchKey();
694 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); 694 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
695 SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey( scratchKey));) 695 SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey( scratchKey));)
696 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 696 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
697 697
698 // Should be able to call this multiple times with no problem. 698 // Should be able to call this multiple times with no problem.
699 find->resourcePriv().removeScratchKey(); 699 find->resourcePriv().removeScratchKey();
700 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); 700 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
701 SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey( scratchKey));) 701 SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey( scratchKey));)
702 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 702 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 scratchKey = scratchKey2; 738 scratchKey = scratchKey2;
739 REPORTER_ASSERT(reporter, scratchKey.size() == TestResource::ExpectedScratch KeySize()); 739 REPORTER_ASSERT(reporter, scratchKey.size() == TestResource::ExpectedScratch KeySize());
740 REPORTER_ASSERT(reporter, scratchKey1 != scratchKey); 740 REPORTER_ASSERT(reporter, scratchKey1 != scratchKey);
741 REPORTER_ASSERT(reporter, scratchKey != scratchKey1); 741 REPORTER_ASSERT(reporter, scratchKey != scratchKey1);
742 REPORTER_ASSERT(reporter, scratchKey2 == scratchKey); 742 REPORTER_ASSERT(reporter, scratchKey2 == scratchKey);
743 REPORTER_ASSERT(reporter, scratchKey == scratchKey2); 743 REPORTER_ASSERT(reporter, scratchKey == scratchKey2);
744 744
745 // Ensure that scratch key lookup is correct for negative case. 745 // Ensure that scratch key lookup is correct for negative case.
746 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key); 746 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key);
747 // (following leaks upon test failure). 747 // (following leaks upon test failure).
748 REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey) == NU LL); 748 REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestR esource::kDefaultSize, 0) == NULL);
749 749
750 // Find the first resource with a scratch key and a copy of a scratch key. 750 // Find the first resource with a scratch key and a copy of a scratch key.
751 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch Key); 751 TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratch Key);
752 GrGpuResource* find = cache->findAndRefScratchResource(scratchKey); 752 GrGpuResource* find = cache->findAndRefScratchResource(scratchKey, TestResou rce::kDefaultSize, 0);
753 REPORTER_ASSERT(reporter, find != NULL); 753 REPORTER_ASSERT(reporter, find != NULL);
754 find->unref(); 754 find->unref();
755 755
756 scratchKey2 = scratchKey; 756 scratchKey2 = scratchKey;
757 find = cache->findAndRefScratchResource(scratchKey2); 757 find = cache->findAndRefScratchResource(scratchKey2, TestResource::kDefaultS ize, 0);
758 REPORTER_ASSERT(reporter, find != NULL); 758 REPORTER_ASSERT(reporter, find != NULL);
759 REPORTER_ASSERT(reporter, find == a || find == b); 759 REPORTER_ASSERT(reporter, find == a || find == b);
760 760
761 GrGpuResource* find2 = cache->findAndRefScratchResource(scratchKey2); 761 GrGpuResource* find2 = cache->findAndRefScratchResource(scratchKey2, TestRes ource::kDefaultSize, 0);
762 REPORTER_ASSERT(reporter, find2 != NULL); 762 REPORTER_ASSERT(reporter, find2 != NULL);
763 REPORTER_ASSERT(reporter, find2 == a || find2 == b); 763 REPORTER_ASSERT(reporter, find2 == a || find2 == b);
764 REPORTER_ASSERT(reporter, find2 != find); 764 REPORTER_ASSERT(reporter, find2 != find);
765 find2->unref(); 765 find2->unref();
766 find->unref(); 766 find->unref();
767 } 767 }
768 768
769 static void test_duplicate_unique_key(skiatest::Reporter* reporter) { 769 static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
770 Mock mock(5, 30000); 770 Mock mock(5, 30000);
771 GrContext* context = mock.context(); 771 GrContext* context = mock.context();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); 909 REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
910 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key3)); 910 REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key3));
911 911
912 // make b purgeable. It should be immediately deleted since it has no key. 912 // make b purgeable. It should be immediately deleted since it has no key.
913 b->unref(); 913 b->unref();
914 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); 914 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
915 915
916 // Make sure we actually get to c via it's scratch key, before we say goodby e. 916 // Make sure we actually get to c via it's scratch key, before we say goodby e.
917 GrScratchKey scratchKey; 917 GrScratchKey scratchKey;
918 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key); 918 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratch Key);
919 GrGpuResource* scratch = cache->findAndRefScratchResource(scratchKey); 919 GrGpuResource* scratch = cache->findAndRefScratchResource(scratchKey, TestRe source::kDefaultSize, 0);
920 REPORTER_ASSERT(reporter, scratch == c); 920 REPORTER_ASSERT(reporter, scratch == c);
921 SkSafeUnref(scratch); 921 SkSafeUnref(scratch);
922 922
923 // Get rid of c. 923 // Get rid of c.
924 cache->purgeAllUnlocked(); 924 cache->purgeAllUnlocked();
925 scratch = cache->findAndRefScratchResource(scratchKey); 925 scratch = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaul tSize, 0);
926 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); 926 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
927 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); 927 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
928 REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); 928 REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes());
929 REPORTER_ASSERT(reporter, !scratch); 929 REPORTER_ASSERT(reporter, !scratch);
930 SkSafeUnref(scratch); 930 SkSafeUnref(scratch);
931 } 931 }
932 932
933 static void test_cache_chained_purge(skiatest::Reporter* reporter) { 933 static void test_cache_chained_purge(skiatest::Reporter* reporter) {
934 Mock mock(3, 30000); 934 Mock mock(3, 30000);
935 GrContext* context = mock.context(); 935 GrContext* context = mock.context();
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 test_purge_invalidated(reporter); 1289 test_purge_invalidated(reporter);
1290 test_cache_chained_purge(reporter); 1290 test_cache_chained_purge(reporter);
1291 test_resource_size_changed(reporter); 1291 test_resource_size_changed(reporter);
1292 test_timestamp_wrap(reporter); 1292 test_timestamp_wrap(reporter);
1293 test_flush(reporter); 1293 test_flush(reporter);
1294 test_large_resource_count(reporter); 1294 test_large_resource_count(reporter);
1295 test_custom_data(reporter); 1295 test_custom_data(reporter);
1296 } 1296 }
1297 1297
1298 #endif 1298 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLRenderTarget.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698