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

Side by Side Diff: tests/RecordOptsTest.cpp

Issue 798593003: Revert of Defer saves() until they're needed (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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 | « tests/RecordDrawTest.cpp ('k') | tests/RecordPatternTest.cpp » ('j') | 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 2014 Google Inc. 2 * Copyright 2014 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 "Test.h" 8 #include "Test.h"
9 #include "RecordTestUtils.h" 9 #include "RecordTestUtils.h"
10 10
11 #include "SkRecord.h" 11 #include "SkRecord.h"
12 #include "SkRecordOpts.h" 12 #include "SkRecordOpts.h"
13 #include "SkRecorder.h" 13 #include "SkRecorder.h"
14 #include "SkRecords.h" 14 #include "SkRecords.h"
15 #include "SkXfermode.h" 15 #include "SkXfermode.h"
16 16
17 static const int W = 1920, H = 1080; 17 static const int W = 1920, H = 1080;
18 18
19 DEF_TEST(RecordOpts_NoopDraw, r) { 19 DEF_TEST(RecordOpts_NoopDrawSaveRestore, r) {
20 SkRecord record; 20 SkRecord record;
21 SkRecorder recorder(&record, W, H); 21 SkRecorder recorder(&record, W, H);
22 22
23 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint()); 23 // The save and restore are pointless if there's only draw commands in the m iddle.
24 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint()); 24 recorder.save();
25 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint()); 25 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint());
26 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint());
27 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint());
28 recorder.restore();
26 29
27 record.replace<SkRecords::NoOp>(1); // NoOps should be allowed. 30 record.replace<SkRecords::NoOp>(2); // NoOps should be allowed.
28 31
29 SkRecordNoopSaveRestores(&record); 32 SkRecordNoopSaveRestores(&record);
30 33
31 REPORTER_ASSERT(r, 2 == count_instances_of_type<SkRecords::DrawRect>(record) ); 34 assert_type<SkRecords::NoOp>(r, record, 0);
35 assert_type<SkRecords::DrawRect>(r, record, 1);
36 assert_type<SkRecords::NoOp>(r, record, 2);
37 assert_type<SkRecords::DrawRect>(r, record, 3);
38 assert_type<SkRecords::NoOp>(r, record, 4);
32 } 39 }
33 40
34 DEF_TEST(RecordOpts_SingleNoopSaveRestore, r) { 41 DEF_TEST(RecordOpts_SingleNoopSaveRestore, r) {
35 SkRecord record; 42 SkRecord record;
36 SkRecorder recorder(&record, W, H); 43 SkRecorder recorder(&record, W, H);
37 44
38 recorder.save(); 45 recorder.save();
39 recorder.clipRect(SkRect::MakeWH(200, 200)); 46 recorder.clipRect(SkRect::MakeWH(200, 200));
40 recorder.restore(); 47 recorder.restore();
41 48
(...skipping 14 matching lines...) Expand all
56 recorder.restore(); 63 recorder.restore();
57 64
58 // As long as we don't draw in there, everything is a noop. 65 // As long as we don't draw in there, everything is a noop.
59 recorder.save(); 66 recorder.save();
60 recorder.clipRect(SkRect::MakeWH(200, 200)); 67 recorder.clipRect(SkRect::MakeWH(200, 200));
61 recorder.clipRect(SkRect::MakeWH(100, 100)); 68 recorder.clipRect(SkRect::MakeWH(100, 100));
62 recorder.restore(); 69 recorder.restore();
63 recorder.restore(); 70 recorder.restore();
64 71
65 SkRecordNoopSaveRestores(&record); 72 SkRecordNoopSaveRestores(&record);
66 for (unsigned index = 0; index < record.count(); index++) { 73 for (unsigned index = 0; index < 8; index++) {
67 assert_type<SkRecords::NoOp>(r, record, index); 74 assert_type<SkRecords::NoOp>(r, record, index);
68 } 75 }
69 } 76 }
70 77
71 DEF_TEST(RecordOpts_SaveSaveLayerRestoreRestore, r) { 78 DEF_TEST(RecordOpts_SaveSaveLayerRestoreRestore, r) {
72 SkRecord record; 79 SkRecord record;
73 SkRecorder recorder(&record, W, H); 80 SkRecorder recorder(&record, W, H);
74 81
75 // A previous bug NoOp'd away the first 3 commands. 82 // A previous bug NoOp'd away the first 3 commands.
76 recorder.save(); 83 recorder.save();
77 recorder.saveLayer(NULL, NULL); 84 recorder.saveLayer(NULL, NULL);
78 recorder.restore(); 85 recorder.restore();
79 recorder.restore(); 86 recorder.restore();
80 87
81 SkRecordNoopSaveRestores(&record); 88 SkRecordNoopSaveRestores(&record);
82 switch (record.count()) { 89 assert_type<SkRecords::Save> (r, record, 0);
83 case 4: 90 assert_type<SkRecords::SaveLayer>(r, record, 1);
84 assert_type<SkRecords::Save> (r, record, 0); 91 assert_type<SkRecords::Restore> (r, record, 2);
85 assert_type<SkRecords::SaveLayer>(r, record, 1); 92 assert_type<SkRecords::Restore> (r, record, 3);
86 assert_type<SkRecords::Restore> (r, record, 2);
87 assert_type<SkRecords::Restore> (r, record, 3);
88 break;
89 case 2:
90 assert_type<SkRecords::SaveLayer>(r, record, 0);
91 assert_type<SkRecords::Restore> (r, record, 1);
92 break;
93 case 0:
94 break;
95 default:
96 REPORTER_ASSERT(r, false);
97 }
98 } 93 }
99 94
100 static void assert_savelayer_restore(skiatest::Reporter* r, 95 static void assert_savelayer_restore(skiatest::Reporter* r,
101 SkRecord* record, 96 SkRecord* record,
102 unsigned i, 97 unsigned i,
103 bool shouldBeNoOped) { 98 bool shouldBeNoOped) {
104 SkRecordNoopSaveLayerDrawRestores(record); 99 SkRecordNoopSaveLayerDrawRestores(record);
105 if (shouldBeNoOped) { 100 if (shouldBeNoOped) {
106 assert_type<SkRecords::NoOp>(r, *record, i); 101 assert_type<SkRecords::NoOp>(r, *record, i);
107 assert_type<SkRecords::NoOp>(r, *record, i+2); 102 assert_type<SkRecords::NoOp>(r, *record, i+2);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // SaveLayer/Restore removed: we can fold in the alpha! 157 // SaveLayer/Restore removed: we can fold in the alpha!
163 recorder.saveLayer(NULL, &goodLayerPaint); 158 recorder.saveLayer(NULL, &goodLayerPaint);
164 recorder.drawRect(draw, goodDrawPaint); 159 recorder.drawRect(draw, goodDrawPaint);
165 recorder.restore(); 160 recorder.restore();
166 assert_savelayer_restore(r, &record, 15, true); 161 assert_savelayer_restore(r, &record, 15, true);
167 162
168 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re cord, 16); 163 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re cord, 16);
169 REPORTER_ASSERT(r, drawRect != NULL); 164 REPORTER_ASSERT(r, drawRect != NULL);
170 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); 165 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202);
171 } 166 }
OLDNEW
« no previous file with comments | « tests/RecordDrawTest.cpp ('k') | tests/RecordPatternTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698