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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 721353002: Allow GPU resources to not be counted against the cache budget. (Closed) Base URL: https://skia.googlesource.com/skia.git@wrap
Patch Set: update Created 6 years, 1 month 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
« src/gpu/GrResourceCache2.cpp ('K') | « src/gpu/GrResourceCache2.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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); 167 REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
168 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); 168 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
169 REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache2->getResourceBytes()); 169 REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache2->getResourceBytes());
170 170
171 b->unref(); 171 b->unref();
172 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); 172 REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
173 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount()); 173 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
174 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes()); 174 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
175 } 175 }
176 176
177 static void test_wrapped(skiatest::Reporter* reporter) { 177 static void test_budgeting(skiatest::Reporter* reporter) {
178 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); 178 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
179 REPORTER_ASSERT(reporter, SkToBool(context)); 179 REPORTER_ASSERT(reporter, SkToBool(context));
180 if (NULL == context) { 180 if (NULL == context) {
181 return; 181 return;
182 } 182 }
183 context->setResourceCacheLimits(10, 300); 183 context->setResourceCacheLimits(10, 300);
184 GrResourceCache2* cache2 = context->getResourceCache2(); 184 GrResourceCache2* cache2 = context->getResourceCache2();
185 cache2->purgeAllUnlocked(); 185 cache2->purgeAllUnlocked();
186 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ; 186 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
187 SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgeted ResourceBytes()); 187 SkASSERT(0 == cache2->getBudgetedResourceCount() && 0 == cache2->getBudgeted ResourceBytes());
188 188
189 GrCacheID::Key keyData; 189 GrCacheID::Key keyData;
190 memset(&keyData, 0, sizeof(keyData)); 190 memset(&keyData, 0, sizeof(keyData));
191 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); 191 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
192 GrResourceKey scratchKey(GrCacheID(GrResourceKey::ScratchDomain(), keyData), t, 0); 192 GrResourceKey scratchKey(GrCacheID(GrResourceKey::ScratchDomain(), keyData), t, 0);
193 GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), t, 0); 193 GrResourceKey contentKey(GrCacheID(GrCacheID::GenerateDomain(), keyData), t, 0);
194 194
195 // Create a scratch, a content, and a wrapped resource 195 // Create a scratch, a content, and a wrapped resource
196 TestResource* scratch = new TestResource(context->getGpu(), scratchKey); 196 TestResource* scratch = new TestResource(context->getGpu(), scratchKey);
197 scratch->setSize(10); 197 scratch->setSize(10);
198 TestResource* content = new TestResource(context->getGpu()); 198 TestResource* content = new TestResource(context->getGpu());
199 scratch->setSize(11); 199 scratch->setSize(11);
200 REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey)); 200 REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey));
201 TestResource* wrapped = new TestResource(context->getGpu(), true); 201 TestResource* wrapped = new TestResource(context->getGpu(), true);
202 scratch->setSize(12); 202 scratch->setSize(12);
203 TestResource* unbudgeted = new TestResource(context->getGpu());
204 unbudgeted->setSize(13);
205 unbudgeted->cacheAccess().setBudgeted(false);
203 206
204 // Make sure we can't add a content key to the wrapped resource 207 // Make sure we can't add a content key to the wrapped resource
205 keyData.fData8[0] = 1; 208 keyData.fData8[0] = 1;
206 GrResourceKey contentKey2(GrCacheID(GrCacheID::GenerateDomain(), keyData), t , 0); 209 GrResourceKey contentKey2(GrCacheID(GrCacheID::GenerateDomain(), keyData), t , 0);
207 REPORTER_ASSERT(reporter, !wrapped->cacheAccess().setContentKey(contentKey2) ); 210 REPORTER_ASSERT(reporter, !wrapped->cacheAccess().setContentKey(contentKey2) );
208 REPORTER_ASSERT(reporter, NULL == cache2->findAndRefContentResource(contentK ey2)); 211 REPORTER_ASSERT(reporter, NULL == cache2->findAndRefContentResource(contentK ey2));
209 212
210 // Make sure sizes are as we expect 213 // Make sure sizes are as we expect
211 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount()); 214 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount());
212 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) + 215 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) +
213 wrapped->gpuMemorySize() == cache2->getResourceByt es()); 216 wrapped->gpuMemorySize() + unbudgeted->gpuMemorySi ze() ==
217 cache2->getResourceBytes());
214 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount()); 218 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
215 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) == 219 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) ==
216 cache2->getBudgetedResourceBytes()); 220 cache2->getBudgetedResourceBytes());
217 221
218 // Our refs mean that the resources are non purgable. 222 // Our refs mean that the resources are non purgable.
219 cache2->purgeAllUnlocked(); 223 cache2->purgeAllUnlocked();
220 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount()); 224 REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount());
221 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) + 225 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) +
222 wrapped->gpuMemorySize() == cache2->getResourceByt es()); 226 wrapped->gpuMemorySize() + unbudgeted->gpuMemorySi ze() ==
227 cache2->getResourceBytes());
223 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount()); 228 REPORTER_ASSERT(reporter, 2 == cache2->getBudgetedResourceCount());
224 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) == 229 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) ==
225 cache2->getBudgetedResourceBytes()); 230 cache2->getBudgetedResourceBytes());
226 231
227 // Unreffing the wrapped resource should free it right away. 232 // Unreffing the wrapped resource should free it right away.
228 wrapped->unref(); 233 wrapped->unref();
229 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 234 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount());
230 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) == 235 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize( ) +
231 cache2->getResourceBytes()); 236 unbudgeted->gpuMemorySize() == cache2->getResource Bytes());
232 237
233 // Now try freeing the other two resources first 238 // Now try freeing the budgeted resources first
234 wrapped = new TestResource(context->getGpu(), true); 239 wrapped = new TestResource(context->getGpu(), true);
235 scratch->setSize(12); 240 scratch->setSize(12);
236 content->unref(); 241 content->unref();
237 cache2->purgeAllUnlocked(); 242 cache2->purgeAllUnlocked();
238 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount()); 243 REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount());
239 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize( ) == 244 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize( ) +
240 cache2->getResourceBytes()); 245 unbudgeted->gpuMemorySize() == cache2->getResource Bytes());
241 REPORTER_ASSERT(reporter, 1 == cache2->getBudgetedResourceCount()); 246 REPORTER_ASSERT(reporter, 1 == cache2->getBudgetedResourceCount());
242 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache2->getBudgetedRes ourceBytes()); 247 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache2->getBudgetedRes ourceBytes());
243 248
244 scratch->unref(); 249 scratch->unref();
245 cache2->purgeAllUnlocked(); 250 cache2->purgeAllUnlocked();
246 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); 251 REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
247 REPORTER_ASSERT(reporter, wrapped->gpuMemorySize() == cache2->getResourceByt es()); 252 REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrapped->gpuMemorySi ze() ==
253 cache2->getResourceBytes());
egdaniel 2014/11/13 20:47:32 align this
bsalomon 2014/11/13 20:53:34 Done.
248 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount()); 254 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceCount());
249 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes()); 255 REPORTER_ASSERT(reporter, 0 == cache2->getBudgetedResourceBytes());
250 256
251 wrapped->unref(); 257 wrapped->unref();
258 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
egdaniel 2014/11/13 20:47:32 I notice at this point we stop checking getBudgete
bsalomon 2014/11/13 20:53:34 Done.
259 REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() == cache2->getResource Bytes());
260
261 unbudgeted->unref();
252 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount()); 262 REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
253 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes()); 263 REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
254 } 264 }
255 265
256 static void test_duplicate_scratch_key(skiatest::Reporter* reporter) { 266 static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
257 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); 267 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
258 REPORTER_ASSERT(reporter, SkToBool(context)); 268 REPORTER_ASSERT(reporter, SkToBool(context));
259 if (NULL == context) { 269 if (NULL == context) {
260 return; 270 return;
261 } 271 }
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 desc.fFlags = kRenderTarget_GrSurfaceFlag; 582 desc.fFlags = kRenderTarget_GrSurfaceFlag;
573 desc.fWidth = gWidth; 583 desc.fWidth = gWidth;
574 desc.fHeight = gHeight; 584 desc.fHeight = gHeight;
575 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); 585 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight);
576 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info )); 586 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info ));
577 test_cache(reporter, context, surface->getCanvas()); 587 test_cache(reporter, context, surface->getCanvas());
578 } 588 }
579 589
580 // The below tests create their own mock contexts. 590 // The below tests create their own mock contexts.
581 test_no_key(reporter); 591 test_no_key(reporter);
582 test_wrapped(reporter); 592 test_budgeting(reporter);
583 test_duplicate_content_key(reporter); 593 test_duplicate_content_key(reporter);
584 test_duplicate_scratch_key(reporter); 594 test_duplicate_scratch_key(reporter);
585 test_purge_invalidated(reporter); 595 test_purge_invalidated(reporter);
586 test_cache_chained_purge(reporter); 596 test_cache_chained_purge(reporter);
587 test_resource_size_changed(reporter); 597 test_resource_size_changed(reporter);
588 } 598 }
589 599
590 #endif 600 #endif
OLDNEW
« src/gpu/GrResourceCache2.cpp ('K') | « src/gpu/GrResourceCache2.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698