aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ResourceCacheTest.cpp
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2018-01-19 18:18:20 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-19 18:18:24 +0000
commit07320e46c0064dc1fe876f4621e94cb9ad529f85 (patch)
tree45d4d7d185beaa1d58e4b67c7c9eb60d9892d86f /tests/ResourceCacheTest.cpp
parentb69a2f66448603c26b0265201cec7161cf6d6f75 (diff)
Revert "Move more internal methods from GrContext to GrContextPriv"
This reverts commit f440cecbfdf1910104f36aedd0e963da2ae8b6a8. Reason for revert: breaking android builds. Original change's description: > Move more internal methods from GrContext to GrContextPriv > > TBR=bsalomon@google.com > Change-Id: Ia8cf0e0d30451c69bc7a08215aafa6abe6e0ddbe > Reviewed-on: https://skia-review.googlesource.com/97080 > Commit-Queue: Robert Phillips <robertphillips@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com Change-Id: If263f8161f0fbe3fc6ee8f34bb09e237705c3694 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/97200 Reviewed-by: Hal Canary <halcanary@google.com> Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'tests/ResourceCacheTest.cpp')
-rw-r--r--tests/ResourceCacheTest.cpp122
1 files changed, 52 insertions, 70 deletions
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 34ed4f7328..dd122a0dea 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -200,7 +200,7 @@ DEF_GPUTEST_FOR_CONTEXTS(ResourceCacheStencilBuffers, &is_rendering_and_not_angl
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
GrResourceProvider* resourceProvider = context->contextPriv().resourceProvider();
- GrGpu* gpu = context->contextPriv().getGpu();
+ GrGpu* gpu = context->getGpu();
// this test is only valid for GL
if (!gpu || !gpu->glContextForTesting()) {
return;
@@ -370,13 +370,12 @@ static void test_no_key(skiatest::Reporter* reporter) {
Mock mock(10, 30000);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
// Create a bunch of resources with no keys
- TestResource* a = new TestResource(gpu);
- TestResource* b = new TestResource(gpu);
- TestResource* c = new TestResource(gpu);
- TestResource* d = new TestResource(gpu);
+ TestResource* a = new TestResource(context->getGpu());
+ TestResource* b = new TestResource(context->getGpu());
+ TestResource* c = new TestResource(context->getGpu());
+ TestResource* d = new TestResource(context->getGpu());
a->setSize(11);
b->setSize(12);
c->setSize(13);
@@ -428,21 +427,21 @@ static void test_budgeting(skiatest::Reporter* reporter) {
Mock mock(10, 300);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
GrUniqueKey uniqueKey;
make_unique_key<0>(&uniqueKey, 0);
// Create a scratch, a unique, and a wrapped resource
TestResource* scratch =
- TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty);
+ TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, TestResource::kB_SimulatedProperty);
scratch->setSize(10);
- TestResource* unique = new TestResource(gpu);
+ TestResource* unique = new TestResource(context->getGpu());
unique->setSize(11);
unique->resourcePriv().setUniqueKey(uniqueKey);
- TestResource* wrapped = TestResource::CreateWrapped(gpu);
+ TestResource* wrapped = TestResource::CreateWrapped(context->getGpu());
wrapped->setSize(12);
- TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo);
+ TestResource* unbudgeted =
+ new TestResource(context->getGpu(), SkBudgeted::kNo);
unbudgeted->setSize(13);
// Make sure we can add a unique key to the wrapped resource
@@ -484,7 +483,7 @@ static void test_budgeting(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes());
// Now try freeing the budgeted resources first
- wrapped = TestResource::CreateWrapped(gpu);
+ wrapped = TestResource::CreateWrapped(context->getGpu());
scratch->setSize(12);
unique->unref();
REPORTER_ASSERT(reporter, 11 == cache->getPurgeableBytes());
@@ -525,7 +524,6 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
Mock mock(10, 30000);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
GrUniqueKey uniqueKey;
make_unique_key<0>(&uniqueKey, 0);
@@ -536,7 +534,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
TestResource* unbudgeted;
// A large uncached or wrapped resource shouldn't evict anything.
- scratch = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
+ scratch = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
TestResource::kB_SimulatedProperty);
scratch->setSize(10);
@@ -547,7 +545,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 10 == cache->getBudgetedResourceBytes());
REPORTER_ASSERT(reporter, 10 == cache->getPurgeableBytes());
- unique = new TestResource(gpu);
+ unique = new TestResource(context->getGpu());
unique->setSize(11);
unique->resourcePriv().setUniqueKey(uniqueKey);
unique->unref();
@@ -558,7 +556,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes());
size_t large = 2 * cache->getResourceBytes();
- unbudgeted = new TestResource(gpu, SkBudgeted::kNo, large);
+ unbudgeted = new TestResource(context->getGpu(), SkBudgeted::kNo, large);
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes());
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
@@ -572,7 +570,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes());
REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes());
- wrapped = TestResource::CreateWrapped(gpu, large);
+ wrapped = TestResource::CreateWrapped(context->getGpu(), large);
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes());
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
@@ -600,10 +598,10 @@ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter);
Mock mock(10, 300);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
TestResource* resource =
- TestResource::CreateScratch(gpu, SkBudgeted::kNo, TestResource::kA_SimulatedProperty);
+ TestResource::CreateScratch(context->getGpu(), SkBudgeted::kNo,
+ TestResource::kA_SimulatedProperty);
GrScratchKey key;
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key);
@@ -664,13 +662,12 @@ static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
Mock mock(5, 30000);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
// Create two resources that have the same scratch key.
- TestResource* a = TestResource::CreateScratch(gpu,
+ TestResource* a = TestResource::CreateScratch(context->getGpu(),
SkBudgeted::kYes,
TestResource::kB_SimulatedProperty);
- TestResource* b = TestResource::CreateScratch(gpu,
+ TestResource* b = TestResource::CreateScratch(context->getGpu(),
SkBudgeted::kYes,
TestResource::kB_SimulatedProperty);
a->setSize(11);
@@ -712,12 +709,11 @@ static void test_remove_scratch_key(skiatest::Reporter* reporter) {
Mock mock(5, 30000);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
// Create two resources that have the same scratch key.
- TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
+ TestResource* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
TestResource::kB_SimulatedProperty);
- TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
+ TestResource* b = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
TestResource::kB_SimulatedProperty);
a->unref();
b->unref();
@@ -772,12 +768,11 @@ static void test_scratch_key_consistency(skiatest::Reporter* reporter) {
Mock mock(5, 30000);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
// Create two resources that have the same scratch key.
- TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
+ TestResource* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
TestResource::kB_SimulatedProperty);
- TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
+ TestResource* b = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
TestResource::kB_SimulatedProperty);
a->unref();
b->unref();
@@ -832,13 +827,12 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
Mock mock(5, 30000);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
GrUniqueKey key;
make_unique_key<0>(&key, 0);
// Create two resources that we will attempt to register with the same unique key.
- TestResource* a = new TestResource(gpu);
+ TestResource* a = new TestResource(context->getGpu());
a->setSize(11);
// Set key on resource a.
@@ -855,7 +849,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
// Create resource b and set the same key. It should replace a's unique key cache entry.
- TestResource* b = new TestResource(gpu);
+ TestResource* b = new TestResource(context->getGpu());
b->setSize(12);
b->resourcePriv().setUniqueKey(key);
REPORTER_ASSERT(reporter, b == cache->findAndRefUniqueResource(key));
@@ -875,7 +869,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
// Now replace b with c, but make sure c can start with one unique key and change it to b's key.
// Also make b be unreffed when replacement occurs.
b->unref();
- TestResource* c = new TestResource(gpu);
+ TestResource* c = new TestResource(context->getGpu());
GrUniqueKey differentKey;
make_unique_key<0>(&differentKey, 1);
c->setSize(13);
@@ -912,7 +906,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
{
GrUniqueKey key2;
make_unique_key<0>(&key2, 0);
- sk_sp<TestResource> d(new TestResource(gpu));
+ sk_sp<TestResource> d(new TestResource(context->getGpu()));
int foo = 4132;
key2.setCustomData(SkData::MakeWithCopy(&foo, sizeof(foo)));
d->resourcePriv().setUniqueKey(key2);
@@ -928,7 +922,6 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) {
Mock mock(5, 30000);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
GrUniqueKey key1, key2, key3;
make_unique_key<0>(&key1, 1);
@@ -936,9 +929,9 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) {
make_unique_key<0>(&key3, 3);
// Add three resources to the cache. Only c is usable as scratch.
- TestResource* a = new TestResource(gpu);
- TestResource* b = new TestResource(gpu);
- TestResource* c = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
+ TestResource* a = new TestResource(context->getGpu());
+ TestResource* b = new TestResource(context->getGpu());
+ TestResource* c = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
TestResource::kA_SimulatedProperty);
a->resourcePriv().setUniqueKey(key1);
b->resourcePriv().setUniqueKey(key2);
@@ -997,14 +990,13 @@ static void test_cache_chained_purge(skiatest::Reporter* reporter) {
Mock mock(3, 30000);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
GrUniqueKey key1, key2;
make_unique_key<0>(&key1, 1);
make_unique_key<0>(&key2, 2);
- TestResource* a = new TestResource(gpu);
- TestResource* b = new TestResource(gpu);
+ TestResource* a = new TestResource(context->getGpu());
+ TestResource* b = new TestResource(context->getGpu());
a->resourcePriv().setUniqueKey(key1);
b->resourcePriv().setUniqueKey(key2);
@@ -1040,13 +1032,12 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) {
Mock mock(3, 30000);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
- TestResource* a = new TestResource(gpu);
+ TestResource* a = new TestResource(context->getGpu());
a->resourcePriv().setUniqueKey(key1);
a->unref();
- TestResource* b = new TestResource(gpu);
+ TestResource* b = new TestResource(context->getGpu());
b->resourcePriv().setUniqueKey(key2);
b->unref();
@@ -1070,14 +1061,13 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) {
Mock mock(2, 300);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
- TestResource* a = new TestResource(gpu);
+ TestResource* a = new TestResource(context->getGpu());
a->setSize(100);
a->resourcePriv().setUniqueKey(key1);
a->unref();
- TestResource* b = new TestResource(gpu);
+ TestResource* b = new TestResource(context->getGpu());
b->setSize(100);
b->resourcePriv().setUniqueKey(key2);
b->unref();
@@ -1110,7 +1100,6 @@ static void test_timestamp_wrap(skiatest::Reporter* reporter) {
Mock mock(kBudgetCnt, kBudgetSize);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
// Pick a random number of resources to add before the timestamp will wrap.
cache->changeTimestamp(SK_MaxU32 - random.nextULessThan(kCount + 1));
@@ -1127,7 +1116,7 @@ static void test_timestamp_wrap(skiatest::Reporter* reporter) {
GrUniqueKey key;
make_unique_key<0>(&key, j);
- TestResource* r = new TestResource(gpu);
+ TestResource* r = new TestResource(context->getGpu());
r->resourcePriv().setUniqueKey(key);
if (random.nextU() % kLockedFreq) {
// Make this is purgeable.
@@ -1167,7 +1156,6 @@ static void test_flush(skiatest::Reporter* reporter) {
Mock mock(1000000, 1000000);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
// The current cache impl will round the max flush count to the next power of 2. So we choose a
// power of two here to keep things simpler.
@@ -1177,7 +1165,7 @@ static void test_flush(skiatest::Reporter* reporter) {
{
// Insert a resource and send a flush notification kFlushCount times.
for (int i = 0; i < kFlushCount; ++i) {
- TestResource* r = new TestResource(gpu);
+ TestResource* r = new TestResource(context->getGpu());
GrUniqueKey k;
make_unique_key<1>(&k, i);
r->resourcePriv().setUniqueKey(k);
@@ -1207,7 +1195,7 @@ static void test_flush(skiatest::Reporter* reporter) {
{
GrGpuResource* refedResources[kFlushCount >> 1];
for (int i = 0; i < kFlushCount; ++i) {
- TestResource* r = new TestResource(gpu);
+ TestResource* r = new TestResource(context->getGpu());
GrUniqueKey k;
make_unique_key<1>(&k, i);
r->resourcePriv().setUniqueKey(k);
@@ -1248,7 +1236,7 @@ static void test_flush(skiatest::Reporter* reporter) {
// eviction.
context->flush();
for (int i = 0; i < 10; ++i) {
- TestResource* r = new TestResource(gpu);
+ TestResource* r = new TestResource(context->getGpu());
GrUniqueKey k;
make_unique_key<1>(&k, i);
r->resourcePriv().setUniqueKey(k);
@@ -1265,7 +1253,6 @@ static void test_time_purge(skiatest::Reporter* reporter) {
Mock mock(1000000, 1000000);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
static constexpr int kCnts[] = {1, 10, 1024};
auto nowish = []() {
@@ -1284,7 +1271,7 @@ static void test_time_purge(skiatest::Reporter* reporter) {
{
// Insert resources and get time points between each addition.
for (int i = 0; i < cnt; ++i) {
- TestResource* r = new TestResource(gpu);
+ TestResource* r = new TestResource(context->getGpu());
GrUniqueKey k;
make_unique_key<1>(&k, i);
r->resourcePriv().setUniqueKey(k);
@@ -1315,7 +1302,7 @@ static void test_time_purge(skiatest::Reporter* reporter) {
{
std::unique_ptr<GrGpuResource* []> refedResources(new GrGpuResource*[cnt / 2]);
for (int i = 0; i < cnt; ++i) {
- TestResource* r = new TestResource(gpu);
+ TestResource* r = new TestResource(context->getGpu());
GrUniqueKey k;
make_unique_key<1>(&k, i);
r->resourcePriv().setUniqueKey(k);
@@ -1350,7 +1337,7 @@ static void test_time_purge(skiatest::Reporter* reporter) {
// eviction
context->flush();
for (int i = 0; i < 10; ++i) {
- TestResource* r = new TestResource(gpu);
+ TestResource* r = new TestResource(context->getGpu());
GrUniqueKey k;
make_unique_key<1>(&k, i);
r->resourcePriv().setUniqueKey(k);
@@ -1368,7 +1355,6 @@ static void test_partial_purge(skiatest::Reporter* reporter) {
Mock mock(6, 100);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
enum TestsCase {
kOnlyScratch_TestCase = 0,
@@ -1388,9 +1374,9 @@ static void test_partial_purge(skiatest::Reporter* reporter) {
make_unique_key<0>(&key3, 3);
// Add three unique resources to the cache.
- TestResource *unique1 = new TestResource(gpu);
- TestResource *unique2 = new TestResource(gpu);
- TestResource *unique3 = new TestResource(gpu);
+ TestResource *unique1 = new TestResource(context->getGpu());
+ TestResource *unique2 = new TestResource(context->getGpu());
+ TestResource *unique3 = new TestResource(context->getGpu());
unique1->resourcePriv().setUniqueKey(key1);
unique2->resourcePriv().setUniqueKey(key2);
@@ -1401,9 +1387,9 @@ static void test_partial_purge(skiatest::Reporter* reporter) {
unique3->setSize(12);
// Add two scratch resources to the cache.
- TestResource *scratch1 = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
+ TestResource *scratch1 = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
TestResource::kA_SimulatedProperty);
- TestResource *scratch2 = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
+ TestResource *scratch2 = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
TestResource::kB_SimulatedProperty);
scratch1->setSize(13);
scratch2->setSize(14);
@@ -1482,7 +1468,6 @@ static void test_large_resource_count(skiatest::Reporter* reporter) {
Mock mock(2 * kResourceCnt, 2 * kResourceCnt + 1000);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
for (int i = 0; i < kResourceCnt; ++i) {
GrUniqueKey key1, key2;
@@ -1491,12 +1476,12 @@ static void test_large_resource_count(skiatest::Reporter* reporter) {
TestResource* resource;
- resource = new TestResource(gpu);
+ resource = new TestResource(context->getGpu());
resource->resourcePriv().setUniqueKey(key1);
resource->setSize(1);
resource->unref();
- resource = new TestResource(gpu);
+ resource = new TestResource(context->getGpu());
resource->resourcePriv().setUniqueKey(key2);
resource->setSize(1);
resource->unref();
@@ -1552,9 +1537,7 @@ static void test_custom_data(skiatest::Reporter* reporter) {
static void test_abandoned(skiatest::Reporter* reporter) {
Mock mock(10, 300);
GrContext* context = mock.context();
- GrGpu* gpu = context->contextPriv().getGpu();
-
- sk_sp<GrGpuResource> resource(new TestResource(gpu));
+ sk_sp<GrGpuResource> resource(new TestResource(context->getGpu()));
context->abandonContext();
REPORTER_ASSERT(reporter, resource->wasDestroyed());
@@ -1588,14 +1571,13 @@ static void test_tags(skiatest::Reporter* reporter) {
Mock mock(kNumResources, kNumResources * TestResource::kDefaultSize);
GrContext* context = mock.context();
GrResourceCache* cache = mock.cache();
- GrGpu* gpu = context->contextPriv().getGpu();
SkString tagStr;
int tagIdx = 0;
int currTagCnt = 0;
for (int i = 0; i < kNumResources; ++i, ++currTagCnt) {
- sk_sp<GrGpuResource> resource(new TestResource(gpu));
+ sk_sp<GrGpuResource> resource(new TestResource(context->getGpu()));
GrUniqueKey key;
if (currTagCnt == tagIdx) {
tagIdx += 1;