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

Side by Side Diff: tests/RecordDrawTest.cpp

Issue 1424553002: SkRecord refactor: fill bounds array instead of BBH directly (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comment Created 5 years, 1 month 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') | 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 #include "RecordTestUtils.h" 9 #include "RecordTestUtils.h"
10 10
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 const SkRecords::SetMatrix* setMatrix; 115 const SkRecords::SetMatrix* setMatrix;
116 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); 116 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0);
117 REPORTER_ASSERT(r, setMatrix->matrix == translate); 117 REPORTER_ASSERT(r, setMatrix->matrix == translate);
118 118
119 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); 119 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 2);
120 SkMatrix expected = scale; 120 SkMatrix expected = scale;
121 expected.postConcat(translate); 121 expected.postConcat(translate);
122 REPORTER_ASSERT(r, setMatrix->matrix == expected); 122 REPORTER_ASSERT(r, setMatrix->matrix == expected);
123 } 123 }
124 124
125 struct TestBBH : public SkBBoxHierarchy {
126 void insert(const SkRect boundsArray[], int N) override {
127 fEntries.setCount(N);
128 for (int i = 0; i < N; i++) {
129 Entry e = { i, boundsArray[i] };
130 fEntries[i] = e;
131 }
132 }
133
134 void search(const SkRect& query, SkTDArray<int>* results) const override {}
135 size_t bytesUsed() const override { return 0; }
136 SkRect getRootBound() const override { return SkRect::MakeEmpty(); }
137
138 struct Entry {
139 int opIndex;
140 SkRect bounds;
141 };
142 SkTDArray<Entry> fEntries;
143 };
144
145 // Like a==b, with a little slop recognizing that float equality can be weird. 125 // Like a==b, with a little slop recognizing that float equality can be weird.
146 static bool sloppy_rect_eq(SkRect a, SkRect b) { 126 static bool sloppy_rect_eq(SkRect a, SkRect b) {
147 SkRect inset(a), outset(a); 127 SkRect inset(a), outset(a);
148 inset.inset(1, 1); 128 inset.inset(1, 1);
149 outset.outset(1, 1); 129 outset.outset(1, 1);
150 return outset.contains(b) && !inset.contains(b); 130 return outset.contains(b) && !inset.contains(b);
151 } 131 }
152 132
153 // This test is not meant to make total sense yet. It's testing the status quo 133 DEF_TEST(RecordDraw_BasicBounds, r) {
154 // of SkRecordFillBounds(), which itself doesn't make total sense yet.
155 DEF_TEST(RecordDraw_BBH, r) {
156 SkRecord record; 134 SkRecord record;
157 SkRecorder recorder(&record, W, H); 135 SkRecorder recorder(&record, W, H);
158 recorder.save(); 136 recorder.save();
159 recorder.clipRect(SkRect::MakeWH(400, 500)); 137 recorder.clipRect(SkRect::MakeWH(400, 500));
160 recorder.scale(2, 2); 138 recorder.scale(2, 2);
161 recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint()); 139 recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint());
162 recorder.restore(); 140 recorder.restore();
163 141
164 TestBBH bbh; 142 SkAutoTMalloc<SkRect> bounds(record.count());
165 SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), recor d, &bbh); 143 SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), recor d, bounds);
166 144
167 REPORTER_ASSERT(r, bbh.fEntries.count() == 5); 145 for (int i = 0; i < record.count(); i++) {
168 for (int i = 0; i < bbh.fEntries.count(); i++) { 146 REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bounds[i]));
169 REPORTER_ASSERT(r, bbh.fEntries[i].opIndex == i);
170
171 REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bbh.fEntries [i].bounds));
172 } 147 }
173 } 148 }
174 149
175 // A regression test for crbug.com/409110. 150 // A regression test for crbug.com/409110.
176 DEF_TEST(RecordDraw_TextBounds, r) { 151 DEF_TEST(RecordDraw_TextBounds, r) {
177 SkRecord record; 152 SkRecord record;
178 SkRecorder recorder(&record, W, H); 153 SkRecorder recorder(&record, W, H);
179 154
180 // Two Chinese characters in UTF-8. 155 // Two Chinese characters in UTF-8.
181 const char text[] = { '\xe6', '\xbc', '\xa2', '\xe5', '\xad', '\x97' }; 156 const char text[] = { '\xe6', '\xbc', '\xa2', '\xe5', '\xad', '\x97' };
182 const size_t bytes = SK_ARRAY_COUNT(text); 157 const size_t bytes = SK_ARRAY_COUNT(text);
183 158
184 const SkScalar xpos[] = { 10, 20 }; 159 const SkScalar xpos[] = { 10, 20 };
185 recorder.drawPosTextH(text, bytes, xpos, 30, SkPaint()); 160 recorder.drawPosTextH(text, bytes, xpos, 30, SkPaint());
186 161
187 const SkPoint pos[] = { {40, 50}, {60, 70} }; 162 const SkPoint pos[] = { {40, 50}, {60, 70} };
188 recorder.drawPosText(text, bytes, pos, SkPaint()); 163 recorder.drawPosText(text, bytes, pos, SkPaint());
189 164
190 TestBBH bbh; 165 SkAutoTMalloc<SkRect> bounds(record.count());
191 SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), recor d, &bbh); 166 SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), recor d, bounds);
192 REPORTER_ASSERT(r, bbh.fEntries.count() == 2);
193 167
194 // We can make these next assertions confidently because SkRecordFillBounds 168 // We can make these next assertions confidently because SkRecordFillBounds
195 // builds its bounds by overestimating font metrics in a platform-independen t way. 169 // builds its bounds by overestimating font metrics in a platform-independen t way.
196 // If that changes, these tests will need to be more flexible. 170 // If that changes, these tests will need to be more flexible.
197 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0 , 0, 140, 60))); 171 REPORTER_ASSERT(r, sloppy_rect_eq(bounds[0], SkRect::MakeLTRB(0, 0, 140, 60 )));
198 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0 , 20, 180, 100))); 172 REPORTER_ASSERT(r, sloppy_rect_eq(bounds[1], SkRect::MakeLTRB(0, 20, 180, 10 0)));
199 } 173 }
200 174
201 // Base test to ensure start/stop range is respected 175 // Base test to ensure start/stop range is respected
202 DEF_TEST(RecordDraw_PartialStartStop, r) { 176 DEF_TEST(RecordDraw_PartialStartStop, r) {
203 static const int kWidth = 10, kHeight = 10; 177 static const int kWidth = 10, kHeight = 10;
204 178
205 SkRect r1 = { 0, 0, kWidth, kHeight }; 179 SkRect r1 = { 0, 0, kWidth, kHeight };
206 SkRect r2 = { 0, 0, kWidth, kHeight/2 }; 180 SkRect r2 = { 0, 0, kWidth, kHeight/2 };
207 SkRect r3 = { 0, 0, kWidth/2, kHeight }; 181 SkRect r3 = { 0, 0, kWidth/2, kHeight };
208 SkPaint p; 182 SkPaint p;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 recorder.saveLayer(nullptr, &paint); 215 recorder.saveLayer(nullptr, &paint);
242 recorder.clipRect(SkRect::MakeWH(20, 40)); 216 recorder.clipRect(SkRect::MakeWH(20, 40));
243 recorder.drawRect(SkRect::MakeWH(20, 40), SkPaint()); 217 recorder.drawRect(SkRect::MakeWH(20, 40), SkPaint());
244 recorder.restore(); 218 recorder.restore();
245 219
246 // Under the original bug, the right edge value of the drawRect would be 20 less than asserted 220 // Under the original bug, the right edge value of the drawRect would be 20 less than asserted
247 // here because we intersected it with a clip that had not been adjusted for the drop shadow. 221 // here because we intersected it with a clip that had not been adjusted for the drop shadow.
248 // 222 //
249 // The second bug showed up as adjusting the picture bounds (0,0,50,50) by t he drop shadow too. 223 // The second bug showed up as adjusting the picture bounds (0,0,50,50) by t he drop shadow too.
250 // The saveLayer, clipRect, and restore bounds were incorrectly (0,0,70,50). 224 // The saveLayer, clipRect, and restore bounds were incorrectly (0,0,70,50).
251 TestBBH bbh; 225 SkAutoTMalloc<SkRect> bounds(record.count());
252 SkRecordFillBounds(SkRect::MakeWH(50, 50), record, &bbh); 226 SkRecordFillBounds(SkRect::MakeWH(50, 50), record, bounds);
253 REPORTER_ASSERT(r, bbh.fEntries.count() == 4); 227 REPORTER_ASSERT(r, sloppy_rect_eq(bounds[0], SkRect::MakeLTRB(0, 0, 50, 50)) );
254 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0 , 0, 50, 50))); 228 REPORTER_ASSERT(r, sloppy_rect_eq(bounds[1], SkRect::MakeLTRB(0, 0, 50, 50)) );
255 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0 , 0, 50, 50))); 229 REPORTER_ASSERT(r, sloppy_rect_eq(bounds[2], SkRect::MakeLTRB(0, 0, 40, 40)) );
256 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLTRB(0 , 0, 40, 40))); 230 REPORTER_ASSERT(r, sloppy_rect_eq(bounds[3], SkRect::MakeLTRB(0, 0, 50, 50)) );
257 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[3].bounds, SkRect::MakeLTRB(0 , 0, 50, 50)));
258 } 231 }
259 232
260 // When a saveLayer provides an explicit bound and has a complex paint (e.g., on e that 233 // When a saveLayer provides an explicit bound and has a complex paint (e.g., on e that
261 // affects transparent black), that bound should serve to shrink the area of the required 234 // affects transparent black), that bound should serve to shrink the area of the required
262 // backing store. 235 // backing store.
263 DEF_TEST(RecordDraw_SaveLayerBoundsAffectsClipBounds, r) { 236 DEF_TEST(RecordDraw_SaveLayerBoundsAffectsClipBounds, r) {
264 SkRecord record; 237 SkRecord record;
265 SkRecorder recorder(&record, 50, 50); 238 SkRecorder recorder(&record, 50, 50);
266 239
267 SkPaint p; 240 SkPaint p;
268 p.setXfermodeMode(SkXfermode::kSrc_Mode); 241 p.setXfermodeMode(SkXfermode::kSrc_Mode);
269 242
270 SkRect bounds = SkRect::MakeLTRB(10, 10, 40, 40); 243 SkRect layerBounds = SkRect::MakeLTRB(10, 10, 40, 40);
271 recorder.saveLayer(&bounds, &p); 244 recorder.saveLayer(&layerBounds, &p);
272 recorder.drawRect(SkRect::MakeLTRB(20, 20, 30, 30), SkPaint()); 245 recorder.drawRect(SkRect::MakeLTRB(20, 20, 30, 30), SkPaint());
273 recorder.restore(); 246 recorder.restore();
274 247
275 TestBBH bbh; 248 SkAutoTMalloc<SkRect> bounds(record.count());
276 SkRecordFillBounds(SkRect::MakeWH(50, 50), record, &bbh); 249 SkRecordFillBounds(SkRect::MakeWH(50, 50), record, bounds);
277 REPORTER_ASSERT(r, bbh.fEntries.count() == 3);
278 if (!SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds()) { 250 if (!SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds()) {
279 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLT RB(10, 10, 40, 40))); 251 REPORTER_ASSERT(r, sloppy_rect_eq(bounds[0], SkRect::MakeLTRB(10, 10, 40 , 40)));
280 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLT RB(20, 20, 30, 30))); 252 REPORTER_ASSERT(r, sloppy_rect_eq(bounds[1], SkRect::MakeLTRB(20, 20, 30 , 30)));
281 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLT RB(10, 10, 40, 40))); 253 REPORTER_ASSERT(r, sloppy_rect_eq(bounds[2], SkRect::MakeLTRB(10, 10, 40 , 40)));
282 } 254 }
283 } 255 }
284 256
285 DEF_TEST(RecordDraw_drawImage, r){ 257 DEF_TEST(RecordDraw_drawImage, r){
286 class SkCanvasMock : public SkCanvas { 258 class SkCanvasMock : public SkCanvas {
287 public: 259 public:
288 SkCanvasMock(int width, int height) : SkCanvas(width, height) { 260 SkCanvasMock(int width, int height) : SkCanvas(width, height) {
289 this->resetTestValues(); 261 this->resetTestValues();
290 } 262 }
291 263
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 296
325 { 297 {
326 SkRecord record; 298 SkRecord record;
327 SkRecorder recorder(&record, 10, 10); 299 SkRecorder recorder(&record, 10, 10);
328 recorder.drawImageRect(image, SkRect::MakeWH(10, 10), nullptr); 300 recorder.drawImageRect(image, SkRect::MakeWH(10, 10), nullptr);
329 SkRecordDraw(record, &canvas, nullptr, nullptr, 0, nullptr, 0); 301 SkRecordDraw(record, &canvas, nullptr, nullptr, 0, nullptr, 0);
330 } 302 }
331 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); 303 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled);
332 304
333 } 305 }
OLDNEW
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698