| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 bool comparePixels = (SkImageEncoder::kPNG_Type == type); | 141 bool comparePixels = (SkImageEncoder::kPNG_Type == type); |
| 142 compare_bitmaps(reporter, original, lazy, comparePixels); | 142 compare_bitmaps(reporter, original, lazy, comparePixels); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 //////////////////////////////////////////////////////////////////////////////// | 146 //////////////////////////////////////////////////////////////////////////////// |
| 147 static bool install_skCachingPixelRef(SkData* encoded, SkBitmap* dst) { | 147 static bool install_skCachingPixelRef(SkData* encoded, SkBitmap* dst) { |
| 148 return SkCachingPixelRef::Install( | 148 return SkCachingPixelRef::Install( |
| 149 SkNEW_ARGS(SkDecodingImageGenerator, (encoded)), dst); | 149 SkNewDecodingImageGenerator(encoded, SkDecoderOptions()), dst); |
| 150 } | 150 } |
| 151 static bool install_skDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { | 151 static bool install_skDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { |
| 152 // Use system-default discardable memory. | 152 // Use system-default discardable memory. |
| 153 return SkDecodingImageGenerator::Install(encoded, dst, NULL); | 153 return SkInstallDiscardablePixelRef( |
| 154 SkNewDecodingImageGenerator(encoded, SkDecoderOptions()), dst, NULL); |
| 154 } | 155 } |
| 155 | 156 |
| 156 //////////////////////////////////////////////////////////////////////////////// | 157 //////////////////////////////////////////////////////////////////////////////// |
| 157 /** | 158 /** |
| 158 * This checks to see that a SkCachingPixelRef and a | 159 * This checks to see that a SkCachingPixelRef and a |
| 159 * SkDiscardablePixelRef works as advertised with a | 160 * SkDiscardablePixelRef works as advertised with a |
| 160 * SkDecodingImageGenerator. | 161 * SkDecodingImageGenerator. |
| 161 */ | 162 */ |
| 162 DEF_TEST(DecodingImageGenerator, reporter) { | 163 DEF_TEST(DecodingImageGenerator, reporter) { |
| 163 test_three_encodings(reporter, install_skCachingPixelRef); | 164 test_three_encodings(reporter, install_skCachingPixelRef); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return false; | 207 return false; |
| 207 } | 208 } |
| 208 char* bytePtr = static_cast<char*>(pixels); | 209 char* bytePtr = static_cast<char*>(pixels); |
| 209 for (int y = 0; y < info.fHeight; ++y) { | 210 for (int y = 0; y < info.fHeight; ++y) { |
| 210 sk_memset32(reinterpret_cast<SkColor*>(bytePtr), | 211 sk_memset32(reinterpret_cast<SkColor*>(bytePtr), |
| 211 TestImageGenerator::Color(), info.fWidth); | 212 TestImageGenerator::Color(), info.fWidth); |
| 212 bytePtr += rowBytes; | 213 bytePtr += rowBytes; |
| 213 } | 214 } |
| 214 return true; | 215 return true; |
| 215 } | 216 } |
| 217 |
| 216 private: | 218 private: |
| 217 const TestType fType; | 219 const TestType fType; |
| 218 skiatest::Reporter* const fReporter; | 220 skiatest::Reporter* const fReporter; |
| 219 }; | 221 }; |
| 222 |
| 220 void CheckTestImageGeneratorBitmap(skiatest::Reporter* reporter, | 223 void CheckTestImageGeneratorBitmap(skiatest::Reporter* reporter, |
| 221 const SkBitmap& bm) { | 224 const SkBitmap& bm) { |
| 222 REPORTER_ASSERT(reporter, TestImageGenerator::Width() == bm.width()); | 225 REPORTER_ASSERT(reporter, TestImageGenerator::Width() == bm.width()); |
| 223 REPORTER_ASSERT(reporter, TestImageGenerator::Height() == bm.height()); | 226 REPORTER_ASSERT(reporter, TestImageGenerator::Height() == bm.height()); |
| 224 SkAutoLockPixels autoLockPixels(bm); | 227 SkAutoLockPixels autoLockPixels(bm); |
| 225 REPORTER_ASSERT(reporter, NULL != bm.getPixels()); | 228 REPORTER_ASSERT(reporter, NULL != bm.getPixels()); |
| 226 if (NULL == bm.getPixels()) { | 229 if (NULL == bm.getPixels()) { |
| 227 return; | 230 return; |
| 228 } | 231 } |
| 229 int errors = 0; | 232 int errors = 0; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 REPORTER_ASSERT(reporter, success | 264 REPORTER_ASSERT(reporter, success |
| 262 == (TestImageGenerator::kFailGetInfo_TestType != type)); | 265 == (TestImageGenerator::kFailGetInfo_TestType != type)); |
| 263 if (TestImageGenerator::kSucceedGetPixels_TestType == type) { | 266 if (TestImageGenerator::kSucceedGetPixels_TestType == type) { |
| 264 CheckTestImageGeneratorBitmap(reporter, lazy); | 267 CheckTestImageGeneratorBitmap(reporter, lazy); |
| 265 } else if (TestImageGenerator::kFailGetPixels_TestType == type) { | 268 } else if (TestImageGenerator::kFailGetPixels_TestType == type) { |
| 266 SkAutoLockPixels autoLockPixels(lazy); | 269 SkAutoLockPixels autoLockPixels(lazy); |
| 267 REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); | 270 REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); |
| 268 } | 271 } |
| 269 } | 272 } |
| 270 } // namespace | 273 } // namespace |
| 274 |
| 271 /** | 275 /** |
| 272 * This tests the basic functionality of SkDiscardablePixelRef with a | 276 * This tests the basic functionality of SkDiscardablePixelRef with a |
| 273 * basic SkImageGenerator implementation and several | 277 * basic SkImageGenerator implementation and several |
| 274 * SkDiscardableMemory::Factory choices. | 278 * SkDiscardableMemory::Factory choices. |
| 275 */ | 279 */ |
| 276 DEF_TEST(DiscardableAndCachingPixelRef, reporter) { | 280 DEF_TEST(DiscardableAndCachingPixelRef, reporter) { |
| 277 CheckPixelRef(TestImageGenerator::kFailGetInfo_TestType, | 281 CheckPixelRef(TestImageGenerator::kFailGetInfo_TestType, |
| 278 reporter, kSkCaching_PixelRefType, NULL); | 282 reporter, kSkCaching_PixelRefType, NULL); |
| 279 CheckPixelRef(TestImageGenerator::kFailGetPixels_TestType, | 283 CheckPixelRef(TestImageGenerator::kFailGetPixels_TestType, |
| 280 reporter, kSkCaching_PixelRefType, NULL); | 284 reporter, kSkCaching_PixelRefType, NULL); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 301 SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool(); | 305 SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool(); |
| 302 // Only acts differently from NULL on a platform that has a | 306 // Only acts differently from NULL on a platform that has a |
| 303 // default discardable memory implementation that differs from the | 307 // default discardable memory implementation that differs from the |
| 304 // global DM pool. | 308 // global DM pool. |
| 305 CheckPixelRef(TestImageGenerator::kFailGetPixels_TestType, | 309 CheckPixelRef(TestImageGenerator::kFailGetPixels_TestType, |
| 306 reporter, kSkDiscardable_PixelRefType, globalPool); | 310 reporter, kSkDiscardable_PixelRefType, globalPool); |
| 307 CheckPixelRef(TestImageGenerator::kSucceedGetPixels_TestType, | 311 CheckPixelRef(TestImageGenerator::kSucceedGetPixels_TestType, |
| 308 reporter, kSkDiscardable_PixelRefType, globalPool); | 312 reporter, kSkDiscardable_PixelRefType, globalPool); |
| 309 } | 313 } |
| 310 //////////////////////////////////////////////////////////////////////////////// | 314 //////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |