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

Side by Side Diff: tests/RecordOptsTest.cpp

Issue 767333002: 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
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 #if 0
robertphillips 2014/12/10 19:04:22 Probably remove & add explicit deferred save test
reed1 2014/12/10 20:42:45 Done.
19 DEF_TEST(RecordOpts_NoopDrawSaveRestore, r) { 20 DEF_TEST(RecordOpts_NoopDrawSaveRestore, r) {
20 SkRecord record; 21 SkRecord record;
21 SkRecorder recorder(&record, W, H); 22 SkRecorder recorder(&record, W, H);
22 23
23 // The save and restore are pointless if there's only draw commands in the m iddle. 24 // The save and restore are pointless if there's only draw commands in the m iddle.
24 recorder.save(); 25 recorder.save();
25 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint()); 26 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint());
26 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint()); 27 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint());
27 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint()); 28 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint());
28 recorder.restore(); 29 recorder.restore();
29 30
30 record.replace<SkRecords::NoOp>(2); // NoOps should be allowed. 31 record.replace<SkRecords::NoOp>(2); // NoOps should be allowed.
31 32
32 SkRecordNoopSaveRestores(&record); 33 SkRecordNoopSaveRestores(&record);
33 34
34 assert_type<SkRecords::NoOp>(r, record, 0); 35 assert_type<SkRecords::NoOp>(r, record, 0);
35 assert_type<SkRecords::DrawRect>(r, record, 1); 36 assert_type<SkRecords::DrawRect>(r, record, 1);
36 assert_type<SkRecords::NoOp>(r, record, 2); 37 assert_type<SkRecords::NoOp>(r, record, 2);
37 assert_type<SkRecords::DrawRect>(r, record, 3); 38 assert_type<SkRecords::DrawRect>(r, record, 3);
38 assert_type<SkRecords::NoOp>(r, record, 4); 39 assert_type<SkRecords::NoOp>(r, record, 4);
39 } 40 }
41 #endif
40 42
41 DEF_TEST(RecordOpts_SingleNoopSaveRestore, r) { 43 DEF_TEST(RecordOpts_SingleNoopSaveRestore, r) {
42 SkRecord record; 44 SkRecord record;
43 SkRecorder recorder(&record, W, H); 45 SkRecorder recorder(&record, W, H);
44 46
45 recorder.save(); 47 recorder.save();
46 recorder.clipRect(SkRect::MakeWH(200, 200)); 48 recorder.clipRect(SkRect::MakeWH(200, 200));
47 recorder.restore(); 49 recorder.restore();
48 50
49 SkRecordNoopSaveRestores(&record); 51 SkRecordNoopSaveRestores(&record);
(...skipping 13 matching lines...) Expand all
63 recorder.restore(); 65 recorder.restore();
64 66
65 // As long as we don't draw in there, everything is a noop. 67 // As long as we don't draw in there, everything is a noop.
66 recorder.save(); 68 recorder.save();
67 recorder.clipRect(SkRect::MakeWH(200, 200)); 69 recorder.clipRect(SkRect::MakeWH(200, 200));
68 recorder.clipRect(SkRect::MakeWH(100, 100)); 70 recorder.clipRect(SkRect::MakeWH(100, 100));
69 recorder.restore(); 71 recorder.restore();
70 recorder.restore(); 72 recorder.restore();
71 73
72 SkRecordNoopSaveRestores(&record); 74 SkRecordNoopSaveRestores(&record);
73 for (unsigned index = 0; index < 8; index++) { 75 for (unsigned index = 0; index < record.count(); index++) {
74 assert_type<SkRecords::NoOp>(r, record, index); 76 assert_type<SkRecords::NoOp>(r, record, index);
75 } 77 }
76 } 78 }
77 79
78 DEF_TEST(RecordOpts_SaveSaveLayerRestoreRestore, r) { 80 DEF_TEST(RecordOpts_SaveSaveLayerRestoreRestore, r) {
79 SkRecord record; 81 SkRecord record;
80 SkRecorder recorder(&record, W, H); 82 SkRecorder recorder(&record, W, H);
81 83
82 // A previous bug NoOp'd away the first 3 commands. 84 // A previous bug NoOp'd away the first 3 commands.
83 recorder.save(); 85 recorder.save();
84 recorder.saveLayer(NULL, NULL); 86 recorder.saveLayer(NULL, NULL);
85 recorder.restore(); 87 recorder.restore();
86 recorder.restore(); 88 recorder.restore();
87 89
88 SkRecordNoopSaveRestores(&record); 90 SkRecordNoopSaveRestores(&record);
89 assert_type<SkRecords::Save> (r, record, 0); 91 switch (record.count()) {
90 assert_type<SkRecords::SaveLayer>(r, record, 1); 92 case 4:
91 assert_type<SkRecords::Restore> (r, record, 2); 93 assert_type<SkRecords::Save> (r, record, 0);
92 assert_type<SkRecords::Restore> (r, record, 3); 94 assert_type<SkRecords::SaveLayer>(r, record, 1);
95 assert_type<SkRecords::Restore> (r, record, 2);
96 assert_type<SkRecords::Restore> (r, record, 3);
97 break;
98 case 2:
99 assert_type<SkRecords::SaveLayer>(r, record, 0);
100 assert_type<SkRecords::Restore> (r, record, 1);
101 break;
102 case 0:
103 break;
104 default:
105 REPORTER_ASSERT(r, false);
106 }
93 } 107 }
94 108
95 static void assert_savelayer_restore(skiatest::Reporter* r, 109 static void assert_savelayer_restore(skiatest::Reporter* r,
96 SkRecord* record, 110 SkRecord* record,
97 unsigned i, 111 unsigned i,
98 bool shouldBeNoOped) { 112 bool shouldBeNoOped) {
99 SkRecordNoopSaveLayerDrawRestores(record); 113 SkRecordNoopSaveLayerDrawRestores(record);
100 if (shouldBeNoOped) { 114 if (shouldBeNoOped) {
101 assert_type<SkRecords::NoOp>(r, *record, i); 115 assert_type<SkRecords::NoOp>(r, *record, i);
102 assert_type<SkRecords::NoOp>(r, *record, i+2); 116 assert_type<SkRecords::NoOp>(r, *record, i+2);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // SaveLayer/Restore removed: we can fold in the alpha! 171 // SaveLayer/Restore removed: we can fold in the alpha!
158 recorder.saveLayer(NULL, &goodLayerPaint); 172 recorder.saveLayer(NULL, &goodLayerPaint);
159 recorder.drawRect(draw, goodDrawPaint); 173 recorder.drawRect(draw, goodDrawPaint);
160 recorder.restore(); 174 recorder.restore();
161 assert_savelayer_restore(r, &record, 15, true); 175 assert_savelayer_restore(r, &record, 15, true);
162 176
163 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re cord, 16); 177 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re cord, 16);
164 REPORTER_ASSERT(r, drawRect != NULL); 178 REPORTER_ASSERT(r, drawRect != NULL);
165 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); 179 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202);
166 } 180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698