| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 // http://skbug.com/2894 | 93 // http://skbug.com/2894 |
| 94 DEF_TEST(BitmapCache_add_rect, reporter) { | 94 DEF_TEST(BitmapCache_add_rect, reporter) { |
| 95 SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardabl
eFactory(); | 95 SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardabl
eFactory(); |
| 96 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); | 96 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); |
| 97 | 97 |
| 98 SkAutoTDelete<SkResourceCache> cache; | 98 SkAutoTDelete<SkResourceCache> cache; |
| 99 if (factory) { | 99 if (factory) { |
| 100 cache.reset(SkNEW_ARGS(SkResourceCache, (factory))); | 100 cache.reset(new SkResourceCache(factory)); |
| 101 } else { | 101 } else { |
| 102 const size_t byteLimit = 100 * 1024; | 102 const size_t byteLimit = 100 * 1024; |
| 103 cache.reset(SkNEW_ARGS(SkResourceCache, (byteLimit))); | 103 cache.reset(new SkResourceCache(byteLimit)); |
| 104 } | 104 } |
| 105 SkBitmap cachedBitmap; | 105 SkBitmap cachedBitmap; |
| 106 make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator); | 106 make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator); |
| 107 cachedBitmap.setImmutable(); | 107 cachedBitmap.setImmutable(); |
| 108 | 108 |
| 109 SkBitmap bm; | 109 SkBitmap bm; |
| 110 SkIRect rect = SkIRect::MakeWH(5, 5); | 110 SkIRect rect = SkIRect::MakeWH(5, 5); |
| 111 uint32_t cachedID = cachedBitmap.getGenerationID(); | 111 uint32_t cachedID = cachedBitmap.getGenerationID(); |
| 112 SkPixelRef* cachedPR = cachedBitmap.pixelRef(); | 112 SkPixelRef* cachedPR = cachedBitmap.pixelRef(); |
| 113 | 113 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 REPORTER_ASSERT(reporter, !found); | 236 REPORTER_ASSERT(reporter, !found); |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 | 239 |
| 240 DEF_TEST(BitmapCache_discarded_bitmap, reporter) { | 240 DEF_TEST(BitmapCache_discarded_bitmap, reporter) { |
| 241 SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardabl
eFactory(); | 241 SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardabl
eFactory(); |
| 242 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); | 242 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); |
| 243 | 243 |
| 244 SkAutoTDelete<SkResourceCache> cache; | 244 SkAutoTDelete<SkResourceCache> cache; |
| 245 if (factory) { | 245 if (factory) { |
| 246 cache.reset(SkNEW_ARGS(SkResourceCache, (factory))); | 246 cache.reset(new SkResourceCache(factory)); |
| 247 } else { | 247 } else { |
| 248 const size_t byteLimit = 100 * 1024; | 248 const size_t byteLimit = 100 * 1024; |
| 249 cache.reset(SkNEW_ARGS(SkResourceCache, (byteLimit))); | 249 cache.reset(new SkResourceCache(byteLimit)); |
| 250 } | 250 } |
| 251 SkBitmap cachedBitmap; | 251 SkBitmap cachedBitmap; |
| 252 make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator); | 252 make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator); |
| 253 cachedBitmap.setImmutable(); | 253 cachedBitmap.setImmutable(); |
| 254 cachedBitmap.unlockPixels(); | 254 cachedBitmap.unlockPixels(); |
| 255 | 255 |
| 256 SkBitmap bm; | 256 SkBitmap bm; |
| 257 SkIRect rect = SkIRect::MakeWH(5, 5); | 257 SkIRect rect = SkIRect::MakeWH(5, 5); |
| 258 | 258 |
| 259 // Add a bitmap to the cache. | 259 // Add a bitmap to the cache. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 279 cachedBitmap.unlockPixels(); | 279 cachedBitmap.unlockPixels(); |
| 280 | 280 |
| 281 // We can add the bitmap back to the cache and find it again. | 281 // We can add the bitmap back to the cache and find it again. |
| 282 REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.pixelRef(), rect,
cachedBitmap, cache)); | 282 REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.pixelRef(), rect,
cachedBitmap, cache)); |
| 283 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID()
, rect, &bm, cache)); | 283 REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID()
, rect, &bm, cache)); |
| 284 | 284 |
| 285 test_mipmapcache(reporter, cache); | 285 test_mipmapcache(reporter, cache); |
| 286 test_bitmap_notify(reporter, cache); | 286 test_bitmap_notify(reporter, cache); |
| 287 test_mipmap_notify(reporter, cache); | 287 test_mipmap_notify(reporter, cache); |
| 288 } | 288 } |
| OLD | NEW |