OLD | NEW |
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 Loading... |
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 | |
642 //////////////////////////////////////////////////////////////////////////////// | 572 //////////////////////////////////////////////////////////////////////////////// |
643 DEF_GPUTEST(ResourceCache, reporter, factory) { | 573 DEF_GPUTEST(ResourceCache, reporter, factory) { |
644 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 574 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
645 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | 575 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
646 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 576 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
647 continue; | 577 continue; |
648 } | 578 } |
649 GrContext* context = factory->get(glType); | 579 GrContext* context = factory->get(glType); |
650 if (NULL == context) { | 580 if (NULL == context) { |
651 continue; | 581 continue; |
652 } | 582 } |
653 GrSurfaceDesc desc; | 583 GrSurfaceDesc desc; |
654 desc.fConfig = kSkia8888_GrPixelConfig; | 584 desc.fConfig = kSkia8888_GrPixelConfig; |
655 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 585 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
656 desc.fWidth = gWidth; | 586 desc.fWidth = gWidth; |
657 desc.fHeight = gHeight; | 587 desc.fHeight = gHeight; |
658 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); | 588 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); |
659 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info
)); | 589 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info
)); |
660 test_cache(reporter, context, surface->getCanvas()); | 590 test_cache(reporter, context, surface->getCanvas()); |
661 } | 591 } |
662 | 592 |
663 // The below tests create their own mock contexts. | 593 // The below tests create their own mock contexts. |
664 test_no_key(reporter); | 594 test_no_key(reporter); |
665 test_budgeting(reporter); | 595 test_budgeting(reporter); |
666 test_duplicate_content_key(reporter); | 596 test_duplicate_content_key(reporter); |
667 test_duplicate_scratch_key(reporter); | 597 test_duplicate_scratch_key(reporter); |
668 test_purge_invalidated(reporter); | 598 test_purge_invalidated(reporter); |
669 test_cache_chained_purge(reporter); | 599 test_cache_chained_purge(reporter); |
670 test_resource_size_changed(reporter); | 600 test_resource_size_changed(reporter); |
671 test_large_resource_count(reporter); | |
672 } | 601 } |
673 | 602 |
674 #endif | 603 #endif |
OLD | NEW |