| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkCachedData.h" | 8 #include "SkCachedData.h" |
| 9 #include "SkDiscardableMemoryPool.h" | 9 #include "SkDiscardableMemoryPool.h" |
| 10 #include "Test.h" | 10 #include "Test.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt); | 24 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt); |
| 25 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cac
heState)); | 25 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cac
heState)); |
| 26 REPORTER_ASSERT(reporter, data->testing_only_isLocked() == (lockedState == k
Locked)); | 26 REPORTER_ASSERT(reporter, data->testing_only_isLocked() == (lockedState == k
Locked)); |
| 27 } | 27 } |
| 28 | 28 |
| 29 static SkCachedData* make_data(size_t size, SkDiscardableMemoryPool* pool) { | 29 static SkCachedData* make_data(size_t size, SkDiscardableMemoryPool* pool) { |
| 30 if (pool) { | 30 if (pool) { |
| 31 SkDiscardableMemory* dm = pool->create(size); | 31 SkDiscardableMemory* dm = pool->create(size); |
| 32 // the pool "can" return null, but it shouldn't in these controlled cond
itions | 32 // the pool "can" return null, but it shouldn't in these controlled cond
itions |
| 33 SK_ALWAYSBREAK(dm); | 33 SK_ALWAYSBREAK(dm); |
| 34 return SkNEW_ARGS(SkCachedData, (size, dm)); | 34 return new SkCachedData(size, dm); |
| 35 } else { | 35 } else { |
| 36 return SkNEW_ARGS(SkCachedData, (sk_malloc_throw(size), size)); | 36 return new SkCachedData(sk_malloc_throw(size), size); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 // returns with the data locked by client and cache | 40 // returns with the data locked by client and cache |
| 41 static SkCachedData* test_locking(skiatest::Reporter* reporter, | 41 static SkCachedData* test_locking(skiatest::Reporter* reporter, |
| 42 size_t size, SkDiscardableMemoryPool* pool) { | 42 size_t size, SkDiscardableMemoryPool* pool) { |
| 43 SkCachedData* data = make_data(size, pool); | 43 SkCachedData* data = make_data(size, pool); |
| 44 | 44 |
| 45 memset(data->writable_data(), 0x80, size); // just to use writable_data() | 45 memset(data->writable_data(), 0x80, size); // just to use writable_data() |
| 46 | 46 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 // test with cache as last owner | 87 // test with cache as last owner |
| 88 data = test_locking(reporter, size, useDiscardable ? pool.get() : NULL); | 88 data = test_locking(reporter, size, useDiscardable ? pool.get() : NULL); |
| 89 check_data(reporter, data, 2, kInCache, kLocked); | 89 check_data(reporter, data, 2, kInCache, kLocked); |
| 90 data->unref(); | 90 data->unref(); |
| 91 check_data(reporter, data, 1, kInCache, kUnlocked); | 91 check_data(reporter, data, 1, kInCache, kUnlocked); |
| 92 data->detachFromCacheAndUnref(); | 92 data->detachFromCacheAndUnref(); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| OLD | NEW |