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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 sk_sp<SkImage> (*buildImage)()) { | 266 sk_sp<SkImage> (*buildImage)()) { |
267 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10)); | 267 auto surface(SkSurface::MakeRasterN32Premul(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 sk_sp<SkImage> image(buildImage()); | 276 sk_sp<SkImage> image(buildImage()); |
277 | 277 |
(...skipping 28 matching lines...) Expand all Loading... |
306 // To exercise the first cache type, we use generated/picture-backed SkImage
s. | 306 // To exercise the first cache type, we use generated/picture-backed SkImage
s. |
307 // To exercise the latter, we draw scaled bitmap images using HQ filters. | 307 // To exercise the latter, we draw scaled bitmap images using HQ filters. |
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 auto surface(SkSurface::MakeRasterN32Premul(10, 10)); |
317 surface->getCanvas()->clear(SK_ColorCYAN); | 317 surface->getCanvas()->clear(SK_ColorCYAN); |
318 return surface->makeImageSnapshot(); | 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 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), | 325 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), |
326 SkISize::Make(10, 10), nullptr, null
ptr); | 326 SkISize::Make(10, 10), nullptr, null
ptr); |
327 }); | 327 }); |
328 } | 328 } |
329 } | 329 } |
OLD | NEW |