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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 1782973002: Revert of Use std::unique_ptr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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/PictureTest.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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 if (bigRT && bigRT->asRenderTarget()) { 129 if (bigRT && bigRT->asRenderTarget()) {
130 resourceProvider->attachStencilAttachment(bigRT->asRenderTarget()); 130 resourceProvider->attachStencilAttachment(bigRT->asRenderTarget());
131 } 131 }
132 REPORTER_ASSERT(reporter, 132 REPORTER_ASSERT(reporter,
133 smallRT0 && bigRT && 133 smallRT0 && bigRT &&
134 smallRT0->asRenderTarget() && bigRT->asRenderTarget() && 134 smallRT0->asRenderTarget() && bigRT->asRenderTarget() &&
135 resourceProvider->attachStencilAttachment(smallRT0->asRender Target()) != 135 resourceProvider->attachStencilAttachment(smallRT0->asRender Target()) !=
136 resourceProvider->attachStencilAttachment(bigRT->asRenderTar get())); 136 resourceProvider->attachStencilAttachment(bigRT->asRenderTar get()));
137 137
138 if (context->caps()->maxSampleCount() >= 4) { 138 if (context->caps()->maxSampleCount() >= 4) {
139 // An RT with a different sample count should not share. 139 // An RT with a different sample count should not share.
140 GrSurfaceDesc smallMSAADesc = smallDesc; 140 GrSurfaceDesc smallMSAADesc = smallDesc;
141 smallMSAADesc.fSampleCnt = 4; 141 smallMSAADesc.fSampleCnt = 4;
142 SkAutoTUnref<GrTexture> smallMSAART0(cache->createTexture(smallMSAADesc, SkBudgeted::kNo)); 142 SkAutoTUnref<GrTexture> smallMSAART0(cache->createTexture(smallMSAADesc, SkBudgeted::kNo));
143 if (smallMSAART0 && smallMSAART0->asRenderTarget()) { 143 if (smallMSAART0 && smallMSAART0->asRenderTarget()) {
144 resourceProvider->attachStencilAttachment(smallMSAART0->asRenderTarg et()); 144 resourceProvider->attachStencilAttachment(smallMSAART0->asRenderTarg et());
145 } 145 }
146 #ifdef SK_BUILD_FOR_ANDROID 146 #ifdef SK_BUILD_FOR_ANDROID
147 if (!smallMSAART0) { 147 if (!smallMSAART0) {
148 // The nexus player seems to fail to create MSAA textures. 148 // The nexus player seems to fail to create MSAA textures.
149 return; 149 return;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 desc.fHeight = kH; 209 desc.fHeight = kH;
210 210
211 desc.fTextureHandle = texHandles[0]; 211 desc.fTextureHandle = texHandles[0];
212 SkAutoTUnref<GrTexture> borrowed(context->textureProvider()->wrapBackendText ure( 212 SkAutoTUnref<GrTexture> borrowed(context->textureProvider()->wrapBackendText ure(
213 desc, kBorrow_GrWrapOwnership)); 213 desc, kBorrow_GrWrapOwnership));
214 214
215 desc.fTextureHandle = texHandles[1]; 215 desc.fTextureHandle = texHandles[1];
216 SkAutoTUnref<GrTexture> adopted(context->textureProvider()->wrapBackendTextu re( 216 SkAutoTUnref<GrTexture> adopted(context->textureProvider()->wrapBackendTextu re(
217 desc, kAdopt_GrWrapOwnership)); 217 desc, kAdopt_GrWrapOwnership));
218 218
219 REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr); 219 REPORTER_ASSERT(reporter, SkToBool(borrowed) && SkToBool(adopted));
220 if (!borrowed || !adopted) { 220 if (!SkToBool(borrowed) || !SkToBool(adopted)) {
221 return; 221 return;
222 } 222 }
223 223
224 borrowed.reset(nullptr); 224 borrowed.reset(nullptr);
225 adopted.reset(nullptr); 225 adopted.reset(nullptr);
226 226
227 context->flush(); 227 context->flush();
228 228
229 bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[0]); 229 bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[0]);
230 bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[1]); 230 bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[1]);
231 231
232 REPORTER_ASSERT(reporter, borrowedIsAlive); 232 REPORTER_ASSERT(reporter, borrowedIsAlive);
233 REPORTER_ASSERT(reporter, !adoptedIsAlive); 233 REPORTER_ASSERT(reporter, !adoptedIsAlive);
234 234
235 gpu->deleteTestingOnlyBackendTexture(texHandles[0], !borrowedIsAlive); 235 gpu->deleteTestingOnlyBackendTexture(texHandles[0], !borrowedIsAlive);
236 gpu->deleteTestingOnlyBackendTexture(texHandles[1], !adoptedIsAlive); 236 gpu->deleteTestingOnlyBackendTexture(texHandles[1], !adoptedIsAlive);
237 237
238 context->resetContext(); 238 context->resetContext();
239 } 239 }
240 240
241 class TestResource : public GrGpuResource { 241 class TestResource : public GrGpuResource {
242 enum ScratchConstructor { kScratchConstructor }; 242 enum ScratchConstructor { kScratchConstructor };
243 public: 243 public:
244 static const size_t kDefaultSize = 100; 244 static const size_t kDefaultSize = 100;
245 245
246 /** Property that distinctly categorizes the resource. 246 /** Property that distinctly categorizes the resource.
247 * For example, textures have width, height, ... */ 247 * For example, textures have width, height, ... */
248 enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty }; 248 enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty };
249 249
250 TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle) 250 TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle)
251 : INHERITED(gpu, lifeCycle) 251 : INHERITED(gpu, lifeCycle)
252 , fToDelete(nullptr) 252 , fToDelete(nullptr)
253 , fSize(size) 253 , fSize(size)
254 , fProperty(kA_SimulatedProperty) { 254 , fProperty(kA_SimulatedProperty) {
255 ++fNumAlive; 255 ++fNumAlive;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); 583 REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
584 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); 584 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
585 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()); 585 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes());
586 resource = static_cast<TestResource*>(cache->findAndRefScratchResource(k ey, TestResource::kDefaultSize, 0)); 586 resource = static_cast<TestResource*>(cache->findAndRefScratchResource(k ey, TestResource::kDefaultSize, 0));
587 REPORTER_ASSERT(reporter, resource); 587 REPORTER_ASSERT(reporter, resource);
588 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y); 588 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y);
589 REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch()); 589 REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch());
590 REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().i sBudgeted()); 590 REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().i sBudgeted());
591 591
592 if (0 == i) { 592 if (0 == i) {
593 // If made unbudgeted, it should return to original state: ref'ed an d unbudgeted. Try 593 // If made unbudgeted, it should return to original state: ref'ed an d unbudgeted. Try
594 // the above tests again. 594 // the above tests again.
595 resource->resourcePriv().makeUnbudgeted(); 595 resource->resourcePriv().makeUnbudgeted();
596 } else { 596 } else {
597 // After the second time around, try removing the scratch key 597 // After the second time around, try removing the scratch key
598 resource->resourcePriv().removeScratchKey(); 598 resource->resourcePriv().removeScratchKey();
599 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 599 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
600 REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); 600 REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
601 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); 601 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
602 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()) ; 602 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()) ;
603 REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey(). isValid()); 603 REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey(). isValid());
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 find->unref(); 777 find->unref();
778 } 778 }
779 779
780 static void test_duplicate_unique_key(skiatest::Reporter* reporter) { 780 static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
781 Mock mock(5, 30000); 781 Mock mock(5, 30000);
782 GrContext* context = mock.context(); 782 GrContext* context = mock.context();
783 GrResourceCache* cache = mock.cache(); 783 GrResourceCache* cache = mock.cache();
784 784
785 GrUniqueKey key; 785 GrUniqueKey key;
786 make_unique_key<0>(&key, 0); 786 make_unique_key<0>(&key, 0);
787 787
788 // Create two resources that we will attempt to register with the same uniqu e key. 788 // Create two resources that we will attempt to register with the same uniqu e key.
789 TestResource* a = new TestResource(context->getGpu()); 789 TestResource* a = new TestResource(context->getGpu());
790 a->setSize(11); 790 a->setSize(11);
791 791
792 // Set key on resource a. 792 // Set key on resource a.
793 a->resourcePriv().setUniqueKey(key); 793 a->resourcePriv().setUniqueKey(key);
794 REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key)); 794 REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key));
795 a->unref(); 795 a->unref();
796 796
797 // Make sure that redundantly setting a's key works. 797 // Make sure that redundantly setting a's key works.
798 a->resourcePriv().setUniqueKey(key); 798 a->resourcePriv().setUniqueKey(key);
799 REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key)); 799 REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key));
800 a->unref(); 800 a->unref();
801 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 801 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 875
876 static void test_purge_invalidated(skiatest::Reporter* reporter) { 876 static void test_purge_invalidated(skiatest::Reporter* reporter) {
877 Mock mock(5, 30000); 877 Mock mock(5, 30000);
878 GrContext* context = mock.context(); 878 GrContext* context = mock.context();
879 GrResourceCache* cache = mock.cache(); 879 GrResourceCache* cache = mock.cache();
880 880
881 GrUniqueKey key1, key2, key3; 881 GrUniqueKey key1, key2, key3;
882 make_unique_key<0>(&key1, 1); 882 make_unique_key<0>(&key1, 1);
883 make_unique_key<0>(&key2, 2); 883 make_unique_key<0>(&key2, 2);
884 make_unique_key<0>(&key3, 3); 884 make_unique_key<0>(&key3, 3);
885 885
886 // Add three resources to the cache. Only c is usable as scratch. 886 // Add three resources to the cache. Only c is usable as scratch.
887 TestResource* a = new TestResource(context->getGpu()); 887 TestResource* a = new TestResource(context->getGpu());
888 TestResource* b = new TestResource(context->getGpu()); 888 TestResource* b = new TestResource(context->getGpu());
889 TestResource* c = TestResource::CreateScratch(context->getGpu(), 889 TestResource* c = TestResource::CreateScratch(context->getGpu(),
890 TestResource::kA_SimulatedProp erty); 890 TestResource::kA_SimulatedProp erty);
891 a->resourcePriv().setUniqueKey(key1); 891 a->resourcePriv().setUniqueKey(key1);
892 b->resourcePriv().setUniqueKey(key2); 892 b->resourcePriv().setUniqueKey(key2);
893 c->resourcePriv().setUniqueKey(key3); 893 c->resourcePriv().setUniqueKey(key3);
894 a->unref(); 894 a->unref();
895 // hold b until *after* the message is sent. 895 // hold b until *after* the message is sent.
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 test_cache_chained_purge(reporter); 1309 test_cache_chained_purge(reporter);
1310 test_resource_size_changed(reporter); 1310 test_resource_size_changed(reporter);
1311 test_timestamp_wrap(reporter); 1311 test_timestamp_wrap(reporter);
1312 test_flush(reporter); 1312 test_flush(reporter);
1313 test_large_resource_count(reporter); 1313 test_large_resource_count(reporter);
1314 test_custom_data(reporter); 1314 test_custom_data(reporter);
1315 test_abandoned(reporter); 1315 test_abandoned(reporter);
1316 } 1316 }
1317 1317
1318 #endif 1318 #endif
OLDNEW
« no previous file with comments | « tests/PictureTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698