| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 4 * | 3 * |
| 5 * 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 |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 9 /* Description: | 8 /* Description: |
| 10 * This test defines a series of elementatry test steps that perform | 9 * 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 | 10 * a single or a small group of canvas API calls. Each test step is |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 | 885 |
| 887 if (false) { // avoid bit rot, suppress warning | 886 if (false) { // avoid bit rot, suppress warning |
| 888 TestNWayCanvasStateConsistency(reporter, testStep, referenceCanvas); | 887 TestNWayCanvasStateConsistency(reporter, testStep, referenceCanvas); |
| 889 } | 888 } |
| 890 | 889 |
| 891 if (false) { // avoid bit rot, suppress warning | 890 if (false) { // avoid bit rot, suppress warning |
| 892 test_clipVisitor(reporter, &referenceCanvas); | 891 test_clipVisitor(reporter, &referenceCanvas); |
| 893 } | 892 } |
| 894 } | 893 } |
| 895 | 894 |
| 895 static void test_newraster(skiatest::Reporter* reporter) { |
| 896 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
| 897 SkCanvas* canvas = SkCanvas::NewRaster(info); |
| 898 REPORTER_ASSERT(reporter, canvas); |
| 899 |
| 900 SkImageInfo info2; |
| 901 size_t rowBytes; |
| 902 const SkPMColor* addr = (const SkPMColor*)canvas->peekPixels(&info2, &rowByt
es); |
| 903 REPORTER_ASSERT(reporter, addr); |
| 904 REPORTER_ASSERT(reporter, info == info2); |
| 905 for (int y = 0; y < info.height(); ++y) { |
| 906 for (int x = 0; x < info.width(); ++x) { |
| 907 REPORTER_ASSERT(reporter, 0 == addr[x]); |
| 908 } |
| 909 addr = (const SkPMColor*)((const char*)addr + rowBytes); |
| 910 } |
| 911 SkDELETE(canvas); |
| 912 |
| 913 // now try a deliberately bad info |
| 914 info.fWidth = -1; |
| 915 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info)); |
| 916 |
| 917 // too big |
| 918 info.fWidth = 1 << 30; |
| 919 info.fHeight = 1 << 30; |
| 920 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info)); |
| 921 |
| 922 // not a valid pixel type |
| 923 info.fWidth = info.fHeight = 10; |
| 924 info.fColorType = kUnknown_SkColorType; |
| 925 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info)); |
| 926 |
| 927 // We should succeed with a zero-sized valid info |
| 928 info = SkImageInfo::MakeN32Premul(0, 0); |
| 929 canvas = SkCanvas::NewRaster(info); |
| 930 REPORTER_ASSERT(reporter, canvas); |
| 931 SkDELETE(canvas); |
| 932 } |
| 933 |
| 896 DEF_TEST(Canvas, reporter) { | 934 DEF_TEST(Canvas, reporter) { |
| 897 // Init global here because bitmap pixels cannot be alocated during | 935 // Init global here because bitmap pixels cannot be alocated during |
| 898 // static initialization | 936 // static initialization |
| 899 kTestBitmap = testBitmap(); | 937 kTestBitmap = testBitmap(); |
| 900 | 938 |
| 901 for (int testStep = 0; testStep < testStepArray().count(); testStep++) { | 939 for (int testStep = 0; testStep < testStepArray().count(); testStep++) { |
| 902 TestOverrideStateConsistency(reporter, testStepArray()[testStep]); | 940 TestOverrideStateConsistency(reporter, testStepArray()[testStep]); |
| 903 SkPictureTester::TestPictureFlattenedObjectReuse(reporter, | 941 SkPictureTester::TestPictureFlattenedObjectReuse(reporter, |
| 904 testStepArray()[testStep], 0); | 942 testStepArray()[testStep], 0); |
| 905 if (testStepArray()[testStep]->enablePdfTesting()) { | 943 if (testStepArray()[testStep]->enablePdfTesting()) { |
| 906 TestPdfDevice(reporter, testStepArray()[testStep]); | 944 TestPdfDevice(reporter, testStepArray()[testStep]); |
| 907 } | 945 } |
| 908 } | 946 } |
| 909 | 947 |
| 910 // Explicitly call reset(), so we don't leak the pixels (since kTestBitmap i
s a global) | 948 // Explicitly call reset(), so we don't leak the pixels (since kTestBitmap i
s a global) |
| 911 kTestBitmap.reset(); | 949 kTestBitmap.reset(); |
| 950 |
| 951 test_newraster(reporter); |
| 912 } | 952 } |
| OLD | NEW |