OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "SkCachedData.h" |
| 9 #include "SkMaskCache.h" |
| 10 #include "SkResourceCache.h" |
| 11 #include "Test.h" |
| 12 |
| 13 enum LockedState { |
| 14 kUnlocked, |
| 15 kLocked |
| 16 }; |
| 17 |
| 18 static void check_data(skiatest::Reporter* reporter, SkCachedData* data, |
| 19 int refcnt, bool isInCache, LockedState lockedState) { |
| 20 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt); |
| 21 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == isInCache); |
| 22 bool isLocked = (data->data() != NULL); |
| 23 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); |
| 24 } |
| 25 |
| 26 DEF_TEST(MaskCache, reporter) { |
| 27 |
| 28 SkResourceCache cache(1024); |
| 29 |
| 30 SkScalar sigma = 2; |
| 31 SkRect r = SkRect::MakeWH(10, 10); |
| 32 SkMask mask; |
| 33 |
| 34 SkCachedData* data = SkMaskCache::FindAndLock(sigma, r, &mask, &cache); |
| 35 REPORTER_ASSERT(reporter, NULL == data); |
| 36 |
| 37 size_t size = 100; |
| 38 data = cache.newCachedData(size); |
| 39 check_data(reporter, data, 1, false, kLocked); |
| 40 |
| 41 memset(data->writable_data(), 0x80, size); // just to use writable_data() |
| 42 mask.fBounds.setXYWH(1, 2, 3, 4); |
| 43 SkMaskCache::Add(sigma, r, mask, data, &cache); |
| 44 check_data(reporter, data, 2, true, kLocked); |
| 45 |
| 46 data->unref(); |
| 47 check_data(reporter, data, 1, true, kUnlocked); |
| 48 |
| 49 sk_bzero(&mask, sizeof(mask)); |
| 50 data = SkMaskCache::FindAndLock(sigma, r, &mask, &cache); |
| 51 check_data(reporter, data, 2, true, kLocked); |
| 52 |
| 53 REPORTER_ASSERT(reporter, data); |
| 54 REPORTER_ASSERT(reporter, data->size() == size); |
| 55 REPORTER_ASSERT(reporter, mask.fBounds.top() == 2); |
| 56 REPORTER_ASSERT(reporter, data->data() == (const void*)mask.fImage); |
| 57 |
| 58 cache.purgeAll(); |
| 59 check_data(reporter, data, 1, false, kLocked); |
| 60 data->unref(); |
| 61 } |
| 62 |
OLD | NEW |