Chromium Code Reviews| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); | 89 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cach e) { | 92 static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cach e) { |
| 93 cache->purgeAll(); | 93 cache->purgeAll(); |
| 94 | 94 |
| 95 SkBitmap src; | 95 SkBitmap src; |
| 96 src.allocN32Pixels(5, 5); | 96 src.allocN32Pixels(5, 5); |
| 97 src.setImmutable(); | 97 src.setImmutable(); |
| 98 | 98 |
| 99 const SkMipMap* mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(s rc), cache); | 99 const SkMipMap::SrcGammaMode mode = SkMipMap::kIgnore_SrcGammaMode; |
| 100 | |
| 101 const SkMipMap* mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(s rc), mode, cache); | |
| 100 REPORTER_ASSERT(reporter, nullptr == mipmap); | 102 REPORTER_ASSERT(reporter, nullptr == mipmap); |
| 101 | 103 |
| 102 mipmap = SkMipMapCache::AddAndRef(src, cache); | 104 mipmap = SkMipMapCache::AddAndRef(src, mode, cache); |
| 103 REPORTER_ASSERT(reporter, mipmap); | 105 REPORTER_ASSERT(reporter, mipmap); |
| 104 | 106 |
| 105 { | 107 { |
| 106 const SkMipMap* mm = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(s rc), cache); | 108 const SkMipMap* mm = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(s rc), mode, cache); |
| 107 REPORTER_ASSERT(reporter, mm); | 109 REPORTER_ASSERT(reporter, mm); |
| 108 REPORTER_ASSERT(reporter, mm == mipmap); | 110 REPORTER_ASSERT(reporter, mm == mipmap); |
| 109 mm->unref(); | 111 mm->unref(); |
| 110 } | 112 } |
| 111 | 113 |
| 112 check_data(reporter, mipmap, 2, kInCache, kLocked); | 114 check_data(reporter, mipmap, 2, kInCache, kLocked); |
| 113 | 115 |
| 114 mipmap->unref(); | 116 mipmap->unref(); |
| 115 // tricky, since technically after this I'm no longer an owner, but since th e cache is | 117 // tricky, since technically after this I'm no longer an owner, but since th e cache is |
| 116 // local, I know it won't get purged behind my back | 118 // local, I know it won't get purged behind my back |
| 117 check_data(reporter, mipmap, 1, kInCache, kNotLocked); | 119 check_data(reporter, mipmap, 1, kInCache, kNotLocked); |
| 118 | 120 |
| 119 // find us again | 121 // find us again |
| 120 mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src), cache); | 122 mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src), mode, cache ); |
| 121 check_data(reporter, mipmap, 2, kInCache, kLocked); | 123 check_data(reporter, mipmap, 2, kInCache, kLocked); |
| 122 | 124 |
| 123 cache->purgeAll(); | 125 cache->purgeAll(); |
| 124 check_data(reporter, mipmap, 1, kNotInCache, kLocked); | 126 check_data(reporter, mipmap, 1, kNotInCache, kLocked); |
| 125 | 127 |
| 126 mipmap->unref(); | 128 mipmap->unref(); |
| 127 } | 129 } |
| 128 | 130 |
| 129 static void test_mipmap_notify(skiatest::Reporter* reporter, SkResourceCache* ca che) { | 131 static void test_mipmap_notify(skiatest::Reporter* reporter, SkResourceCache* ca che) { |
| 132 const SkMipMap::SrcGammaMode mode = SkMipMap::kIgnore_SrcGammaMode; | |
| 130 const int N = 3; | 133 const int N = 3; |
| 134 | |
| 131 SkBitmap src[N]; | 135 SkBitmap src[N]; |
| 132 for (int i = 0; i < N; ++i) { | 136 for (int i = 0; i < N; ++i) { |
| 133 src[i].allocN32Pixels(5, 5); | 137 src[i].allocN32Pixels(5, 5); |
| 134 src[i].setImmutable(); | 138 src[i].setImmutable(); |
| 135 SkMipMapCache::AddAndRef(src[i], cache)->unref(); | 139 SkMipMapCache::AddAndRef(src[i], mode, cache)->unref(); |
| 136 } | 140 } |
| 137 | 141 |
| 138 for (int i = 0; i < N; ++i) { | 142 for (int i = 0; i < N; ++i) { |
| 139 const SkMipMap* mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Ma ke(src[i]), cache); | 143 const SkMipMap* mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Ma ke(src[i]), mode, cache); |
|
msarett
2016/06/03 16:54:17
nit: 100 chars
reed1
2016/06/07 16:01:10
Done.
| |
| 140 if (cache) { | 144 if (cache) { |
| 141 // if cache is null, we're working on the global cache, and other th reads might purge | 145 // if cache is null, we're working on the global cache, and other th reads might purge |
| 142 // it, making this check fragile. | 146 // it, making this check fragile. |
| 143 REPORTER_ASSERT(reporter, mipmap); | 147 REPORTER_ASSERT(reporter, mipmap); |
| 144 } | 148 } |
| 145 SkSafeUnref(mipmap); | 149 SkSafeUnref(mipmap); |
| 146 | 150 |
| 147 src[i].reset(); // delete the underlying pixelref, which *should* remove us from the cache | 151 src[i].reset(); // delete the underlying pixelref, which *should* remove us from the cache |
| 148 | 152 |
| 149 mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src[i]), cach e); | 153 mipmap = SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(src[i]), mode , cache); |
| 150 REPORTER_ASSERT(reporter, !mipmap); | 154 REPORTER_ASSERT(reporter, !mipmap); |
| 151 } | 155 } |
| 152 } | 156 } |
| 153 | 157 |
| 154 static void test_bitmap_notify(skiatest::Reporter* reporter, SkResourceCache* ca che) { | 158 static void test_bitmap_notify(skiatest::Reporter* reporter, SkResourceCache* ca che) { |
| 155 const SkIRect subset = SkIRect::MakeWH(5, 5); | 159 const SkIRect subset = SkIRect::MakeWH(5, 5); |
| 156 const int N = 3; | 160 const int N = 3; |
| 157 SkBitmap src[N], dst[N]; | 161 SkBitmap src[N], dst[N]; |
| 158 for (int i = 0; i < N; ++i) { | 162 for (int i = 0; i < N; ++i) { |
| 159 src[i].allocN32Pixels(5, 5); | 163 src[i].allocN32Pixels(5, 5); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 | 324 |
| 321 test_discarded_image(reporter, xforms[i], []() { | 325 test_discarded_image(reporter, xforms[i], []() { |
| 322 SkPictureRecorder recorder; | 326 SkPictureRecorder recorder; |
| 323 SkCanvas* canvas = recorder.beginRecording(10, 10); | 327 SkCanvas* canvas = recorder.beginRecording(10, 10); |
| 324 canvas->clear(SK_ColorCYAN); | 328 canvas->clear(SK_ColorCYAN); |
| 325 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), | 329 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), |
| 326 SkISize::Make(10, 10), nullptr, null ptr); | 330 SkISize::Make(10, 10), nullptr, null ptr); |
| 327 }); | 331 }); |
| 328 } | 332 } |
| 329 } | 333 } |
| OLD | NEW |