OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 REPORTER_ASSERT(reporter, NULL != lazy.getPixels()); | 135 REPORTER_ASSERT(reporter, NULL != lazy.getPixels()); |
136 if (NULL == lazy.getPixels()) { | 136 if (NULL == lazy.getPixels()) { |
137 continue; | 137 continue; |
138 } | 138 } |
139 } | 139 } |
140 bool comparePixels = (SkImageEncoder::kPNG_Type == type); | 140 bool comparePixels = (SkImageEncoder::kPNG_Type == type); |
141 compare_bitmaps(reporter, original, lazy, comparePixels); | 141 compare_bitmaps(reporter, original, lazy, comparePixels); |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
| 145 static void purge_global_scaled_image_cache() { |
| 146 size_t byteLimit = SkScaledImageCache::GetByteLimit(); |
| 147 SkScaledImageCache::SetByteLimit(0); |
| 148 SkScaledImageCache::SetByteLimit(byteLimit); |
| 149 } |
| 150 |
145 //////////////////////////////////////////////////////////////////////////////// | 151 //////////////////////////////////////////////////////////////////////////////// |
146 static bool install_skCachingPixelRef(SkData* encoded, SkBitmap* dst) { | 152 static bool install_skCachingPixelRef(SkData* encoded, SkBitmap* dst) { |
147 return SkCachingPixelRef::Install( | 153 return SkCachingPixelRef::Install( |
148 SkDecodingImageGenerator::Create( | 154 SkDecodingImageGenerator::Create( |
149 encoded, SkDecodingImageGenerator::Options()), dst); | 155 encoded, SkDecodingImageGenerator::Options()), dst); |
150 } | 156 } |
151 static bool install_skDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { | 157 static bool install_skDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { |
152 // Use system-default discardable memory. | 158 // Use system-default discardable memory. |
153 return SkInstallDiscardablePixelRef( | 159 return SkInstallDiscardablePixelRef( |
154 SkDecodingImageGenerator::Create( | 160 SkDecodingImageGenerator::Create( |
155 encoded, SkDecodingImageGenerator::Options()), dst, NULL); | 161 encoded, SkDecodingImageGenerator::Options()), dst, NULL); |
156 } | 162 } |
157 | 163 |
158 //////////////////////////////////////////////////////////////////////////////// | 164 //////////////////////////////////////////////////////////////////////////////// |
159 /** | 165 /** |
160 * This checks to see that a SkCachingPixelRef and a | 166 * This checks to see that a SkCachingPixelRef and a |
161 * SkDiscardablePixelRef works as advertised with a | 167 * SkDiscardablePixelRef works as advertised with a |
162 * SkDecodingImageGenerator. | 168 * SkDecodingImageGenerator. |
163 */ | 169 */ |
164 DEF_TEST(DecodingImageGenerator, reporter) { | 170 DEF_TEST(DecodingImageGenerator, reporter) { |
165 test_three_encodings(reporter, install_skCachingPixelRef); | 171 test_three_encodings(reporter, install_skCachingPixelRef); |
| 172 purge_global_scaled_image_cache(); |
166 test_three_encodings(reporter, install_skDiscardablePixelRef); | 173 test_three_encodings(reporter, install_skDiscardablePixelRef); |
167 } | 174 } |
168 | 175 |
169 class TestImageGenerator : public SkImageGenerator { | 176 class TestImageGenerator : public SkImageGenerator { |
170 public: | 177 public: |
171 enum TestType { | 178 enum TestType { |
172 kFailGetInfo_TestType, | 179 kFailGetInfo_TestType, |
173 kFailGetPixels_TestType, | 180 kFailGetPixels_TestType, |
174 kSucceedGetPixels_TestType, | 181 kSucceedGetPixels_TestType, |
175 kLast_TestType = kSucceedGetPixels_TestType | 182 kLast_TestType = kSucceedGetPixels_TestType |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 DEF_TEST(DiscardableAndCachingPixelRef, reporter) { | 295 DEF_TEST(DiscardableAndCachingPixelRef, reporter) { |
289 test_newlockdelete(reporter); | 296 test_newlockdelete(reporter); |
290 | 297 |
291 check_pixelref(TestImageGenerator::kFailGetInfo_TestType, | 298 check_pixelref(TestImageGenerator::kFailGetInfo_TestType, |
292 reporter, kSkCaching_PixelRefType, NULL); | 299 reporter, kSkCaching_PixelRefType, NULL); |
293 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, | 300 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, |
294 reporter, kSkCaching_PixelRefType, NULL); | 301 reporter, kSkCaching_PixelRefType, NULL); |
295 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, | 302 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, |
296 reporter, kSkCaching_PixelRefType, NULL); | 303 reporter, kSkCaching_PixelRefType, NULL); |
297 | 304 |
| 305 purge_global_scaled_image_cache(); |
| 306 |
298 check_pixelref(TestImageGenerator::kFailGetInfo_TestType, | 307 check_pixelref(TestImageGenerator::kFailGetInfo_TestType, |
299 reporter, kSkDiscardable_PixelRefType, NULL); | 308 reporter, kSkDiscardable_PixelRefType, NULL); |
300 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, | 309 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, |
301 reporter, kSkDiscardable_PixelRefType, NULL); | 310 reporter, kSkDiscardable_PixelRefType, NULL); |
302 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, | 311 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, |
303 reporter, kSkDiscardable_PixelRefType, NULL); | 312 reporter, kSkDiscardable_PixelRefType, NULL); |
304 | 313 |
305 SkAutoTUnref<SkDiscardableMemoryPool> pool( | 314 SkAutoTUnref<SkDiscardableMemoryPool> pool( |
306 SkNEW_ARGS(SkDiscardableMemoryPool, (1, NULL))); | 315 SkNEW_ARGS(SkDiscardableMemoryPool, (1, NULL))); |
307 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); | 316 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); |
308 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, | 317 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, |
309 reporter, kSkDiscardable_PixelRefType, pool); | 318 reporter, kSkDiscardable_PixelRefType, pool); |
310 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); | 319 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); |
311 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, | 320 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, |
312 reporter, kSkDiscardable_PixelRefType, pool); | 321 reporter, kSkDiscardable_PixelRefType, pool); |
313 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); | 322 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); |
314 | 323 |
315 SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool(); | 324 SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool(); |
316 // Only acts differently from NULL on a platform that has a | 325 // Only acts differently from NULL on a platform that has a |
317 // default discardable memory implementation that differs from the | 326 // default discardable memory implementation that differs from the |
318 // global DM pool. | 327 // global DM pool. |
319 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, | 328 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, |
320 reporter, kSkDiscardable_PixelRefType, globalPool); | 329 reporter, kSkDiscardable_PixelRefType, globalPool); |
321 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, | 330 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, |
322 reporter, kSkDiscardable_PixelRefType, globalPool); | 331 reporter, kSkDiscardable_PixelRefType, globalPool); |
323 } | 332 } |
OLD | NEW |