blob: a1ca236ab6201ab01f32240b1854959b4a2d3341 [file] [log] [blame]
reed@google.com37f3ae02011-11-28 16:06:04 +00001
2/*
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +00003 * Copyright 2012 Google Inc.
reed@google.com37f3ae02011-11-28 16:06:04 +00004 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +00008
9/* Description:
10 * This test defines a series of elementatry test steps that perform
11 * a single or a small group of canvas API calls. Each test step is
12 * used in several test cases that verify that different types of SkCanvas
13 * flavors and derivatives pass it and yield consistent behavior. The
14 * test cases analyse results that are queryable through the API. They do
15 * not look at rendering results.
16 *
17 * Adding test stepss:
18 * The general pattern for creating a new test step is to write a test
19 * function of the form:
20 *
21 * static void MyTestStepFunction(SkCanvas* canvas,
22 * skiatest::Reporter* reporter,
23 * CanvasTestStep* testStep)
24 * {
25 * canvas->someCanvasAPImethod();
26 * (...)
27 * REPORTER_ASSERT_MESSAGE(reporter, (...), \
28 * testStep->assertMessage());
29 * }
30 *
31 * The definition of the test step function should be followed by an
32 * invocation of the TEST_STEP macro, which generates a class and
33 * instance for the test step:
34 *
35 * TEST_STEP(MyTestStep, MyTestStepFunction)
36 *
37 * There are also short hand macros for defining simple test steps
38 * in a single line of code. A simple test step is a one that is made
39 * of a single canvas API call.
40 *
41 * SIMPLE_TEST_STEP(MytestStep, someCanvasAPIMethod());
42 *
43 * There is another macro called SIMPLE_TEST_STEP_WITH_ASSERT that
44 * works the same way as SIMPLE_TEST_STEP, and additionally verifies
45 * that the invoked method returns a non-zero value.
46 */
reed@google.com37f3ae02011-11-28 16:06:04 +000047#include "SkBitmap.h"
48#include "SkCanvas.h"
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +000049#include "SkDeferredCanvas.h"
50#include "SkDevice.h"
51#include "SkMatrix.h"
52#include "SkNWayCanvas.h"
53#include "SkPaint.h"
54#include "SkPath.h"
55#include "SkPicture.h"
56#include "SkPictureRecord.h"
57#include "SkProxyCanvas.h"
58#include "SkRect.h"
59#include "SkRegion.h"
60#include "SkShader.h"
61#include "SkStream.h"
62#include "SkTDArray.h"
63#include "Test.h"
reed@google.com37f3ae02011-11-28 16:06:04 +000064
reed@google.com90c07ea2012-04-13 13:50:27 +000065class Canvas2CanvasClipVisitor : public SkCanvas::ClipVisitor {
66public:
67 Canvas2CanvasClipVisitor(SkCanvas* target) : fTarget(target) {}
68
69 virtual void clipRect(const SkRect& r, SkRegion::Op op, bool aa) {
70 fTarget->clipRect(r, op, aa);
71 }
72 virtual void clipPath(const SkPath& p, SkRegion::Op op, bool aa) {
73 fTarget->clipPath(p, op, aa);
74 }
75
76private:
77 SkCanvas* fTarget;
78};
79
80static void test_clipVisitor(skiatest::Reporter* reporter, SkCanvas* canvas) {
81 SkISize size = canvas->getDeviceSize();
82
83 SkBitmap bm;
84 bm.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height());
85 SkCanvas c(bm);
86
87 Canvas2CanvasClipVisitor visitor(&c);
88 canvas->replayClips(&visitor);
89
90 REPORTER_ASSERT(reporter, c.getTotalClip() == canvas->getTotalClip());
91}
92
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +000093static const int kWidth = 2;
94static const int kHeight = 2;
95// Maximum stream length for picture serialization
96static const size_t kMaxPictureBufferSize = 1024;
reed@google.com7c202932011-12-14 18:48:05 +000097
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +000098// Format strings that describe the test context. The %s token is where
99// the name of the test step is inserted. The context is required for
100// disambiguating the error in the case of failures that are reported in
101// functions that are called multiple times in different contexts (test
102// cases and test steps).
103static const char* const kDefaultAssertMessageFormat = "%s";
104static const char* const kCanvasDrawAssertMessageFormat =
105 "Drawing test step %s with SkCanvas";
106static const char* const kPictureDrawAssertMessageFormat =
107 "Drawing test step %s with SkPicture";
108static const char* const kPictureSecondDrawAssertMessageFormat =
109 "Duplicate draw of test step %s with SkPicture";
110static const char* const kPictureReDrawAssertMessageFormat =
111 "Playing back test step %s from an SkPicture to another SkPicture";
112static const char* const kDeferredDrawAssertMessageFormat =
113 "Drawing test step %s with SkDeferredCanvas";
114static const char* const kProxyDrawAssertMessageFormat =
115 "Drawing test step %s with SkProxyCanvas";
116static const char* const kNWayDrawAssertMessageFormat =
117 "Drawing test step %s with SkNWayCanvas";
118static const char* const kRoundTripAssertMessageFormat =
119 "test step %s, SkPicture consistency after round trip";
120static const char* const kPictureRecoringAssertMessageFormat =
121 "test step %s, SkPicture state consistency after recording";
122static const char* const kPicturePlaybackAssertMessageFormat =
123 "test step %s, SkPicture state consistency in playback canvas";
124static const char* const kDeferredPreFlushAssertMessageFormat =
125 "test step %s, SkDeferredCanvas state consistency before flush";
126static const char* const kDeferredPostFlushAssertMessageFormat =
127 "test step %s, SkDeferredCanvas state consistency after flush";
128static const char* const kPictureResourceReuseMessageFormat =
129 "test step %s, SkPicture duplicate flattened object test";
130static const char* const kProxyStateAssertMessageFormat =
131 "test step %s, SkProxyCanvas state consistency";
132static const char* const kProxyIndirectStateAssertMessageFormat =
133 "test step %s, SkProxyCanvas indirect canvas state consistency";
134static const char* const kNWayStateAssertMessageFormat =
135 "test step %s, SkNWayCanvas state consistency";
136static const char* const kNWayIndirect1StateAssertMessageFormat =
137 "test step %s, SkNWayCanvas indirect canvas 1 state consistency";
138static const char* const kNWayIndirect2StateAssertMessageFormat =
139 "test step %s, SkNWayCanvas indirect canvas 2 state consistency";
140
141static void createBitmap(SkBitmap* bm, SkBitmap::Config config, SkColor color) {
142 bm->setConfig(config, kWidth, kHeight);
143 bm->allocPixels();
144 bm->eraseColor(color);
145}
146
147class CanvasTestStep;
148static SkTDArray<CanvasTestStep*>& testStepArray() {
149 static SkTDArray<CanvasTestStep*> theTests;
150 return theTests;
151}
152
153class CanvasTestStep {
154public:
155 CanvasTestStep() {
156 *testStepArray().append() = this;
157 fAssertMessageFormat = kDefaultAssertMessageFormat;
158 }
djsollen@google.come63793a2012-03-21 15:39:03 +0000159 virtual ~CanvasTestStep() { }
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000160
161 virtual void draw(SkCanvas*, skiatest::Reporter*) = 0;
162 virtual const char* name() const = 0;
163
164 const char* assertMessage() {
165 fAssertMessage.printf(fAssertMessageFormat, name());
166 return fAssertMessage.c_str();
167 }
168
169 void setAssertMessageFormat(const char* format) {
170 fAssertMessageFormat = format;
171 }
172
173private:
174 SkString fAssertMessage;
175 const char* fAssertMessageFormat;
176};
177
178///////////////////////////////////////////////////////////////////////////////
179// Constants used by test steps
180
181const SkRect kTestRect =
182 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
183 SkIntToScalar(2), SkIntToScalar(1));
184static SkMatrix testMatrix() {
185 SkMatrix matrix;
186 matrix.reset();
187 matrix.setScale(SkIntToScalar(2), SkIntToScalar(3));
188 return matrix;
189}
190const SkMatrix kTestMatrix = testMatrix();
191static SkPath testPath() {
192 SkPath path;
193 path.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
194 SkIntToScalar(2), SkIntToScalar(1)));
195 return path;
196}
197const SkPath kTestPath = testPath();
198static SkRegion testRegion() {
199 SkRegion region;
200 SkIRect rect = SkIRect::MakeXYWH(0, 0, 2, 1);
201 region.setRect(rect);
202 return region;
203}
204const SkIRect kTestIRect = SkIRect::MakeXYWH(0, 0, 2, 1);
205const SkRegion kTestRegion = testRegion();
206const SkColor kTestColor = 0x01020304;
207const SkPaint kTestPaint;
208const SkPoint kTestPoints[3] = {
209 {SkIntToScalar(0), SkIntToScalar(0)},
210 {SkIntToScalar(2), SkIntToScalar(1)},
211 {SkIntToScalar(0), SkIntToScalar(2)}
212};
213const size_t kTestPointCount = 3;
214static SkBitmap testBitmap() {
215 SkBitmap bitmap;
216 createBitmap(&bitmap, SkBitmap::kARGB_8888_Config, 0x05060708);
217 return bitmap;
218}
219SkBitmap kTestBitmap; // cannot be created during static init
220SkString kTestText("Hello World");
robertphillips@google.com977b9c82012-06-05 19:35:09 +0000221SkPoint kTestPoints2[] = {
222 { SkIntToScalar(0), SkIntToScalar(1) },
223 { SkIntToScalar(1), SkIntToScalar(1) },
224 { SkIntToScalar(2), SkIntToScalar(1) },
225 { SkIntToScalar(3), SkIntToScalar(1) },
226 { SkIntToScalar(4), SkIntToScalar(1) },
227 { SkIntToScalar(5), SkIntToScalar(1) },
228 { SkIntToScalar(6), SkIntToScalar(1) },
229 { SkIntToScalar(7), SkIntToScalar(1) },
230 { SkIntToScalar(8), SkIntToScalar(1) },
231 { SkIntToScalar(9), SkIntToScalar(1) },
232 { SkIntToScalar(10), SkIntToScalar(1) },
233};
234
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000235
236///////////////////////////////////////////////////////////////////////////////
237// Macros for defining test steps
238
239#define TEST_STEP(NAME, FUNCTION) \
240class NAME##_TestStep : public CanvasTestStep{ \
241public: \
242 virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \
243 FUNCTION (canvas, reporter, this); \
244 } \
245 virtual const char* name() const {return #NAME ;} \
246}; \
247static NAME##_TestStep NAME##_TestStepInstance;
248
249#define SIMPLE_TEST_STEP(NAME, CALL) \
250static void NAME##TestStep(SkCanvas* canvas, skiatest::Reporter*, \
251 CanvasTestStep*) { \
252 canvas-> CALL ; \
253} \
254TEST_STEP(NAME, NAME##TestStep )
255
256#define SIMPLE_TEST_STEP_WITH_ASSERT(NAME, CALL) \
257static void NAME##TestStep(SkCanvas* canvas, skiatest::Reporter* reporter, \
258 CanvasTestStep* testStep) { \
259 REPORTER_ASSERT_MESSAGE(reporter, canvas-> CALL , \
260 testStep->assertMessage()); \
261} \
262TEST_STEP(NAME, NAME##TestStep )
263
264
265///////////////////////////////////////////////////////////////////////////////
266// Basic test steps for most virtual methods in SkCanvas that draw or affect
267// the state of the canvas.
268
junov@chromium.orga907ac32012-02-24 21:54:07 +0000269SIMPLE_TEST_STEP(SaveMatrix, save(SkCanvas::kMatrix_SaveFlag));
270SIMPLE_TEST_STEP(SaveClip, save(SkCanvas::kClip_SaveFlag));
271SIMPLE_TEST_STEP(SaveMatrixClip, save(SkCanvas::kMatrixClip_SaveFlag));
272SIMPLE_TEST_STEP(SaveLayer, saveLayer(NULL, NULL));
273SIMPLE_TEST_STEP(BoundedSaveLayer, saveLayer(&kTestRect, NULL));
274SIMPLE_TEST_STEP(PaintSaveLayer, saveLayer(NULL, &kTestPaint));
275SIMPLE_TEST_STEP_WITH_ASSERT(Translate,
276 translate(SkIntToScalar(1), SkIntToScalar(2)));
277SIMPLE_TEST_STEP_WITH_ASSERT(Scale,
278 scale(SkIntToScalar(1), SkIntToScalar(2)));
279SIMPLE_TEST_STEP_WITH_ASSERT(Rotate, rotate(SkIntToScalar(1)));
280SIMPLE_TEST_STEP_WITH_ASSERT(Skew,
281 skew(SkIntToScalar(1), SkIntToScalar(2)));
282SIMPLE_TEST_STEP_WITH_ASSERT(Concat, concat(kTestMatrix));
283SIMPLE_TEST_STEP(SetMatrix, setMatrix(kTestMatrix));
284SIMPLE_TEST_STEP_WITH_ASSERT(ClipRect, clipRect(kTestRect));
285SIMPLE_TEST_STEP_WITH_ASSERT(ClipPath, clipPath(kTestPath));
286SIMPLE_TEST_STEP_WITH_ASSERT(ClipRegion,
287 clipRegion(kTestRegion, SkRegion::kReplace_Op));
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000288SIMPLE_TEST_STEP(Clear, clear(kTestColor));
289SIMPLE_TEST_STEP(DrawPaint, drawPaint(kTestPaint));
290SIMPLE_TEST_STEP(DrawPointsPoints, drawPoints(SkCanvas::kPoints_PointMode,
291 kTestPointCount, kTestPoints, kTestPaint));
292SIMPLE_TEST_STEP(DrawPointsLiness, drawPoints(SkCanvas::kLines_PointMode,
293 kTestPointCount, kTestPoints, kTestPaint));
294SIMPLE_TEST_STEP(DrawPointsPolygon, drawPoints(SkCanvas::kPolygon_PointMode,
295 kTestPointCount, kTestPoints, kTestPaint));
296SIMPLE_TEST_STEP(DrawRect, drawRect(kTestRect, kTestPaint));
297SIMPLE_TEST_STEP(DrawPath, drawPath(kTestPath, kTestPaint));
junov@chromium.org87f982c2012-02-23 21:34:34 +0000298SIMPLE_TEST_STEP(DrawBitmap, drawBitmap(kTestBitmap, 0, 0));
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000299SIMPLE_TEST_STEP(DrawBitmapPaint, drawBitmap(kTestBitmap, 0, 0, &kTestPaint));
300SIMPLE_TEST_STEP(DrawBitmapRect, drawBitmapRect(kTestBitmap, NULL, kTestRect,
301 NULL));
302SIMPLE_TEST_STEP(DrawBitmapRectSrcRect, drawBitmapRect(kTestBitmap,
303 &kTestIRect, kTestRect, NULL));
304SIMPLE_TEST_STEP(DrawBitmapRectPaint, drawBitmapRect(kTestBitmap, NULL,
305 kTestRect, &kTestPaint));
306SIMPLE_TEST_STEP(DrawBitmapMatrix, drawBitmapMatrix(kTestBitmap, kTestMatrix,
307 NULL));
308SIMPLE_TEST_STEP(DrawBitmapMatrixPaint, drawBitmapMatrix(kTestBitmap,
309 kTestMatrix, &kTestPaint));
310SIMPLE_TEST_STEP(DrawBitmapNine, drawBitmapNine(kTestBitmap, kTestIRect,
311 kTestRect, NULL));
312SIMPLE_TEST_STEP(DrawBitmapNinePaint, drawBitmapNine(kTestBitmap, kTestIRect,
313 kTestRect, &kTestPaint));
junov@chromium.org87f982c2012-02-23 21:34:34 +0000314SIMPLE_TEST_STEP(DrawSprite, drawSprite(kTestBitmap, 0, 0, NULL));
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000315SIMPLE_TEST_STEP(DrawSpritePaint, drawSprite(kTestBitmap, 0, 0, &kTestPaint));
316SIMPLE_TEST_STEP(DrawText, drawText(kTestText.c_str(), kTestText.size(),
317 0, 1, kTestPaint));
318SIMPLE_TEST_STEP(DrawPosText, drawPosText(kTestText.c_str(),
robertphillips@google.com977b9c82012-06-05 19:35:09 +0000319 kTestText.size(), kTestPoints2, kTestPaint));
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000320SIMPLE_TEST_STEP(DrawTextOnPath, drawTextOnPath(kTestText.c_str(),
321 kTestText.size(), kTestPath, NULL, kTestPaint));
322SIMPLE_TEST_STEP(DrawTextOnPathMatrix, drawTextOnPath(kTestText.c_str(),
323 kTestText.size(), kTestPath, &kTestMatrix, kTestPaint));
324SIMPLE_TEST_STEP(SetExternalMatrix, setExternalMatrix(&kTestMatrix));
325SIMPLE_TEST_STEP(DrawData, drawData(kTestText.c_str(), kTestText.size()));
326
327///////////////////////////////////////////////////////////////////////////////
328// Complex test steps
329
junov@chromium.orga6c9e0e2012-07-12 17:47:34 +0000330static void TwoClipOpsStep(SkCanvas* canvas,
331 skiatest::Reporter* reporter,
332 CanvasTestStep* testStep) {
333 // This test exercises a functionality in SkPicture that leads to the
334 // recording of restore offset placeholders. This test will trigger an
335 // assertion at playback time if the placeholders are not properly
336 // filled when the recording ends.
337 canvas->clipRect(kTestRect);
338 canvas->clipRegion(kTestRegion);
339}
340TEST_STEP(TwoClipOps, TwoClipOpsStep);
341
epoger@google.com94fa43c2012-04-11 17:51:01 +0000342// exercise fix for http://code.google.com/p/skia/issues/detail?id=560
343// ('SkPathStroker::lineTo() fails for line with length SK_ScalarNearlyZero')
344static void DrawNearlyZeroLengthPathTestStep(SkCanvas* canvas,
345 skiatest::Reporter* reporter,
346 CanvasTestStep* testStep) {
347 SkPaint paint;
348 paint.setStrokeWidth(SkIntToScalar(1));
349 paint.setStyle(SkPaint::kStroke_Style);
350
351 SkPath path;
352 SkPoint pt1 = { 0, 0 };
353 SkPoint pt2 = { 0, SK_ScalarNearlyZero };
354 SkPoint pt3 = { SkIntToScalar(1), 0 };
355 SkPoint pt4 = { SkIntToScalar(1), SK_ScalarNearlyZero/2 };
356 path.moveTo(pt1);
357 path.lineTo(pt2);
358 path.lineTo(pt3);
359 path.lineTo(pt4);
360
361 canvas->drawPath(path, paint);
362}
363TEST_STEP(DrawNearlyZeroLengthPath, DrawNearlyZeroLengthPathTestStep);
364
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000365static void DrawVerticesShaderTestStep(SkCanvas* canvas,
366 skiatest::Reporter* reporter,
367 CanvasTestStep* testStep) {
368 SkPoint pts[4];
369 pts[0].set(0, 0);
370 pts[1].set(SkIntToScalar(kWidth), 0);
371 pts[2].set(SkIntToScalar(kWidth), SkIntToScalar(kHeight));
372 pts[3].set(0, SkIntToScalar(kHeight));
373 SkPaint paint;
374 SkShader* shader = SkShader::CreateBitmapShader(kTestBitmap,
375 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
376 paint.setShader(shader)->unref();
377 canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts,
378 NULL, NULL, NULL, 0, paint);
379}
380TEST_STEP(DrawVerticesShader, DrawVerticesShaderTestStep);
381
382static void DrawPictureTestStep(SkCanvas* canvas,
383 skiatest::Reporter* reporter,
384 CanvasTestStep* testStep) {
385 SkPicture* testPicture = SkNEW_ARGS(SkPicture, ());
386 SkAutoUnref aup(testPicture);
387 SkCanvas* testCanvas = testPicture->beginRecording(kWidth, kHeight);
388 testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1));
389 testCanvas->clipRect(kTestRect);
390 testCanvas->drawRect(kTestRect, kTestPaint);
391 canvas->drawPicture(*testPicture);
392}
393TEST_STEP(DrawPicture, DrawPictureTestStep);
394
395static void SaveRestoreTestStep(SkCanvas* canvas,
396 skiatest::Reporter* reporter,
397 CanvasTestStep* testStep) {
398 REPORTER_ASSERT_MESSAGE(reporter, 1 == canvas->getSaveCount(),
399 testStep->assertMessage());
400 size_t n = canvas->save();
401 REPORTER_ASSERT_MESSAGE(reporter, 1 == n, testStep->assertMessage());
402 REPORTER_ASSERT_MESSAGE(reporter, 2 == canvas->getSaveCount(),
403 testStep->assertMessage());
404 canvas->save();
405 canvas->save();
406 REPORTER_ASSERT_MESSAGE(reporter, 4 == canvas->getSaveCount(),
407 testStep->assertMessage());
408 canvas->restoreToCount(2);
409 REPORTER_ASSERT_MESSAGE(reporter, 2 == canvas->getSaveCount(),
410 testStep->assertMessage());
411
412 // should this pin to 1, or be a no-op, or crash?
413 canvas->restoreToCount(0);
414 REPORTER_ASSERT_MESSAGE(reporter, 1 == canvas->getSaveCount(),
415 testStep->assertMessage());
416}
417TEST_STEP(SaveRestore, SaveRestoreTestStep);
418
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000419static void DrawLayerTestStep(SkCanvas* canvas,
420 skiatest::Reporter* reporter,
421 CanvasTestStep* testStep) {
422 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(),
423 testStep->assertMessage());
424 canvas->save();
425 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(),
426 testStep->assertMessage());
reed@google.com7c202932011-12-14 18:48:05 +0000427
428 const SkRect* bounds = NULL; // null means include entire bounds
429 const SkPaint* paint = NULL;
430
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000431 canvas->saveLayer(bounds, paint);
432 REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(),
433 testStep->assertMessage());
434 canvas->restore();
435 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(),
436 testStep->assertMessage());
reed@google.com7c202932011-12-14 18:48:05 +0000437
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000438 canvas->saveLayer(bounds, paint);
439 canvas->saveLayer(bounds, paint);
440 REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(),
441 testStep->assertMessage());
442 canvas->restore();
443 REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(),
444 testStep->assertMessage());
445 canvas->restore();
reed@google.com7c202932011-12-14 18:48:05 +0000446 // now layer count should be 0
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000447 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(),
448 testStep->assertMessage());
449}
450TEST_STEP(DrawLayer, DrawLayerTestStep);
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000451
452static void AssertCanvasStatesEqual(skiatest::Reporter* reporter,
453 const SkCanvas* canvas1,
454 const SkCanvas* canvas2,
455 CanvasTestStep* testStep) {
456 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() ==
457 canvas2->getDeviceSize(), testStep->assertMessage());
458 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() ==
459 canvas2->getSaveCount(), testStep->assertMessage());
460 REPORTER_ASSERT_MESSAGE(reporter, canvas1->isDrawingToLayer() ==
461 canvas2->isDrawingToLayer(), testStep->assertMessage());
462 SkRect bounds1, bounds2;
463 REPORTER_ASSERT_MESSAGE(reporter,
464 canvas1->getClipBounds(&bounds1, SkCanvas::kAA_EdgeType) ==
465 canvas2->getClipBounds(&bounds2, SkCanvas::kAA_EdgeType),
466 testStep->assertMessage());
467 REPORTER_ASSERT_MESSAGE(reporter, bounds1 == bounds2,
468 testStep->assertMessage());
469 REPORTER_ASSERT_MESSAGE(reporter,
470 canvas1->getClipBounds(&bounds1, SkCanvas::kBW_EdgeType) ==
471 canvas2->getClipBounds(&bounds2, SkCanvas::kBW_EdgeType),
472 testStep->assertMessage());
473 REPORTER_ASSERT_MESSAGE(reporter, bounds1 == bounds2,
474 testStep->assertMessage());
475 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDrawFilter() ==
476 canvas2->getDrawFilter(), testStep->assertMessage());
477 SkIRect deviceBounds1, deviceBounds2;
478 REPORTER_ASSERT_MESSAGE(reporter,
479 canvas1->getClipDeviceBounds(&deviceBounds1) ==
480 canvas2->getClipDeviceBounds(&deviceBounds2),
481 testStep->assertMessage());
482 REPORTER_ASSERT_MESSAGE(reporter, deviceBounds1 == deviceBounds2,
483 testStep->assertMessage());
484 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getBounder() ==
485 canvas2->getBounder(), testStep->assertMessage());
486 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalMatrix() ==
487 canvas2->getTotalMatrix(), testStep->assertMessage());
488 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getClipType() ==
489 canvas2->getClipType(), testStep->assertMessage());
490 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalClip() ==
491 canvas2->getTotalClip(), testStep->assertMessage());
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000492
493 // The following test code is commented out because the test fails when
494 // the canvas is an SkPictureRecord or SkDeferredCanvas
495 // Issue: http://code.google.com/p/skia/issues/detail?id=498
496 // Also, creating a LayerIter on an SkProxyCanvas crashes
497 // Issue: http://code.google.com/p/skia/issues/detail?id=499
498 /*
499 SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false);
500 SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false);
501 while (!layerIter1.done() && !layerIter2.done()) {
502 REPORTER_ASSERT_MESSAGE(reporter, layerIter1.matrix() ==
503 layerIter2.matrix(), testStep->assertMessage());
504 REPORTER_ASSERT_MESSAGE(reporter, layerIter1.clip() ==
505 layerIter2.clip(), testStep->assertMessage());
506 REPORTER_ASSERT_MESSAGE(reporter, layerIter1.paint() ==
507 layerIter2.paint(), testStep->assertMessage());
508 REPORTER_ASSERT_MESSAGE(reporter, layerIter1.x() ==
509 layerIter2.x(), testStep->assertMessage());
510 REPORTER_ASSERT_MESSAGE(reporter, layerIter1.y() ==
511 layerIter2.y(), testStep->assertMessage());
512 layerIter1.next();
513 layerIter2.next();
514 }
515 REPORTER_ASSERT_MESSAGE(reporter, layerIter1.done(),
516 testStep->assertMessage());
517 REPORTER_ASSERT_MESSAGE(reporter, layerIter2.done(),
518 testStep->assertMessage());
519 */
520}
521
522// The following class groups static functions that need to access
523// the privates members of SkPictureRecord
524class SkPictureTester {
525private:
reed@google.come2589ae2012-07-10 19:38:01 +0000526 static int EQ(const SkFlatData* a, const SkFlatData* b) {
527 return *a == *b;
528 }
529
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000530 static void AssertFlattenedObjectsEqual(
531 SkPictureRecord* referenceRecord,
532 SkPictureRecord* testRecord,
533 skiatest::Reporter* reporter,
534 CanvasTestStep* testStep) {
535
536 REPORTER_ASSERT_MESSAGE(reporter,
537 referenceRecord->fBitmaps.count() ==
538 testRecord->fBitmaps.count(), testStep->assertMessage());
539 for (int i = 0; i < referenceRecord->fBitmaps.count(); ++i) {
540 REPORTER_ASSERT_MESSAGE(reporter,
reed@google.come2589ae2012-07-10 19:38:01 +0000541 EQ(referenceRecord->fBitmaps[i], testRecord->fBitmaps[i]),
542 testStep->assertMessage());
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000543 }
544 REPORTER_ASSERT_MESSAGE(reporter,
545 referenceRecord->fMatrices.count() ==
546 testRecord->fMatrices.count(), testStep->assertMessage());
547 for (int i = 0; i < referenceRecord->fMatrices.count(); ++i) {
548 REPORTER_ASSERT_MESSAGE(reporter,
reed@google.come2589ae2012-07-10 19:38:01 +0000549 EQ(referenceRecord->fMatrices[i], testRecord->fMatrices[i]),
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000550 testStep->assertMessage());
551 }
552 REPORTER_ASSERT_MESSAGE(reporter,
553 referenceRecord->fPaints.count() ==
554 testRecord->fPaints.count(), testStep->assertMessage());
555 for (int i = 0; i < referenceRecord->fPaints.count(); ++i) {
556 REPORTER_ASSERT_MESSAGE(reporter,
reed@google.come2589ae2012-07-10 19:38:01 +0000557 EQ(referenceRecord->fPaints[i], testRecord->fPaints[i]),
558 testStep->assertMessage());
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000559 }
560 REPORTER_ASSERT_MESSAGE(reporter,
561 referenceRecord->fRegions.count() ==
562 testRecord->fRegions.count(), testStep->assertMessage());
563 for (int i = 0; i < referenceRecord->fRegions.count(); ++i) {
564 REPORTER_ASSERT_MESSAGE(reporter,
reed@google.come2589ae2012-07-10 19:38:01 +0000565 EQ(referenceRecord->fRegions[i], testRecord->fRegions[i]),
566 testStep->assertMessage());
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000567 }
568 REPORTER_ASSERT_MESSAGE(reporter,
569 !referenceRecord->fPathHeap ==
570 !testRecord->fPathHeap,
571 testStep->assertMessage());
junov@chromium.orgdadcfdc2012-02-23 14:59:22 +0000572 // The following tests are commented out because they currently
573 // fail. Issue: http://code.google.com/p/skia/issues/detail?id=507
574 /*
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000575 if (referenceRecord->fPathHeap) {
576 REPORTER_ASSERT_MESSAGE(reporter,
577 referenceRecord->fPathHeap->count() ==
578 testRecord->fPathHeap->count(),
579 testStep->assertMessage());
580 for (int i = 0; i < referenceRecord->fPathHeap->count(); ++i) {
581 REPORTER_ASSERT_MESSAGE(reporter,
582 (*referenceRecord->fPathHeap)[i] ==
583 (*testRecord->fPathHeap)[i], testStep->assertMessage());
584 }
585 }
junov@chromium.orgdadcfdc2012-02-23 14:59:22 +0000586 */
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000587
588 }
589
590public:
591
592 static void TestPictureSerializationRoundTrip(skiatest::Reporter* reporter,
junov@chromium.org4866cc02012-06-01 21:23:07 +0000593 CanvasTestStep* testStep,
594 uint32_t recordFlags) {
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000595 testStep->setAssertMessageFormat(kPictureDrawAssertMessageFormat);
596 SkPicture referencePicture;
junov@chromium.org4866cc02012-06-01 21:23:07 +0000597 testStep->draw(referencePicture.beginRecording(kWidth, kHeight,
598 recordFlags), reporter);
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000599 SkPicture initialPicture;
junov@chromium.org4866cc02012-06-01 21:23:07 +0000600 testStep->draw(initialPicture.beginRecording(kWidth, kHeight,
601 recordFlags), reporter);
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000602 testStep->setAssertMessageFormat(kPictureReDrawAssertMessageFormat);
603 SkPicture roundTripPicture;
junov@chromium.org4866cc02012-06-01 21:23:07 +0000604 initialPicture.draw(roundTripPicture.beginRecording(kWidth, kHeight,
605 recordFlags));
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000606
607 SkPictureRecord* referenceRecord = static_cast<SkPictureRecord*>(
608 referencePicture.getRecordingCanvas());
609 SkPictureRecord* roundTripRecord = static_cast<SkPictureRecord*>(
610 roundTripPicture.getRecordingCanvas());
611
612 testStep->setAssertMessageFormat(kPictureReDrawAssertMessageFormat);
613
614 // Verify that deserialization-serialization round trip conserves all
615 // data by comparing referenceRecord to roundTripRecord
djsollen@google.comd2700ee2012-05-30 16:54:13 +0000616 REPORTER_ASSERT_MESSAGE(reporter, referenceRecord->fBitmaps.count() ==
617 roundTripRecord->fBitmaps.count(), testStep->assertMessage());
618 REPORTER_ASSERT_MESSAGE(reporter, referenceRecord->fMatrices.count() ==
619 roundTripRecord->fMatrices.count(), testStep->assertMessage());
620 REPORTER_ASSERT_MESSAGE(reporter, referenceRecord->fPaints.count() ==
621 roundTripRecord->fPaints.count(), testStep->assertMessage());
622 REPORTER_ASSERT_MESSAGE(reporter, referenceRecord->fRegions.count() ==
623 roundTripRecord->fRegions.count(), testStep->assertMessage());
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000624 char referenceBuffer[kMaxPictureBufferSize];
625 SkMemoryWStream referenceStream(referenceBuffer,
626 kMaxPictureBufferSize);
627 referenceRecord->fWriter.writeToStream(&referenceStream);
628 char roundTripBuffer[kMaxPictureBufferSize];
629 SkMemoryWStream roundTripStream(roundTripBuffer,
630 kMaxPictureBufferSize);
631 roundTripRecord->fWriter.writeToStream(&roundTripStream);
632 REPORTER_ASSERT_MESSAGE(reporter,
633 roundTripStream.bytesWritten() == referenceStream.bytesWritten(),
634 testStep->assertMessage());
635 REPORTER_ASSERT_MESSAGE(reporter, 0 == memcmp(referenceBuffer,
636 roundTripBuffer, roundTripStream.bytesWritten()),
637 testStep->assertMessage());
638 REPORTER_ASSERT_MESSAGE(reporter, referenceRecord->fRecordFlags ==
639 roundTripRecord->fRecordFlags, testStep->assertMessage());
640 REPORTER_ASSERT_MESSAGE(reporter,
641 referenceRecord->fRestoreOffsetStack ==
642 roundTripRecord->fRestoreOffsetStack,
643 testStep->assertMessage());
644 AssertFlattenedObjectsEqual(referenceRecord, roundTripRecord,
645 reporter, testStep);
646 AssertCanvasStatesEqual(reporter, referenceRecord, roundTripRecord,
647 testStep);
648 }
649
650 static void TestPictureFlattenedObjectReuse(skiatest::Reporter* reporter,
junov@chromium.org4866cc02012-06-01 21:23:07 +0000651 CanvasTestStep* testStep,
652 uint32_t recordFlags) {
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000653 // Verify that when a test step is executed twice, no extra resources
654 // are flattened during the second execution
655 testStep->setAssertMessageFormat(kPictureDrawAssertMessageFormat);
656 SkPicture referencePicture;
657 SkCanvas* referenceCanvas = referencePicture.beginRecording(kWidth,
junov@chromium.org4866cc02012-06-01 21:23:07 +0000658 kHeight, recordFlags);
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000659 testStep->draw(referenceCanvas, reporter);
660 SkPicture testPicture;
junov@chromium.orgdadcfdc2012-02-23 14:59:22 +0000661 SkCanvas* testCanvas = testPicture.beginRecording(kWidth,
junov@chromium.org4866cc02012-06-01 21:23:07 +0000662 kHeight, recordFlags);
junov@chromium.orgdadcfdc2012-02-23 14:59:22 +0000663 testStep->draw(testCanvas, reporter);
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000664 testStep->setAssertMessageFormat(kPictureSecondDrawAssertMessageFormat);
junov@chromium.orgdadcfdc2012-02-23 14:59:22 +0000665 testStep->draw(testCanvas, reporter);
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000666
667 SkPictureRecord* referenceRecord = static_cast<SkPictureRecord*>(
668 referenceCanvas);
669 SkPictureRecord* testRecord = static_cast<SkPictureRecord*>(
670 testCanvas);
671 testStep->setAssertMessageFormat(kPictureResourceReuseMessageFormat);
672 AssertFlattenedObjectsEqual(referenceRecord, testRecord,
junov@chromium.org76b9c4b2012-02-22 21:24:41 +0000673 reporter, testStep);
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000674 }
675};
676
677static void TestPictureStateConsistency(skiatest::Reporter* reporter,
678 CanvasTestStep* testStep,
junov@chromium.org4866cc02012-06-01 21:23:07 +0000679 const SkCanvas& referenceCanvas,
680 uint32_t recordFlags) {
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000681 // Verify that the recording canvas's state is consistent
682 // with that of a regular canvas
683 SkPicture testPicture;
junov@chromium.org4866cc02012-06-01 21:23:07 +0000684 SkCanvas* pictureCanvas = testPicture.beginRecording(kWidth, kHeight,
685 recordFlags);
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000686 testStep->setAssertMessageFormat(kPictureDrawAssertMessageFormat);
687 testStep->draw(pictureCanvas, reporter);
688 testStep->setAssertMessageFormat(kPictureRecoringAssertMessageFormat);
689 AssertCanvasStatesEqual(reporter, pictureCanvas, &referenceCanvas,
690 testStep);
691
692 SkBitmap playbackStore;
693 createBitmap(&playbackStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
694 SkDevice playbackDevice(playbackStore);
695 SkCanvas playbackCanvas(&playbackDevice);
696 testPicture.draw(&playbackCanvas);
697 testStep->setAssertMessageFormat(kPicturePlaybackAssertMessageFormat);
698 AssertCanvasStatesEqual(reporter, &playbackCanvas, &referenceCanvas,
699 testStep);
700
701 // The following test code is commented out because SkPicture is not
702 // currently expected to preserve state when restarting recording.
703 /*
junov@chromium.org4866cc02012-06-01 21:23:07 +0000704 SkCanvas* pictureCanvas = testPicture.beginRecording(kWidth, kHeight,
705 recordFlags);
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000706 testStep->setAssertMessageFormat(kPictureResumeAssertMessageFormat);
707 AssertCanvasStatesEqual(reporter, pictureCanvas, &referenceCanvas,
708 testStep);
709 */
710}
711
712static void TestDeferredCanvasStateConsistency(
713 skiatest::Reporter* reporter,
714 CanvasTestStep* testStep,
715 const SkCanvas& referenceCanvas) {
716
717 SkBitmap deferredStore;
718 createBitmap(&deferredStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
719 SkDevice deferredDevice(deferredStore);
720 SkDeferredCanvas deferredCanvas(&deferredDevice);
721 testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat);
722 testStep->draw(&deferredCanvas, reporter);
723 testStep->setAssertMessageFormat(kDeferredPreFlushAssertMessageFormat);
724 AssertCanvasStatesEqual(reporter, &deferredCanvas, &referenceCanvas,
725 testStep);
726
727 // Verified that deferred canvas state is not affected by flushing
728 // pending draw operations
729
730 // The following test code is commented out because it currently fails.
731 // Issue: http://code.google.com/p/skia/issues/detail?id=496
732 /*
733 deferredCanvas.flush();
734 testStep->setAssertMessageFormat(kDeferredPostFlushAssertMessageFormat);
735 AssertCanvasStatesEqual(reporter, &deferredCanvas, &referenceCanvas,
736 testStep);
737 */
738}
739
caryclark@google.com42639cd2012-06-06 12:03:39 +0000740// unused
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000741static void TestProxyCanvasStateConsistency(
742 skiatest::Reporter* reporter,
743 CanvasTestStep* testStep,
744 const SkCanvas& referenceCanvas) {
745
746 SkBitmap indirectStore;
747 createBitmap(&indirectStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
748 SkDevice indirectDevice(indirectStore);
749 SkCanvas indirectCanvas(&indirectDevice);
750 SkProxyCanvas proxyCanvas(&indirectCanvas);
751 testStep->setAssertMessageFormat(kProxyDrawAssertMessageFormat);
752 testStep->draw(&proxyCanvas, reporter);
753 // Verify that the SkProxyCanvas reports consitent state
754 testStep->setAssertMessageFormat(kProxyStateAssertMessageFormat);
755 AssertCanvasStatesEqual(reporter, &proxyCanvas, &referenceCanvas,
756 testStep);
757 // Verify that the indirect canvas reports consitent state
758 testStep->setAssertMessageFormat(kProxyIndirectStateAssertMessageFormat);
759 AssertCanvasStatesEqual(reporter, &indirectCanvas, &referenceCanvas,
760 testStep);
761}
762
caryclark@google.com42639cd2012-06-06 12:03:39 +0000763// unused
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000764static void TestNWayCanvasStateConsistency(
765 skiatest::Reporter* reporter,
766 CanvasTestStep* testStep,
767 const SkCanvas& referenceCanvas) {
768
769 SkBitmap indirectStore1;
770 createBitmap(&indirectStore1, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
771 SkDevice indirectDevice1(indirectStore1);
772 SkCanvas indirectCanvas1(&indirectDevice1);
773
774 SkBitmap indirectStore2;
775 createBitmap(&indirectStore2, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
776 SkDevice indirectDevice2(indirectStore2);
777 SkCanvas indirectCanvas2(&indirectDevice2);
778
djsollen@google.comf0a062b2012-05-01 16:50:25 +0000779 SkISize canvasSize = referenceCanvas.getDeviceSize();
780 SkNWayCanvas nWayCanvas(canvasSize.width(), canvasSize.height());
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000781 nWayCanvas.addCanvas(&indirectCanvas1);
782 nWayCanvas.addCanvas(&indirectCanvas2);
783
784 testStep->setAssertMessageFormat(kNWayDrawAssertMessageFormat);
785 testStep->draw(&nWayCanvas, reporter);
786 // Verify that the SkProxyCanvas reports consitent state
787 testStep->setAssertMessageFormat(kNWayStateAssertMessageFormat);
788 AssertCanvasStatesEqual(reporter, &nWayCanvas, &referenceCanvas,
789 testStep);
790 // Verify that the indirect canvases report consitent state
791 testStep->setAssertMessageFormat(kNWayIndirect1StateAssertMessageFormat);
792 AssertCanvasStatesEqual(reporter, &indirectCanvas1, &referenceCanvas,
793 testStep);
794 testStep->setAssertMessageFormat(kNWayIndirect2StateAssertMessageFormat);
795 AssertCanvasStatesEqual(reporter, &indirectCanvas2, &referenceCanvas,
796 testStep);
797}
798
799/*
800 * This sub-test verifies that the test step passes when executed
801 * with SkCanvas and with classes derrived from SkCanvas. It also verifies
802 * that the all canvas derivatives report the same state as an SkCanvas
803 * after having executed the test step.
804 */
805static void TestOverrideStateConsistency(skiatest::Reporter* reporter,
806 CanvasTestStep* testStep) {
807 SkBitmap referenceStore;
808 createBitmap(&referenceStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
809 SkDevice referenceDevice(referenceStore);
810 SkCanvas referenceCanvas(&referenceDevice);
811 testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat);
812 testStep->draw(&referenceCanvas, reporter);
813
junov@chromium.org4866cc02012-06-01 21:23:07 +0000814 TestPictureStateConsistency(reporter, testStep, referenceCanvas, 0);
815 TestPictureStateConsistency(reporter, testStep, referenceCanvas,
816 SkPicture::kFlattenMutableNonTexturePixelRefs_RecordingFlag);
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000817 TestDeferredCanvasStateConsistency(reporter, testStep, referenceCanvas);
818
caryclark@google.com42639cd2012-06-06 12:03:39 +0000819 // The following test code is disabled because SkProxyCanvas is
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000820 // missing a lot of virtual overrides on get* methods, which are used
821 // to verify canvas state.
822 // Issue: http://code.google.com/p/skia/issues/detail?id=500
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000823
caryclark@google.com42639cd2012-06-06 12:03:39 +0000824 if (false) { // avoid bit rot, suppress warning
825 TestProxyCanvasStateConsistency(reporter, testStep, referenceCanvas);
826 }
827
828 // The following test code is disabled because SkNWayCanvas does not
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000829 // report correct clipping and device bounds information
830 // Issue: http://code.google.com/p/skia/issues/detail?id=501
caryclark@google.com42639cd2012-06-06 12:03:39 +0000831
832 if (false) { // avoid bit rot, suppress warning
833 TestNWayCanvasStateConsistency(reporter, testStep, referenceCanvas);
834 }
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000835
caryclark@google.com42639cd2012-06-06 12:03:39 +0000836 if (false) { // avoid bit rot, suppress warning
837 test_clipVisitor(reporter, &referenceCanvas);
838 }
reed@google.com7c202932011-12-14 18:48:05 +0000839}
reed@google.com37f3ae02011-11-28 16:06:04 +0000840
841static void TestCanvas(skiatest::Reporter* reporter) {
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000842 // Init global here because bitmap pixels cannot be alocated during
843 // static initialization
844 kTestBitmap = testBitmap();
reed@google.com37f3ae02011-11-28 16:06:04 +0000845
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000846 for (int testStep = 0; testStep < testStepArray().count(); testStep++) {
847 TestOverrideStateConsistency(reporter, testStepArray()[testStep]);
848 SkPictureTester::TestPictureSerializationRoundTrip(reporter,
junov@chromium.org4866cc02012-06-01 21:23:07 +0000849 testStepArray()[testStep], 0);
850 SkPictureTester::TestPictureSerializationRoundTrip(reporter,
851 testStepArray()[testStep],
852 SkPicture::kFlattenMutableNonTexturePixelRefs_RecordingFlag);
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000853 SkPictureTester::TestPictureFlattenedObjectReuse(reporter,
junov@chromium.org4866cc02012-06-01 21:23:07 +0000854 testStepArray()[testStep], 0);
855 SkPictureTester::TestPictureFlattenedObjectReuse(reporter,
856 testStepArray()[testStep],
857 SkPicture::kFlattenMutableNonTexturePixelRefs_RecordingFlag);
junov@chromium.org1cc8f6f2012-02-22 21:00:42 +0000858 }
reed@google.com37f3ae02011-11-28 16:06:04 +0000859}
860
861#include "TestClassDef.h"
862DEFINE_TESTCLASS("Canvas", TestCanvasClass, TestCanvas)