| 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 SkAutoTUnref<SkDiscardableMemoryPool> pool( | 256 SkAutoTUnref<SkDiscardableMemoryPool> pool( |
| 257 SkDiscardableMemoryPool::Create(byteLimit, nullptr)); | 257 SkDiscardableMemoryPool::Create(byteLimit, nullptr)); |
| 258 gPool = pool.get(); | 258 gPool = pool.get(); |
| 259 SkResourceCache::DiscardableFactory factory = pool_factory; | 259 SkResourceCache::DiscardableFactory factory = pool_factory; |
| 260 SkResourceCache cache(factory); | 260 SkResourceCache cache(factory); |
| 261 testBitmapCache_discarded_bitmap(reporter, &cache, factory); | 261 testBitmapCache_discarded_bitmap(reporter, &cache, factory); |
| 262 } | 262 } |
| 263 } | 263 } |
| 264 | 264 |
| 265 static void test_discarded_image(skiatest::Reporter* reporter, const SkMatrix& t
ransform, | 265 static void test_discarded_image(skiatest::Reporter* reporter, const SkMatrix& t
ransform, |
| 266 SkImage* (*buildImage)()) { | 266 sk_sp<SkImage> (*buildImage)()) { |
| 267 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10)); | 267 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10)); |
| 268 SkCanvas* canvas = surface->getCanvas(); | 268 SkCanvas* canvas = surface->getCanvas(); |
| 269 | 269 |
| 270 // SkBitmapCache is global, so other threads could be evicting our bitmaps.
Loop a few times | 270 // SkBitmapCache is global, so other threads could be evicting our bitmaps.
Loop a few times |
| 271 // to mitigate this risk. | 271 // to mitigate this risk. |
| 272 const unsigned kRepeatCount = 42; | 272 const unsigned kRepeatCount = 42; |
| 273 for (unsigned i = 0; i < kRepeatCount; ++i) { | 273 for (unsigned i = 0; i < kRepeatCount; ++i) { |
| 274 SkAutoCanvasRestore acr(canvas, true); | 274 SkAutoCanvasRestore acr(canvas, true); |
| 275 | 275 |
| 276 SkAutoTUnref<SkImage> image(buildImage()); | 276 sk_sp<SkImage> image(buildImage()); |
| 277 | 277 |
| 278 // always use high quality to ensure caching when scaled | 278 // always use high quality to ensure caching when scaled |
| 279 SkPaint paint; | 279 SkPaint paint; |
| 280 paint.setFilterQuality(kHigh_SkFilterQuality); | 280 paint.setFilterQuality(kHigh_SkFilterQuality); |
| 281 | 281 |
| 282 // draw the image (with a transform, to tickle different code paths) to
ensure | 282 // draw the image (with a transform, to tickle different code paths) to
ensure |
| 283 // any associated resources get cached | 283 // any associated resources get cached |
| 284 canvas->concat(transform); | 284 canvas->concat(transform); |
| 285 canvas->drawImage(image, 0, 0, &paint); | 285 canvas->drawImage(image, 0, 0, &paint); |
| 286 | 286 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 308 | 308 |
| 309 const SkMatrix xforms[] = { | 309 const SkMatrix xforms[] = { |
| 310 SkMatrix::MakeScale(1, 1), | 310 SkMatrix::MakeScale(1, 1), |
| 311 SkMatrix::MakeScale(1.7f, 0.5f), | 311 SkMatrix::MakeScale(1.7f, 0.5f), |
| 312 }; | 312 }; |
| 313 | 313 |
| 314 for (size_t i = 0; i < SK_ARRAY_COUNT(xforms); ++i) { | 314 for (size_t i = 0; i < SK_ARRAY_COUNT(xforms); ++i) { |
| 315 test_discarded_image(reporter, xforms[i], []() { | 315 test_discarded_image(reporter, xforms[i], []() { |
| 316 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10
)); | 316 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10
)); |
| 317 surface->getCanvas()->clear(SK_ColorCYAN); | 317 surface->getCanvas()->clear(SK_ColorCYAN); |
| 318 return surface->newImageSnapshot(); | 318 return surface->makeImageSnapshot(); |
| 319 }); | 319 }); |
| 320 | 320 |
| 321 test_discarded_image(reporter, xforms[i], []() { | 321 test_discarded_image(reporter, xforms[i], []() { |
| 322 SkPictureRecorder recorder; | 322 SkPictureRecorder recorder; |
| 323 SkCanvas* canvas = recorder.beginRecording(10, 10); | 323 SkCanvas* canvas = recorder.beginRecording(10, 10); |
| 324 canvas->clear(SK_ColorCYAN); | 324 canvas->clear(SK_ColorCYAN); |
| 325 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 325 sk_sp<SkPicture> picture(recorder.endRecording()); |
| 326 return SkImage::NewFromPicture(picture, SkISize::Make(10, 10), nullp
tr, nullptr); | 326 return SkImage::MakeFromPicture(picture, SkISize::Make(10, 10), null
ptr, nullptr); |
| 327 }); | 327 }); |
| 328 } | 328 } |
| 329 } | 329 } |
| OLD | NEW |