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" |
| 11 #include "SkDecodingImageGenerator.h" |
11 #include "SkForceLinking.h" | 12 #include "SkForceLinking.h" |
12 #include "SkImageDecoder.h" | 13 #include "SkImageDecoder.h" |
13 #include "SkImagePriv.h" | 14 #include "SkImagePriv.h" |
14 #include "SkLazyCachingPixelRef.h" | 15 #include "SkLazyCachingPixelRef.h" |
15 #include "SkLazyPixelRef.h" | 16 #include "SkLazyPixelRef.h" |
16 #include "SkScaledImageCache.h" | 17 #include "SkScaledImageCache.h" |
17 #include "SkStream.h" | 18 #include "SkStream.h" |
18 | 19 |
19 #include "Test.h" | 20 #include "Test.h" |
20 #include "TestClassDef.h" | 21 #include "TestClassDef.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 DEF_TEST(CachingPixelRef, reporter) { | 238 DEF_TEST(CachingPixelRef, reporter) { |
238 SkBitmap lazy; | 239 SkBitmap lazy; |
239 // test the error handling | 240 // test the error handling |
240 REPORTER_ASSERT(reporter, !TestPixelRef::Install(&lazy, 0)); | 241 REPORTER_ASSERT(reporter, !TestPixelRef::Install(&lazy, 0)); |
241 // onDecodeInfo should succeed, allowing installation | 242 // onDecodeInfo should succeed, allowing installation |
242 REPORTER_ASSERT(reporter, TestPixelRef::Install(&lazy, 1)); | 243 REPORTER_ASSERT(reporter, TestPixelRef::Install(&lazy, 1)); |
243 SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. | 244 SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. |
244 // onDecodePixels should fail, so getting pixels will fail. | 245 // onDecodePixels should fail, so getting pixels will fail. |
245 REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); | 246 REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); |
246 } | 247 } |
| 248 |
| 249 static void compare_with_SkDecodingImageGenerator(skiatest::Reporter* reporter, |
| 250 SkData* encoded, |
| 251 const SkBitmap& original, |
| 252 bool comparePixels) { |
| 253 |
| 254 SkBitmap lazy; |
| 255 bool success = SkDecodingImageGenerator::Install(encoded, &lazy); |
| 256 REPORTER_ASSERT(reporter, success); |
| 257 if (!success) { |
| 258 return; |
| 259 } |
| 260 |
| 261 REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); |
| 262 { |
| 263 SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. |
| 264 REPORTER_ASSERT(reporter, NULL != lazy.getPixels()); |
| 265 if (NULL == lazy.getPixels()) { |
| 266 return; |
| 267 } |
| 268 } |
| 269 // pixels should be gone! |
| 270 REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); |
| 271 { |
| 272 SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. |
| 273 REPORTER_ASSERT(reporter, NULL != lazy.getPixels()); |
| 274 } |
| 275 compare_bitmaps(reporter, original, lazy, comparePixels); |
| 276 } |
| 277 DEF_TEST(DecodingImageGenerator, reporter) { |
| 278 test_three_encodings(reporter, compare_with_SkDecodingImageGenerator); |
| 279 } |
OLD | NEW |