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::NewRasterN32Premul(kWidth, kHeight); | 76 SkSurface* surface = SkSurface::NewRasterPMColor(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 const size_t minRowBytes = info.minRowBytes(); | 751 SkCanvas* canvas = SkCanvas::NewRaster(info); |
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); | |
758 REPORTER_ASSERT(reporter, canvas); | 752 REPORTER_ASSERT(reporter, canvas); |
759 | 753 |
760 SkImageInfo info2; | 754 SkImageInfo info2; |
761 size_t rowBytes; | 755 size_t rowBytes; |
762 const SkPMColor* addr = (const SkPMColor*)canvas->peekPixels(&info2, &rowByt
es); | 756 const SkPMColor* addr = (const SkPMColor*)canvas->peekPixels(&info2, &rowByt
es); |
763 REPORTER_ASSERT(reporter, addr); | 757 REPORTER_ASSERT(reporter, addr); |
764 REPORTER_ASSERT(reporter, info == info2); | 758 REPORTER_ASSERT(reporter, info == info2); |
765 REPORTER_ASSERT(reporter, minRowBytes == rowBytes); | |
766 for (int y = 0; y < info.height(); ++y) { | 759 for (int y = 0; y < info.height(); ++y) { |
767 for (int x = 0; x < info.width(); ++x) { | 760 for (int x = 0; x < info.width(); ++x) { |
768 REPORTER_ASSERT(reporter, 0 == addr[x]); | 761 REPORTER_ASSERT(reporter, 0 == addr[x]); |
769 } | 762 } |
770 addr = (const SkPMColor*)((const char*)addr + rowBytes); | 763 addr = (const SkPMColor*)((const char*)addr + rowBytes); |
771 } | 764 } |
772 SkDELETE(canvas); | 765 SkDELETE(canvas); |
773 | 766 |
774 // now try a deliberately bad info | 767 // now try a deliberately bad info |
775 info = info.makeWH(-1, info.height()); | 768 info = info.makeWH(-1, info.height()); |
776 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr,
minRowBytes)); | 769 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info)); |
777 | 770 |
778 // too big | 771 // too big |
779 info = info.makeWH(1 << 30, 1 << 30); | 772 info = info.makeWH(1 << 30, 1 << 30); |
780 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr,
minRowBytes)); | 773 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info)); |
781 | 774 |
782 // not a valid pixel type | 775 // not a valid pixel type |
783 info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType()); | 776 info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType()); |
784 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr,
minRowBytes)); | 777 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info)); |
785 | 778 |
786 // We should succeed with a zero-sized valid info | 779 // We should succeed with a zero-sized valid info |
787 info = SkImageInfo::MakeN32Premul(0, 0); | 780 info = SkImageInfo::MakeN32Premul(0, 0); |
788 canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes); | 781 canvas = SkCanvas::NewRaster(info); |
789 REPORTER_ASSERT(reporter, canvas); | 782 REPORTER_ASSERT(reporter, canvas); |
790 SkDELETE(canvas); | 783 SkDELETE(canvas); |
791 } | 784 } |
792 | 785 |
793 DEF_TEST(Canvas, reporter) { | 786 DEF_TEST(Canvas, reporter) { |
794 TestData d; | 787 TestData d; |
795 | 788 |
796 for (int testStep = 0; testStep < testStepArray().count(); testStep++) { | 789 for (int testStep = 0; testStep < testStepArray().count(); testStep++) { |
797 TestOverrideStateConsistency(reporter, d, testStepArray()[testStep]); | 790 TestOverrideStateConsistency(reporter, d, testStepArray()[testStep]); |
798 if (testStepArray()[testStep]->enablePdfTesting()) { | 791 if (testStepArray()[testStep]->enablePdfTesting()) { |
(...skipping 14 matching lines...) Expand all Loading... |
813 | 806 |
814 n = canvas.saveLayer(NULL, NULL); | 807 n = canvas.saveLayer(NULL, NULL); |
815 REPORTER_ASSERT(reporter, 2 == n); | 808 REPORTER_ASSERT(reporter, 2 == n); |
816 REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount()); | 809 REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount()); |
817 | 810 |
818 canvas.restore(); | 811 canvas.restore(); |
819 REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount()); | 812 REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount()); |
820 canvas.restore(); | 813 canvas.restore(); |
821 REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount()); | 814 REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount()); |
822 } | 815 } |
OLD | NEW |