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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 1728093005: Move Budgeted enum out of SkSurface, use in GrTextureProvider (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add aliases for Chrome 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 SkSurface::kNo_Bu dgeted, info)); 41 SkBudgeted::kNo, 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, true)); 94 SkAutoTUnref<GrTexture> smallRT0(cache->createTexture(smallDesc, SkBudgeted: :kYes));
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, true)); 99 SkAutoTUnref<GrTexture> smallRT1(cache->createTexture(smallDesc, SkBudgeted: :kYes));
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, false)); 111 SkAutoTUnref<GrTexture> smallRT2(cache->createTexture(smallDesc, SkBudgeted: :kNo));
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, false)); 128 SkAutoTUnref<GrTexture> bigRT(cache->createTexture(bigDesc, SkBudgeted::kNo) );
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, false)); 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;
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, false)); 158 SkAutoTUnref<GrTexture> smallMSAART1(cache->createTexture(smallMSAADesc, SkBudgeted::kNo));
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, false)); 174 smallMSAART1.reset(cache->createTexture(smallMSAADesc, SkBudgeted::k No));
175 SkAutoTUnref<GrTexture> smallMSAART1(cache->createTexture(smallMSAAD esc, false)); 175 SkAutoTUnref<GrTexture> smallMSAART1(
176 cache->createTexture(smallMSAADesc, SkBudgeted::kNo));
176 if (smallMSAART1 && smallMSAART1->asRenderTarget()) { 177 if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
177 resourceProvider->attachStencilAttachment(smallMSAART1->asRender Target()); 178 resourceProvider->attachStencilAttachment(smallMSAART1->asRender Target());
178 } 179 }
179 REPORTER_ASSERT(reporter, 180 REPORTER_ASSERT(reporter,
180 smallMSAART0 && smallMSAART1 && 181 smallMSAART0 && smallMSAART1 &&
181 smallMSAART0->asRenderTarget() && 182 smallMSAART0->asRenderTarget() &&
182 smallMSAART1->asRenderTarget() && 183 smallMSAART1->asRenderTarget() &&
183 resourceProvider->attachStencilAttachment(smallMSAART0-> asRenderTarget()) != 184 resourceProvider->attachStencilAttachment(smallMSAART0-> asRenderTarget()) !=
184 resourceProvider->attachStencilAttachment(smallMSAART1-> asRenderTarget())); 185 resourceProvider->attachStencilAttachment(smallMSAART1-> asRenderTarget()));
185 } 186 }
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 TestResource* resource = 563 TestResource* resource =
563 TestResource::CreateScratch(context->getGpu(), TestResource::kA_Simulate dProperty, false); 564 TestResource::CreateScratch(context->getGpu(), TestResource::kA_Simulate dProperty, false);
564 GrScratchKey key; 565 GrScratchKey key;
565 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key); 566 TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key);
566 567
567 size_t size = resource->gpuMemorySize(); 568 size_t size = resource->gpuMemorySize();
568 for (int i = 0; i < 2; ++i) { 569 for (int i = 0; i < 2; ++i) {
569 // Since this resource is unbudgeted, it should not be reachable as scra tch. 570 // Since this resource is unbudgeted, it should not be reachable as scra tch.
570 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y); 571 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y);
571 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); 572 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
572 REPORTER_ASSERT(reporter, !resource->resourcePriv().isBudgeted()); 573 REPORTER_ASSERT(reporter, SkBudgeted::kNo == resource->resourcePriv().is Budgeted());
573 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(ke y, TestResource::kDefaultSize, 0)); 574 REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(ke y, TestResource::kDefaultSize, 0));
574 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 575 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
575 REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); 576 REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
576 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); 577 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
577 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); 578 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
578 579
579 // Once it is unrefed, it should become available as scratch. 580 // Once it is unrefed, it should become available as scratch.
580 resource->unref(); 581 resource->unref();
581 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 582 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
582 REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); 583 REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
583 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); 584 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
584 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()); 585 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes());
585 resource = static_cast<TestResource*>(cache->findAndRefScratchResource(k ey, TestResource::kDefaultSize, 0)); 586 resource = static_cast<TestResource*>(cache->findAndRefScratchResource(k ey, TestResource::kDefaultSize, 0));
586 REPORTER_ASSERT(reporter, resource); 587 REPORTER_ASSERT(reporter, resource);
587 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y); 588 REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == ke y);
588 REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch()); 589 REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch());
589 REPORTER_ASSERT(reporter, resource->resourcePriv().isBudgeted()); 590 REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().i sBudgeted());
590 591
591 if (0 == i) { 592 if (0 == i) {
592 // 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
593 // the above tests again. 594 // the above tests again.
594 resource->resourcePriv().makeUnbudgeted(); 595 resource->resourcePriv().makeUnbudgeted();
595 } else { 596 } else {
596 // After the second time around, try removing the scratch key 597 // After the second time around, try removing the scratch key
597 resource->resourcePriv().removeScratchKey(); 598 resource->resourcePriv().removeScratchKey();
598 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); 599 REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
599 REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); 600 REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
600 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); 601 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
601 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()) ; 602 REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()) ;
602 REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey(). isValid()); 603 REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey(). isValid());
603 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); 604 REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
604 REPORTER_ASSERT(reporter, resource->resourcePriv().isBudgeted()); 605 REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv ().isBudgeted());
605 606
606 // now when it is unrefed it should die since it has no key. 607 // now when it is unrefed it should die since it has no key.
607 resource->unref(); 608 resource->unref();
608 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); 609 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
609 REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); 610 REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes());
610 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); 611 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
611 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); 612 REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes());
612 } 613 }
613 } 614 }
614 } 615 }
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 test_cache_chained_purge(reporter); 1309 test_cache_chained_purge(reporter);
1309 test_resource_size_changed(reporter); 1310 test_resource_size_changed(reporter);
1310 test_timestamp_wrap(reporter); 1311 test_timestamp_wrap(reporter);
1311 test_flush(reporter); 1312 test_flush(reporter);
1312 test_large_resource_count(reporter); 1313 test_large_resource_count(reporter);
1313 test_custom_data(reporter); 1314 test_custom_data(reporter);
1314 test_abandoned(reporter); 1315 test_abandoned(reporter);
1315 } 1316 }
1316 1317
1317 #endif 1318 #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