OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 /* Description: | 9 /* Description: |
10 * This test defines a series of elementatry test steps that perform | 10 * This test defines a series of elementatry test steps that perform |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 | 78 |
79 private: | 79 private: |
80 SkCanvas* fTarget; | 80 SkCanvas* fTarget; |
81 }; | 81 }; |
82 | 82 |
83 static void test_clipVisitor(skiatest::Reporter* reporter, SkCanvas* canvas) { | 83 static void test_clipVisitor(skiatest::Reporter* reporter, SkCanvas* canvas) { |
84 SkISize size = canvas->getDeviceSize(); | 84 SkISize size = canvas->getDeviceSize(); |
85 | 85 |
86 SkBitmap bm; | 86 SkBitmap bm; |
87 bm.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); | 87 bm.setConfig(SkImageInfo::MakeN32Premul(size.width(), size.height())); |
88 SkCanvas c(bm); | 88 SkCanvas c(bm); |
89 | 89 |
90 Canvas2CanvasClipVisitor visitor(&c); | 90 Canvas2CanvasClipVisitor visitor(&c); |
91 canvas->replayClips(&visitor); | 91 canvas->replayClips(&visitor); |
92 | 92 |
93 REPORTER_ASSERT(reporter, c.getTotalClip() == canvas->getTotalClip()); | 93 REPORTER_ASSERT(reporter, c.getTotalClip() == canvas->getTotalClip()); |
94 } | 94 } |
95 | 95 |
96 static const int kWidth = 2; | 96 static const int kWidth = 2; |
97 static const int kHeight = 2; | 97 static const int kHeight = 2; |
(...skipping 30 matching lines...) Expand all Loading... |
128 "test step %s, SkProxyCanvas indirect canvas state consistency"; | 128 "test step %s, SkProxyCanvas indirect canvas state consistency"; |
129 static const char* const kNWayStateAssertMessageFormat = | 129 static const char* const kNWayStateAssertMessageFormat = |
130 "test step %s, SkNWayCanvas state consistency"; | 130 "test step %s, SkNWayCanvas state consistency"; |
131 static const char* const kNWayIndirect1StateAssertMessageFormat = | 131 static const char* const kNWayIndirect1StateAssertMessageFormat = |
132 "test step %s, SkNWayCanvas indirect canvas 1 state consistency"; | 132 "test step %s, SkNWayCanvas indirect canvas 1 state consistency"; |
133 static const char* const kNWayIndirect2StateAssertMessageFormat = | 133 static const char* const kNWayIndirect2StateAssertMessageFormat = |
134 "test step %s, SkNWayCanvas indirect canvas 2 state consistency"; | 134 "test step %s, SkNWayCanvas indirect canvas 2 state consistency"; |
135 static const char* const kPdfAssertMessageFormat = | 135 static const char* const kPdfAssertMessageFormat = |
136 "PDF sanity check failed %s"; | 136 "PDF sanity check failed %s"; |
137 | 137 |
138 static void createBitmap(SkBitmap* bm, SkBitmap::Config config, SkColor color) { | 138 static void createBitmap(SkBitmap* bm, SkColor color) { |
139 bm->setConfig(config, kWidth, kHeight); | 139 bm->allocN32Pixels(kWidth, kHeight); |
140 bm->allocPixels(); | |
141 bm->eraseColor(color); | 140 bm->eraseColor(color); |
142 } | 141 } |
143 | 142 |
144 static SkSurface* createSurface(SkColor color) { | 143 static SkSurface* createSurface(SkColor color) { |
145 SkSurface* surface = SkSurface::NewRasterPMColor(kWidth, kHeight); | 144 SkSurface* surface = SkSurface::NewRasterPMColor(kWidth, kHeight); |
146 surface->getCanvas()->clear(color); | 145 surface->getCanvas()->clear(color); |
147 return surface; | 146 return surface; |
148 } | 147 } |
149 | 148 |
150 class CanvasTestStep; | 149 class CanvasTestStep; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 const SkColor kTestColor = 0x01020304; | 212 const SkColor kTestColor = 0x01020304; |
214 const SkPaint kTestPaint; | 213 const SkPaint kTestPaint; |
215 const SkPoint kTestPoints[3] = { | 214 const SkPoint kTestPoints[3] = { |
216 {SkIntToScalar(0), SkIntToScalar(0)}, | 215 {SkIntToScalar(0), SkIntToScalar(0)}, |
217 {SkIntToScalar(2), SkIntToScalar(1)}, | 216 {SkIntToScalar(2), SkIntToScalar(1)}, |
218 {SkIntToScalar(0), SkIntToScalar(2)} | 217 {SkIntToScalar(0), SkIntToScalar(2)} |
219 }; | 218 }; |
220 const size_t kTestPointCount = 3; | 219 const size_t kTestPointCount = 3; |
221 static SkBitmap testBitmap() { | 220 static SkBitmap testBitmap() { |
222 SkBitmap bitmap; | 221 SkBitmap bitmap; |
223 createBitmap(&bitmap, SkBitmap::kARGB_8888_Config, 0x05060708); | 222 createBitmap(&bitmap, 0x05060708); |
224 return bitmap; | 223 return bitmap; |
225 } | 224 } |
226 SkBitmap kTestBitmap; // cannot be created during static init | 225 SkBitmap kTestBitmap; // cannot be created during static init |
227 SkString kTestText("Hello World"); | 226 SkString kTestText("Hello World"); |
228 SkPoint kTestPoints2[] = { | 227 SkPoint kTestPoints2[] = { |
229 { SkIntToScalar(0), SkIntToScalar(1) }, | 228 { SkIntToScalar(0), SkIntToScalar(1) }, |
230 { SkIntToScalar(1), SkIntToScalar(1) }, | 229 { SkIntToScalar(1), SkIntToScalar(1) }, |
231 { SkIntToScalar(2), SkIntToScalar(1) }, | 230 { SkIntToScalar(2), SkIntToScalar(1) }, |
232 { SkIntToScalar(3), SkIntToScalar(1) }, | 231 { SkIntToScalar(3), SkIntToScalar(1) }, |
233 { SkIntToScalar(4), SkIntToScalar(1) }, | 232 { SkIntToScalar(4), SkIntToScalar(1) }, |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 } | 790 } |
792 }; | 791 }; |
793 | 792 |
794 // unused | 793 // unused |
795 static void TestProxyCanvasStateConsistency( | 794 static void TestProxyCanvasStateConsistency( |
796 skiatest::Reporter* reporter, | 795 skiatest::Reporter* reporter, |
797 CanvasTestStep* testStep, | 796 CanvasTestStep* testStep, |
798 const SkCanvas& referenceCanvas) { | 797 const SkCanvas& referenceCanvas) { |
799 | 798 |
800 SkBitmap indirectStore; | 799 SkBitmap indirectStore; |
801 createBitmap(&indirectStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); | 800 createBitmap(&indirectStore, 0xFFFFFFFF); |
802 SkBitmapDevice indirectDevice(indirectStore); | 801 SkBitmapDevice indirectDevice(indirectStore); |
803 SkCanvas indirectCanvas(&indirectDevice); | 802 SkCanvas indirectCanvas(&indirectDevice); |
804 SkProxyCanvas proxyCanvas(&indirectCanvas); | 803 SkProxyCanvas proxyCanvas(&indirectCanvas); |
805 testStep->setAssertMessageFormat(kProxyDrawAssertMessageFormat); | 804 testStep->setAssertMessageFormat(kProxyDrawAssertMessageFormat); |
806 testStep->draw(&proxyCanvas, reporter); | 805 testStep->draw(&proxyCanvas, reporter); |
807 // Verify that the SkProxyCanvas reports consitent state | 806 // Verify that the SkProxyCanvas reports consitent state |
808 testStep->setAssertMessageFormat(kProxyStateAssertMessageFormat); | 807 testStep->setAssertMessageFormat(kProxyStateAssertMessageFormat); |
809 AssertCanvasStatesEqual(reporter, &proxyCanvas, &referenceCanvas, | 808 AssertCanvasStatesEqual(reporter, &proxyCanvas, &referenceCanvas, |
810 testStep); | 809 testStep); |
811 // Verify that the indirect canvas reports consitent state | 810 // Verify that the indirect canvas reports consitent state |
812 testStep->setAssertMessageFormat(kProxyIndirectStateAssertMessageFormat); | 811 testStep->setAssertMessageFormat(kProxyIndirectStateAssertMessageFormat); |
813 AssertCanvasStatesEqual(reporter, &indirectCanvas, &referenceCanvas, | 812 AssertCanvasStatesEqual(reporter, &indirectCanvas, &referenceCanvas, |
814 testStep); | 813 testStep); |
815 } | 814 } |
816 | 815 |
817 // unused | 816 // unused |
818 static void TestNWayCanvasStateConsistency( | 817 static void TestNWayCanvasStateConsistency( |
819 skiatest::Reporter* reporter, | 818 skiatest::Reporter* reporter, |
820 CanvasTestStep* testStep, | 819 CanvasTestStep* testStep, |
821 const SkCanvas& referenceCanvas) { | 820 const SkCanvas& referenceCanvas) { |
822 | 821 |
823 SkBitmap indirectStore1; | 822 SkBitmap indirectStore1; |
824 createBitmap(&indirectStore1, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); | 823 createBitmap(&indirectStore1, 0xFFFFFFFF); |
825 SkBitmapDevice indirectDevice1(indirectStore1); | 824 SkBitmapDevice indirectDevice1(indirectStore1); |
826 SkCanvas indirectCanvas1(&indirectDevice1); | 825 SkCanvas indirectCanvas1(&indirectDevice1); |
827 | 826 |
828 SkBitmap indirectStore2; | 827 SkBitmap indirectStore2; |
829 createBitmap(&indirectStore2, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); | 828 createBitmap(&indirectStore2, 0xFFFFFFFF); |
830 SkBitmapDevice indirectDevice2(indirectStore2); | 829 SkBitmapDevice indirectDevice2(indirectStore2); |
831 SkCanvas indirectCanvas2(&indirectDevice2); | 830 SkCanvas indirectCanvas2(&indirectDevice2); |
832 | 831 |
833 SkISize canvasSize = referenceCanvas.getDeviceSize(); | 832 SkISize canvasSize = referenceCanvas.getDeviceSize(); |
834 SkNWayCanvas nWayCanvas(canvasSize.width(), canvasSize.height()); | 833 SkNWayCanvas nWayCanvas(canvasSize.width(), canvasSize.height()); |
835 nWayCanvas.addCanvas(&indirectCanvas1); | 834 nWayCanvas.addCanvas(&indirectCanvas1); |
836 nWayCanvas.addCanvas(&indirectCanvas2); | 835 nWayCanvas.addCanvas(&indirectCanvas2); |
837 | 836 |
838 testStep->setAssertMessageFormat(kNWayDrawAssertMessageFormat); | 837 testStep->setAssertMessageFormat(kNWayDrawAssertMessageFormat); |
839 testStep->draw(&nWayCanvas, reporter); | 838 testStep->draw(&nWayCanvas, reporter); |
(...skipping 12 matching lines...) Expand all Loading... |
852 | 851 |
853 /* | 852 /* |
854 * This sub-test verifies that the test step passes when executed | 853 * This sub-test verifies that the test step passes when executed |
855 * with SkCanvas and with classes derrived from SkCanvas. It also verifies | 854 * with SkCanvas and with classes derrived from SkCanvas. It also verifies |
856 * that the all canvas derivatives report the same state as an SkCanvas | 855 * that the all canvas derivatives report the same state as an SkCanvas |
857 * after having executed the test step. | 856 * after having executed the test step. |
858 */ | 857 */ |
859 static void TestOverrideStateConsistency(skiatest::Reporter* reporter, | 858 static void TestOverrideStateConsistency(skiatest::Reporter* reporter, |
860 CanvasTestStep* testStep) { | 859 CanvasTestStep* testStep) { |
861 SkBitmap referenceStore; | 860 SkBitmap referenceStore; |
862 createBitmap(&referenceStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); | 861 createBitmap(&referenceStore, 0xFFFFFFFF); |
863 SkBitmapDevice referenceDevice(referenceStore); | 862 SkBitmapDevice referenceDevice(referenceStore); |
864 SkCanvas referenceCanvas(&referenceDevice); | 863 SkCanvas referenceCanvas(&referenceDevice); |
865 testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat); | 864 testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat); |
866 testStep->draw(&referenceCanvas, reporter); | 865 testStep->draw(&referenceCanvas, reporter); |
867 | 866 |
868 SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testSte
p, referenceCanvas, false); | 867 SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testSte
p, referenceCanvas, false); |
869 | 868 |
870 SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testSte
p, referenceCanvas, true); | 869 SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testSte
p, referenceCanvas, true); |
871 | 870 |
872 // The following test code is disabled because SkProxyCanvas is | 871 // The following test code is disabled because SkProxyCanvas is |
(...skipping 28 matching lines...) Expand all Loading... |
901 SkPictureTester::TestPictureFlattenedObjectReuse(reporter, | 900 SkPictureTester::TestPictureFlattenedObjectReuse(reporter, |
902 testStepArray()[testStep], 0); | 901 testStepArray()[testStep], 0); |
903 if (testStepArray()[testStep]->enablePdfTesting()) { | 902 if (testStepArray()[testStep]->enablePdfTesting()) { |
904 TestPdfDevice(reporter, testStepArray()[testStep]); | 903 TestPdfDevice(reporter, testStepArray()[testStep]); |
905 } | 904 } |
906 } | 905 } |
907 | 906 |
908 // Explicitly call reset(), so we don't leak the pixels (since kTestBitmap i
s a global) | 907 // Explicitly call reset(), so we don't leak the pixels (since kTestBitmap i
s a global) |
909 kTestBitmap.reset(); | 908 kTestBitmap.reset(); |
910 } | 909 } |
OLD | NEW |