OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 /* Description: | 8 /* Description: |
9 * This test defines a series of elementatry test steps that perform | 9 * This test defines a series of elementatry test steps that perform |
10 * a single or a small group of canvas API calls. Each test step is | 10 * a single or a small group of canvas API calls. Each test step is |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 #include "SkPictureRecorder.h" | 58 #include "SkPictureRecorder.h" |
59 #include "SkProxyCanvas.h" | 59 #include "SkProxyCanvas.h" |
60 #include "SkRect.h" | 60 #include "SkRect.h" |
61 #include "SkRegion.h" | 61 #include "SkRegion.h" |
62 #include "SkShader.h" | 62 #include "SkShader.h" |
63 #include "SkStream.h" | 63 #include "SkStream.h" |
64 #include "SkSurface.h" | 64 #include "SkSurface.h" |
65 #include "SkTDArray.h" | 65 #include "SkTDArray.h" |
66 #include "Test.h" | 66 #include "Test.h" |
67 | 67 |
68 static const int kWidth = 2, kHeight = 2; | |
69 | |
70 static void createBitmap(SkBitmap* bm, SkColor color) { | |
71 bm->allocN32Pixels(kWidth, kHeight); | |
72 bm->eraseColor(color); | |
73 } | |
74 | |
75 static SkSurface* createSurface(SkColor color) { | |
76 SkSurface* surface = SkSurface::NewRasterPMColor(kWidth, kHeight); | |
77 surface->getCanvas()->clear(color); | |
78 return surface; | |
79 } | |
80 | |
81 /////////////////////////////////////////////////////////////////////////////// | |
82 // Constants used by test steps | |
83 const SkPoint hkTestPoints[] = { | |
84 {SkIntToScalar(0), SkIntToScalar(0)}, | |
85 {SkIntToScalar(2), SkIntToScalar(1)}, | |
86 {SkIntToScalar(0), SkIntToScalar(2)} | |
87 }; | |
88 const SkPoint hkTestPoints2[] = { | |
89 { SkIntToScalar(0), SkIntToScalar(1) }, | |
90 { SkIntToScalar(1), SkIntToScalar(1) }, | |
91 { SkIntToScalar(2), SkIntToScalar(1) }, | |
92 { SkIntToScalar(3), SkIntToScalar(1) }, | |
93 { SkIntToScalar(4), SkIntToScalar(1) }, | |
94 { SkIntToScalar(5), SkIntToScalar(1) }, | |
95 { SkIntToScalar(6), SkIntToScalar(1) }, | |
96 { SkIntToScalar(7), SkIntToScalar(1) }, | |
97 { SkIntToScalar(8), SkIntToScalar(1) }, | |
98 { SkIntToScalar(9), SkIntToScalar(1) }, | |
99 { SkIntToScalar(10), SkIntToScalar(1) } | |
100 }; | |
101 | |
102 struct TestData { | |
103 public: | |
104 TestData() | |
105 : fTestRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), | |
106 SkIntToScalar(2), SkIntToScalar(1))) | |
107 , fTestMatrix(testMatrix()) | |
108 , fTestPath(test_path()) | |
109 , fNearlyZeroLengthPath(test_nearly_zero_length_path()) | |
110 , fTestIRect(SkIRect::MakeXYWH(0, 0, 2, 1)) | |
111 , fTestRegion(testRegion()) | |
112 , fTestColor(0x01020304) | |
113 , fTestPoints(hkTestPoints) | |
114 , fTestPointCount(3) | |
115 , fWidth(2) | |
116 , fHeight(2) | |
117 , fTestText("Hello World") | |
118 , fTestPoints2(hkTestPoints2) | |
119 , fTestBitmap(testBitmap()) | |
120 { } | |
121 | |
122 const SkRect fTestRect; | |
123 const SkMatrix fTestMatrix;; | |
124 const SkPath fTestPath; | |
125 const SkPath fNearlyZeroLengthPath; | |
126 const SkIRect fTestIRect; | |
127 const SkRegion fTestRegion; | |
128 const SkColor fTestColor; | |
129 const SkPaint fTestPaint; | |
130 const SkPoint* fTestPoints; | |
131 const size_t fTestPointCount; | |
132 const int fWidth; | |
133 const int fHeight; | |
134 const SkString fTestText; | |
135 const SkPoint* fTestPoints2; | |
136 const SkBitmap fTestBitmap; | |
137 private: | |
138 static SkMatrix testMatrix() { | |
139 SkMatrix matrix; | |
140 matrix.reset(); | |
141 matrix.setScale(SkIntToScalar(2), SkIntToScalar(3)); | |
142 | |
143 return matrix; | |
144 } | |
145 static SkPath test_path() { | |
146 SkPath path; | |
147 path.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), | |
148 SkIntToScalar(2), SkIntToScalar(1))); | |
149 return path; | |
150 } | |
151 static SkPath test_nearly_zero_length_path() { | |
reed1
2014/10/02 19:53:06
nit: Static methods are Capitalized
Rémi Piotaix
2014/10/02 20:02:26
Done.
| |
152 SkPath path; | |
153 SkPoint pt1 = { 0, 0 }; | |
154 SkPoint pt2 = { 0, SK_ScalarNearlyZero }; | |
155 SkPoint pt3 = { SkIntToScalar(1), 0 }; | |
156 SkPoint pt4 = { SkIntToScalar(1), SK_ScalarNearlyZero/2 }; | |
157 path.moveTo(pt1); | |
158 path.lineTo(pt2); | |
159 path.lineTo(pt3); | |
160 path.lineTo(pt4); | |
161 return path; | |
162 } | |
163 static SkRegion testRegion() { | |
reed1
2014/10/02 19:53:06
same static function nit
Rémi Piotaix
2014/10/02 20:02:26
Done.
| |
164 SkRegion region; | |
165 SkIRect rect = SkIRect::MakeXYWH(0, 0, 2, 1); | |
166 region.setRect(rect); | |
167 return region; | |
168 } | |
169 static SkBitmap testBitmap() { | |
170 SkBitmap bitmap; | |
171 createBitmap(&bitmap, 0x05060708); | |
172 return bitmap; | |
173 } | |
174 }; | |
175 | |
68 static bool equal_clips(const SkCanvas& a, const SkCanvas& b) { | 176 static bool equal_clips(const SkCanvas& a, const SkCanvas& b) { |
69 if (a.isClipEmpty()) { | 177 if (a.isClipEmpty()) { |
70 return b.isClipEmpty(); | 178 return b.isClipEmpty(); |
71 } | 179 } |
72 if (!a.isClipRect()) { | 180 if (!a.isClipRect()) { |
73 // this is liberally true, since we don't expose a way to know this exac tly (for non-rects) | 181 // this is liberally true, since we don't expose a way to know this exac tly (for non-rects) |
74 return !b.isClipRect(); | 182 return !b.isClipRect(); |
75 } | 183 } |
76 SkIRect ar, br; | 184 SkIRect ar, br; |
77 a.getClipDeviceBounds(&ar); | 185 a.getClipDeviceBounds(&ar); |
(...skipping 25 matching lines...) Expand all Loading... | |
103 SkBitmap bm; | 211 SkBitmap bm; |
104 bm.setInfo(SkImageInfo::MakeN32Premul(size.width(), size.height())); | 212 bm.setInfo(SkImageInfo::MakeN32Premul(size.width(), size.height())); |
105 SkCanvas c(bm); | 213 SkCanvas c(bm); |
106 | 214 |
107 Canvas2CanvasClipVisitor visitor(&c); | 215 Canvas2CanvasClipVisitor visitor(&c); |
108 canvas->replayClips(&visitor); | 216 canvas->replayClips(&visitor); |
109 | 217 |
110 REPORTER_ASSERT(reporter, equal_clips(c, *canvas)); | 218 REPORTER_ASSERT(reporter, equal_clips(c, *canvas)); |
111 } | 219 } |
112 | 220 |
113 static const int kWidth = 2; | |
114 static const int kHeight = 2; | |
115 | |
116 // Format strings that describe the test context. The %s token is where | 221 // Format strings that describe the test context. The %s token is where |
117 // the name of the test step is inserted. The context is required for | 222 // the name of the test step is inserted. The context is required for |
118 // disambiguating the error in the case of failures that are reported in | 223 // disambiguating the error in the case of failures that are reported in |
119 // functions that are called multiple times in different contexts (test | 224 // functions that are called multiple times in different contexts (test |
120 // cases and test steps). | 225 // cases and test steps). |
121 static const char* const kDefaultAssertMessageFormat = "%s"; | 226 static const char* const kDefaultAssertMessageFormat = "%s"; |
122 static const char* const kCanvasDrawAssertMessageFormat = | 227 static const char* const kCanvasDrawAssertMessageFormat = |
123 "Drawing test step %s with SkCanvas"; | 228 "Drawing test step %s with SkCanvas"; |
124 static const char* const kDeferredDrawAssertMessageFormat = | 229 static const char* const kDeferredDrawAssertMessageFormat = |
125 "Drawing test step %s with SkDeferredCanvas"; | 230 "Drawing test step %s with SkDeferredCanvas"; |
(...skipping 13 matching lines...) Expand all Loading... | |
139 "test step %s, SkProxyCanvas indirect canvas state consistency"; | 244 "test step %s, SkProxyCanvas indirect canvas state consistency"; |
140 static const char* const kNWayStateAssertMessageFormat = | 245 static const char* const kNWayStateAssertMessageFormat = |
141 "test step %s, SkNWayCanvas state consistency"; | 246 "test step %s, SkNWayCanvas state consistency"; |
142 static const char* const kNWayIndirect1StateAssertMessageFormat = | 247 static const char* const kNWayIndirect1StateAssertMessageFormat = |
143 "test step %s, SkNWayCanvas indirect canvas 1 state consistency"; | 248 "test step %s, SkNWayCanvas indirect canvas 1 state consistency"; |
144 static const char* const kNWayIndirect2StateAssertMessageFormat = | 249 static const char* const kNWayIndirect2StateAssertMessageFormat = |
145 "test step %s, SkNWayCanvas indirect canvas 2 state consistency"; | 250 "test step %s, SkNWayCanvas indirect canvas 2 state consistency"; |
146 static const char* const kPdfAssertMessageFormat = | 251 static const char* const kPdfAssertMessageFormat = |
147 "PDF sanity check failed %s"; | 252 "PDF sanity check failed %s"; |
148 | 253 |
149 static void createBitmap(SkBitmap* bm, SkColor color) { | |
150 bm->allocN32Pixels(kWidth, kHeight); | |
151 bm->eraseColor(color); | |
152 } | |
153 | |
154 static SkSurface* createSurface(SkColor color) { | |
155 SkSurface* surface = SkSurface::NewRasterPMColor(kWidth, kHeight); | |
156 surface->getCanvas()->clear(color); | |
157 return surface; | |
158 } | |
159 | |
160 class CanvasTestStep; | 254 class CanvasTestStep; |
161 static SkTDArray<CanvasTestStep*>& testStepArray() { | 255 static SkTDArray<CanvasTestStep*>& testStepArray() { |
162 static SkTDArray<CanvasTestStep*> theTests; | 256 static SkTDArray<CanvasTestStep*> theTests; |
163 return theTests; | 257 return theTests; |
164 } | 258 } |
165 | 259 |
166 class CanvasTestStep { | 260 class CanvasTestStep { |
167 public: | 261 public: |
168 CanvasTestStep(bool fEnablePdfTesting = true) { | 262 CanvasTestStep(bool fEnablePdfTesting = true) { |
169 *testStepArray().append() = this; | 263 *testStepArray().append() = this; |
170 fAssertMessageFormat = kDefaultAssertMessageFormat; | 264 fAssertMessageFormat = kDefaultAssertMessageFormat; |
171 this->fEnablePdfTesting = fEnablePdfTesting; | 265 this->fEnablePdfTesting = fEnablePdfTesting; |
172 } | 266 } |
173 virtual ~CanvasTestStep() { } | 267 virtual ~CanvasTestStep() { } |
174 | 268 |
175 virtual void draw(SkCanvas*, skiatest::Reporter*) = 0; | 269 virtual void draw(SkCanvas*, const TestData&, skiatest::Reporter*) = 0; |
176 virtual const char* name() const = 0; | 270 virtual const char* name() const = 0; |
177 | 271 |
178 const char* assertMessage() { | 272 const char* assertMessage() { |
179 fAssertMessage.printf(fAssertMessageFormat, name()); | 273 fAssertMessage.printf(fAssertMessageFormat, name()); |
180 return fAssertMessage.c_str(); | 274 return fAssertMessage.c_str(); |
181 } | 275 } |
182 | 276 |
183 void setAssertMessageFormat(const char* format) { | 277 void setAssertMessageFormat(const char* format) { |
184 fAssertMessageFormat = format; | 278 fAssertMessageFormat = format; |
185 } | 279 } |
186 | 280 |
187 bool enablePdfTesting() { return fEnablePdfTesting; } | 281 bool enablePdfTesting() { return fEnablePdfTesting; } |
188 | 282 |
189 private: | 283 private: |
190 SkString fAssertMessage; | 284 SkString fAssertMessage; |
191 const char* fAssertMessageFormat; | 285 const char* fAssertMessageFormat; |
192 bool fEnablePdfTesting; | 286 bool fEnablePdfTesting; |
193 }; | 287 }; |
194 | 288 |
195 /////////////////////////////////////////////////////////////////////////////// | 289 /////////////////////////////////////////////////////////////////////////////// |
196 // Constants used by test steps | |
197 | |
198 const SkRect kTestRect = | |
199 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), | |
200 SkIntToScalar(2), SkIntToScalar(1)); | |
201 static SkMatrix testMatrix() { | |
202 SkMatrix matrix; | |
203 matrix.reset(); | |
204 matrix.setScale(SkIntToScalar(2), SkIntToScalar(3)); | |
205 return matrix; | |
206 } | |
207 const SkMatrix kTestMatrix = testMatrix(); | |
208 static SkPath test_path() { | |
209 SkPath path; | |
210 path.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), | |
211 SkIntToScalar(2), SkIntToScalar(1))); | |
212 return path; | |
213 } | |
214 const SkPath kTestPath = test_path(); | |
215 static SkPath test_nearly_zero_length_path() { | |
216 SkPath path; | |
217 SkPoint pt1 = { 0, 0 }; | |
218 SkPoint pt2 = { 0, SK_ScalarNearlyZero }; | |
219 SkPoint pt3 = { SkIntToScalar(1), 0 }; | |
220 SkPoint pt4 = { SkIntToScalar(1), SK_ScalarNearlyZero/2 }; | |
221 path.moveTo(pt1); | |
222 path.lineTo(pt2); | |
223 path.lineTo(pt3); | |
224 path.lineTo(pt4); | |
225 return path; | |
226 } | |
227 const SkPath kNearlyZeroLengthPath = test_nearly_zero_length_path(); | |
228 static SkRegion testRegion() { | |
229 SkRegion region; | |
230 SkIRect rect = SkIRect::MakeXYWH(0, 0, 2, 1); | |
231 region.setRect(rect); | |
232 return region; | |
233 } | |
234 const SkIRect kTestIRect = SkIRect::MakeXYWH(0, 0, 2, 1); | |
235 const SkRegion kTestRegion = testRegion(); | |
236 const SkColor kTestColor = 0x01020304; | |
237 const SkPaint kTestPaint; | |
238 const SkPoint kTestPoints[3] = { | |
239 {SkIntToScalar(0), SkIntToScalar(0)}, | |
240 {SkIntToScalar(2), SkIntToScalar(1)}, | |
241 {SkIntToScalar(0), SkIntToScalar(2)} | |
242 }; | |
243 const size_t kTestPointCount = 3; | |
244 static SkBitmap testBitmap() { | |
245 SkBitmap bitmap; | |
246 createBitmap(&bitmap, 0x05060708); | |
247 return bitmap; | |
248 } | |
249 SkBitmap kTestBitmap; // cannot be created during static init | |
250 SkString kTestText("Hello World"); | |
251 SkPoint kTestPoints2[] = { | |
252 { SkIntToScalar(0), SkIntToScalar(1) }, | |
253 { SkIntToScalar(1), SkIntToScalar(1) }, | |
254 { SkIntToScalar(2), SkIntToScalar(1) }, | |
255 { SkIntToScalar(3), SkIntToScalar(1) }, | |
256 { SkIntToScalar(4), SkIntToScalar(1) }, | |
257 { SkIntToScalar(5), SkIntToScalar(1) }, | |
258 { SkIntToScalar(6), SkIntToScalar(1) }, | |
259 { SkIntToScalar(7), SkIntToScalar(1) }, | |
260 { SkIntToScalar(8), SkIntToScalar(1) }, | |
261 { SkIntToScalar(9), SkIntToScalar(1) }, | |
262 { SkIntToScalar(10), SkIntToScalar(1) }, | |
263 }; | |
264 | |
265 | |
266 /////////////////////////////////////////////////////////////////////////////// | |
267 // Macros for defining test steps | 290 // Macros for defining test steps |
268 | 291 |
269 #define TEST_STEP(NAME, FUNCTION) \ | 292 #define TEST_STEP(NAME, FUNCTION) \ |
270 class NAME##_TestStep : public CanvasTestStep{ \ | 293 class NAME##_TestStep : public CanvasTestStep{ \ |
271 public: \ | 294 public: \ |
272 virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \ | 295 virtual void draw(SkCanvas* canvas, const TestData& testData, \ |
273 FUNCTION (canvas, reporter, this); \ | 296 skiatest::Reporter* reporter) { \ |
297 FUNCTION (canvas, testData, reporter, this); \ | |
274 } \ | 298 } \ |
275 virtual const char* name() const {return #NAME ;} \ | 299 virtual const char* name() const {return #NAME ;} \ |
276 }; \ | 300 }; \ |
277 static NAME##_TestStep NAME##_TestStepInstance; | 301 static NAME##_TestStep NAME##_TestStepInstance; |
278 | 302 |
279 #define TEST_STEP_NO_PDF(NAME, FUNCTION) \ | 303 #define TEST_STEP_NO_PDF(NAME, FUNCTION) \ |
280 class NAME##_TestStep : public CanvasTestStep{ \ | 304 class NAME##_TestStep : public CanvasTestStep{ \ |
281 public: \ | 305 public: \ |
282 NAME##_TestStep() : CanvasTestStep(false) {} \ | 306 NAME##_TestStep() : CanvasTestStep(false) {} \ |
283 virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \ | 307 virtual void draw(SkCanvas* canvas, const TestData& testData, \ |
284 FUNCTION (canvas, reporter, this); \ | 308 skiatest::Reporter* reporter) { \ |
309 FUNCTION (canvas, testData, reporter, this); \ | |
285 } \ | 310 } \ |
286 virtual const char* name() const {return #NAME ;} \ | 311 virtual const char* name() const {return #NAME ;} \ |
287 }; \ | 312 }; \ |
288 static NAME##_TestStep NAME##_TestStepInstance; | 313 static NAME##_TestStep NAME##_TestStepInstance; |
289 | 314 |
290 #define SIMPLE_TEST_STEP(NAME, CALL) \ | 315 #define SIMPLE_TEST_STEP(NAME, CALL) \ |
291 static void NAME##TestStep(SkCanvas* canvas, skiatest::Reporter*, \ | 316 static void NAME##TestStep(SkCanvas* canvas, const TestData& testData, \ |
292 CanvasTestStep*) { \ | 317 skiatest::Reporter*, CanvasTestStep*) { \ |
293 canvas-> CALL ; \ | 318 canvas-> CALL ; \ |
294 } \ | 319 } \ |
295 TEST_STEP(NAME, NAME##TestStep ) | 320 TEST_STEP(NAME, NAME##TestStep ) |
296 | 321 |
297 #define SIMPLE_TEST_STEP_WITH_ASSERT(NAME, CALL) \ | 322 #define SIMPLE_TEST_STEP_WITH_ASSERT(NAME, CALL) \ |
298 static void NAME##TestStep(SkCanvas* canvas, skiatest::Reporter* reporter, \ | 323 static void NAME##TestStep(SkCanvas* canvas, const TestData& testData, \ |
299 CanvasTestStep* testStep) { \ | 324 skiatest::Reporter*, CanvasTestStep* testStep) { \ |
300 REPORTER_ASSERT_MESSAGE(reporter, canvas-> CALL , \ | 325 REPORTER_ASSERT_MESSAGE(reporter, canvas-> CALL , \ |
301 testStep->assertMessage()); \ | 326 testStep->assertMessage()); \ |
302 } \ | 327 } \ |
303 TEST_STEP(NAME, NAME##TestStep ) | 328 TEST_STEP(NAME, NAME##TestStep ) |
304 | 329 |
305 | 330 |
306 /////////////////////////////////////////////////////////////////////////////// | 331 /////////////////////////////////////////////////////////////////////////////// |
307 // Basic test steps for most virtual methods in SkCanvas that draw or affect | 332 // Basic test steps for most virtual methods in SkCanvas that draw or affect |
308 // the state of the canvas. | 333 // the state of the canvas. |
309 | 334 |
310 SIMPLE_TEST_STEP(Translate, translate(SkIntToScalar(1), SkIntToScalar(2))); | 335 SIMPLE_TEST_STEP(Translate, translate(SkIntToScalar(1), SkIntToScalar(2))); |
311 SIMPLE_TEST_STEP(Scale, scale(SkIntToScalar(1), SkIntToScalar(2))); | 336 SIMPLE_TEST_STEP(Scale, scale(SkIntToScalar(1), SkIntToScalar(2))); |
312 SIMPLE_TEST_STEP(Rotate, rotate(SkIntToScalar(1))); | 337 SIMPLE_TEST_STEP(Rotate, rotate(SkIntToScalar(1))); |
313 SIMPLE_TEST_STEP(Skew, skew(SkIntToScalar(1), SkIntToScalar(2))); | 338 SIMPLE_TEST_STEP(Skew, skew(SkIntToScalar(1), SkIntToScalar(2))); |
314 SIMPLE_TEST_STEP(Concat, concat(kTestMatrix)); | 339 SIMPLE_TEST_STEP(Concat, concat(testData.fTestMatrix)); |
315 SIMPLE_TEST_STEP(SetMatrix, setMatrix(kTestMatrix)); | 340 SIMPLE_TEST_STEP(SetMatrix, setMatrix(testData.fTestMatrix)); |
316 SIMPLE_TEST_STEP(ClipRect, clipRect(kTestRect)); | 341 SIMPLE_TEST_STEP(ClipRect, clipRect(testData.fTestRect)); |
317 SIMPLE_TEST_STEP(ClipPath, clipPath(kTestPath)); | 342 SIMPLE_TEST_STEP(ClipPath, clipPath(testData.fTestPath)); |
318 SIMPLE_TEST_STEP(ClipRegion, | 343 SIMPLE_TEST_STEP(ClipRegion, |
319 clipRegion(kTestRegion, SkRegion::kReplace_Op)); | 344 clipRegion(testData.fTestRegion, SkRegion::kReplace_Op)); |
320 SIMPLE_TEST_STEP(Clear, clear(kTestColor)); | 345 SIMPLE_TEST_STEP(Clear, clear(testData.fTestColor)); |
321 SIMPLE_TEST_STEP(DrawPaint, drawPaint(kTestPaint)); | 346 SIMPLE_TEST_STEP(DrawPaint, drawPaint(testData.fTestPaint)); |
322 SIMPLE_TEST_STEP(DrawPointsPoints, drawPoints(SkCanvas::kPoints_PointMode, | 347 SIMPLE_TEST_STEP(DrawPointsPoints, drawPoints(SkCanvas::kPoints_PointMode, |
323 kTestPointCount, kTestPoints, kTestPaint)); | 348 testData.fTestPointCount, testData.fTestPoints, testData.fTestPaint)); |
324 SIMPLE_TEST_STEP(DrawPointsLiness, drawPoints(SkCanvas::kLines_PointMode, | 349 SIMPLE_TEST_STEP(DrawPointsLiness, drawPoints(SkCanvas::kLines_PointMode, |
325 kTestPointCount, kTestPoints, kTestPaint)); | 350 testData.fTestPointCount, testData.fTestPoints, testData.fTestPaint)); |
326 SIMPLE_TEST_STEP(DrawPointsPolygon, drawPoints(SkCanvas::kPolygon_PointMode, | 351 SIMPLE_TEST_STEP(DrawPointsPolygon, drawPoints(SkCanvas::kPolygon_PointMode, |
327 kTestPointCount, kTestPoints, kTestPaint)); | 352 testData.fTestPointCount, testData.fTestPoints, testData.fTestPaint)); |
328 SIMPLE_TEST_STEP(DrawRect, drawRect(kTestRect, kTestPaint)); | 353 SIMPLE_TEST_STEP(DrawRect, drawRect(testData.fTestRect, testData.fTestPaint)); |
329 SIMPLE_TEST_STEP(DrawPath, drawPath(kTestPath, kTestPaint)); | 354 SIMPLE_TEST_STEP(DrawPath, drawPath(testData.fTestPath, testData.fTestPaint)); |
330 SIMPLE_TEST_STEP(DrawBitmap, drawBitmap(kTestBitmap, 0, 0)); | 355 SIMPLE_TEST_STEP(DrawBitmap, drawBitmap(testData.fTestBitmap, 0, 0)); |
331 SIMPLE_TEST_STEP(DrawBitmapPaint, drawBitmap(kTestBitmap, 0, 0, &kTestPaint)); | 356 SIMPLE_TEST_STEP(DrawBitmapPaint, drawBitmap(testData.fTestBitmap, 0, 0, &testDa ta.fTestPaint)); |
332 SIMPLE_TEST_STEP(DrawBitmapRect, drawBitmapRect(kTestBitmap, NULL, kTestRect, | 357 SIMPLE_TEST_STEP(DrawBitmapRect, drawBitmapRect(testData.fTestBitmap, NULL, test Data.fTestRect, |
333 NULL)); | 358 NULL)); |
334 SIMPLE_TEST_STEP(DrawBitmapRectSrcRect, drawBitmapRect(kTestBitmap, | 359 SIMPLE_TEST_STEP(DrawBitmapRectSrcRect, drawBitmapRect(testData.fTestBitmap, |
335 &kTestIRect, kTestRect, NULL)); | 360 &testData.fTestIRect, testData.fTestRect, NULL)); |
336 SIMPLE_TEST_STEP(DrawBitmapRectPaint, drawBitmapRect(kTestBitmap, NULL, | 361 SIMPLE_TEST_STEP(DrawBitmapRectPaint, drawBitmapRect(testData.fTestBitmap, NULL, |
337 kTestRect, &kTestPaint)); | 362 testData.fTestRect, &testData.fTestPaint)); |
338 SIMPLE_TEST_STEP(DrawBitmapMatrix, drawBitmapMatrix(kTestBitmap, kTestMatrix, | 363 SIMPLE_TEST_STEP(DrawBitmapMatrix, drawBitmapMatrix(testData.fTestBitmap, testDa ta.fTestMatrix, |
339 NULL)); | 364 NULL)); |
340 SIMPLE_TEST_STEP(DrawBitmapMatrixPaint, drawBitmapMatrix(kTestBitmap, | 365 SIMPLE_TEST_STEP(DrawBitmapMatrixPaint, drawBitmapMatrix(testData.fTestBitmap, |
341 kTestMatrix, &kTestPaint)); | 366 testData.fTestMatrix, &testData.fTestPaint)); |
342 SIMPLE_TEST_STEP(DrawBitmapNine, drawBitmapNine(kTestBitmap, kTestIRect, | 367 SIMPLE_TEST_STEP(DrawBitmapNine, drawBitmapNine(testData.fTestBitmap, testData.f TestIRect, |
343 kTestRect, NULL)); | 368 testData.fTestRect, NULL)); |
344 SIMPLE_TEST_STEP(DrawBitmapNinePaint, drawBitmapNine(kTestBitmap, kTestIRect, | 369 SIMPLE_TEST_STEP(DrawBitmapNinePaint, drawBitmapNine(testData.fTestBitmap, testD ata.fTestIRect, |
345 kTestRect, &kTestPaint)); | 370 testData.fTestRect, &testData.fTestPaint)); |
346 SIMPLE_TEST_STEP(DrawSprite, drawSprite(kTestBitmap, 0, 0, NULL)); | 371 SIMPLE_TEST_STEP(DrawSprite, drawSprite(testData.fTestBitmap, 0, 0, NULL)); |
347 SIMPLE_TEST_STEP(DrawSpritePaint, drawSprite(kTestBitmap, 0, 0, &kTestPaint)); | 372 SIMPLE_TEST_STEP(DrawSpritePaint, drawSprite(testData.fTestBitmap, 0, 0, &testDa ta.fTestPaint)); |
348 SIMPLE_TEST_STEP(DrawText, drawText(kTestText.c_str(), kTestText.size(), | 373 SIMPLE_TEST_STEP(DrawText, drawText(testData.fTestText.c_str(), testData.fTestTe xt.size(), |
349 0, 1, kTestPaint)); | 374 0, 1, testData.fTestPaint)); |
350 SIMPLE_TEST_STEP(DrawPosText, drawPosText(kTestText.c_str(), | 375 SIMPLE_TEST_STEP(DrawPosText, drawPosText(testData.fTestText.c_str(), |
351 kTestText.size(), kTestPoints2, kTestPaint)); | 376 testData.fTestText.size(), testData.fTestPoints2, testData.fTestPaint)); |
352 SIMPLE_TEST_STEP(DrawTextOnPath, drawTextOnPath(kTestText.c_str(), | 377 SIMPLE_TEST_STEP(DrawTextOnPath, drawTextOnPath(testData.fTestText.c_str(), |
353 kTestText.size(), kTestPath, NULL, kTestPaint)); | 378 testData.fTestText.size(), testData.fTestPath, NULL, testData.fTestPaint)); |
354 SIMPLE_TEST_STEP(DrawTextOnPathMatrix, drawTextOnPath(kTestText.c_str(), | 379 SIMPLE_TEST_STEP(DrawTextOnPathMatrix, drawTextOnPath(testData.fTestText.c_str() , |
355 kTestText.size(), kTestPath, &kTestMatrix, kTestPaint)); | 380 testData.fTestText.size(), testData.fTestPath, &testData.fTestMatrix, testDa ta.fTestPaint)); |
356 SIMPLE_TEST_STEP(DrawData, drawData(kTestText.c_str(), kTestText.size())); | 381 SIMPLE_TEST_STEP(DrawData, drawData(testData.fTestText.c_str(), testData.fTestTe xt.size())); |
357 SIMPLE_TEST_STEP(BeginGroup, beginCommentGroup(kTestText.c_str())); | 382 SIMPLE_TEST_STEP(BeginGroup, beginCommentGroup(testData.fTestText.c_str())); |
358 SIMPLE_TEST_STEP(AddComment, addComment(kTestText.c_str(), kTestText.c_str())); | 383 SIMPLE_TEST_STEP(AddComment, addComment(testData.fTestText.c_str(), testData.fTe stText.c_str())); |
359 SIMPLE_TEST_STEP(EndGroup, endCommentGroup()); | 384 SIMPLE_TEST_STEP(EndGroup, endCommentGroup()); |
360 | 385 |
361 /////////////////////////////////////////////////////////////////////////////// | 386 /////////////////////////////////////////////////////////////////////////////// |
362 // Complex test steps | 387 // Complex test steps |
363 | 388 |
364 static void SaveMatrixClipStep(SkCanvas* canvas, | 389 static void SaveMatrixClipStep(SkCanvas* canvas, const TestData& testData, |
365 skiatest::Reporter* reporter, | 390 skiatest::Reporter* reporter, CanvasTestStep* tes tStep) { |
366 CanvasTestStep* testStep) { | |
367 int saveCount = canvas->getSaveCount(); | 391 int saveCount = canvas->getSaveCount(); |
368 canvas->save(); | 392 canvas->save(); |
369 canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); | 393 canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); |
370 canvas->clipRegion(kTestRegion); | 394 canvas->clipRegion(testData.fTestRegion); |
371 canvas->restore(); | 395 canvas->restore(); |
372 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, | 396 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
373 testStep->assertMessage()); | 397 testStep->assertMessage()); |
374 REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(), | 398 REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(), |
375 testStep->assertMessage()); | 399 testStep->assertMessage()); |
376 // REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, t estStep->assertMessage()); | 400 // REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, t estStep->assertMessage()); |
377 } | 401 } |
378 TEST_STEP(SaveMatrixClip, SaveMatrixClipStep); | 402 TEST_STEP(SaveMatrixClip, SaveMatrixClipStep); |
379 | 403 |
380 static void SaveLayerStep(SkCanvas* canvas, | 404 static void SaveLayerStep(SkCanvas* canvas, const TestData& testData, |
381 skiatest::Reporter* reporter, | 405 skiatest::Reporter* reporter, CanvasTestStep* testStep ) { |
382 CanvasTestStep* testStep) { | |
383 int saveCount = canvas->getSaveCount(); | 406 int saveCount = canvas->getSaveCount(); |
384 canvas->saveLayer(NULL, NULL); | 407 canvas->saveLayer(NULL, NULL); |
385 canvas->restore(); | 408 canvas->restore(); |
386 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, | 409 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
387 testStep->assertMessage()); | 410 testStep->assertMessage()); |
388 } | 411 } |
389 TEST_STEP(SaveLayer, SaveLayerStep); | 412 TEST_STEP(SaveLayer, SaveLayerStep); |
390 | 413 |
391 static void BoundedSaveLayerStep(SkCanvas* canvas, | 414 static void BoundedSaveLayerStep(SkCanvas* canvas, const TestData& testData, |
392 skiatest::Reporter* reporter, | 415 skiatest::Reporter* reporter, CanvasTestStep* t estStep) { |
393 CanvasTestStep* testStep) { | |
394 int saveCount = canvas->getSaveCount(); | 416 int saveCount = canvas->getSaveCount(); |
395 canvas->saveLayer(&kTestRect, NULL); | 417 canvas->saveLayer(&testData.fTestRect, NULL); |
396 canvas->restore(); | 418 canvas->restore(); |
397 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, | 419 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
398 testStep->assertMessage()); | 420 testStep->assertMessage()); |
399 } | 421 } |
400 TEST_STEP(BoundedSaveLayer, BoundedSaveLayerStep); | 422 TEST_STEP(BoundedSaveLayer, BoundedSaveLayerStep); |
401 | 423 |
402 static void PaintSaveLayerStep(SkCanvas* canvas, | 424 static void PaintSaveLayerStep(SkCanvas* canvas, const TestData& testData, |
403 skiatest::Reporter* reporter, | 425 skiatest::Reporter* reporter, CanvasTestStep* tes tStep) { |
404 CanvasTestStep* testStep) { | |
405 int saveCount = canvas->getSaveCount(); | 426 int saveCount = canvas->getSaveCount(); |
406 canvas->saveLayer(NULL, &kTestPaint); | 427 canvas->saveLayer(NULL, &testData.fTestPaint); |
407 canvas->restore(); | 428 canvas->restore(); |
408 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, | 429 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
409 testStep->assertMessage()); | 430 testStep->assertMessage()); |
410 } | 431 } |
411 TEST_STEP(PaintSaveLayer, PaintSaveLayerStep); | 432 TEST_STEP(PaintSaveLayer, PaintSaveLayerStep); |
412 | 433 |
413 static void TwoClipOpsStep(SkCanvas* canvas, | 434 static void TwoClipOpsStep(SkCanvas* canvas, const TestData& testData, |
414 skiatest::Reporter*, | 435 skiatest::Reporter*, CanvasTestStep*) { |
415 CanvasTestStep*) { | |
416 // This test exercises a functionality in SkPicture that leads to the | 436 // This test exercises a functionality in SkPicture that leads to the |
417 // recording of restore offset placeholders. This test will trigger an | 437 // recording of restore offset placeholders. This test will trigger an |
418 // assertion at playback time if the placeholders are not properly | 438 // assertion at playback time if the placeholders are not properly |
419 // filled when the recording ends. | 439 // filled when the recording ends. |
420 canvas->clipRect(kTestRect); | 440 canvas->clipRect(testData.fTestRect); |
421 canvas->clipRegion(kTestRegion); | 441 canvas->clipRegion(testData.fTestRegion); |
422 } | 442 } |
423 TEST_STEP(TwoClipOps, TwoClipOpsStep); | 443 TEST_STEP(TwoClipOps, TwoClipOpsStep); |
424 | 444 |
425 // exercise fix for http://code.google.com/p/skia/issues/detail?id=560 | 445 // exercise fix for http://code.google.com/p/skia/issues/detail?id=560 |
426 // ('SkPathStroker::lineTo() fails for line with length SK_ScalarNearlyZero') | 446 // ('SkPathStroker::lineTo() fails for line with length SK_ScalarNearlyZero') |
427 static void DrawNearlyZeroLengthPathTestStep(SkCanvas* canvas, | 447 static void DrawNearlyZeroLengthPathTestStep(SkCanvas* canvas, const TestData& t estData, |
428 skiatest::Reporter*, | 448 skiatest::Reporter*, CanvasTestStep *) { |
429 CanvasTestStep*) { | |
430 SkPaint paint; | 449 SkPaint paint; |
431 paint.setStrokeWidth(SkIntToScalar(1)); | 450 paint.setStrokeWidth(SkIntToScalar(1)); |
432 paint.setStyle(SkPaint::kStroke_Style); | 451 paint.setStyle(SkPaint::kStroke_Style); |
433 | 452 |
434 canvas->drawPath(kNearlyZeroLengthPath, paint); | 453 canvas->drawPath(testData.fNearlyZeroLengthPath, paint); |
435 } | 454 } |
436 TEST_STEP(DrawNearlyZeroLengthPath, DrawNearlyZeroLengthPathTestStep); | 455 TEST_STEP(DrawNearlyZeroLengthPath, DrawNearlyZeroLengthPathTestStep); |
437 | 456 |
438 static void DrawVerticesShaderTestStep(SkCanvas* canvas, | 457 static void DrawVerticesShaderTestStep(SkCanvas* canvas, const TestData& testDat a, |
439 skiatest::Reporter*, | 458 skiatest::Reporter*, CanvasTestStep*) { |
440 CanvasTestStep*) { | |
441 SkPoint pts[4]; | 459 SkPoint pts[4]; |
442 pts[0].set(0, 0); | 460 pts[0].set(0, 0); |
443 pts[1].set(SkIntToScalar(kWidth), 0); | 461 pts[1].set(SkIntToScalar(testData.fWidth), 0); |
444 pts[2].set(SkIntToScalar(kWidth), SkIntToScalar(kHeight)); | 462 pts[2].set(SkIntToScalar(testData.fWidth), SkIntToScalar(testData.fHeight)); |
445 pts[3].set(0, SkIntToScalar(kHeight)); | 463 pts[3].set(0, SkIntToScalar(testData.fHeight)); |
446 SkPaint paint; | 464 SkPaint paint; |
447 SkShader* shader = SkShader::CreateBitmapShader(kTestBitmap, | 465 SkShader* shader = SkShader::CreateBitmapShader(testData.fTestBitmap, |
448 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); | 466 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
449 paint.setShader(shader)->unref(); | 467 paint.setShader(shader)->unref(); |
450 canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts, | 468 canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts, |
451 NULL, NULL, NULL, 0, paint); | 469 NULL, NULL, NULL, 0, paint); |
452 } | 470 } |
453 // NYI: issue 240. | 471 // NYI: issue 240. |
454 TEST_STEP_NO_PDF(DrawVerticesShader, DrawVerticesShaderTestStep); | 472 TEST_STEP_NO_PDF(DrawVerticesShader, DrawVerticesShaderTestStep); |
455 | 473 |
456 static void DrawPictureTestStep(SkCanvas* canvas, | 474 static void DrawPictureTestStep(SkCanvas* canvas, const TestData& testData, |
457 skiatest::Reporter*, | 475 skiatest::Reporter*, CanvasTestStep*) { |
458 CanvasTestStep*) { | |
459 SkPictureRecorder recorder; | 476 SkPictureRecorder recorder; |
460 SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT oScalar(kHeight), | 477 SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(testData.fWidth ), SkIntToScalar(testData.fHeight), |
461 NULL, 0); | 478 NULL, 0); |
462 testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1)); | 479 testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1)); |
463 testCanvas->clipRect(kTestRect); | 480 testCanvas->clipRect(testData.fTestRect); |
464 testCanvas->drawRect(kTestRect, kTestPaint); | 481 testCanvas->drawRect(testData.fTestRect, testData.fTestPaint); |
465 SkAutoTUnref<SkPicture> testPicture(recorder.endRecording()); | 482 SkAutoTUnref<SkPicture> testPicture(recorder.endRecording()); |
466 | 483 |
467 canvas->drawPicture(testPicture); | 484 canvas->drawPicture(testPicture); |
468 } | 485 } |
469 TEST_STEP(DrawPicture, DrawPictureTestStep); | 486 TEST_STEP(DrawPicture, DrawPictureTestStep); |
470 | 487 |
471 static void SaveRestoreTestStep(SkCanvas* canvas, | 488 static void SaveRestoreTestStep(SkCanvas* canvas, const TestData& testData, |
472 skiatest::Reporter* reporter, | 489 skiatest::Reporter* reporter, CanvasTestStep* te stStep) { |
473 CanvasTestStep* testStep) { | |
474 int baseSaveCount = canvas->getSaveCount(); | 490 int baseSaveCount = canvas->getSaveCount(); |
475 int n = canvas->save(); | 491 int n = canvas->save(); |
476 REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount == n, testStep->assertMessag e()); | 492 REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount == n, testStep->assertMessag e()); |
477 REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 1 == canvas->getSaveCount( ), | 493 REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 1 == canvas->getSaveCount( ), |
478 testStep->assertMessage()); | 494 testStep->assertMessage()); |
479 canvas->save(); | 495 canvas->save(); |
480 canvas->save(); | 496 canvas->save(); |
481 REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 3 == canvas->getSaveCount( ), | 497 REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 3 == canvas->getSaveCount( ), |
482 testStep->assertMessage()); | 498 testStep->assertMessage()); |
483 canvas->restoreToCount(baseSaveCount + 1); | 499 canvas->restoreToCount(baseSaveCount + 1); |
484 REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 1 == canvas->getSaveCount( ), | 500 REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 1 == canvas->getSaveCount( ), |
485 testStep->assertMessage()); | 501 testStep->assertMessage()); |
486 | 502 |
487 // should this pin to 1, or be a no-op, or crash? | 503 // should this pin to 1, or be a no-op, or crash? |
488 canvas->restoreToCount(0); | 504 canvas->restoreToCount(0); |
489 REPORTER_ASSERT_MESSAGE(reporter, 1 == canvas->getSaveCount(), | 505 REPORTER_ASSERT_MESSAGE(reporter, 1 == canvas->getSaveCount(), |
490 testStep->assertMessage()); | 506 testStep->assertMessage()); |
491 } | 507 } |
492 TEST_STEP(SaveRestore, SaveRestoreTestStep); | 508 TEST_STEP(SaveRestore, SaveRestoreTestStep); |
493 | 509 |
494 static void DrawLayerTestStep(SkCanvas* canvas, | 510 static void DrawLayerTestStep(SkCanvas* canvas, const TestData& testData, |
495 skiatest::Reporter* reporter, | 511 skiatest::Reporter* reporter, CanvasTestStep* test Step) { |
496 CanvasTestStep* testStep) { | |
497 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), | 512 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), |
498 testStep->assertMessage()); | 513 testStep->assertMessage()); |
499 canvas->save(); | 514 canvas->save(); |
500 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), | 515 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), |
501 testStep->assertMessage()); | 516 testStep->assertMessage()); |
502 canvas->restore(); | 517 canvas->restore(); |
503 | 518 |
504 const SkRect* bounds = NULL; // null means include entire bounds | 519 const SkRect* bounds = NULL; // null means include entire bounds |
505 const SkPaint* paint = NULL; | 520 const SkPaint* paint = NULL; |
506 | 521 |
(...skipping 11 matching lines...) Expand all Loading... | |
518 canvas->restore(); | 533 canvas->restore(); |
519 REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(), | 534 REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(), |
520 testStep->assertMessage()); | 535 testStep->assertMessage()); |
521 canvas->restore(); | 536 canvas->restore(); |
522 // now layer count should be 0 | 537 // now layer count should be 0 |
523 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), | 538 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), |
524 testStep->assertMessage()); | 539 testStep->assertMessage()); |
525 } | 540 } |
526 TEST_STEP(DrawLayer, DrawLayerTestStep); | 541 TEST_STEP(DrawLayer, DrawLayerTestStep); |
527 | 542 |
528 static void NestedSaveRestoreWithSolidPaintTestStep(SkCanvas* canvas, | 543 static void NestedSaveRestoreWithSolidPaintTestStep(SkCanvas* canvas, const Test Data& testData, |
529 skiatest::Reporter*, | 544 skiatest::Reporter*, CanvasT estStep*) { |
530 CanvasTestStep*) { | |
531 // This test step challenges the TestDeferredCanvasStateConsistency | 545 // This test step challenges the TestDeferredCanvasStateConsistency |
532 // test cases because the opaque paint can trigger an optimization | 546 // test cases because the opaque paint can trigger an optimization |
533 // that discards previously recorded commands. The challenge is to maintain | 547 // that discards previously recorded commands. The challenge is to maintain |
534 // correct clip and matrix stack state. | 548 // correct clip and matrix stack state. |
535 canvas->resetMatrix(); | 549 canvas->resetMatrix(); |
536 canvas->rotate(SkIntToScalar(30)); | 550 canvas->rotate(SkIntToScalar(30)); |
537 canvas->save(); | 551 canvas->save(); |
538 canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); | 552 canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); |
539 canvas->save(); | 553 canvas->save(); |
540 canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); | 554 canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); |
541 SkPaint paint; | 555 SkPaint paint; |
542 paint.setColor(0xFFFFFFFF); | 556 paint.setColor(0xFFFFFFFF); |
543 canvas->drawPaint(paint); | 557 canvas->drawPaint(paint); |
544 canvas->restore(); | 558 canvas->restore(); |
545 canvas->restore(); | 559 canvas->restore(); |
546 } | 560 } |
547 TEST_STEP(NestedSaveRestoreWithSolidPaint, \ | 561 TEST_STEP(NestedSaveRestoreWithSolidPaint, \ |
548 NestedSaveRestoreWithSolidPaintTestStep); | 562 NestedSaveRestoreWithSolidPaintTestStep); |
549 | 563 |
550 static void NestedSaveRestoreWithFlushTestStep(SkCanvas* canvas, | 564 static void NestedSaveRestoreWithFlushTestStep(SkCanvas* canvas, const TestData& testData, |
551 skiatest::Reporter*, | 565 skiatest::Reporter*, CanvasTestSt ep*) { |
552 CanvasTestStep*) { | |
553 // This test step challenges the TestDeferredCanvasStateConsistency | 566 // This test step challenges the TestDeferredCanvasStateConsistency |
554 // test case because the canvas flush on a deferred canvas will | 567 // test case because the canvas flush on a deferred canvas will |
555 // reset the recording session. The challenge is to maintain correct | 568 // reset the recording session. The challenge is to maintain correct |
556 // clip and matrix stack state on the playback canvas. | 569 // clip and matrix stack state on the playback canvas. |
557 canvas->resetMatrix(); | 570 canvas->resetMatrix(); |
558 canvas->rotate(SkIntToScalar(30)); | 571 canvas->rotate(SkIntToScalar(30)); |
559 canvas->save(); | 572 canvas->save(); |
560 canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); | 573 canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); |
561 canvas->save(); | 574 canvas->save(); |
562 canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); | 575 canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); |
563 canvas->drawRect(kTestRect,kTestPaint); | 576 canvas->drawRect(testData.fTestRect,testData.fTestPaint); |
564 canvas->flush(); | 577 canvas->flush(); |
565 canvas->restore(); | 578 canvas->restore(); |
566 canvas->restore(); | 579 canvas->restore(); |
567 } | 580 } |
568 TEST_STEP(NestedSaveRestoreWithFlush, \ | 581 TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep); |
569 NestedSaveRestoreWithFlushTestStep); | |
570 | 582 |
571 static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, | 583 static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData & testData, |
572 const SkCanvas* canvas1, | 584 const SkCanvas* canvas1, const SkCanvas* can vas2, |
573 const SkCanvas* canvas2, | |
574 CanvasTestStep* testStep) { | 585 CanvasTestStep* testStep) { |
575 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() == | 586 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() == |
576 canvas2->getDeviceSize(), testStep->assertMessage()); | 587 canvas2->getDeviceSize(), testStep->assertMessage()); |
577 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() == | 588 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() == |
578 canvas2->getSaveCount(), testStep->assertMessage()); | 589 canvas2->getSaveCount(), testStep->assertMessage()); |
579 REPORTER_ASSERT_MESSAGE(reporter, canvas1->isDrawingToLayer() == | 590 REPORTER_ASSERT_MESSAGE(reporter, canvas1->isDrawingToLayer() == |
580 canvas2->isDrawingToLayer(), testStep->assertMessage()); | 591 canvas2->isDrawingToLayer(), testStep->assertMessage()); |
581 | 592 |
582 SkRect bounds1, bounds2; | 593 SkRect bounds1, bounds2; |
583 REPORTER_ASSERT_MESSAGE(reporter, | 594 REPORTER_ASSERT_MESSAGE(reporter, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
668 (*referenceRecord->fPathHeap)[i] == | 679 (*referenceRecord->fPathHeap)[i] == |
669 (*testRecord->fPathHeap)[i], testStep->assertMessage()); | 680 (*testRecord->fPathHeap)[i], testStep->assertMessage()); |
670 } | 681 } |
671 } | 682 } |
672 */ | 683 */ |
673 | 684 |
674 } | 685 } |
675 }; | 686 }; |
676 | 687 |
677 static void TestPdfDevice(skiatest::Reporter* reporter, | 688 static void TestPdfDevice(skiatest::Reporter* reporter, |
689 const TestData& testData, | |
678 CanvasTestStep* testStep) { | 690 CanvasTestStep* testStep) { |
679 SkISize pageSize = SkISize::Make(kWidth, kHeight); | 691 SkISize pageSize = SkISize::Make(testData.fWidth, testData.fHeight); |
680 SkPDFDevice device(pageSize, pageSize, SkMatrix::I()); | 692 SkPDFDevice device(pageSize, pageSize, SkMatrix::I()); |
681 SkCanvas canvas(&device); | 693 SkCanvas canvas(&device); |
682 testStep->setAssertMessageFormat(kPdfAssertMessageFormat); | 694 testStep->setAssertMessageFormat(kPdfAssertMessageFormat); |
683 testStep->draw(&canvas, reporter); | 695 testStep->draw(&canvas, testData, reporter); |
684 SkPDFDocument doc; | 696 SkPDFDocument doc; |
685 doc.appendPage(&device); | 697 doc.appendPage(&device); |
686 SkDynamicMemoryWStream stream; | 698 SkDynamicMemoryWStream stream; |
687 doc.emitPDF(&stream); | 699 doc.emitPDF(&stream); |
688 } | 700 } |
689 | 701 |
690 // The following class groups static functions that need to access | 702 // The following class groups static functions that need to access |
691 // the privates members of SkDeferredCanvas | 703 // the privates members of SkDeferredCanvas |
692 class SkDeferredCanvasTester { | 704 class SkDeferredCanvasTester { |
693 public: | 705 public: |
694 static void TestDeferredCanvasStateConsistency( | 706 static void TestDeferredCanvasStateConsistency( |
695 skiatest::Reporter* reporter, | 707 skiatest::Reporter* reporter, |
708 const TestData& testData, | |
696 CanvasTestStep* testStep, | 709 CanvasTestStep* testStep, |
697 const SkCanvas& referenceCanvas, bool silent) { | 710 const SkCanvas& referenceCanvas, bool silent) { |
698 | 711 |
699 SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF)); | 712 SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF)); |
700 SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(s urface.get())); | 713 SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(s urface.get())); |
701 | 714 |
702 testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat); | 715 testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat); |
703 testStep->draw(deferredCanvas, reporter); | 716 testStep->draw(deferredCanvas, testData, reporter); |
704 testStep->setAssertMessageFormat(kDeferredPreFlushAssertMessageFormat); | 717 testStep->setAssertMessageFormat(kDeferredPreFlushAssertMessageFormat); |
705 AssertCanvasStatesEqual(reporter, deferredCanvas, &referenceCanvas, | 718 AssertCanvasStatesEqual(reporter, testData, deferredCanvas, &referenceCa nvas, testStep); |
706 testStep); | |
707 | 719 |
708 if (silent) { | 720 if (silent) { |
709 deferredCanvas->silentFlush(); | 721 deferredCanvas->silentFlush(); |
710 } else { | 722 } else { |
711 deferredCanvas->flush(); | 723 deferredCanvas->flush(); |
712 } | 724 } |
713 | 725 |
714 testStep->setAssertMessageFormat( | 726 testStep->setAssertMessageFormat( |
715 silent ? kDeferredPostSilentFlushPlaybackAssertMessageFormat : | 727 silent ? kDeferredPostSilentFlushPlaybackAssertMessageFormat : |
716 kDeferredPostFlushPlaybackAssertMessageFormat); | 728 kDeferredPostFlushPlaybackAssertMessageFormat); |
717 AssertCanvasStatesEqual(reporter, | 729 AssertCanvasStatesEqual(reporter, testData, deferredCanvas->immediateCan vas(), |
718 deferredCanvas->immediateCanvas(), | 730 &referenceCanvas, testStep); |
719 &referenceCanvas, testStep); | |
720 | 731 |
721 // Verified that deferred canvas state is not affected by flushing | 732 // Verified that deferred canvas state is not affected by flushing |
722 // pending draw operations | 733 // pending draw operations |
723 | 734 |
724 // The following test code is commented out because it currently fails. | 735 // The following test code is commented out because it currently fails. |
725 // Issue: http://code.google.com/p/skia/issues/detail?id=496 | 736 // Issue: http://code.google.com/p/skia/issues/detail?id=496 |
726 /* | 737 /* |
727 testStep->setAssertMessageFormat(kDeferredPostFlushAssertMessageFormat); | 738 testStep->setAssertMessageFormat(kDeferredPostFlushAssertMessageFormat); |
728 AssertCanvasStatesEqual(reporter, &deferredCanvas, &referenceCanvas, | 739 AssertCanvasStatesEqual(reporter, &deferredCanvas, &referenceCanvas, |
729 testStep); | 740 testStep); |
730 */ | 741 */ |
731 } | 742 } |
732 }; | 743 }; |
733 | 744 |
734 // unused | 745 // unused |
735 static void TestProxyCanvasStateConsistency( | 746 static void TestProxyCanvasStateConsistency( |
736 skiatest::Reporter* reporter, | 747 skiatest::Reporter* reporter, |
748 const TestData& testData, | |
737 CanvasTestStep* testStep, | 749 CanvasTestStep* testStep, |
738 const SkCanvas& referenceCanvas) { | 750 const SkCanvas& referenceCanvas) { |
739 | 751 |
740 SkBitmap indirectStore; | 752 SkBitmap indirectStore; |
741 createBitmap(&indirectStore, 0xFFFFFFFF); | 753 createBitmap(&indirectStore, 0xFFFFFFFF); |
742 SkCanvas indirectCanvas(indirectStore); | 754 SkCanvas indirectCanvas(indirectStore); |
743 SkProxyCanvas proxyCanvas(&indirectCanvas); | 755 SkProxyCanvas proxyCanvas(&indirectCanvas); |
744 testStep->setAssertMessageFormat(kProxyDrawAssertMessageFormat); | 756 testStep->setAssertMessageFormat(kProxyDrawAssertMessageFormat); |
745 testStep->draw(&proxyCanvas, reporter); | 757 testStep->draw(&proxyCanvas, testData, reporter); |
746 // Verify that the SkProxyCanvas reports consitent state | 758 // Verify that the SkProxyCanvas reports consitent state |
747 testStep->setAssertMessageFormat(kProxyStateAssertMessageFormat); | 759 testStep->setAssertMessageFormat(kProxyStateAssertMessageFormat); |
748 AssertCanvasStatesEqual(reporter, &proxyCanvas, &referenceCanvas, | 760 AssertCanvasStatesEqual(reporter, testData, &proxyCanvas, &referenceCanvas, testStep); |
749 testStep); | |
750 // Verify that the indirect canvas reports consitent state | 761 // Verify that the indirect canvas reports consitent state |
751 testStep->setAssertMessageFormat(kProxyIndirectStateAssertMessageFormat); | 762 testStep->setAssertMessageFormat(kProxyIndirectStateAssertMessageFormat); |
752 AssertCanvasStatesEqual(reporter, &indirectCanvas, &referenceCanvas, | 763 AssertCanvasStatesEqual(reporter, testData, &indirectCanvas, &referenceCanva s, testStep); |
753 testStep); | |
754 } | 764 } |
755 | 765 |
756 // unused | 766 // unused |
757 static void TestNWayCanvasStateConsistency( | 767 static void TestNWayCanvasStateConsistency( |
758 skiatest::Reporter* reporter, | 768 skiatest::Reporter* reporter, |
769 const TestData& testData, | |
759 CanvasTestStep* testStep, | 770 CanvasTestStep* testStep, |
760 const SkCanvas& referenceCanvas) { | 771 const SkCanvas& referenceCanvas) { |
761 | 772 |
762 SkBitmap indirectStore1; | 773 SkBitmap indirectStore1; |
763 createBitmap(&indirectStore1, 0xFFFFFFFF); | 774 createBitmap(&indirectStore1, 0xFFFFFFFF); |
764 SkCanvas indirectCanvas1(indirectStore1); | 775 SkCanvas indirectCanvas1(indirectStore1); |
765 | 776 |
766 SkBitmap indirectStore2; | 777 SkBitmap indirectStore2; |
767 createBitmap(&indirectStore2, 0xFFFFFFFF); | 778 createBitmap(&indirectStore2, 0xFFFFFFFF); |
768 SkCanvas indirectCanvas2(indirectStore2); | 779 SkCanvas indirectCanvas2(indirectStore2); |
769 | 780 |
770 SkISize canvasSize = referenceCanvas.getDeviceSize(); | 781 SkISize canvasSize = referenceCanvas.getDeviceSize(); |
771 SkNWayCanvas nWayCanvas(canvasSize.width(), canvasSize.height()); | 782 SkNWayCanvas nWayCanvas(canvasSize.width(), canvasSize.height()); |
772 nWayCanvas.addCanvas(&indirectCanvas1); | 783 nWayCanvas.addCanvas(&indirectCanvas1); |
773 nWayCanvas.addCanvas(&indirectCanvas2); | 784 nWayCanvas.addCanvas(&indirectCanvas2); |
774 | 785 |
775 testStep->setAssertMessageFormat(kNWayDrawAssertMessageFormat); | 786 testStep->setAssertMessageFormat(kNWayDrawAssertMessageFormat); |
776 testStep->draw(&nWayCanvas, reporter); | 787 testStep->draw(&nWayCanvas, testData, reporter); |
777 // Verify that the SkProxyCanvas reports consitent state | 788 // Verify that the SkProxyCanvas reports consitent state |
778 testStep->setAssertMessageFormat(kNWayStateAssertMessageFormat); | 789 testStep->setAssertMessageFormat(kNWayStateAssertMessageFormat); |
779 AssertCanvasStatesEqual(reporter, &nWayCanvas, &referenceCanvas, | 790 AssertCanvasStatesEqual(reporter, testData, &nWayCanvas, &referenceCanvas, t estStep); |
780 testStep); | |
781 // Verify that the indirect canvases report consitent state | 791 // Verify that the indirect canvases report consitent state |
782 testStep->setAssertMessageFormat(kNWayIndirect1StateAssertMessageFormat); | 792 testStep->setAssertMessageFormat(kNWayIndirect1StateAssertMessageFormat); |
783 AssertCanvasStatesEqual(reporter, &indirectCanvas1, &referenceCanvas, | 793 AssertCanvasStatesEqual(reporter, testData, &indirectCanvas1, &referenceCanv as, testStep); |
784 testStep); | |
785 testStep->setAssertMessageFormat(kNWayIndirect2StateAssertMessageFormat); | 794 testStep->setAssertMessageFormat(kNWayIndirect2StateAssertMessageFormat); |
786 AssertCanvasStatesEqual(reporter, &indirectCanvas2, &referenceCanvas, | 795 AssertCanvasStatesEqual(reporter, testData, &indirectCanvas2, &referenceCanv as, testStep); |
787 testStep); | |
788 } | 796 } |
789 | 797 |
790 /* | 798 /* |
791 * This sub-test verifies that the test step passes when executed | 799 * This sub-test verifies that the test step passes when executed |
792 * with SkCanvas and with classes derrived from SkCanvas. It also verifies | 800 * with SkCanvas and with classes derrived from SkCanvas. It also verifies |
793 * that the all canvas derivatives report the same state as an SkCanvas | 801 * that the all canvas derivatives report the same state as an SkCanvas |
794 * after having executed the test step. | 802 * after having executed the test step. |
795 */ | 803 */ |
796 static void TestOverrideStateConsistency(skiatest::Reporter* reporter, | 804 static void TestOverrideStateConsistency(skiatest::Reporter* reporter, const Tes tData& testData, |
797 CanvasTestStep* testStep) { | 805 CanvasTestStep* testStep) { |
798 SkBitmap referenceStore; | 806 SkBitmap referenceStore; |
799 createBitmap(&referenceStore, 0xFFFFFFFF); | 807 createBitmap(&referenceStore, 0xFFFFFFFF); |
800 SkCanvas referenceCanvas(referenceStore); | 808 SkCanvas referenceCanvas(referenceStore); |
801 testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat); | 809 testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat); |
802 testStep->draw(&referenceCanvas, reporter); | 810 testStep->draw(&referenceCanvas, testData, reporter); |
803 | 811 |
804 SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testSte p, referenceCanvas, false); | 812 SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testDat a, testStep, referenceCanvas, false); |
805 | 813 |
806 SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testSte p, referenceCanvas, true); | 814 SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testDat a, testStep, referenceCanvas, true); |
807 | 815 |
808 // The following test code is disabled because SkProxyCanvas is | 816 // The following test code is disabled because SkProxyCanvas is |
809 // missing a lot of virtual overrides on get* methods, which are used | 817 // missing a lot of virtual overrides on get* methods, which are used |
810 // to verify canvas state. | 818 // to verify canvas state. |
811 // Issue: http://code.google.com/p/skia/issues/detail?id=500 | 819 // Issue: http://code.google.com/p/skia/issues/detail?id=500 |
812 | 820 |
813 if (false) { // avoid bit rot, suppress warning | 821 if (false) { // avoid bit rot, suppress warning |
814 TestProxyCanvasStateConsistency(reporter, testStep, referenceCanvas); | 822 TestProxyCanvasStateConsistency(reporter, testData, testStep, referenceC anvas); |
815 } | 823 } |
816 | 824 |
817 // The following test code is disabled because SkNWayCanvas does not | 825 // The following test code is disabled because SkNWayCanvas does not |
818 // report correct clipping and device bounds information | 826 // report correct clipping and device bounds information |
819 // Issue: http://code.google.com/p/skia/issues/detail?id=501 | 827 // Issue: http://code.google.com/p/skia/issues/detail?id=501 |
820 | 828 |
821 if (false) { // avoid bit rot, suppress warning | 829 if (false) { // avoid bit rot, suppress warning |
822 TestNWayCanvasStateConsistency(reporter, testStep, referenceCanvas); | 830 TestNWayCanvasStateConsistency(reporter, testData, testStep, referenceCa nvas); |
823 } | 831 } |
824 | 832 |
825 if (false) { // avoid bit rot, suppress warning | 833 if (false) { // avoid bit rot, suppress warning |
826 test_clipVisitor(reporter, &referenceCanvas); | 834 test_clipVisitor(reporter, &referenceCanvas); |
827 } | 835 } |
828 } | 836 } |
829 | 837 |
830 static void test_newraster(skiatest::Reporter* reporter) { | 838 static void test_newraster(skiatest::Reporter* reporter) { |
831 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); | 839 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
832 SkCanvas* canvas = SkCanvas::NewRaster(info); | 840 SkCanvas* canvas = SkCanvas::NewRaster(info); |
(...skipping 27 matching lines...) Expand all Loading... | |
860 // We should succeed with a zero-sized valid info | 868 // We should succeed with a zero-sized valid info |
861 info = SkImageInfo::MakeN32Premul(0, 0); | 869 info = SkImageInfo::MakeN32Premul(0, 0); |
862 canvas = SkCanvas::NewRaster(info); | 870 canvas = SkCanvas::NewRaster(info); |
863 REPORTER_ASSERT(reporter, canvas); | 871 REPORTER_ASSERT(reporter, canvas); |
864 SkDELETE(canvas); | 872 SkDELETE(canvas); |
865 } | 873 } |
866 | 874 |
867 DEF_TEST(Canvas, reporter) { | 875 DEF_TEST(Canvas, reporter) { |
868 // Init global here because bitmap pixels cannot be alocated during | 876 // Init global here because bitmap pixels cannot be alocated during |
869 // static initialization | 877 // static initialization |
870 kTestBitmap = testBitmap(); | 878 // kTestBitmap = testBitmap(); |
reed1
2014/10/02 19:53:06
can we remove this // line?
Rémi Piotaix
2014/10/02 20:02:26
Done.
| |
879 TestData testData; | |
871 | 880 |
872 for (int testStep = 0; testStep < testStepArray().count(); testStep++) { | 881 for (int testStep = 0; testStep < testStepArray().count(); testStep++) { |
873 TestOverrideStateConsistency(reporter, testStepArray()[testStep]); | 882 TestOverrideStateConsistency(reporter, testData, testStepArray()[testSte p]); |
874 if (testStepArray()[testStep]->enablePdfTesting()) { | 883 if (testStepArray()[testStep]->enablePdfTesting()) { |
875 TestPdfDevice(reporter, testStepArray()[testStep]); | 884 TestPdfDevice(reporter, testData, testStepArray()[testStep]); |
876 } | 885 } |
877 } | 886 } |
878 | 887 |
879 // Explicitly call reset(), so we don't leak the pixels (since kTestBitmap i s a global) | 888 // Explicitly call reset(), so we don't leak the pixels (since kTestBitmap i s a global) |
880 kTestBitmap.reset(); | 889 // kTestBitmap.reset(); |
reed1
2014/10/02 19:53:06
can we remove this reset()?
Rémi Piotaix
2014/10/02 20:02:26
Done.
| |
881 | 890 |
882 test_newraster(reporter); | 891 test_newraster(reporter); |
883 } | 892 } |
OLD | NEW |