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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 858123002: Add specialized content key class for resources. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove default template arg 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 static int NumAlive() { return fNumAlive; } 114 static int NumAlive() { return fNumAlive; }
115 115
116 void setUnrefWhenDestroyed(TestResource* resource) { 116 void setUnrefWhenDestroyed(TestResource* resource) {
117 SkRefCnt_SafeAssign(fToDelete, resource); 117 SkRefCnt_SafeAssign(fToDelete, resource);
118 } 118 }
119 119
120 static void ComputeScratchKey(SimulatedProperty property, GrScratchKey* key) { 120 static void ComputeScratchKey(SimulatedProperty property, GrScratchKey* key) {
121 static GrScratchKey::ResourceType t = GrScratchKey::GenerateResourceType (); 121 static GrScratchKey::ResourceType t = GrScratchKey::GenerateResourceType ();
122 GrScratchKey::Builder builder(key, t, kScratchKeyFieldCnt); 122 GrScratchKey::Builder builder(key, t, kScratchKeyFieldCnt);
123 for (size_t i = 0; i < kScratchKeyFieldCnt; ++i) { 123 for (int i = 0; i < kScratchKeyFieldCnt; ++i) {
124 builder[i] = i + static_cast<int>(property); 124 builder[i] = static_cast<uint32_t>(i + property);
125 } 125 }
126 } 126 }
127 127
128 static size_t ExpectedScratchKeySize() { 128 static size_t ExpectedScratchKeySize() {
129 return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaData Cnt); 129 return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaData Cnt);
130 } 130 }
131 131
132 private: 132 private:
133 static const size_t kScratchKeyFieldCnt = 6; 133 static const int kScratchKeyFieldCnt = 6;
134 134
135 TestResource(GrGpu* gpu, SimulatedProperty property, ScratchConstructor) 135 TestResource(GrGpu* gpu, SimulatedProperty property, ScratchConstructor)
136 : INHERITED(gpu, kCached_LifeCycle) 136 : INHERITED(gpu, kCached_LifeCycle)
137 , fToDelete(NULL) 137 , fToDelete(NULL)
138 , fSize(kDefaultSize) 138 , fSize(kDefaultSize)
139 , fProperty(property) { 139 , fProperty(property) {
140 GrScratchKey scratchKey; 140 GrScratchKey scratchKey;
141 ComputeScratchKey(fProperty, &scratchKey); 141 ComputeScratchKey(fProperty, &scratchKey);
142 this->setScratchKey(scratchKey); 142 this->setScratchKey(scratchKey);
143 ++fNumAlive; 143 ++fNumAlive;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); 202 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
203 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); 203 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
204 REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache2->getResourceBytes()); 204 REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache2->getResourceBytes());
205 205
206 b->unref(); 206 b->unref();
207 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); 207 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
208 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount()); 208 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
209 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes()); 209 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
210 } 210 }
211 211
212 // Each integer passed as a template param creates a new domain.
213 template <int> static void make_content_key(GrContentKey* key, int data) {
214 static GrContentKey::Domain d = GrContentKey::GenerateDomain();
215 GrContentKey::Builder builder(key, d, 1);
216 builder[0] = data;
217 }
218
212 static void test_budgeting(skiatest::Reporter* reporter) { 219 static void test_budgeting(skiatest::Reporter* reporter) {
213 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); 220 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
214 REPORTER_ASSERT(reporter, SkToBool(context)); 221 REPORTER_ASSERT(reporter, SkToBool(context));
215 if (NULL == context) { 222 if (NULL == context) {
216 return; 223 return;
217 } 224 }
218 context->setResourceCacheLimits(10, 300); 225 context->setResourceCacheLimits(10, 300);
219 GrResourceCache2* cache2 = context->getResourceCache2(); 226 GrResourceCache2* cache2 = context->getResourceCache2();
220 cache2->purgeAllUnlocked(); 227 cache2->purgeAllUnlocked();
221 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 228 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
222 SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgeted ResourceBytes()); 229 SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgeted ResourceBytes());
223 230
224 GrCacheID::Key keyData; 231 GrContentKey contentKey;
225 memset(&keyData, 0, sizeof(keyData)); 232 make_content_key<0>(&contentKey, 0);
226 GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0) ;
227 233
228 // Create a scratch, a content, and a wrapped resource 234 // Create a scratch, a content, and a wrapped resource
229 TestResource* scratch = 235 TestResource* scratch =
230 TestResource::CreateScratchTestResource(context->getGpu(), 236 TestResource::CreateScratchTestResource(context->getGpu(),
231 TestResource::kProperty2_Sim ulatedProperty); 237 TestResource::kProperty2_Sim ulatedProperty);
232 scratch->setSize(10); 238 scratch->setSize(10);
233 TestResource* content = SkNEW_ARGS(TestResource, (context->getGpu())); 239 TestResource* content = SkNEW_ARGS(TestResource, (context->getGpu()));
234 content->setSize(11); 240 content->setSize(11);
235 REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey)); 241 REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey));
236 TestResource* wrapped = SkNEW_ARGS(TestResource, 242 TestResource* wrapped = SkNEW_ARGS(TestResource,
237 (context->getGpu(), GrGpuResource::kWrapp ed_LifeCycle)); 243 (context->getGpu(), GrGpuResource::kWrapp ed_LifeCycle));
238 wrapped->setSize(12); 244 wrapped->setSize(12);
239 TestResource* unbudgeted = SkNEW_ARGS(TestResource, 245 TestResource* unbudgeted = SkNEW_ARGS(TestResource,
240 (context->getGpu(), GrGpuResource::kUn cached_LifeCycle)); 246 (context->getGpu(), GrGpuResource::kUn cached_LifeCycle));
241 unbudgeted->setSize(13); 247 unbudgeted->setSize(13);
242 248
243 // Make sure we can't add a content key to the wrapped resource 249 // Make sure we can't add a content key to the wrapped resource
244 keyData.fData8[0] = 1; 250 GrContentKey contentKey2;
245 GrResourceKey contentKey2(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0 ); 251 make_content_key<0>(&contentKey2, 1);
246 REPORTER_ASSERT(reporter, !wrapped->cacheAccess().setContentKey(contentKey2) ); 252 REPORTER_ASSERT(reporter, !wrapped->cacheAccess().setContentKey(contentKey2) );
247 REPORTER_ASSERT(reporter, NULL == cache2->findAndRefContentResource(contentK ey2)); 253 REPORTER_ASSERT(reporter, NULL == cache2->findAndRefContentResource(contentK ey2));
248 254
249 // Make sure sizes are as we expect 255 // Make sure sizes are as we expect
250 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount()); 256 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount());
251 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) + 257 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) +
252 wrapped->gpuMemorySize() + unbudgeted->gpuMemorySi ze() == 258 wrapped->gpuMemorySize() + unbudgeted->gpuMemorySi ze() ==
253 cache2->getResourceBytes()); 259 cache2->getResourceBytes());
254 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount()); 260 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
255 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) == 261 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) ==
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 REPORTER_ASSERT(reporter, SkToBool(context)); 314 REPORTER_ASSERT(reporter, SkToBool(context));
309 if (NULL == context) { 315 if (NULL == context) {
310 return; 316 return;
311 } 317 }
312 context->setResourceCacheLimits(10, 300); 318 context->setResourceCacheLimits(10, 300);
313 GrResourceCache2* cache2 = context->getResourceCache2(); 319 GrResourceCache2* cache2 = context->getResourceCache2();
314 cache2->purgeAllUnlocked(); 320 cache2->purgeAllUnlocked();
315 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 321 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
316 SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgeted ResourceBytes()); 322 SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgeted ResourceBytes());
317 323
318 GrCacheID::Key keyData; 324 GrContentKey contentKey;
319 memset(&keyData, 0, sizeof(keyData)); 325 make_content_key<0>(&contentKey, 0);
320 GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), 0) ;
321 326
322 TestResource* scratch; 327 TestResource* scratch;
323 TestResource* content; 328 TestResource* content;
324 TestResource* wrapped; 329 TestResource* wrapped;
325 TestResource* unbudgeted; 330 TestResource* unbudgeted;
326 331
327 // A large uncached or wrapped resource shouldn't evict anything. 332 // A large uncached or wrapped resource shouldn't evict anything.
328 scratch = TestResource::CreateScratchTestResource(context->getGpu(), 333 scratch = TestResource::CreateScratchTestResource(context->getGpu(),
329 TestResource::kProperty2_S imulatedProperty); 334 TestResource::kProperty2_S imulatedProperty);
330 scratch->setSize(10); 335 scratch->setSize(10);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); 574 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
570 REPORTER_ASSERT(reporter, SkToBool(context)); 575 REPORTER_ASSERT(reporter, SkToBool(context));
571 if (NULL == context) { 576 if (NULL == context) {
572 return; 577 return;
573 } 578 }
574 context->setResourceCacheLimits(5, 30000); 579 context->setResourceCacheLimits(5, 30000);
575 GrResourceCache2* cache2 = context->getResourceCache2(); 580 GrResourceCache2* cache2 = context->getResourceCache2();
576 cache2->purgeAllUnlocked(); 581 cache2->purgeAllUnlocked();
577 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 582 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
578 583
579 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); 584 GrContentKey key;
580 GrCacheID::Key keyData; 585 make_content_key<0>(&key, 0);
581 memset(&keyData, 0, sizeof(keyData));
582 GrResourceKey key(GrCacheID(domain, keyData), 0);
583 586
584 // Create two resources that we will attempt to register with the same conte nt key. 587 // Create two resources that we will attempt to register with the same conte nt key.
585 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); 588 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
586 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); 589 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
587 a->setSize(11); 590 a->setSize(11);
588 b->setSize(12); 591 b->setSize(12);
589 592
590 // Can't set the same content key on two resources. 593 // Can't set the same content key on two resources.
591 REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key)); 594 REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key));
592 REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key)); 595 REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key));
(...skipping 27 matching lines...) Expand all
620 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); 623 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
621 } 624 }
622 625
623 static void test_purge_invalidated(skiatest::Reporter* reporter) { 626 static void test_purge_invalidated(skiatest::Reporter* reporter) {
624 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); 627 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
625 REPORTER_ASSERT(reporter, SkToBool(context)); 628 REPORTER_ASSERT(reporter, SkToBool(context));
626 if (NULL == context) { 629 if (NULL == context) {
627 return; 630 return;
628 } 631 }
629 632
630 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); 633 GrContentKey key1, key2, key3;
631 GrCacheID::Key keyData; 634 make_content_key<0>(&key1, 1);
632 memset(&keyData, 0, sizeof(keyData)); 635 make_content_key<0>(&key2, 2);
633 636 make_content_key<0>(&key3, 3);
634 keyData.fData64[0] = 1;
635 GrResourceKey key1(GrCacheID(domain, keyData), 0);
636 keyData.fData64[0] = 2;
637 GrResourceKey key2(GrCacheID(domain, keyData), 0);
638 keyData.fData64[0] = 3;
639 GrResourceKey key3(GrCacheID(domain, keyData), 0);
640 637
641 context->setResourceCacheLimits(5, 30000); 638 context->setResourceCacheLimits(5, 30000);
642 GrResourceCache2* cache2 = context->getResourceCache2(); 639 GrResourceCache2* cache2 = context->getResourceCache2();
643 cache2->purgeAllUnlocked(); 640 cache2->purgeAllUnlocked();
644 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 641 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
645 642
646 // Add three resources to the cache. 643 // Add three resources to the cache.
647 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); 644 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
648 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); 645 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
649 TestResource* c = SkNEW_ARGS(TestResource, (context->getGpu())); 646 TestResource* c = SkNEW_ARGS(TestResource, (context->getGpu()));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes()); 684 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
688 } 685 }
689 686
690 static void test_cache_chained_purge(skiatest::Reporter* reporter) { 687 static void test_cache_chained_purge(skiatest::Reporter* reporter) {
691 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); 688 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
692 REPORTER_ASSERT(reporter, SkToBool(context)); 689 REPORTER_ASSERT(reporter, SkToBool(context));
693 if (NULL == context) { 690 if (NULL == context) {
694 return; 691 return;
695 } 692 }
696 693
697 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); 694 GrContentKey key1, key2;
698 GrCacheID::Key keyData; 695 make_content_key<0>(&key1, 1);
699 memset(&keyData, 0, sizeof(keyData)); 696 make_content_key<0>(&key2, 2);
700
701 keyData.fData64[0] = 1;
702 GrResourceKey key1(GrCacheID(domain, keyData), 0);
703
704 keyData.fData64[0] = 2;
705 GrResourceKey key2(GrCacheID(domain, keyData), 0);
706 697
707 { 698 {
708 context->setResourceCacheLimits(3, 30000); 699 context->setResourceCacheLimits(3, 30000);
709 GrResourceCache2* cache2 = context->getResourceCache2(); 700 GrResourceCache2* cache2 = context->getResourceCache2();
710 cache2->purgeAllUnlocked(); 701 cache2->purgeAllUnlocked();
711 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s()); 702 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s());
712 703
713 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); 704 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
714 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); 705 TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu()));
715 a->cacheAccess().setContentKey(key1); 706 a->cacheAccess().setContentKey(key1);
(...skipping 22 matching lines...) Expand all
738 } 729 }
739 } 730 }
740 731
741 static void test_resource_size_changed(skiatest::Reporter* reporter) { 732 static void test_resource_size_changed(skiatest::Reporter* reporter) {
742 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); 733 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
743 REPORTER_ASSERT(reporter, SkToBool(context)); 734 REPORTER_ASSERT(reporter, SkToBool(context));
744 if (NULL == context) { 735 if (NULL == context) {
745 return; 736 return;
746 } 737 }
747 738
748 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); 739 GrContentKey key1, key2;
749 740 make_content_key<0>(&key1, 1);
750 GrCacheID::Key key1Data; 741 make_content_key<0>(&key2, 2);
751 key1Data.fData64[0] = 0;
752 key1Data.fData64[1] = 0;
753 GrResourceKey key1(GrCacheID(domain, key1Data), 0);
754
755 GrCacheID::Key key2Data;
756 key2Data.fData64[0] = 1;
757 key2Data.fData64[1] = 0;
758 GrResourceKey key2(GrCacheID(domain, key2Data), 0);
759 742
760 // Test changing resources sizes (both increase & decrease). 743 // Test changing resources sizes (both increase & decrease).
761 { 744 {
762 context->setResourceCacheLimits(3, 30000); 745 context->setResourceCacheLimits(3, 30000);
763 GrResourceCache2* cache2 = context->getResourceCache2(); 746 GrResourceCache2* cache2 = context->getResourceCache2();
764 cache2->purgeAllUnlocked(); 747 cache2->purgeAllUnlocked();
765 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s()); 748 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s());
766 749
767 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); 750 TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu()));
768 a->cacheAccess().setContentKey(key1); 751 a->cacheAccess().setContentKey(key1);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 808
826 static const int kResourceCnt = 2000; 809 static const int kResourceCnt = 2000;
827 // Set the cache size to double the resource count because we're going to cr eate 2x that number 810 // Set the cache size to double the resource count because we're going to cr eate 2x that number
828 // resources, using two different key domains. Add a little slop to the byte s because we resize 811 // resources, using two different key domains. Add a little slop to the byte s because we resize
829 // down to 1 byte after creating the resource. 812 // down to 1 byte after creating the resource.
830 context->setResourceCacheLimits(2 * kResourceCnt, 2 * kResourceCnt + 1000); 813 context->setResourceCacheLimits(2 * kResourceCnt, 2 * kResourceCnt + 1000);
831 GrResourceCache2* cache2 = context->getResourceCache2(); 814 GrResourceCache2* cache2 = context->getResourceCache2();
832 cache2->purgeAllUnlocked(); 815 cache2->purgeAllUnlocked();
833 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 816 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
834 817
835 GrCacheID::Domain domain0 = GrCacheID::GenerateDomain();
836 GrCacheID::Domain domain1 = GrCacheID::GenerateDomain();
837
838 GrCacheID::Key keyData;
839 memset(&keyData, 0, sizeof(keyData));
840 818
841 for (int i = 0; i < kResourceCnt; ++i) { 819 for (int i = 0; i < kResourceCnt; ++i) {
820 GrContentKey key1, key2;
821 make_content_key<1>(&key1, i);
822 make_content_key<2>(&key2, i);
823
842 TestResource* resource; 824 TestResource* resource;
843 keyData.fData32[0] = i;
844 825
845 GrResourceKey key0(GrCacheID(domain0, keyData), 0);
846 resource = SkNEW_ARGS(TestResource, (context->getGpu()));
847 resource->cacheAccess().setContentKey(key0);
848 resource->setSize(1);
849 resource->unref();
850
851 GrResourceKey key1(GrCacheID(domain1, keyData), 0);
852 resource = SkNEW_ARGS(TestResource, (context->getGpu())); 826 resource = SkNEW_ARGS(TestResource, (context->getGpu()));
853 resource->cacheAccess().setContentKey(key1); 827 resource->cacheAccess().setContentKey(key1);
854 resource->setSize(1); 828 resource->setSize(1);
855 resource->unref(); 829 resource->unref();
830
831 resource = SkNEW_ARGS(TestResource, (context->getGpu()));
832 resource->cacheAccess().setContentKey(key2);
833 resource->setSize(1);
834 resource->unref();
856 } 835 }
857 836
858 REPORTER_ASSERT(reporter, TestResource::NumAlive() == 2 * kResourceCnt); 837 REPORTER_ASSERT(reporter, TestResource::NumAlive() == 2 * kResourceCnt);
859 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 2 * kResourc eCnt); 838 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 2 * kResourc eCnt);
860 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 2 * kResourc eCnt); 839 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 2 * kResourc eCnt);
861 REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 2 * kResourceCnt); 840 REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 2 * kResourceCnt);
862 REPORTER_ASSERT(reporter, cache2->getResourceCount() == 2 * kResourceCnt); 841 REPORTER_ASSERT(reporter, cache2->getResourceCount() == 2 * kResourceCnt);
863 for (int i = 0; i < kResourceCnt; ++i) { 842 for (int i = 0; i < kResourceCnt; ++i) {
864 keyData.fData32[0] = i; 843 GrContentKey key1, key2;
865 GrResourceKey key0(GrCacheID(domain0, keyData), 0); 844 make_content_key<1>(&key1, i);
866 REPORTER_ASSERT(reporter, cache2->hasContentKey(key0)); 845 make_content_key<2>(&key2, i);
867 GrResourceKey key1(GrCacheID(domain0, keyData), 0); 846
868 REPORTER_ASSERT(reporter, cache2->hasContentKey(key1)); 847 REPORTER_ASSERT(reporter, cache2->hasContentKey(key1));
848 REPORTER_ASSERT(reporter, cache2->hasContentKey(key2));
869 } 849 }
870 850
871 cache2->purgeAllUnlocked(); 851 cache2->purgeAllUnlocked();
872 REPORTER_ASSERT(reporter, TestResource::NumAlive() == 0); 852 REPORTER_ASSERT(reporter, TestResource::NumAlive() == 0);
873 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 0); 853 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 0);
874 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 0); 854 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 0);
875 REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 0); 855 REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 0);
876 REPORTER_ASSERT(reporter, cache2->getResourceCount() == 0); 856 REPORTER_ASSERT(reporter, cache2->getResourceCount() == 0);
877 857
878 for (int i = 0; i < kResourceCnt; ++i) { 858 for (int i = 0; i < kResourceCnt; ++i) {
879 keyData.fData32[0] = i; 859 GrContentKey key1, key2;
880 GrResourceKey key0(GrCacheID(domain0, keyData), 0); 860 make_content_key<1>(&key1, i);
881 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key0)); 861 make_content_key<2>(&key2, i);
882 GrResourceKey key1(GrCacheID(domain0, keyData), 0); 862
883 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1)); 863 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1));
864 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key2));
884 } 865 }
885 } 866 }
886 867
887 868
888 //////////////////////////////////////////////////////////////////////////////// 869 ////////////////////////////////////////////////////////////////////////////////
889 DEF_GPUTEST(ResourceCache, reporter, factory) { 870 DEF_GPUTEST(ResourceCache, reporter, factory) {
890 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { 871 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
891 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type); 872 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type);
892 if (!GrContextFactory::IsRenderingGLContext(glType)) { 873 if (!GrContextFactory::IsRenderingGLContext(glType)) {
893 continue; 874 continue;
(...skipping 21 matching lines...) Expand all
915 test_duplicate_scratch_key(reporter); 896 test_duplicate_scratch_key(reporter);
916 test_remove_scratch_key(reporter); 897 test_remove_scratch_key(reporter);
917 test_scratch_key_consistency(reporter); 898 test_scratch_key_consistency(reporter);
918 test_purge_invalidated(reporter); 899 test_purge_invalidated(reporter);
919 test_cache_chained_purge(reporter); 900 test_cache_chained_purge(reporter);
920 test_resource_size_changed(reporter); 901 test_resource_size_changed(reporter);
921 test_large_resource_count(reporter); 902 test_large_resource_count(reporter);
922 } 903 }
923 904
924 #endif 905 #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