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 12 matching lines...) Expand all Loading... |
23 int refcnt, CachedState cacheState, LockedState lockedSta
te) { | 23 int refcnt, CachedState cacheState, LockedState lockedSta
te) { |
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 SkASSERT_RELEASE(dm); | 33 SK_ALWAYSBREAK(dm); |
34 return new SkCachedData(size, dm); | 34 return new SkCachedData(size, dm); |
35 } else { | 35 } else { |
36 return new 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); |
(...skipping 42 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() : nullpt
r); | 88 data = test_locking(reporter, size, useDiscardable ? pool.get() : nullpt
r); |
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 |