Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: tests/SkResourceCacheTest.cpp

Issue 1817383002: switch surface to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/ResourceCacheTest.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « tests/ResourceCacheTest.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698