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

Side by Side Diff: tests/SerializationTest.cpp

Issue 1832223002: switch xfermodes over to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "SkAnnotationKeys.h" 8 #include "SkAnnotationKeys.h"
9 #include "Resources.h" 9 #include "Resources.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 239 }
240 240
241 static void TestBitmapSerialization(const SkBitmap& validBitmap, 241 static void TestBitmapSerialization(const SkBitmap& validBitmap,
242 const SkBitmap& invalidBitmap, 242 const SkBitmap& invalidBitmap,
243 bool shouldSucceed, 243 bool shouldSucceed,
244 skiatest::Reporter* reporter) { 244 skiatest::Reporter* reporter) {
245 sk_sp<SkImage> validImage(SkImage::MakeFromBitmap(validBitmap)); 245 sk_sp<SkImage> validImage(SkImage::MakeFromBitmap(validBitmap));
246 SkAutoTUnref<SkImageFilter> validBitmapSource(SkImageSource::Create(validIma ge.get())); 246 SkAutoTUnref<SkImageFilter> validBitmapSource(SkImageSource::Create(validIma ge.get()));
247 sk_sp<SkImage> invalidImage(SkImage::MakeFromBitmap(invalidBitmap)); 247 sk_sp<SkImage> invalidImage(SkImage::MakeFromBitmap(invalidBitmap));
248 SkAutoTUnref<SkImageFilter> invalidBitmapSource(SkImageSource::Create(invali dImage.get())); 248 SkAutoTUnref<SkImageFilter> invalidBitmapSource(SkImageSource::Create(invali dImage.get()));
249 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode)) ; 249 sk_sp<SkImageFilter> xfermodeImageFilter(
250 SkAutoTUnref<SkImageFilter> xfermodeImageFilter( 250 SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kSrcOver_Mode),
251 SkXfermodeImageFilter::Create(mode, invalidBitmapSource, validBitmapSour ce)); 251 invalidBitmapSource, validBitmapSource, null ptr));
252 252
253 SkAutoTUnref<SkImageFilter> deserializedFilter( 253 SkAutoTUnref<SkImageFilter> deserializedFilter(
254 TestFlattenableSerialization<SkImageFilter>( 254 TestFlattenableSerialization<SkImageFilter>(
255 xfermodeImageFilter, shouldSucceed, reporter)); 255 xfermodeImageFilter.get(), shouldSucceed, reporter));
256 256
257 // Try to render a small bitmap using the invalid deserialized filter 257 // Try to render a small bitmap using the invalid deserialized filter
258 // to make sure we don't crash while trying to render it 258 // to make sure we don't crash while trying to render it
259 if (shouldSucceed) { 259 if (shouldSucceed) {
260 SkBitmap bitmap; 260 SkBitmap bitmap;
261 bitmap.allocN32Pixels(24, 24); 261 bitmap.allocN32Pixels(24, 24);
262 SkCanvas canvas(bitmap); 262 SkCanvas canvas(bitmap);
263 canvas.clear(0x00000000); 263 canvas.clear(0x00000000);
264 SkPaint paint; 264 SkPaint paint;
265 paint.setImageFilter(deserializedFilter); 265 paint.setImageFilter(deserializedFilter);
266 canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar( 24))); 266 canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar( 24)));
267 canvas.drawBitmap(bitmap, 0, 0, &paint); 267 canvas.drawBitmap(bitmap, 0, 0, &paint);
268 } 268 }
269 } 269 }
270 270
271 static void TestXfermodeSerialization(skiatest::Reporter* reporter) { 271 static void TestXfermodeSerialization(skiatest::Reporter* reporter) {
272 for (size_t i = 0; i <= SkXfermode::kLastMode; ++i) { 272 for (size_t i = 0; i <= SkXfermode::kLastMode; ++i) {
273 if (i == SkXfermode::kSrcOver_Mode) { 273 if (i == SkXfermode::kSrcOver_Mode) {
274 // skip SrcOver, as it is allowed to return nullptr from Create() 274 // skip SrcOver, as it is allowed to return nullptr from Create()
275 continue; 275 continue;
276 } 276 }
277 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(static_cast<SkXfermode: :Mode>(i))); 277 auto mode(SkXfermode::Make(static_cast<SkXfermode::Mode>(i)));
278 REPORTER_ASSERT(reporter, mode.get()); 278 REPORTER_ASSERT(reporter, mode);
279 SkAutoTUnref<SkXfermode> copy( 279 SkAutoTUnref<SkXfermode> copy(
280 TestFlattenableSerialization<SkXfermode>(mode.get(), true, reporter) ); 280 TestFlattenableSerialization<SkXfermode>(mode.get(), true, reporter) );
281 } 281 }
282 } 282 }
283 283
284 static void TestColorFilterSerialization(skiatest::Reporter* reporter) { 284 static void TestColorFilterSerialization(skiatest::Reporter* reporter) {
285 uint8_t table[256]; 285 uint8_t table[256];
286 for (int i = 0; i < 256; ++i) { 286 for (int i = 0; i < 256; ++i) {
287 table[i] = (i * 41) % 256; 287 table[i] = (i * 41) % 256;
288 } 288 }
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 }, 620 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 },
621 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 }, 621 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 },
622 }; 622 };
623 623
624 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); 624 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture());
625 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); 625 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get()));
626 626
627 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); 627 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs));
628 canvas.drawPicture(pict1); 628 canvas.drawPicture(pict1);
629 } 629 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698