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

Side by Side Diff: tests/PictureTest.cpp

Issue 150653010: Add unit test for unbalanced save and restores in pictures. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix typo Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « include/core/SkCanvas.h ('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 2012 Google Inc. 2 * Copyright 2012 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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 canvas->restore(); 674 canvas->restore();
675 } else if (unit <= 0.9) { 675 } else if (unit <= 0.9) {
676 // SkDebugf("clip\n"); 676 // SkDebugf("clip\n");
677 canvas->clipRect(rect); 677 canvas->clipRect(rect);
678 } else { 678 } else {
679 // SkDebugf("draw\n"); 679 // SkDebugf("draw\n");
680 canvas->drawPaint(paint); 680 canvas->drawPaint(paint);
681 } 681 }
682 } 682 }
683 683
684 static void set_canvas_to_save_count_4(SkCanvas* canvas) {
685 canvas->restoreToCount(1);
686 canvas->save();
687 canvas->save();
688 canvas->save();
689 }
690
691 static void test_unbalanced_save_restores(skiatest::Reporter* reporter) {
692 SkCanvas testCanvas(100, 100);
693 set_canvas_to_save_count_4(&testCanvas);
694
695 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
696
697 SkPaint paint;
698 SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000);
699
700 SkPicture extra_save_picture;
701 extra_save_picture.beginRecording(100, 100);
702 extra_save_picture.getRecordingCanvas()->save();
703 extra_save_picture.getRecordingCanvas()->translate(10, 10);
704 extra_save_picture.getRecordingCanvas()->drawRect(rect, paint);
705 extra_save_picture.getRecordingCanvas()->save();
706 extra_save_picture.getRecordingCanvas()->translate(10, 10);
707 extra_save_picture.getRecordingCanvas()->drawRect(rect, paint);
708
709 testCanvas.drawPicture(extra_save_picture);
710 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
711
712 set_canvas_to_save_count_4(&testCanvas);
713
714 SkPicture extra_restore_picture;
715 extra_restore_picture.beginRecording(100, 100);
716 extra_restore_picture.getRecordingCanvas()->save();
717 extra_restore_picture.getRecordingCanvas()->translate(10, 10);
718 extra_restore_picture.getRecordingCanvas()->drawRect(rect, paint);
719 extra_restore_picture.getRecordingCanvas()->save();
720 extra_restore_picture.getRecordingCanvas()->translate(10, 10);
721 extra_restore_picture.getRecordingCanvas()->drawRect(rect, paint);
722 extra_restore_picture.getRecordingCanvas()->restore();
723 extra_restore_picture.getRecordingCanvas()->restore();
724 extra_restore_picture.getRecordingCanvas()->restore();
725 extra_restore_picture.getRecordingCanvas()->restore();
726
727 testCanvas.drawPicture(extra_save_picture);
728 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
729
730 SkPicture no_save_picture;
731 extra_restore_picture.beginRecording(100, 100);
732 extra_restore_picture.getRecordingCanvas()->translate(10, 10);
733 extra_restore_picture.getRecordingCanvas()->drawRect(rect, paint);
734
735 testCanvas.drawPicture(extra_save_picture);
736 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
737 REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity());
738 }
739
684 static void test_peephole() { 740 static void test_peephole() {
685 SkRandom rand; 741 SkRandom rand;
686 742
687 for (int j = 0; j < 100; j++) { 743 for (int j = 0; j < 100; j++) {
688 SkRandom rand2(rand); // remember the seed 744 SkRandom rand2(rand); // remember the seed
689 745
690 SkPicture picture; 746 SkPicture picture;
691 SkCanvas* canvas = picture.beginRecording(100, 100); 747 SkCanvas* canvas = picture.beginRecording(100, 100);
692 748
693 for (int i = 0; i < 1000; ++i) { 749 for (int i = 0; i < 1000; ++i) {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 REPORTER_ASSERT(reporter, parentWBWB.willPlayBackBitmaps()); // 2 1071 REPORTER_ASSERT(reporter, parentWBWB.willPlayBackBitmaps()); // 2
1016 } 1072 }
1017 1073
1018 DEF_TEST(Picture, reporter) { 1074 DEF_TEST(Picture, reporter) {
1019 #ifdef SK_DEBUG 1075 #ifdef SK_DEBUG
1020 test_deleting_empty_playback(); 1076 test_deleting_empty_playback();
1021 test_serializing_empty_picture(); 1077 test_serializing_empty_picture();
1022 #else 1078 #else
1023 test_bad_bitmap(); 1079 test_bad_bitmap();
1024 #endif 1080 #endif
1081 test_unbalanced_save_restores(reporter);
1025 test_peephole(); 1082 test_peephole();
1026 test_gatherpixelrefs(reporter); 1083 test_gatherpixelrefs(reporter);
1027 test_gatherpixelrefsandrects(reporter); 1084 test_gatherpixelrefsandrects(reporter);
1028 test_bitmap_with_encoded_data(reporter); 1085 test_bitmap_with_encoded_data(reporter);
1029 test_clone_empty(reporter); 1086 test_clone_empty(reporter);
1030 test_clip_bound_opt(reporter); 1087 test_clip_bound_opt(reporter);
1031 test_clip_expansion(reporter); 1088 test_clip_expansion(reporter);
1032 test_hierarchical(reporter); 1089 test_hierarchical(reporter);
1033 } 1090 }
1034 1091
(...skipping 24 matching lines...) Expand all
1059 } 1116 }
1060 1117
1061 DEF_TEST(Canvas_EmptyBitmap, r) { 1118 DEF_TEST(Canvas_EmptyBitmap, r) {
1062 SkBitmap dst; 1119 SkBitmap dst;
1063 dst.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); 1120 dst.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
1064 dst.allocPixels(); 1121 dst.allocPixels();
1065 SkCanvas canvas(dst); 1122 SkCanvas canvas(dst);
1066 1123
1067 test_draw_bitmaps(&canvas); 1124 test_draw_bitmaps(&canvas);
1068 } 1125 }
OLDNEW
« no previous file with comments | « include/core/SkCanvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698