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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 1734043002: Revert of Move Budgeted enum out of SkSurface, use in GrTextureProvider (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/RectangleTextureTest.cpp ('k') | tests/SRGBReadWritePixelsTest.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 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
33 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, context) { 33 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, context) {
34 GrSurfaceDesc desc; 34 GrSurfaceDesc desc;
35 desc.fConfig = kSkia8888_GrPixelConfig; 35 desc.fConfig = kSkia8888_GrPixelConfig;
36 desc.fFlags = kRenderTarget_GrSurfaceFlag; 36 desc.fFlags = kRenderTarget_GrSurfaceFlag;
37 desc.fWidth = gWidth; 37 desc.fWidth = gWidth;
38 desc.fHeight = gHeight; 38 desc.fHeight = gHeight;
39 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); 39 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight);
40 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, 40 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context,
41 SkBudgeted::kNo, info)); 41 SkSurface::kNo_Bu dgeted, info));
42 SkCanvas* canvas = surface->getCanvas(); 42 SkCanvas* canvas = surface->getCanvas();
43 43
44 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); 44 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight);
45 45
46 SkBitmap src; 46 SkBitmap src;
47 src.allocN32Pixels(size.width(), size.height()); 47 src.allocN32Pixels(size.width(), size.height());
48 src.eraseColor(SK_ColorBLACK); 48 src.eraseColor(SK_ColorBLACK);
49 size_t srcSize = src.getSize(); 49 size_t srcSize = src.getSize();
50 50
51 size_t initialCacheSize; 51 size_t initialCacheSize;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 GrSurfaceDesc smallDesc; 84 GrSurfaceDesc smallDesc;
85 smallDesc.fFlags = kRenderTarget_GrSurfaceFlag; 85 smallDesc.fFlags = kRenderTarget_GrSurfaceFlag;
86 smallDesc.fConfig = kSkia8888_GrPixelConfig; 86 smallDesc.fConfig = kSkia8888_GrPixelConfig;
87 smallDesc.fWidth = 4; 87 smallDesc.fWidth = 4;
88 smallDesc.fHeight = 4; 88 smallDesc.fHeight = 4;
89 smallDesc.fSampleCnt = 0; 89 smallDesc.fSampleCnt = 0;
90 90
91 GrTextureProvider* cache = context->textureProvider(); 91 GrTextureProvider* cache = context->textureProvider();
92 GrResourceProvider* resourceProvider = context->resourceProvider(); 92 GrResourceProvider* resourceProvider = context->resourceProvider();
93 // Test that two budgeted RTs with the same desc share a stencil buffer. 93 // Test that two budgeted RTs with the same desc share a stencil buffer.
94 SkAutoTUnref<GrTexture> smallRT0(cache->createTexture(smallDesc, SkBudgeted: :kYes)); 94 SkAutoTUnref<GrTexture> smallRT0(cache->createTexture(smallDesc, true));
95 if (smallRT0 && smallRT0->asRenderTarget()) { 95 if (smallRT0 && smallRT0->asRenderTarget()) {
96 resourceProvider->attachStencilAttachment(smallRT0->asRenderTarget()); 96 resourceProvider->attachStencilAttachment(smallRT0->asRenderTarget());
97 } 97 }
98 98
99 SkAutoTUnref<GrTexture> smallRT1(cache->createTexture(smallDesc, SkBudgeted: :kYes)); 99 SkAutoTUnref<GrTexture> smallRT1(cache->createTexture(smallDesc, true));
100 if (smallRT1 && smallRT1->asRenderTarget()) { 100 if (smallRT1 && smallRT1->asRenderTarget()) {
101 resourceProvider->attachStencilAttachment(smallRT1->asRenderTarget()); 101 resourceProvider->attachStencilAttachment(smallRT1->asRenderTarget());
102 } 102 }
103 103
104 REPORTER_ASSERT(reporter, 104 REPORTER_ASSERT(reporter,
105 smallRT0 && smallRT1 && 105 smallRT0 && smallRT1 &&
106 smallRT0->asRenderTarget() && smallRT1->asRenderTarget() && 106 smallRT0->asRenderTarget() && smallRT1->asRenderTarget() &&
107 resourceProvider->attachStencilAttachment(smallRT0->asRender Target()) == 107 resourceProvider->attachStencilAttachment(smallRT0->asRender Target()) ==
108 resourceProvider->attachStencilAttachment(smallRT1->asRender Target())); 108 resourceProvider->attachStencilAttachment(smallRT1->asRender Target()));
109 109
110 // An unbudgeted RT with the same desc should also share. 110 // An unbudgeted RT with the same desc should also share.
111 SkAutoTUnref<GrTexture> smallRT2(cache->createTexture(smallDesc, SkBudgeted: :kNo)); 111 SkAutoTUnref<GrTexture> smallRT2(cache->createTexture(smallDesc, false));
112 if (smallRT2 && smallRT2->asRenderTarget()) { 112 if (smallRT2 && smallRT2->asRenderTarget()) {
113 resourceProvider->attachStencilAttachment(smallRT2->asRenderTarget()); 113 resourceProvider->attachStencilAttachment(smallRT2->asRenderTarget());
114 } 114 }
115 REPORTER_ASSERT(reporter, 115 REPORTER_ASSERT(reporter,
116 smallRT0 && smallRT2 && 116 smallRT0 && smallRT2 &&
117 smallRT0->asRenderTarget() && smallRT2->asRenderTarget() && 117 smallRT0->asRenderTarget() && smallRT2->asRenderTarget() &&
118 resourceProvider->attachStencilAttachment(smallRT0->asRender Target()) == 118 resourceProvider->attachStencilAttachment(smallRT0->asRender Target()) ==
119 resourceProvider->attachStencilAttachment(smallRT2->asRender Target())); 119 resourceProvider->attachStencilAttachment(smallRT2->asRender Target()));
120 120
121 // An RT with a much larger size should not share. 121 // An RT with a much larger size should not share.
122 GrSurfaceDesc bigDesc; 122 GrSurfaceDesc bigDesc;
123 bigDesc.fFlags = kRenderTarget_GrSurfaceFlag; 123 bigDesc.fFlags = kRenderTarget_GrSurfaceFlag;
124 bigDesc.fConfig = kSkia8888_GrPixelConfig; 124 bigDesc.fConfig = kSkia8888_GrPixelConfig;
125 bigDesc.fWidth = 400; 125 bigDesc.fWidth = 400;
126 bigDesc.fHeight = 200; 126 bigDesc.fHeight = 200;
127 bigDesc.fSampleCnt = 0; 127 bigDesc.fSampleCnt = 0;
128 SkAutoTUnref<GrTexture> bigRT(cache->createTexture(bigDesc, SkBudgeted::kNo) ); 128 SkAutoTUnref<GrTexture> bigRT(cache->createTexture(bigDesc, false));
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, false));
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;
150 } 150 }
151 #endif 151 #endif
152 REPORTER_ASSERT(reporter, 152 REPORTER_ASSERT(reporter,
153 smallRT0 && smallMSAART0 && 153 smallRT0 && smallMSAART0 &&
154 smallRT0->asRenderTarget() && smallMSAART0->asRenderTarg et() && 154 smallRT0->asRenderTarget() && smallMSAART0->asRenderTarg et() &&
155 resourceProvider->attachStencilAttachment(smallRT0->asRe nderTarget()) != 155 resourceProvider->attachStencilAttachment(smallRT0->asRe nderTarget()) !=
156 resourceProvider->attachStencilAttachment(smallMSAART0-> asRenderTarget())); 156 resourceProvider->attachStencilAttachment(smallMSAART0-> asRenderTarget()));
157 // A second MSAA RT should share with the first MSAA RT. 157 // A second MSAA RT should share with the first MSAA RT.
158 SkAutoTUnref<GrTexture> smallMSAART1(cache->createTexture(smallMSAADesc, SkBudgeted::kNo)); 158 SkAutoTUnref<GrTexture> smallMSAART1(cache->createTexture(smallMSAADesc, false));
159 if (smallMSAART1 && smallMSAART1->asRenderTarget()) { 159 if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
160 resourceProvider->attachStencilAttachment(smallMSAART1->asRenderTarg et()); 160 resourceProvider->attachStencilAttachment(smallMSAART1->asRenderTarg et());
161 } 161 }
162 REPORTER_ASSERT(reporter, 162 REPORTER_ASSERT(reporter,
163 smallMSAART0 && smallMSAART1 && 163 smallMSAART0 && smallMSAART1 &&
164 smallMSAART0->asRenderTarget() && 164 smallMSAART0->asRenderTarget() &&
165 smallMSAART1->asRenderTarget() && 165 smallMSAART1->asRenderTarget() &&
166 resourceProvider->attachStencilAttachment(smallMSAART0-> asRenderTarget()) == 166 resourceProvider->attachStencilAttachment(smallMSAART0-> asRenderTarget()) ==
167 resourceProvider->attachStencilAttachment(smallMSAART1-> asRenderTarget())); 167 resourceProvider->attachStencilAttachment(smallMSAART1-> asRenderTarget()));
168 // But not one with a larger sample count should not. (Also check that t he request for 4 168 // But not one with a larger sample count should not. (Also check that t he request for 4
169 // samples didn't get rounded up to >= 8 or else they could share.). 169 // samples didn't get rounded up to >= 8 or else they could share.).
170 if (context->caps()->maxSampleCount() >= 8 && 170 if (context->caps()->maxSampleCount() >= 8 &&
171 smallMSAART0 && smallMSAART0->asRenderTarget() && 171 smallMSAART0 && smallMSAART0->asRenderTarget() &&
172 smallMSAART0->asRenderTarget()->numColorSamples() < 8) { 172 smallMSAART0->asRenderTarget()->numColorSamples() < 8) {
173 smallMSAADesc.fSampleCnt = 8; 173 smallMSAADesc.fSampleCnt = 8;
174 smallMSAART1.reset(cache->createTexture(smallMSAADesc, SkBudgeted::k No)); 174 smallMSAART1.reset(cache->createTexture(smallMSAADesc, false));
175 SkAutoTUnref<GrTexture> smallMSAART1( 175 SkAutoTUnref<GrTexture> smallMSAART1(cache->createTexture(smallMSAAD esc, false));
176 cache->createTexture(smallMSAADesc, SkBudgeted::kNo));
177 if (smallMSAART1 && smallMSAART1->asRenderTarget()) { 176 if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
178 resourceProvider->attachStencilAttachment(smallMSAART1->asRender Target()); 177 resourceProvider->attachStencilAttachment(smallMSAART1->asRender Target());
179 } 178 }
180 REPORTER_ASSERT(reporter, 179 REPORTER_ASSERT(reporter,
181 smallMSAART0 && smallMSAART1 && 180 smallMSAART0 && smallMSAART1 &&
182 smallMSAART0->asRenderTarget() && 181 smallMSAART0->asRenderTarget() &&
183 smallMSAART1->asRenderTarget() && 182 smallMSAART1->asRenderTarget() &&
184 resourceProvider->attachStencilAttachment(smallMSAART0-> asRenderTarget()) != 183 resourceProvider->attachStencilAttachment(smallMSAART0-> asRenderTarget()) !=
185 resourceProvider->attachStencilAttachment(smallMSAART1-> asRenderTarget())); 184 resourceProvider->attachStencilAttachment(smallMSAART1-> asRenderTarget()));
186 } 185 }
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 TestResource* resource = 562 TestResource* resource =
564 TestResource::CreateScratch(context->getGpu(), TestResource::kA_Simulate dProperty, false); 563 TestResource::CreateScratch(context->getGpu(), TestResource::kA_Simulate dProperty, false);
565 GrScratchKey key; 564 GrScratchKey key;
566 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key); 565 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key);
567 566
568 size_t size = resource->gpuMemorySize(); 567 size_t size = resource->gpuMemorySize();
569 for (int i = 0; i < 2; ++i) { 568 for (int i = 0; i < 2; ++i) {
570 // Since this resource is unbudgeted, it should not be reachable as scra tch. 569 // Since this resource is unbudgeted, it should not be reachable as scra tch.
571 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y); 570 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y);
572 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); 571 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
573 REPORTER_ASSERT(reporter, SkBudgeted::kNo == resource->resourcePriv().is Budgeted()); 572 REPORTER_ASSERT(reporter, !resource->resourcePriv().isBudgeted());
574 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(ke y, TestResource::kDefaultSize, 0)); 573 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(ke y, TestResource::kDefaultSize, 0));
575 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 574 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
576 REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); 575 REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
577 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); 576 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
578 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); 577 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
579 578
580 // Once it is unrefed, it should become available as scratch. 579 // Once it is unrefed, it should become available as scratch.
581 resource->unref(); 580 resource->unref();
582 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 581 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
583 REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); 582 REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
584 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); 583 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
585 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()); 584 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes());
586 resource = static_cast<TestResource*>(cache->findAndRefScratchResource(k ey, TestResource::kDefaultSize, 0)); 585 resource = static_cast<TestResource*>(cache->findAndRefScratchResource(k ey, TestResource::kDefaultSize, 0));
587 REPORTER_ASSERT(reporter, resource); 586 REPORTER_ASSERT(reporter, resource);
588 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y); 587 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y);
589 REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch()); 588 REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch());
590 REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().i sBudgeted()); 589 REPORTER_ASSERT(reporter, resource->resourcePriv().isBudgeted());
591 590
592 if (0 == i) { 591 if (0 == i) {
593 // If made unbudgeted, it should return to original state: ref'ed an d unbudgeted. Try 592 // If made unbudgeted, it should return to original state: ref'ed an d unbudgeted. Try
594 // the above tests again. 593 // the above tests again.
595 resource->resourcePriv().makeUnbudgeted(); 594 resource->resourcePriv().makeUnbudgeted();
596 } else { 595 } else {
597 // After the second time around, try removing the scratch key 596 // After the second time around, try removing the scratch key
598 resource->resourcePriv().removeScratchKey(); 597 resource->resourcePriv().removeScratchKey();
599 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 598 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
600 REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); 599 REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
601 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); 600 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
602 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()) ; 601 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()) ;
603 REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey(). isValid()); 602 REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey(). isValid());
604 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); 603 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
605 REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv ().isBudgeted()); 604 REPORTER_ASSERT(reporter, resource->resourcePriv().isBudgeted());
606 605
607 // now when it is unrefed it should die since it has no key. 606 // now when it is unrefed it should die since it has no key.
608 resource->unref(); 607 resource->unref();
609 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); 608 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
610 REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); 609 REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes());
611 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); 610 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
612 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); 611 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
613 } 612 }
614 } 613 }
615 } 614 }
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 test_cache_chained_purge(reporter); 1308 test_cache_chained_purge(reporter);
1310 test_resource_size_changed(reporter); 1309 test_resource_size_changed(reporter);
1311 test_timestamp_wrap(reporter); 1310 test_timestamp_wrap(reporter);
1312 test_flush(reporter); 1311 test_flush(reporter);
1313 test_large_resource_count(reporter); 1312 test_large_resource_count(reporter);
1314 test_custom_data(reporter); 1313 test_custom_data(reporter);
1315 test_abandoned(reporter); 1314 test_abandoned(reporter);
1316 } 1315 }
1317 1316
1318 #endif 1317 #endif
OLDNEW
« no previous file with comments | « tests/RectangleTextureTest.cpp ('k') | tests/SRGBReadWritePixelsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698