| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #ifdef SK_DEBUG | 8 #ifdef SK_DEBUG |
| 9 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| 11 #include "SkBitmapFactory.h" | 11 #include "SkBitmapFactory.h" |
| 12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkColor.h" | 13 #include "SkColor.h" |
| 14 #include "SkData.h" | 14 #include "SkData.h" |
| 15 #include "SkImageDecoder.h" | 15 #include "SkImageDecoder.h" |
| 16 #include "SkImageEncoder.h" | 16 #include "SkImageEncoder.h" |
| 17 #include "SkLazyPixelRef.h" | |
| 18 #include "SkLruImageCache.h" | 17 #include "SkLruImageCache.h" |
| 19 #include "SkPaint.h" | 18 #include "SkPaint.h" |
| 20 #include "SkPurgeableImageCache.h" | 19 #include "SkPurgeableImageCache.h" |
| 21 #include "SkStream.h" | 20 #include "SkStream.h" |
| 22 #include "SkTemplates.h" | 21 #include "SkTemplates.h" |
| 23 #include "Test.h" | 22 #include "Test.h" |
| 24 | 23 |
| 25 static SkBitmap* create_bitmap() { | 24 static SkBitmap* create_bitmap() { |
| 26 SkBitmap* bm = SkNEW(SkBitmap); | 25 SkBitmap* bm = SkNEW(SkBitmap); |
| 27 // Use a large bitmap. | 26 // Use a large bitmap. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 assert_bounds_equal(reporter, origBitmap, *bitmapFromFactory.get()); | 106 assert_bounds_equal(reporter, origBitmap, *bitmapFromFactory.get()); |
| 108 | 107 |
| 109 SkPixelRef* pixelRef = bitmapFromFactory->pixelRef(); | 108 SkPixelRef* pixelRef = bitmapFromFactory->pixelRef(); |
| 110 REPORTER_ASSERT(reporter, pixelRef != NULL); | 109 REPORTER_ASSERT(reporter, pixelRef != NULL); |
| 111 if (NULL == cache) { | 110 if (NULL == cache) { |
| 112 // This assumes that installPixelRef called lockPixels. | 111 // This assumes that installPixelRef called lockPixels. |
| 113 REPORTER_ASSERT(reporter, bitmapFromFactory->readyToDraw()); | 112 REPORTER_ASSERT(reporter, bitmapFromFactory->readyToDraw()); |
| 114 } else { | 113 } else { |
| 115 // Lazy decoding | 114 // Lazy decoding |
| 116 REPORTER_ASSERT(reporter, !bitmapFromFactory->readyToDraw()); | 115 REPORTER_ASSERT(reporter, !bitmapFromFactory->readyToDraw()); |
| 117 SkLazyPixelRef* lazyRef = static_cast<SkLazyPixelRef*>(pixelRef); | |
| 118 intptr_t cacheID = lazyRef->getCacheId(); | |
| 119 REPORTER_ASSERT(reporter, cache->getMemoryStatus(cacheID) | |
| 120 != SkImageCache::kPinned_MemoryStatus); | |
| 121 { | 116 { |
| 122 SkAutoLockPixels alp(*bitmapFromFactory.get()); | 117 SkAutoLockPixels alp(*bitmapFromFactory.get()); |
| 123 REPORTER_ASSERT(reporter, bitmapFromFactory->readyToDraw()); | 118 REPORTER_ASSERT(reporter, bitmapFromFactory->readyToDraw()); |
| 124 cacheID = lazyRef->getCacheId(); | |
| 125 REPORTER_ASSERT(reporter, cache->getMemoryStatus(cacheID) | |
| 126 == SkImageCache::kPinned_MemoryStatus); | |
| 127 } | 119 } |
| 128 REPORTER_ASSERT(reporter, !bitmapFromFactory->readyToDraw()); | 120 REPORTER_ASSERT(reporter, !bitmapFromFactory->readyToDraw()); |
| 129 REPORTER_ASSERT(reporter, cache->getMemoryStatus(cacheID) | |
| 130 != SkImageCache::kPinned_MemoryStatus); | |
| 131 bitmapFromFactory.free(); | |
| 132 REPORTER_ASSERT(reporter, cache->getMemoryStatus(cacheID) | |
| 133 == SkImageCache::kFreed_MemoryStatus); | |
| 134 } | 121 } |
| 135 } | 122 } |
| 136 | 123 |
| 137 class ImageCacheHolder : public SkNoncopyable { | 124 class ImageCacheHolder : public SkNoncopyable { |
| 138 | 125 |
| 139 public: | 126 public: |
| 140 ~ImageCacheHolder() { | 127 ~ImageCacheHolder() { |
| 141 fCaches.safeUnrefAll(); | 128 fCaches.safeUnrefAll(); |
| 142 } | 129 } |
| 143 | 130 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 if (encodeSucceeded) { | 175 if (encodeSucceeded) { |
| 189 test_factory(reporter, cache, encodedBitmap, *bitmap.get()); | 176 test_factory(reporter, cache, encodedBitmap, *bitmap.get()); |
| 190 } | 177 } |
| 191 } | 178 } |
| 192 } | 179 } |
| 193 | 180 |
| 194 #include "TestClassDef.h" | 181 #include "TestClassDef.h" |
| 195 DEFINE_TESTCLASS("BitmapFactory", TestBitmapFactoryClass, TestBitmapFactory) | 182 DEFINE_TESTCLASS("BitmapFactory", TestBitmapFactoryClass, TestBitmapFactory) |
| 196 | 183 |
| 197 #endif // SK_DEBUG | 184 #endif // SK_DEBUG |
| OLD | NEW |