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

Side by Side Diff: tests/SerializationTest.cpp

Issue 596333002: Fix SkXfermode deserialization. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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 | « src/core/SkXfermode.cpp ('k') | no next file » | 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 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 "Resources.h" 8 #include "Resources.h"
9 #include "SkBitmapSource.h" 9 #include "SkBitmapSource.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 bitmap.allocN32Pixels(24, 24); 254 bitmap.allocN32Pixels(24, 24);
255 SkCanvas canvas(bitmap); 255 SkCanvas canvas(bitmap);
256 canvas.clear(0x00000000); 256 canvas.clear(0x00000000);
257 SkPaint paint; 257 SkPaint paint;
258 paint.setImageFilter(deserializedFilter); 258 paint.setImageFilter(deserializedFilter);
259 canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar( 24))); 259 canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar( 24)));
260 canvas.drawBitmap(bitmap, 0, 0, &paint); 260 canvas.drawBitmap(bitmap, 0, 0, &paint);
261 } 261 }
262 } 262 }
263 263
264 static void TestXfermodeSerialization(skiatest::Reporter* reporter) {
reed1 2014/09/24 15:58:46 Ensuring that this list matches the enum in SkXfer
Stephen White 2014/09/24 16:38:39 Good idea. Done.
265 const SkXfermode::Mode gModes[] = {
266 SkXfermode::kClear_Mode,
267 SkXfermode::kSrc_Mode,
268 SkXfermode::kDst_Mode,
269 // Don't test SrcOver_Mode, since this (correctly) deserializes as NULL
270 // SkXfermode::kSrcOver_Mode,
271 SkXfermode::kDstOver_Mode,
272 SkXfermode::kSrcIn_Mode,
273 SkXfermode::kDstIn_Mode,
274 SkXfermode::kSrcOut_Mode,
275 SkXfermode::kDstOut_Mode,
276 SkXfermode::kSrcATop_Mode,
277 SkXfermode::kDstATop_Mode,
278 SkXfermode::kXor_Mode,
279
280 SkXfermode::kPlus_Mode,
281 SkXfermode::kModulate_Mode,
282 SkXfermode::kScreen_Mode,
283 SkXfermode::kOverlay_Mode,
284 SkXfermode::kDarken_Mode,
285 SkXfermode::kLighten_Mode,
286 SkXfermode::kColorDodge_Mode,
287 SkXfermode::kColorBurn_Mode,
288 SkXfermode::kHardLight_Mode,
289 SkXfermode::kSoftLight_Mode,
290 SkXfermode::kDifference_Mode,
291 SkXfermode::kExclusion_Mode,
292 SkXfermode::kMultiply_Mode,
293 SkXfermode::kHue_Mode,
294 SkXfermode::kSaturation_Mode,
295 SkXfermode::kColor_Mode,
296 SkXfermode::kLuminosity_Mode,
297 };
298
299 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
300 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i]));
301 REPORTER_ASSERT(reporter, mode.get());
302 TestFlattenableSerialization<SkXfermode>(mode.get(), true, reporter);
303 }
304 }
305
264 static SkBitmap draw_picture(SkPicture& picture) { 306 static SkBitmap draw_picture(SkPicture& picture) {
265 SkBitmap bitmap; 307 SkBitmap bitmap;
266 bitmap.allocN32Pixels(SkScalarCeilToInt(picture.cullRect().width()), 308 bitmap.allocN32Pixels(SkScalarCeilToInt(picture.cullRect().width()),
267 SkScalarCeilToInt(picture.cullRect().height())); 309 SkScalarCeilToInt(picture.cullRect().height()));
268 SkCanvas canvas(bitmap); 310 SkCanvas canvas(bitmap);
269 picture.playback(&canvas); 311 picture.playback(&canvas);
270 return bitmap; 312 return bitmap;
271 } 313 }
272 314
273 static void compare_bitmaps(skiatest::Reporter* reporter, 315 static void compare_bitmaps(skiatest::Reporter* reporter,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 SkPath path; 441 SkPath path;
400 TestObjectSerialization(&path, reporter); 442 TestObjectSerialization(&path, reporter);
401 } 443 }
402 444
403 // Test region serialization 445 // Test region serialization
404 { 446 {
405 SkRegion region; 447 SkRegion region;
406 TestObjectSerialization(&region, reporter); 448 TestObjectSerialization(&region, reporter);
407 } 449 }
408 450
451 // Test xfermode serialization
452 {
453 TestXfermodeSerialization(reporter);
454 }
455
409 // Test string serialization 456 // Test string serialization
410 { 457 {
411 SkString string("string"); 458 SkString string("string");
412 TestObjectSerializationNoAlign<SkString, false>(&string, reporter); 459 TestObjectSerializationNoAlign<SkString, false>(&string, reporter);
413 TestObjectSerializationNoAlign<SkString, true>(&string, reporter); 460 TestObjectSerializationNoAlign<SkString, true>(&string, reporter);
414 } 461 }
415 462
416 // Test rrect serialization 463 // Test rrect serialization
417 { 464 {
418 // SkRRect does not initialize anything. 465 // SkRRect does not initialize anything.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 535
489 // Deserialize picture 536 // Deserialize picture
490 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); 537 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size);
491 SkAutoTUnref<SkPicture> readPict( 538 SkAutoTUnref<SkPicture> readPict(
492 SkPicture::CreateFromBuffer(reader)); 539 SkPicture::CreateFromBuffer(reader));
493 REPORTER_ASSERT(reporter, readPict.get()); 540 REPORTER_ASSERT(reporter, readPict.get());
494 } 541 }
495 542
496 TestPictureTypefaceSerialization(reporter); 543 TestPictureTypefaceSerialization(reporter);
497 } 544 }
OLDNEW
« no previous file with comments | « src/core/SkXfermode.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698