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 "SkMaskCache.h" | 9 #include "SkMaskCache.h" |
10 #include "SkResourceCache.h" | 10 #include "SkResourceCache.h" |
11 #include "Test.h" | 11 #include "Test.h" |
12 | 12 |
13 enum LockedState { | 13 enum LockedState { |
14 kUnlocked, | 14 kUnlocked, |
15 kLocked, | 15 kLocked, |
16 }; | 16 }; |
17 | 17 |
18 enum CachedState { | 18 enum CachedState { |
19 kNotInCache, | 19 kNotInCache, |
20 kInCache, | 20 kInCache, |
21 }; | 21 }; |
22 | 22 |
23 static void check_data(skiatest::Reporter* reporter, SkCachedData* data, | 23 static void check_data(skiatest::Reporter* reporter, SkCachedData* data, |
24 int refcnt, CachedState cacheState, LockedState lockedSta
te) { | 24 int refcnt, CachedState cacheState, LockedState lockedSta
te) { |
25 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt); | 25 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt); |
26 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cac
heState)); | 26 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cac
heState)); |
27 bool isLocked = (data->data() != NULL); | 27 bool isLocked = (data->data() != nullptr); |
28 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); | 28 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); |
29 } | 29 } |
30 | 30 |
31 DEF_TEST(RRectMaskCache, reporter) { | 31 DEF_TEST(RRectMaskCache, reporter) { |
32 SkResourceCache cache(1024); | 32 SkResourceCache cache(1024); |
33 | 33 |
34 SkScalar sigma = 0.8f; | 34 SkScalar sigma = 0.8f; |
35 SkRect rect = SkRect::MakeWH(100, 100); | 35 SkRect rect = SkRect::MakeWH(100, 100); |
36 SkRRect rrect; | 36 SkRRect rrect; |
37 rrect.setRectXY(rect, 30, 30); | 37 rrect.setRectXY(rect, 30, 30); |
38 SkBlurStyle style = kNormal_SkBlurStyle; | 38 SkBlurStyle style = kNormal_SkBlurStyle; |
39 SkBlurQuality quality = kLow_SkBlurQuality; | 39 SkBlurQuality quality = kLow_SkBlurQuality; |
40 SkMask mask; | 40 SkMask mask; |
41 | 41 |
42 SkCachedData* data = SkMaskCache::FindAndRef(sigma, style, quality, rrect, &
mask, &cache); | 42 SkCachedData* data = SkMaskCache::FindAndRef(sigma, style, quality, rrect, &
mask, &cache); |
43 REPORTER_ASSERT(reporter, NULL == data); | 43 REPORTER_ASSERT(reporter, nullptr == data); |
44 | 44 |
45 size_t size = 256; | 45 size_t size = 256; |
46 data = cache.newCachedData(size); | 46 data = cache.newCachedData(size); |
47 memset(data->writable_data(), 0xff, size); | 47 memset(data->writable_data(), 0xff, size); |
48 mask.fBounds.setXYWH(0, 0, 100, 100); | 48 mask.fBounds.setXYWH(0, 0, 100, 100); |
49 mask.fRowBytes = 100; | 49 mask.fRowBytes = 100; |
50 mask.fFormat = SkMask::kBW_Format; | 50 mask.fFormat = SkMask::kBW_Format; |
51 SkMaskCache::Add(sigma, style, quality, rrect, mask, data, &cache); | 51 SkMaskCache::Add(sigma, style, quality, rrect, mask, data, &cache); |
52 check_data(reporter, data, 2, kInCache, kLocked); | 52 check_data(reporter, data, 2, kInCache, kLocked); |
53 | 53 |
(...skipping 17 matching lines...) Expand all Loading... |
71 SkResourceCache cache(1024); | 71 SkResourceCache cache(1024); |
72 | 72 |
73 SkScalar sigma = 0.8f; | 73 SkScalar sigma = 0.8f; |
74 SkRect rect = SkRect::MakeWH(100, 100); | 74 SkRect rect = SkRect::MakeWH(100, 100); |
75 SkRect rects[2] = {rect}; | 75 SkRect rects[2] = {rect}; |
76 SkBlurStyle style = kNormal_SkBlurStyle; | 76 SkBlurStyle style = kNormal_SkBlurStyle; |
77 SkBlurQuality quality = kLow_SkBlurQuality; | 77 SkBlurQuality quality = kLow_SkBlurQuality; |
78 SkMask mask; | 78 SkMask mask; |
79 | 79 |
80 SkCachedData* data = SkMaskCache::FindAndRef(sigma, style, quality, rects, 1
, &mask, &cache); | 80 SkCachedData* data = SkMaskCache::FindAndRef(sigma, style, quality, rects, 1
, &mask, &cache); |
81 REPORTER_ASSERT(reporter, NULL == data); | 81 REPORTER_ASSERT(reporter, nullptr == data); |
82 | 82 |
83 size_t size = 256; | 83 size_t size = 256; |
84 data = cache.newCachedData(size); | 84 data = cache.newCachedData(size); |
85 memset(data->writable_data(), 0xff, size); | 85 memset(data->writable_data(), 0xff, size); |
86 mask.fBounds.setXYWH(0, 0, 100, 100); | 86 mask.fBounds.setXYWH(0, 0, 100, 100); |
87 mask.fRowBytes = 100; | 87 mask.fRowBytes = 100; |
88 mask.fFormat = SkMask::kBW_Format; | 88 mask.fFormat = SkMask::kBW_Format; |
89 SkMaskCache::Add(sigma, style, quality, rects, 1, mask, data, &cache); | 89 SkMaskCache::Add(sigma, style, quality, rects, 1, mask, data, &cache); |
90 check_data(reporter, data, 2, kInCache, kLocked); | 90 check_data(reporter, data, 2, kInCache, kLocked); |
91 | 91 |
92 data->unref(); | 92 data->unref(); |
93 check_data(reporter, data, 1, kInCache, kUnlocked); | 93 check_data(reporter, data, 1, kInCache, kUnlocked); |
94 | 94 |
95 sk_bzero(&mask, sizeof(mask)); | 95 sk_bzero(&mask, sizeof(mask)); |
96 data = SkMaskCache::FindAndRef(sigma, style, quality, rects, 1, &mask, &cach
e); | 96 data = SkMaskCache::FindAndRef(sigma, style, quality, rects, 1, &mask, &cach
e); |
97 REPORTER_ASSERT(reporter, data); | 97 REPORTER_ASSERT(reporter, data); |
98 REPORTER_ASSERT(reporter, data->size() == size); | 98 REPORTER_ASSERT(reporter, data->size() == size); |
99 REPORTER_ASSERT(reporter, mask.fBounds.top() == 0 && mask.fBounds.bottom() =
= 100); | 99 REPORTER_ASSERT(reporter, mask.fBounds.top() == 0 && mask.fBounds.bottom() =
= 100); |
100 REPORTER_ASSERT(reporter, data->data() == (const void*)mask.fImage); | 100 REPORTER_ASSERT(reporter, data->data() == (const void*)mask.fImage); |
101 check_data(reporter, data, 2, kInCache, kLocked); | 101 check_data(reporter, data, 2, kInCache, kLocked); |
102 | 102 |
103 cache.purgeAll(); | 103 cache.purgeAll(); |
104 check_data(reporter, data, 1, kNotInCache, kLocked); | 104 check_data(reporter, data, 1, kNotInCache, kLocked); |
105 data->unref(); | 105 data->unref(); |
106 } | 106 } |
OLD | NEW |