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 "Test.h" | 8 #include "Test.h" |
9 #include "SkBitmapCache.h" | 9 #include "SkBitmapCache.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); | 89 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); |
90 } | 90 } |
91 | 91 |
92 static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cach
e) { | 92 static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cach
e) { |
93 cache->purgeAll(); | 93 cache->purgeAll(); |
94 | 94 |
95 SkBitmap src; | 95 SkBitmap src; |
96 src.allocN32Pixels(5, 5); | 96 src.allocN32Pixels(5, 5); |
97 src.setImmutable(); | 97 src.setImmutable(); |
98 | 98 |
99 const SkMipMap* mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(s
rc), cache); | 99 const SkSourceGammaTreatment treatment = SkSourceGammaTreatment::kIgnore; |
| 100 |
| 101 const SkMipMap* mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(s
rc), treatment, |
| 102 cache); |
100 REPORTER_ASSERT(reporter, nullptr == mipmap); | 103 REPORTER_ASSERT(reporter, nullptr == mipmap); |
101 | 104 |
102 mipmap = SkMipMapCache::AddAndRef(src, cache); | 105 mipmap = SkMipMapCache::AddAndRef(src, treatment, cache); |
103 REPORTER_ASSERT(reporter, mipmap); | 106 REPORTER_ASSERT(reporter, mipmap); |
104 | 107 |
105 { | 108 { |
106 const SkMipMap* mm = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(s
rc), cache); | 109 const SkMipMap* mm = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(s
rc), treatment, |
| 110 cache); |
107 REPORTER_ASSERT(reporter, mm); | 111 REPORTER_ASSERT(reporter, mm); |
108 REPORTER_ASSERT(reporter, mm == mipmap); | 112 REPORTER_ASSERT(reporter, mm == mipmap); |
109 mm->unref(); | 113 mm->unref(); |
110 } | 114 } |
111 | 115 |
112 check_data(reporter, mipmap, 2, kInCache, kLocked); | 116 check_data(reporter, mipmap, 2, kInCache, kLocked); |
113 | 117 |
114 mipmap->unref(); | 118 mipmap->unref(); |
115 // tricky, since technically after this I'm no longer an owner, but since th
e cache is | 119 // tricky, since technically after this I'm no longer an owner, but since th
e cache is |
116 // local, I know it won't get purged behind my back | 120 // local, I know it won't get purged behind my back |
117 check_data(reporter, mipmap, 1, kInCache, kNotLocked); | 121 check_data(reporter, mipmap, 1, kInCache, kNotLocked); |
118 | 122 |
119 // find us again | 123 // find us again |
120 mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src), cache); | 124 mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src), treatment,
cache); |
121 check_data(reporter, mipmap, 2, kInCache, kLocked); | 125 check_data(reporter, mipmap, 2, kInCache, kLocked); |
122 | 126 |
123 cache->purgeAll(); | 127 cache->purgeAll(); |
124 check_data(reporter, mipmap, 1, kNotInCache, kLocked); | 128 check_data(reporter, mipmap, 1, kNotInCache, kLocked); |
125 | 129 |
126 mipmap->unref(); | 130 mipmap->unref(); |
127 } | 131 } |
128 | 132 |
129 static void test_mipmap_notify(skiatest::Reporter* reporter, SkResourceCache* ca
che) { | 133 static void test_mipmap_notify(skiatest::Reporter* reporter, SkResourceCache* ca
che) { |
| 134 const SkSourceGammaTreatment treatment = SkSourceGammaTreatment::kIgnore; |
130 const int N = 3; | 135 const int N = 3; |
| 136 |
131 SkBitmap src[N]; | 137 SkBitmap src[N]; |
132 for (int i = 0; i < N; ++i) { | 138 for (int i = 0; i < N; ++i) { |
133 src[i].allocN32Pixels(5, 5); | 139 src[i].allocN32Pixels(5, 5); |
134 src[i].setImmutable(); | 140 src[i].setImmutable(); |
135 SkMipMapCache::AddAndRef(src[i], cache)->unref(); | 141 SkMipMapCache::AddAndRef(src[i], treatment, cache)->unref(); |
136 } | 142 } |
137 | 143 |
138 for (int i = 0; i < N; ++i) { | 144 for (int i = 0; i < N; ++i) { |
139 const SkMipMap* mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Ma
ke(src[i]), cache); | 145 const SkMipMap* mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Ma
ke(src[i]), |
| 146 treatment, cache); |
140 if (cache) { | 147 if (cache) { |
141 // if cache is null, we're working on the global cache, and other th
reads might purge | 148 // if cache is null, we're working on the global cache, and other th
reads might purge |
142 // it, making this check fragile. | 149 // it, making this check fragile. |
143 REPORTER_ASSERT(reporter, mipmap); | 150 REPORTER_ASSERT(reporter, mipmap); |
144 } | 151 } |
145 SkSafeUnref(mipmap); | 152 SkSafeUnref(mipmap); |
146 | 153 |
147 src[i].reset(); // delete the underlying pixelref, which *should* remove
us from the cache | 154 src[i].reset(); // delete the underlying pixelref, which *should* remove
us from the cache |
148 | 155 |
149 mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src[i]), cach
e); | 156 mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src[i]), trea
tment, cache); |
150 REPORTER_ASSERT(reporter, !mipmap); | 157 REPORTER_ASSERT(reporter, !mipmap); |
151 } | 158 } |
152 } | 159 } |
153 | 160 |
154 static void test_bitmap_notify(skiatest::Reporter* reporter, SkResourceCache* ca
che) { | 161 static void test_bitmap_notify(skiatest::Reporter* reporter, SkResourceCache* ca
che) { |
155 const SkIRect subset = SkIRect::MakeWH(5, 5); | 162 const SkIRect subset = SkIRect::MakeWH(5, 5); |
156 const int N = 3; | 163 const int N = 3; |
157 SkBitmap src[N], dst[N]; | 164 SkBitmap src[N], dst[N]; |
158 for (int i = 0; i < N; ++i) { | 165 for (int i = 0; i < N; ++i) { |
159 src[i].allocN32Pixels(5, 5); | 166 src[i].allocN32Pixels(5, 5); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 327 |
321 test_discarded_image(reporter, xforms[i], []() { | 328 test_discarded_image(reporter, xforms[i], []() { |
322 SkPictureRecorder recorder; | 329 SkPictureRecorder recorder; |
323 SkCanvas* canvas = recorder.beginRecording(10, 10); | 330 SkCanvas* canvas = recorder.beginRecording(10, 10); |
324 canvas->clear(SK_ColorCYAN); | 331 canvas->clear(SK_ColorCYAN); |
325 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), | 332 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), |
326 SkISize::Make(10, 10), nullptr, null
ptr); | 333 SkISize::Make(10, 10), nullptr, null
ptr); |
327 }); | 334 }); |
328 } | 335 } |
329 } | 336 } |
OLD | NEW |