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

Side by Side Diff: tests/RecordDrawTest.cpp

Issue 527423002: SkRecordPartialDraw with less code duplication (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: test Created 6 years, 3 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/SkRecordDraw.cpp ('k') | tools/DumpRecord.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
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 REPORTER_ASSERT(r, bbh.entries.count() == 5); 136 REPORTER_ASSERT(r, bbh.entries.count() == 5);
137 for (int i = 0; i < bbh.entries.count(); i++) { 137 for (int i = 0; i < bbh.entries.count(); i++) {
138 REPORTER_ASSERT(r, bbh.entries[i].data == (uintptr_t)i); 138 REPORTER_ASSERT(r, bbh.entries[i].data == (uintptr_t)i);
139 139
140 // We'd like to assert bounds == SkRect::MakeWH(400, 480). 140 // We'd like to assert bounds == SkRect::MakeWH(400, 480).
141 // But we allow a little slop in recognition that float equality can be weird. 141 // But we allow a little slop in recognition that float equality can be weird.
142 REPORTER_ASSERT(r, SkRect::MakeLTRB(-1, -1, 401, 481).contains(bbh.entr ies[i].bounds)); 142 REPORTER_ASSERT(r, SkRect::MakeLTRB(-1, -1, 401, 481).contains(bbh.entr ies[i].bounds));
143 REPORTER_ASSERT(r, !SkRect::MakeLTRB(+1, +1, 399, 479).contains(bbh.entr ies[i].bounds)); 143 REPORTER_ASSERT(r, !SkRect::MakeLTRB(+1, +1, 399, 479).contains(bbh.entr ies[i].bounds));
144 } 144 }
145 } 145 }
146
147 // Base test to ensure start/stop range is respected
148 DEF_TEST(RecordDraw_PartialStartStop, r) {
149 static const int kWidth = 10, kHeight = 10;
150
151 SkRect r1 = { 0, 0, kWidth, kHeight };
152 SkRect r2 = { 0, 0, kWidth, kHeight/2 };
153 SkRect r3 = { 0, 0, kWidth/2, kHeight };
154 SkPaint p;
155
156 SkRecord record;
157 SkRecorder recorder(&record, kWidth, kHeight);
158 recorder.drawRect(r1, p);
159 recorder.drawRect(r2, p);
160 recorder.drawRect(r3, p);
161
162 SkRecord rerecord;
163 SkRecorder canvas(&rerecord, kWidth, kHeight);
164 SkRecordPartialDraw(record, &canvas, r1, 1, 2); // replay just drawRect of r 2
165
166 REPORTER_ASSERT(r, 3 == rerecord.count());
167 assert_type<SkRecords::Save> (r, rerecord, 0);
168 assert_type<SkRecords::DrawRect> (r, rerecord, 1);
169 assert_type<SkRecords::Restore> (r, rerecord, 2);
170
171 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re record, 1);
172 REPORTER_ASSERT(r, drawRect->rect == r2);
173 }
174
175 // Check that clears are converted to drawRects
176 DEF_TEST(RecordDraw_PartialClear, r) {
177 static const int kWidth = 10, kHeight = 10;
178
179 SkRect rect = { 0, 0, kWidth, kHeight };
180
181 SkRecord record;
182 SkRecorder recorder(&record, kWidth, kHeight);
183 recorder.clear(SK_ColorRED);
184
185 SkRecord rerecord;
186 SkRecorder canvas(&rerecord, kWidth, kHeight);
187 SkRecordPartialDraw(record, &canvas, rect, 0, 1); // replay just the clear
188
189 REPORTER_ASSERT(r, 3 == rerecord.count());
190 assert_type<SkRecords::Save> (r, rerecord, 0);
191 assert_type<SkRecords::DrawRect>(r, rerecord, 1);
192 assert_type<SkRecords::Restore> (r, rerecord, 2);
193
194 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re record, 1);
195 REPORTER_ASSERT(r, drawRect->rect == rect);
196 REPORTER_ASSERT(r, drawRect->paint.getColor() == SK_ColorRED);
197 }
OLDNEW
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | tools/DumpRecord.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698