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

Side by Side Diff: tests/PictureTest.cpp

Issue 316063005: Fix error revealed by Android unit test (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix typo Created 6 years, 6 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/SkPictureRecorder.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 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 "SkBlurImageFilter.h" 9 #include "SkBlurImageFilter.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 SkPictureRecorder recorder2; 979 SkPictureRecorder recorder2;
980 980
981 SkCanvas* canvas = recorder2.beginRecording(10, 10); 981 SkCanvas* canvas = recorder2.beginRecording(10, 10);
982 982
983 recorder->partialReplay(canvas); 983 recorder->partialReplay(canvas);
984 984
985 return recorder2.endRecording(); 985 return recorder2.endRecording();
986 } 986 }
987 }; 987 };
988 988
989 static void create_imbalance(SkCanvas* canvas) {
990 SkRect clipRect = SkRect::MakeWH(2, 2);
991 SkRect drawRect = SkRect::MakeWH(10, 10);
992 canvas->save();
993 canvas->clipRect(clipRect, SkRegion::kReplace_Op);
994 canvas->translate(1.0f, 1.0f);
995 SkPaint p;
996 p.setColor(SK_ColorGREEN);
997 canvas->drawRect(drawRect, p);
998 // no restore
999 }
1000
1001 // This tests that replaying a potentially unbalanced picture into a canvas
1002 // doesn't affect the canvas' save count or matrix/clip state.
1003 static void check_balance(skiatest::Reporter* reporter, SkPicture* picture) {
1004 SkBitmap bm;
1005 bm.allocN32Pixels(4, 3);
1006 SkCanvas canvas(bm);
1007
1008 int beforeSaveCount = canvas.getSaveCount();
1009
1010 SkMatrix beforeMatrix = canvas.getTotalMatrix();
1011
1012 SkRect beforeClip;
1013
1014 canvas.getClipBounds(&beforeClip);
1015
1016 canvas.drawPicture(picture);
1017
1018 REPORTER_ASSERT(reporter, beforeSaveCount == canvas.getSaveCount());
1019 REPORTER_ASSERT(reporter, beforeMatrix == canvas.getTotalMatrix());
1020
1021 SkRect afterClip;
1022
1023 canvas.getClipBounds(&afterClip);
1024
1025 REPORTER_ASSERT(reporter, afterClip == beforeClip);
1026 }
1027
989 // Test out SkPictureRecorder::partialReplay 1028 // Test out SkPictureRecorder::partialReplay
990 DEF_TEST(PictureRecorder_replay, reporter) { 1029 DEF_TEST(PictureRecorder_replay, reporter) {
991 // check save/saveLayer state 1030 // check save/saveLayer state
992 { 1031 {
993 SkPictureRecorder recorder; 1032 SkPictureRecorder recorder;
994 1033
995 SkCanvas* canvas = recorder.beginRecording(10, 10); 1034 SkCanvas* canvas = recorder.beginRecording(10, 10);
996 1035
997 canvas->saveLayer(NULL, NULL); 1036 canvas->saveLayer(NULL, NULL);
998 1037
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 canvas->drawBitmapRectToRect(bm, NULL, r); 1072 canvas->drawBitmapRectToRect(bm, NULL, r);
1034 1073
1035 SkAutoTUnref<SkPicture> final(recorder.endRecording()); 1074 SkAutoTUnref<SkPicture> final(recorder.endRecording());
1036 REPORTER_ASSERT(reporter, final->willPlayBackBitmaps()); 1075 REPORTER_ASSERT(reporter, final->willPlayBackBitmaps());
1037 1076
1038 REPORTER_ASSERT(reporter, copy->uniqueID() != final->uniqueID()); 1077 REPORTER_ASSERT(reporter, copy->uniqueID() != final->uniqueID());
1039 1078
1040 // The snapshot shouldn't pick up any operations added after it was made 1079 // The snapshot shouldn't pick up any operations added after it was made
1041 REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps()); 1080 REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps());
1042 } 1081 }
1082
1083 // Recreate the Android partialReplay test case
1084 {
1085 SkPictureRecorder recorder;
1086
1087 SkCanvas* canvas = recorder.beginRecording(4, 3, NULL, 0);
1088 create_imbalance(canvas);
1089
1090 int expectedSaveCount = canvas->getSaveCount();
1091
1092 SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&record er));
1093 check_balance(reporter, copy);
1094
1095 REPORTER_ASSERT(reporter, expectedSaveCount = canvas->getSaveCount());
1096
1097 // End the recording of source to test the picture finalization
1098 // process isn't complicated by the partialReplay step
1099 SkAutoTUnref<SkPicture> final(recorder.endRecording());
1100 }
1043 } 1101 }
1044 1102
1045 static void test_unbalanced_save_restores(skiatest::Reporter* reporter) { 1103 static void test_unbalanced_save_restores(skiatest::Reporter* reporter) {
1046 SkCanvas testCanvas(100, 100); 1104 SkCanvas testCanvas(100, 100);
1047 set_canvas_to_save_count_4(&testCanvas); 1105 set_canvas_to_save_count_4(&testCanvas);
1048 1106
1049 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); 1107 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
1050 1108
1051 SkPaint paint; 1109 SkPaint paint;
1052 SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000); 1110 SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000);
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1636 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1579 } 1637 }
1580 1638
1581 DEF_TEST(Canvas_EmptyBitmap, r) { 1639 DEF_TEST(Canvas_EmptyBitmap, r) {
1582 SkBitmap dst; 1640 SkBitmap dst;
1583 dst.allocN32Pixels(10, 10); 1641 dst.allocN32Pixels(10, 10);
1584 SkCanvas canvas(dst); 1642 SkCanvas canvas(dst);
1585 1643
1586 test_draw_bitmaps(&canvas); 1644 test_draw_bitmaps(&canvas);
1587 } 1645 }
OLDNEW
« no previous file with comments | « src/core/SkPictureRecorder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698