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 28 matching lines...) Expand all Loading... |
39 * | 39 * |
40 * SIMPLE_TEST_STEP(MytestStep, someCanvasAPIMethod()); | 40 * SIMPLE_TEST_STEP(MytestStep, someCanvasAPIMethod()); |
41 * | 41 * |
42 * There is another macro called SIMPLE_TEST_STEP_WITH_ASSERT that | 42 * There is another macro called SIMPLE_TEST_STEP_WITH_ASSERT that |
43 * works the same way as SIMPLE_TEST_STEP, and additionally verifies | 43 * works the same way as SIMPLE_TEST_STEP, and additionally verifies |
44 * that the invoked method returns a non-zero value. | 44 * that the invoked method returns a non-zero value. |
45 */ | 45 */ |
46 #include "SkBitmap.h" | 46 #include "SkBitmap.h" |
47 #include "SkCanvas.h" | 47 #include "SkCanvas.h" |
48 #include "SkClipStack.h" | 48 #include "SkClipStack.h" |
49 #include "SkDeferredCanvas.h" | |
50 #include "SkDevice.h" | 49 #include "SkDevice.h" |
51 #include "SkDocument.h" | 50 #include "SkDocument.h" |
52 #include "SkMatrix.h" | 51 #include "SkMatrix.h" |
53 #include "SkNWayCanvas.h" | 52 #include "SkNWayCanvas.h" |
54 #include "SkPaint.h" | 53 #include "SkPaint.h" |
55 #include "SkPaintFilterCanvas.h" | 54 #include "SkPaintFilterCanvas.h" |
56 #include "SkPath.h" | 55 #include "SkPath.h" |
57 #include "SkPicture.h" | 56 #include "SkPicture.h" |
58 #include "SkPictureRecord.h" | 57 #include "SkPictureRecord.h" |
59 #include "SkPictureRecorder.h" | 58 #include "SkPictureRecorder.h" |
60 #include "SkRect.h" | 59 #include "SkRect.h" |
61 #include "SkRegion.h" | 60 #include "SkRegion.h" |
62 #include "SkShader.h" | 61 #include "SkShader.h" |
63 #include "SkStream.h" | 62 #include "SkStream.h" |
64 #include "SkSurface.h" | 63 #include "SkSurface.h" |
65 #include "SkTDArray.h" | 64 #include "SkTDArray.h" |
66 #include "Test.h" | 65 #include "Test.h" |
67 | 66 |
68 static const int kWidth = 2, kHeight = 2; | 67 static const int kWidth = 2, kHeight = 2; |
69 | 68 |
70 static void createBitmap(SkBitmap* bm, SkColor color) { | 69 static void createBitmap(SkBitmap* bm, SkColor color) { |
71 bm->allocN32Pixels(kWidth, kHeight); | 70 bm->allocN32Pixels(kWidth, kHeight); |
72 bm->eraseColor(color); | 71 bm->eraseColor(color); |
73 } | 72 } |
74 | 73 |
75 static SkSurface* createSurface(SkColor color) { | |
76 SkSurface* surface = SkSurface::NewRasterN32Premul(kWidth, kHeight); | |
77 surface->getCanvas()->clear(color); | |
78 return surface; | |
79 } | |
80 | |
81 /////////////////////////////////////////////////////////////////////////////// | 74 /////////////////////////////////////////////////////////////////////////////// |
82 // Constants used by test steps | 75 // Constants used by test steps |
83 const SkPoint kTestPoints[] = { | 76 const SkPoint kTestPoints[] = { |
84 {SkIntToScalar(0), SkIntToScalar(0)}, | 77 {SkIntToScalar(0), SkIntToScalar(0)}, |
85 {SkIntToScalar(2), SkIntToScalar(1)}, | 78 {SkIntToScalar(2), SkIntToScalar(1)}, |
86 {SkIntToScalar(0), SkIntToScalar(2)} | 79 {SkIntToScalar(0), SkIntToScalar(2)} |
87 }; | 80 }; |
88 const SkPoint kTestPoints2[] = { | 81 const SkPoint kTestPoints2[] = { |
89 { SkIntToScalar(0), SkIntToScalar(1) }, | 82 { SkIntToScalar(0), SkIntToScalar(1) }, |
90 { SkIntToScalar(1), SkIntToScalar(1) }, | 83 { SkIntToScalar(1), SkIntToScalar(1) }, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } | 225 } |
233 | 226 |
234 // Format strings that describe the test context. The %s token is where | 227 // Format strings that describe the test context. The %s token is where |
235 // the name of the test step is inserted. The context is required for | 228 // the name of the test step is inserted. The context is required for |
236 // disambiguating the error in the case of failures that are reported in | 229 // disambiguating the error in the case of failures that are reported in |
237 // functions that are called multiple times in different contexts (test | 230 // functions that are called multiple times in different contexts (test |
238 // cases and test steps). | 231 // cases and test steps). |
239 static const char* const kDefaultAssertMessageFormat = "%s"; | 232 static const char* const kDefaultAssertMessageFormat = "%s"; |
240 static const char* const kCanvasDrawAssertMessageFormat = | 233 static const char* const kCanvasDrawAssertMessageFormat = |
241 "Drawing test step %s with SkCanvas"; | 234 "Drawing test step %s with SkCanvas"; |
242 static const char* const kDeferredDrawAssertMessageFormat = | |
243 "Drawing test step %s with SkDeferredCanvas"; | |
244 static const char* const kNWayDrawAssertMessageFormat = | 235 static const char* const kNWayDrawAssertMessageFormat = |
245 "Drawing test step %s with SkNWayCanvas"; | 236 "Drawing test step %s with SkNWayCanvas"; |
246 static const char* const kDeferredPreFlushAssertMessageFormat = | |
247 "test step %s, SkDeferredCanvas state consistency before flush"; | |
248 static const char* const kDeferredPostFlushPlaybackAssertMessageFormat = | |
249 "test step %s, SkDeferredCanvas playback canvas state consistency after flus
h"; | |
250 static const char* const kDeferredPostSilentFlushPlaybackAssertMessageFormat = | |
251 "test step %s, SkDeferredCanvas playback canvas state consistency after sile
nt flush"; | |
252 static const char* const kNWayStateAssertMessageFormat = | 237 static const char* const kNWayStateAssertMessageFormat = |
253 "test step %s, SkNWayCanvas state consistency"; | 238 "test step %s, SkNWayCanvas state consistency"; |
254 static const char* const kNWayIndirect1StateAssertMessageFormat = | 239 static const char* const kNWayIndirect1StateAssertMessageFormat = |
255 "test step %s, SkNWayCanvas indirect canvas 1 state consistency"; | 240 "test step %s, SkNWayCanvas indirect canvas 1 state consistency"; |
256 static const char* const kNWayIndirect2StateAssertMessageFormat = | 241 static const char* const kNWayIndirect2StateAssertMessageFormat = |
257 "test step %s, SkNWayCanvas indirect canvas 2 state consistency"; | 242 "test step %s, SkNWayCanvas indirect canvas 2 state consistency"; |
258 static const char* const kPdfAssertMessageFormat = | 243 static const char* const kPdfAssertMessageFormat = |
259 "PDF sanity check failed %s"; | 244 "PDF sanity check failed %s"; |
260 | 245 |
261 class CanvasTestStep; | 246 class CanvasTestStep; |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 } | 564 } |
580 SkCanvas* canvas = doc->beginPage(SkIntToScalar(d.fWidth), | 565 SkCanvas* canvas = doc->beginPage(SkIntToScalar(d.fWidth), |
581 SkIntToScalar(d.fHeight)); | 566 SkIntToScalar(d.fHeight)); |
582 REPORTER_ASSERT(reporter, canvas); | 567 REPORTER_ASSERT(reporter, canvas); |
583 testStep->setAssertMessageFormat(kPdfAssertMessageFormat); | 568 testStep->setAssertMessageFormat(kPdfAssertMessageFormat); |
584 testStep->draw(canvas, d, reporter); | 569 testStep->draw(canvas, d, reporter); |
585 | 570 |
586 REPORTER_ASSERT(reporter, doc->close()); | 571 REPORTER_ASSERT(reporter, doc->close()); |
587 } | 572 } |
588 | 573 |
589 // The following class groups static functions that need to access | |
590 // the privates members of SkDeferredCanvas | |
591 class SkDeferredCanvasTester { | |
592 public: | |
593 static void TestDeferredCanvasStateConsistency( | |
594 skiatest::Reporter* reporter, | |
595 const TestData& d, | |
596 CanvasTestStep* testStep, | |
597 const SkCanvas& referenceCanvas, bool silent) { | |
598 | |
599 SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF)); | |
600 SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(s
urface.get())); | |
601 | |
602 testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat); | |
603 testStep->draw(deferredCanvas, d, reporter); | |
604 testStep->setAssertMessageFormat(kDeferredPreFlushAssertMessageFormat); | |
605 AssertCanvasStatesEqual(reporter, d, deferredCanvas, &referenceCanvas, t
estStep); | |
606 | |
607 if (silent) { | |
608 deferredCanvas->silentFlush(); | |
609 } else { | |
610 deferredCanvas->flush(); | |
611 } | |
612 | |
613 testStep->setAssertMessageFormat( | |
614 silent ? kDeferredPostSilentFlushPlaybackAssertMessageFormat : | |
615 kDeferredPostFlushPlaybackAssertMessageFormat); | |
616 AssertCanvasStatesEqual(reporter, d, deferredCanvas->immediateCanvas(), | |
617 &referenceCanvas, testStep); | |
618 | |
619 // Verified that deferred canvas state is not affected by flushing | |
620 // pending draw operations | |
621 | |
622 // The following test code is commented out because it currently fails. | |
623 // Issue: http://code.google.com/p/skia/issues/detail?id=496 | |
624 /* | |
625 testStep->setAssertMessageFormat(kDeferredPostFlushAssertMessageFormat); | |
626 AssertCanvasStatesEqual(reporter, &deferredCanvas, &referenceCanvas, | |
627 testStep); | |
628 */ | |
629 } | |
630 }; | |
631 | |
632 // unused | 574 // unused |
633 static void TestNWayCanvasStateConsistency( | 575 static void TestNWayCanvasStateConsistency( |
634 skiatest::Reporter* reporter, | 576 skiatest::Reporter* reporter, |
635 const TestData& d, | 577 const TestData& d, |
636 CanvasTestStep* testStep, | 578 CanvasTestStep* testStep, |
637 const SkCanvas& referenceCanvas) { | 579 const SkCanvas& referenceCanvas) { |
638 | 580 |
639 SkBitmap indirectStore1; | 581 SkBitmap indirectStore1; |
640 createBitmap(&indirectStore1, 0xFFFFFFFF); | 582 createBitmap(&indirectStore1, 0xFFFFFFFF); |
641 SkCanvas indirectCanvas1(indirectStore1); | 583 SkCanvas indirectCanvas1(indirectStore1); |
(...skipping 26 matching lines...) Expand all Loading... |
668 * after having executed the test step. | 610 * after having executed the test step. |
669 */ | 611 */ |
670 static void TestOverrideStateConsistency(skiatest::Reporter* reporter, const Tes
tData& d, | 612 static void TestOverrideStateConsistency(skiatest::Reporter* reporter, const Tes
tData& d, |
671 CanvasTestStep* testStep) { | 613 CanvasTestStep* testStep) { |
672 SkBitmap referenceStore; | 614 SkBitmap referenceStore; |
673 createBitmap(&referenceStore, 0xFFFFFFFF); | 615 createBitmap(&referenceStore, 0xFFFFFFFF); |
674 SkCanvas referenceCanvas(referenceStore); | 616 SkCanvas referenceCanvas(referenceStore); |
675 testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat); | 617 testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat); |
676 testStep->draw(&referenceCanvas, d, reporter); | 618 testStep->draw(&referenceCanvas, d, reporter); |
677 | 619 |
678 SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, d, test
Step, referenceCanvas, false); | |
679 | |
680 SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, d, test
Step, referenceCanvas, true); | |
681 | |
682 // The following test code is disabled because SkNWayCanvas does not | 620 // The following test code is disabled because SkNWayCanvas does not |
683 // report correct clipping and device bounds information | 621 // report correct clipping and device bounds information |
684 // Issue: http://code.google.com/p/skia/issues/detail?id=501 | 622 // Issue: http://code.google.com/p/skia/issues/detail?id=501 |
685 | 623 |
686 if (false) { // avoid bit rot, suppress warning | 624 if (false) { // avoid bit rot, suppress warning |
687 TestNWayCanvasStateConsistency(reporter, d, testStep, referenceCanvas); | 625 TestNWayCanvasStateConsistency(reporter, d, testStep, referenceCanvas); |
688 } | 626 } |
689 | 627 |
690 if (false) { // avoid bit rot, suppress warning | 628 if (false) { // avoid bit rot, suppress warning |
691 test_clipVisitor(reporter, &referenceCanvas); | 629 test_clipVisitor(reporter, &referenceCanvas); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 749 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
812 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 750 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
813 REPORTER_ASSERT(reporter, clip1 == clip2); | 751 REPORTER_ASSERT(reporter, clip1 == clip2); |
814 | 752 |
815 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); | 753 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); |
816 filterCanvas.scale(0.75f, 0.5f); | 754 filterCanvas.scale(0.75f, 0.5f); |
817 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 755 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
818 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 756 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
819 REPORTER_ASSERT(reporter, clip1 == clip2); | 757 REPORTER_ASSERT(reporter, clip1 == clip2); |
820 } | 758 } |
OLD | NEW |