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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 754833002: Cleanup res cache bench and split out into a unit test. (Closed) Base URL: https://skia.googlesource.com/skia.git@sb
Patch Set: fix index Created 6 years 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 | « bench/GrResourceCacheBench.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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2-> findAndRefContentResource(key2))); 562 SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2-> findAndRefContentResource(key2)));
563 find2->setSize(201); 563 find2->setSize(201);
564 } 564 }
565 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1)); 565 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1));
566 566
567 REPORTER_ASSERT(reporter, 201 == cache2->getResourceBytes()); 567 REPORTER_ASSERT(reporter, 201 == cache2->getResourceBytes());
568 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount()); 568 REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
569 } 569 }
570 } 570 }
571 571
572 static void test_large_resource_count(skiatest::Reporter* reporter) {
573 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
574 REPORTER_ASSERT(reporter, SkToBool(context));
575 if (NULL == context) {
576 return;
577 }
578
579 static const int kResourceCnt = 2000;
580 // Set the cache size to double the resource count because we're going to cr eate 2x that number
581 // resources, using two different key domains. Add a little slop to the byte s because we resize
582 // down to 1 byte after creating the resource.
583 context->setResourceCacheLimits(2 * kResourceCnt, 2 * kResourceCnt + 1000);
584 GrResourceCache2* cache2 = context->getResourceCache2();
585 cache2->purgeAllUnlocked();
586 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes()) ;
587
588 GrCacheID::Domain domain0 = GrCacheID::GenerateDomain();
589 GrCacheID::Domain domain1 = GrCacheID::GenerateDomain();
590 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
591
592 GrCacheID::Key keyData;
593 memset(&keyData, 0, sizeof(keyData));
594
595 for (int i = 0; i < kResourceCnt; ++i) {
596 TestResource* resource;
597 keyData.fData32[0] = i;
598
599 GrResourceKey key0(GrCacheID(domain0, keyData), t, 0);
600 resource = SkNEW_ARGS(TestResource, (context->getGpu()));
601 resource->cacheAccess().setContentKey(key0);
602 resource->setSize(1);
603 resource->unref();
604
605 GrResourceKey key1(GrCacheID(domain1, keyData), t, 0);
606 resource = SkNEW_ARGS(TestResource, (context->getGpu()));
607 resource->cacheAccess().setContentKey(key1);
608 resource->setSize(1);
609 resource->unref();
610 }
611
612 REPORTER_ASSERT(reporter, TestResource::NumAlive() == 2 * kResourceCnt);
613 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 2 * kResourc eCnt);
614 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 2 * kResourc eCnt);
615 REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 2 * kResourceCnt);
616 REPORTER_ASSERT(reporter, cache2->getResourceCount() == 2 * kResourceCnt);
617 for (int i = 0; i < kResourceCnt; ++i) {
618 keyData.fData32[0] = i;
619 GrResourceKey key0(GrCacheID(domain0, keyData), t, 0);
620 REPORTER_ASSERT(reporter, cache2->hasContentKey(key0));
621 GrResourceKey key1(GrCacheID(domain0, keyData), t, 0);
622 REPORTER_ASSERT(reporter, cache2->hasContentKey(key1));
623 }
624
625 cache2->purgeAllUnlocked();
626 REPORTER_ASSERT(reporter, TestResource::NumAlive() == 0);
627 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceBytes() == 0);
628 REPORTER_ASSERT(reporter, cache2->getBudgetedResourceCount() == 0);
629 REPORTER_ASSERT(reporter, cache2->getResourceBytes() == 0);
630 REPORTER_ASSERT(reporter, cache2->getResourceCount() == 0);
631
632 for (int i = 0; i < kResourceCnt; ++i) {
633 keyData.fData32[0] = i;
634 GrResourceKey key0(GrCacheID(domain0, keyData), t, 0);
635 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key0));
636 GrResourceKey key1(GrCacheID(domain0, keyData), t, 0);
637 REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1));
638 }
639 }
640
641
572 //////////////////////////////////////////////////////////////////////////////// 642 ////////////////////////////////////////////////////////////////////////////////
573 DEF_GPUTEST(ResourceCache, reporter, factory) { 643 DEF_GPUTEST(ResourceCache, reporter, factory) {
574 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { 644 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
575 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type); 645 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type);
576 if (!GrContextFactory::IsRenderingGLContext(glType)) { 646 if (!GrContextFactory::IsRenderingGLContext(glType)) {
577 continue; 647 continue;
578 } 648 }
579 GrContext* context = factory->get(glType); 649 GrContext* context = factory->get(glType);
580 if (NULL == context) { 650 if (NULL == context) {
581 continue; 651 continue;
582 } 652 }
583 GrSurfaceDesc desc; 653 GrSurfaceDesc desc;
584 desc.fConfig = kSkia8888_GrPixelConfig; 654 desc.fConfig = kSkia8888_GrPixelConfig;
585 desc.fFlags = kRenderTarget_GrSurfaceFlag; 655 desc.fFlags = kRenderTarget_GrSurfaceFlag;
586 desc.fWidth = gWidth; 656 desc.fWidth = gWidth;
587 desc.fHeight = gHeight; 657 desc.fHeight = gHeight;
588 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); 658 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight);
589 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info )); 659 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info ));
590 test_cache(reporter, context, surface->getCanvas()); 660 test_cache(reporter, context, surface->getCanvas());
591 } 661 }
592 662
593 // The below tests create their own mock contexts. 663 // The below tests create their own mock contexts.
594 test_no_key(reporter); 664 test_no_key(reporter);
595 test_budgeting(reporter); 665 test_budgeting(reporter);
596 test_duplicate_content_key(reporter); 666 test_duplicate_content_key(reporter);
597 test_duplicate_scratch_key(reporter); 667 test_duplicate_scratch_key(reporter);
598 test_purge_invalidated(reporter); 668 test_purge_invalidated(reporter);
599 test_cache_chained_purge(reporter); 669 test_cache_chained_purge(reporter);
600 test_resource_size_changed(reporter); 670 test_resource_size_changed(reporter);
671 test_large_resource_count(reporter);
601 } 672 }
602 673
603 #endif 674 #endif
OLDNEW
« no previous file with comments | « bench/GrResourceCacheBench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698