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

Side by Side Diff: tests/RecordDrawTest.cpp

Issue 696763002: Shrink saveLayer device bounds when it supplies an explicit bounds and has a complex paint (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address code review comments Created 6 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 DEF_TEST(RecordDraw_BBH, r) { 130 DEF_TEST(RecordDraw_BBH, r) {
131 SkRecord record; 131 SkRecord record;
132 SkRecorder recorder(&record, W, H); 132 SkRecorder recorder(&record, W, H);
133 recorder.save(); 133 recorder.save();
134 recorder.clipRect(SkRect::MakeWH(400, 500)); 134 recorder.clipRect(SkRect::MakeWH(400, 500));
135 recorder.scale(2, 2); 135 recorder.scale(2, 2);
136 recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint()); 136 recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint());
137 recorder.restore(); 137 recorder.restore();
138 138
139 TestBBH bbh; 139 TestBBH bbh;
140 SkRecordFillBounds(record, &bbh); 140 SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), recor d, &bbh);
141 141
142 REPORTER_ASSERT(r, bbh.fEntries.count() == 5); 142 REPORTER_ASSERT(r, bbh.fEntries.count() == 5);
143 for (int i = 0; i < bbh.fEntries.count(); i++) { 143 for (int i = 0; i < bbh.fEntries.count(); i++) {
144 REPORTER_ASSERT(r, bbh.fEntries[i].opIndex == (unsigned)i); 144 REPORTER_ASSERT(r, bbh.fEntries[i].opIndex == (unsigned)i);
145 145
146 REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bbh.fEntries [i].bounds)); 146 REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bbh.fEntries [i].bounds));
147 } 147 }
148 } 148 }
149 149
150 // A regression test for crbug.com/409110. 150 // A regression test for crbug.com/409110.
151 DEF_TEST(RecordDraw_TextBounds, r) { 151 DEF_TEST(RecordDraw_TextBounds, r) {
152 SkRecord record; 152 SkRecord record;
153 SkRecorder recorder(&record, W, H); 153 SkRecorder recorder(&record, W, H);
154 154
155 // Two Chinese characters in UTF-8. 155 // Two Chinese characters in UTF-8.
156 const char text[] = { '\xe6', '\xbc', '\xa2', '\xe5', '\xad', '\x97' }; 156 const char text[] = { '\xe6', '\xbc', '\xa2', '\xe5', '\xad', '\x97' };
157 const size_t bytes = SK_ARRAY_COUNT(text); 157 const size_t bytes = SK_ARRAY_COUNT(text);
158 158
159 const SkScalar xpos[] = { 10, 20 }; 159 const SkScalar xpos[] = { 10, 20 };
160 recorder.drawPosTextH(text, bytes, xpos, 30, SkPaint()); 160 recorder.drawPosTextH(text, bytes, xpos, 30, SkPaint());
161 161
162 const SkPoint pos[] = { {40, 50}, {60, 70} }; 162 const SkPoint pos[] = { {40, 50}, {60, 70} };
163 recorder.drawPosText(text, bytes, pos, SkPaint()); 163 recorder.drawPosText(text, bytes, pos, SkPaint());
164 164
165 TestBBH bbh; 165 TestBBH bbh;
166 SkRecordFillBounds(record, &bbh); 166 SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), recor d, &bbh);
167 REPORTER_ASSERT(r, bbh.fEntries.count() == 2); 167 REPORTER_ASSERT(r, bbh.fEntries.count() == 2);
168 168
169 // We can make these next assertions confidently because SkRecordFillBounds 169 // We can make these next assertions confidently because SkRecordFillBounds
170 // builds its bounds by overestimating font metrics in a platform-independen t way. 170 // builds its bounds by overestimating font metrics in a platform-independen t way.
171 // If that changes, these tests will need to be more flexible. 171 // If that changes, these tests will need to be more flexible.
172 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(- 110, 0, 140, 60))); 172 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0 , 0, 140, 60)));
173 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(- 80, 20, 180, 100))); 173 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0 , 20, 180, 100)));
174 } 174 }
175 175
176 // Base test to ensure start/stop range is respected 176 // Base test to ensure start/stop range is respected
177 DEF_TEST(RecordDraw_PartialStartStop, r) { 177 DEF_TEST(RecordDraw_PartialStartStop, r) {
178 static const int kWidth = 10, kHeight = 10; 178 static const int kWidth = 10, kHeight = 10;
179 179
180 SkRect r1 = { 0, 0, kWidth, kHeight }; 180 SkRect r1 = { 0, 0, kWidth, kHeight };
181 SkRect r2 = { 0, 0, kWidth, kHeight/2 }; 181 SkRect r2 = { 0, 0, kWidth, kHeight/2 };
182 SkRect r3 = { 0, 0, kWidth/2, kHeight }; 182 SkRect r3 = { 0, 0, kWidth/2, kHeight };
183 SkPaint p; 183 SkPaint p;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 recorder.clipRect(SkRect::MakeWH(20, 40)); 244 recorder.clipRect(SkRect::MakeWH(20, 40));
245 recorder.drawRect(SkRect::MakeWH(20, 40), SkPaint()); 245 recorder.drawRect(SkRect::MakeWH(20, 40), SkPaint());
246 recorder.restore(); 246 recorder.restore();
247 247
248 // Under the original bug, the right edge value of the drawRect would be 20 less than asserted 248 // Under the original bug, the right edge value of the drawRect would be 20 less than asserted
249 // here because we intersected it with a clip that had not been adjusted for the drop shadow. 249 // here because we intersected it with a clip that had not been adjusted for the drop shadow.
250 // 250 //
251 // The second bug showed up as adjusting the picture bounds (0,0,50,50) by t he drop shadow too. 251 // The second bug showed up as adjusting the picture bounds (0,0,50,50) by t he drop shadow too.
252 // The saveLayer, clipRect, and restore bounds were incorrectly (0,0,70,50). 252 // The saveLayer, clipRect, and restore bounds were incorrectly (0,0,70,50).
253 TestBBH bbh; 253 TestBBH bbh;
254 SkRecordFillBounds(record, &bbh); 254 SkRecordFillBounds(SkRect::MakeWH(50, 50), record, &bbh);
255 REPORTER_ASSERT(r, bbh.fEntries.count() == 4); 255 REPORTER_ASSERT(r, bbh.fEntries.count() == 4);
256 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0 , 0, 50, 50))); 256 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0 , 0, 50, 50)));
257 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0 , 0, 50, 50))); 257 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0 , 0, 50, 50)));
258 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLTRB(0 , 0, 40, 40))); 258 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLTRB(0 , 0, 40, 40)));
259 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[3].bounds, SkRect::MakeLTRB(0 , 0, 50, 50))); 259 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[3].bounds, SkRect::MakeLTRB(0 , 0, 50, 50)));
260 } 260 }
261 261
262 // When a saveLayer provides an explicit bound and has a complex paint (e.g., on e that
263 // affects transparent black), that bound should serve to shrink the area of the required
264 // backing store.
265 DEF_TEST(RecordDraw_SaveLayerBoundsAffectsClipBounds, r) {
266 SkRecord record;
267 SkRecorder recorder(&record, 50, 50);
268
269 SkPaint p;
270 p.setXfermodeMode(SkXfermode::kSrc_Mode);
271
272 SkRect bounds = SkRect::MakeLTRB(10, 10, 40, 40);
273 recorder.saveLayer(&bounds, &p);
274 recorder.drawRect(SkRect::MakeLTRB(20, 20, 30, 30), SkPaint());
275 recorder.restore();
276
277 TestBBH bbh;
278 SkRecordFillBounds(SkRect::MakeWH(50, 50), record, &bbh);
279 REPORTER_ASSERT(r, bbh.fEntries.count() == 3);
280 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(1 0, 10, 40, 40)));
281 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(2 0, 20, 30, 30)));
282 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLTRB(1 0, 10, 40, 40)));
283 }
284
262 DEF_TEST(RecordDraw_drawImage, r){ 285 DEF_TEST(RecordDraw_drawImage, r){
263 class SkCanvasMock : public SkCanvas { 286 class SkCanvasMock : public SkCanvas {
264 public: 287 public:
265 SkCanvasMock(int width, int height) : INHERITED(width, height) { 288 SkCanvasMock(int width, int height) : INHERITED(width, height) {
266 this->resetTestValues(); 289 this->resetTestValues();
267 } 290 }
268 virtual ~SkCanvasMock() {} 291 virtual ~SkCanvasMock() {}
269 virtual void drawImage(const SkImage* image, SkScalar left, SkScalar top , 292 virtual void drawImage(const SkImage* image, SkScalar left, SkScalar top ,
270 const SkPaint* paint = NULL) SK_OVERRIDE { 293 const SkPaint* paint = NULL) SK_OVERRIDE {
271 294
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 328
306 { 329 {
307 SkRecord record; 330 SkRecord record;
308 SkRecorder recorder(&record, 10, 10); 331 SkRecorder recorder(&record, 10, 10);
309 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10)); 332 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10));
310 SkRecordDraw(record, &canvas, 0, 0); 333 SkRecordDraw(record, &canvas, 0, 0);
311 } 334 }
312 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); 335 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled);
313 336
314 } 337 }
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