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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 #include "Test.h" | 66 #include "Test.h" |
67 | 67 |
68 static const int kWidth = 2, kHeight = 2; | 68 static const int kWidth = 2, kHeight = 2; |
69 | 69 |
70 static void createBitmap(SkBitmap* bm, SkColor color) { | 70 static void createBitmap(SkBitmap* bm, SkColor color) { |
71 bm->allocN32Pixels(kWidth, kHeight); | 71 bm->allocN32Pixels(kWidth, kHeight); |
72 bm->eraseColor(color); | 72 bm->eraseColor(color); |
73 } | 73 } |
74 | 74 |
75 static SkSurface* createSurface(SkColor color) { | 75 static SkSurface* createSurface(SkColor color) { |
76 SkSurface* surface = SkSurface::NewRasterPMColor(kWidth, kHeight); | 76 SkSurface* surface = SkSurface::NewRasterN32Premul(kWidth, kHeight); |
77 surface->getCanvas()->clear(color); | 77 surface->getCanvas()->clear(color); |
78 return surface; | 78 return surface; |
79 } | 79 } |
80 | 80 |
81 /////////////////////////////////////////////////////////////////////////////// | 81 /////////////////////////////////////////////////////////////////////////////// |
82 // Constants used by test steps | 82 // Constants used by test steps |
83 const SkPoint kTestPoints[] = { | 83 const SkPoint kTestPoints[] = { |
84 {SkIntToScalar(0), SkIntToScalar(0)}, | 84 {SkIntToScalar(0), SkIntToScalar(0)}, |
85 {SkIntToScalar(2), SkIntToScalar(1)}, | 85 {SkIntToScalar(2), SkIntToScalar(1)}, |
86 {SkIntToScalar(0), SkIntToScalar(2)} | 86 {SkIntToScalar(0), SkIntToScalar(2)} |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 TestNWayCanvasStateConsistency(reporter, d, testStep, referenceCanvas); | 741 TestNWayCanvasStateConsistency(reporter, d, testStep, referenceCanvas); |
742 } | 742 } |
743 | 743 |
744 if (false) { // avoid bit rot, suppress warning | 744 if (false) { // avoid bit rot, suppress warning |
745 test_clipVisitor(reporter, &referenceCanvas); | 745 test_clipVisitor(reporter, &referenceCanvas); |
746 } | 746 } |
747 } | 747 } |
748 | 748 |
749 static void test_newraster(skiatest::Reporter* reporter) { | 749 static void test_newraster(skiatest::Reporter* reporter) { |
750 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); | 750 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
751 SkCanvas* canvas = SkCanvas::NewRaster(info); | 751 const size_t minRowBytes = info.minRowBytes(); |
| 752 const size_t size = info.getSafeSize(minRowBytes); |
| 753 SkAutoMalloc storage(size); |
| 754 SkPMColor* baseAddr = static_cast<SkPMColor*>(storage.get()); |
| 755 sk_bzero(baseAddr, size); |
| 756 |
| 757 SkCanvas* canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes); |
752 REPORTER_ASSERT(reporter, canvas); | 758 REPORTER_ASSERT(reporter, canvas); |
753 | 759 |
754 SkImageInfo info2; | 760 SkImageInfo info2; |
755 size_t rowBytes; | 761 size_t rowBytes; |
756 const SkPMColor* addr = (const SkPMColor*)canvas->peekPixels(&info2, &rowByt
es); | 762 const SkPMColor* addr = (const SkPMColor*)canvas->peekPixels(&info2, &rowByt
es); |
757 REPORTER_ASSERT(reporter, addr); | 763 REPORTER_ASSERT(reporter, addr); |
758 REPORTER_ASSERT(reporter, info == info2); | 764 REPORTER_ASSERT(reporter, info == info2); |
| 765 REPORTER_ASSERT(reporter, minRowBytes == rowBytes); |
759 for (int y = 0; y < info.height(); ++y) { | 766 for (int y = 0; y < info.height(); ++y) { |
760 for (int x = 0; x < info.width(); ++x) { | 767 for (int x = 0; x < info.width(); ++x) { |
761 REPORTER_ASSERT(reporter, 0 == addr[x]); | 768 REPORTER_ASSERT(reporter, 0 == addr[x]); |
762 } | 769 } |
763 addr = (const SkPMColor*)((const char*)addr + rowBytes); | 770 addr = (const SkPMColor*)((const char*)addr + rowBytes); |
764 } | 771 } |
765 SkDELETE(canvas); | 772 SkDELETE(canvas); |
766 | 773 |
767 // now try a deliberately bad info | 774 // now try a deliberately bad info |
768 info = info.makeWH(-1, info.height()); | 775 info = info.makeWH(-1, info.height()); |
769 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info)); | 776 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr,
minRowBytes)); |
770 | 777 |
771 // too big | 778 // too big |
772 info = info.makeWH(1 << 30, 1 << 30); | 779 info = info.makeWH(1 << 30, 1 << 30); |
773 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info)); | 780 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr,
minRowBytes)); |
774 | 781 |
775 // not a valid pixel type | 782 // not a valid pixel type |
776 info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType()); | 783 info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType()); |
777 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info)); | 784 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr,
minRowBytes)); |
778 | 785 |
779 // We should succeed with a zero-sized valid info | 786 // We should succeed with a zero-sized valid info |
780 info = SkImageInfo::MakeN32Premul(0, 0); | 787 info = SkImageInfo::MakeN32Premul(0, 0); |
781 canvas = SkCanvas::NewRaster(info); | 788 canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes); |
782 REPORTER_ASSERT(reporter, canvas); | 789 REPORTER_ASSERT(reporter, canvas); |
783 SkDELETE(canvas); | 790 SkDELETE(canvas); |
784 } | 791 } |
785 | 792 |
786 DEF_TEST(Canvas, reporter) { | 793 DEF_TEST(Canvas, reporter) { |
787 TestData d; | 794 TestData d; |
788 | 795 |
789 for (int testStep = 0; testStep < testStepArray().count(); testStep++) { | 796 for (int testStep = 0; testStep < testStepArray().count(); testStep++) { |
790 TestOverrideStateConsistency(reporter, d, testStepArray()[testStep]); | 797 TestOverrideStateConsistency(reporter, d, testStepArray()[testStep]); |
791 if (testStepArray()[testStep]->enablePdfTesting()) { | 798 if (testStepArray()[testStep]->enablePdfTesting()) { |
(...skipping 14 matching lines...) Expand all Loading... |
806 | 813 |
807 n = canvas.saveLayer(NULL, NULL); | 814 n = canvas.saveLayer(NULL, NULL); |
808 REPORTER_ASSERT(reporter, 2 == n); | 815 REPORTER_ASSERT(reporter, 2 == n); |
809 REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount()); | 816 REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount()); |
810 | 817 |
811 canvas.restore(); | 818 canvas.restore(); |
812 REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount()); | 819 REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount()); |
813 canvas.restore(); | 820 canvas.restore(); |
814 REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount()); | 821 REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount()); |
815 } | 822 } |
OLD | NEW |