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

Side by Side Diff: tests/PictureTest.cpp

Issue 286033005: Ensure playing back a picture always balances saves and restores (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 7 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 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 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 { 968 {
969 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); 969 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0);
970 canvas->translate(10, 10); 970 canvas->translate(10, 10);
971 canvas->drawRect(rect, paint); 971 canvas->drawRect(rect, paint);
972 SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording()); 972 SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording());
973 973
974 testCanvas.drawPicture(*noSavePicture); 974 testCanvas.drawPicture(*noSavePicture);
975 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); 975 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
976 REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity()); 976 REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity());
977 } 977 }
978
979 #if defined(SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD) && defined(SK_SUPPORT_LEGACY_D ERIVED_PICTURE_CLASSES)
scroggo 2014/05/16 18:20:53 Aren't we going to change Android to use the newer
scroggo 2014/05/16 18:37:57 Also, it appears we only define SK_SUPPORT_LEGACY_
robertphillips 2014/05/16 19:18:15 I'm trying to separate the fix for this SkPicture
980 set_canvas_to_save_count_4(&testCanvas);
981
982 // Due to "fake" endRecording, the old SkPicture recording interface
983 // allowed unbalanced saves/restores to leak out. This sub-test checks
984 // that the situation has been remedied.
985 {
986 SkPicture p;
987
988 SkCanvas* canvas = p.beginRecording(100, 100);
989 for (int i = 0; i < 4; ++i) {
990 canvas->save();
991 }
992 SkRect r = SkRect::MakeWH(50, 50);
993 SkPaint paint;
994 canvas->drawRect(r, paint);
995
996 // Copying a mid-recording picture could result in unbalanced saves/rest ores
997 SkPicture p2(p);
998
999 testCanvas.drawPicture(p2);
1000 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
1001 set_canvas_to_save_count_4(&testCanvas);
1002
1003 // Cloning a mid-recording picture could result in unbalanced saves/rest ores
1004 SkAutoTUnref<SkPicture> p3(p.clone());
1005 testCanvas.drawPicture(*p3);
1006 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
1007 set_canvas_to_save_count_4(&testCanvas);
1008
1009 // Serializing a mid-recording picture could result in unbalanced saves/ restores
1010 SkDynamicMemoryWStream wStream;
1011 p.serialize(&wStream);
1012 SkAutoDataUnref data(wStream.copyToData());
1013 SkMemoryStream stream(data);
1014 SkAutoTUnref<SkPicture> p4(SkPicture::CreateFromStream(&stream, NULL));
1015 testCanvas.drawPicture(*p4);
1016 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
1017 }
1018 #endif
978 } 1019 }
979 1020
980 static void test_peephole() { 1021 static void test_peephole() {
981 SkRandom rand; 1022 SkRandom rand;
982 1023
983 SkPictureRecorder recorder; 1024 SkPictureRecorder recorder;
984 1025
985 for (int j = 0; j < 100; j++) { 1026 for (int j = 0; j < 100; j++) {
986 SkRandom rand2(rand); // remember the seed 1027 SkRandom rand2(rand); // remember the seed
987 1028
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1499 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1459 } 1500 }
1460 1501
1461 DEF_TEST(Canvas_EmptyBitmap, r) { 1502 DEF_TEST(Canvas_EmptyBitmap, r) {
1462 SkBitmap dst; 1503 SkBitmap dst;
1463 dst.allocN32Pixels(10, 10); 1504 dst.allocN32Pixels(10, 10);
1464 SkCanvas canvas(dst); 1505 SkCanvas canvas(dst);
1465 1506
1466 test_draw_bitmaps(&canvas); 1507 test_draw_bitmaps(&canvas);
1467 } 1508 }
OLDNEW
« src/core/SkPicturePlayback.cpp ('K') | « src/core/SkPicturePlayback.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698