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

Side by Side Diff: tests/RecordOptsTest.cpp

Issue 269813010: Add SaveLayer-Draw-Restore optimization. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: notes 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
« no previous file with comments | « src/record/SkRecordOpts.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 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 9
10 #include "SkRecord.h" 10 #include "SkRecord.h"
11 #include "SkRecordOpts.h" 11 #include "SkRecordOpts.h"
12 #include "SkRecorder.h" 12 #include "SkRecorder.h"
13 #include "SkRecords.h" 13 #include "SkRecords.h"
14 14
15 #include "SkXfermode.h"
16
15 static const int W = 1920, H = 1080; 17 static const int W = 1920, H = 1080;
16 18
17 // If the command we're reading is a U, set ptr to it, otherwise set it to NULL. 19 // If the command we're reading is a U, set ptr to it, otherwise set it to NULL.
18 template <typename U> 20 template <typename U>
19 struct ReadAs { 21 struct ReadAs {
20 explicit ReadAs(const U** ptr) : ptr(ptr), type(SkRecords::Type(~0)) {} 22 explicit ReadAs(const U** ptr) : ptr(ptr), type(SkRecords::Type(~0)) {}
21 23
22 const U** ptr; 24 const U** ptr;
23 SkRecords::Type type; 25 SkRecords::Type type;
24 26
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 146
145 SkRecordNoopSaveRestores(&record); 147 SkRecordNoopSaveRestores(&record);
146 148
147 for (unsigned index = 0; index < 8; index++) { 149 for (unsigned index = 0; index < 8; index++) {
148 assert_type<SkRecords::NoOp>(r, record, index); 150 assert_type<SkRecords::NoOp>(r, record, index);
149 } 151 }
150 assert_type<SkRecords::Save>(r, record, 8); 152 assert_type<SkRecords::Save>(r, record, 8);
151 assert_type<SkRecords::DrawRect>(r, record, 9); 153 assert_type<SkRecords::DrawRect>(r, record, 9);
152 assert_type<SkRecords::Restore>(r, record, 10); 154 assert_type<SkRecords::Restore>(r, record, 10);
153 } 155 }
156
157 static void assert_savelayer_restore(skiatest::Reporter* r,
158 SkRecord* record,
159 unsigned i,
160 bool shouldBeNoOped) {
161 SkRecordNoopSaveLayerDrawRestores(record);
162 if (shouldBeNoOped) {
163 assert_type<SkRecords::NoOp>(r, *record, i);
164 assert_type<SkRecords::NoOp>(r, *record, i+2);
165 } else {
166 assert_type<SkRecords::SaveLayer>(r, *record, i);
167 assert_type<SkRecords::Restore>(r, *record, i+2);
168 }
169 }
170
171 DEF_TEST(RecordOpts_NoopSaveLayerDrawRestore, r) {
172 SkRecord record;
173 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H);
174
175 SkRect bounds = SkRect::MakeWH(100, 200);
176 SkRect draw = SkRect::MakeWH(50, 60);
177
178 SkPaint goodLayerPaint, badLayerPaint, worseLayerPaint;
179 goodLayerPaint.setColor(0x03000000); // Only alpha.
180 badLayerPaint.setColor( 0x03040506); // Not only alpha.
181 worseLayerPaint.setXfermodeMode(SkXfermode::kDstIn_Mode); // Any effect wil l do.
182
183 SkPaint goodDrawPaint, badDrawPaint;
184 goodDrawPaint.setColor(0xFF020202); // Opaque.
185 badDrawPaint.setColor( 0x0F020202); // Not opaque.
186
187 // No change: optimization can't handle bounds.
188 recorder.saveLayer(&bounds, NULL);
189 recorder.drawRect(draw, goodDrawPaint);
190 recorder.restore();
191 assert_savelayer_restore(r, &record, 0, false);
192
193 // SaveLayer/Restore removed: no bounds + no paint = no point.
194 recorder.saveLayer(NULL, NULL);
195 recorder.drawRect(draw, goodDrawPaint);
196 recorder.restore();
197 assert_savelayer_restore(r, &record, 3, true);
198
199 // TODO(mtklein): test case with null draw paint
200
201 // No change: layer paint isn't alpha-only.
202 recorder.saveLayer(NULL, &badLayerPaint);
203 recorder.drawRect(draw, goodDrawPaint);
204 recorder.restore();
205 assert_savelayer_restore(r, &record, 6, false);
206
207 // No change: layer paint has an effect.
208 recorder.saveLayer(NULL, &worseLayerPaint);
209 recorder.drawRect(draw, goodDrawPaint);
210 recorder.restore();
211 assert_savelayer_restore(r, &record, 9, false);
212
213 // No change: draw paint isn't opaque.
214 recorder.saveLayer(NULL, &goodLayerPaint);
215 recorder.drawRect(draw, badDrawPaint);
216 recorder.restore();
217 assert_savelayer_restore(r, &record, 12, false);
218
219 // SaveLayer/Restore removed: we can fold in the alpha!
220 recorder.saveLayer(NULL, &goodLayerPaint);
221 recorder.drawRect(draw, goodDrawPaint);
222 recorder.restore();
223 assert_savelayer_restore(r, &record, 15, true);
224
225 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re cord, 16);
226 REPORTER_ASSERT(r, drawRect != NULL);
227 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202);
228 }
OLDNEW
« no previous file with comments | « src/record/SkRecordOpts.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698