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