OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 | 9 |
10 #include "Test.h" | 10 #include "Test.h" |
11 | 11 |
| 12 static void test_allocpixels(skiatest::Reporter* reporter) { |
| 13 const int width = 10; |
| 14 const int height = 10; |
| 15 const SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 16 const size_t explicitRowBytes = info.minRowBytes() + 24; |
| 17 |
| 18 SkBitmap bm; |
| 19 bm.setInfo(info); |
| 20 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes()); |
| 21 bm.allocPixels(); |
| 22 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes()); |
| 23 bm.reset(); |
| 24 bm.allocPixels(info); |
| 25 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes()); |
| 26 |
| 27 bm.setInfo(info, explicitRowBytes); |
| 28 REPORTER_ASSERT(reporter, explicitRowBytes == bm.rowBytes()); |
| 29 bm.allocPixels(); |
| 30 REPORTER_ASSERT(reporter, explicitRowBytes == bm.rowBytes()); |
| 31 bm.reset(); |
| 32 bm.allocPixels(info, explicitRowBytes); |
| 33 REPORTER_ASSERT(reporter, explicitRowBytes == bm.rowBytes()); |
| 34 |
| 35 bm.reset(); |
| 36 bm.setInfo(info, 0); |
| 37 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes()); |
| 38 bm.reset(); |
| 39 bm.allocPixels(info, 0); |
| 40 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes()); |
| 41 |
| 42 bm.reset(); |
| 43 bool success = bm.setInfo(info, info.minRowBytes() - 1); // invalid for 32
bit |
| 44 REPORTER_ASSERT(reporter, !success); |
| 45 REPORTER_ASSERT(reporter, bm.isNull()); |
| 46 } |
| 47 |
12 static void test_bigwidth(skiatest::Reporter* reporter) { | 48 static void test_bigwidth(skiatest::Reporter* reporter) { |
13 SkBitmap bm; | 49 SkBitmap bm; |
14 int width = 1 << 29; // *4 will be the high-bit of 32bit int | 50 int width = 1 << 29; // *4 will be the high-bit of 32bit int |
15 | 51 |
16 SkImageInfo info = SkImageInfo::MakeA8(width, 1); | 52 SkImageInfo info = SkImageInfo::MakeA8(width, 1); |
17 REPORTER_ASSERT(reporter, bm.setInfo(info)); | 53 REPORTER_ASSERT(reporter, bm.setInfo(info)); |
18 info.fColorType = kRGB_565_SkColorType; | 54 info.fColorType = kRGB_565_SkColorType; |
19 REPORTER_ASSERT(reporter, bm.setInfo(info)); | 55 REPORTER_ASSERT(reporter, bm.setInfo(info)); |
20 | 56 |
21 // for a 4-byte config, this width will compute a rowbytes of 0x80000000, | 57 // for a 4-byte config, this width will compute a rowbytes of 0x80000000, |
(...skipping 17 matching lines...) Expand all Loading... |
39 bool setConf = bm.setInfo(SkImageInfo::MakeN32Premul(width, height))
; | 75 bool setConf = bm.setInfo(SkImageInfo::MakeN32Premul(width, height))
; |
40 REPORTER_ASSERT(reporter, setConf); | 76 REPORTER_ASSERT(reporter, setConf); |
41 if (setConf) { | 77 if (setConf) { |
42 REPORTER_ASSERT(reporter, bm.allocPixels(NULL)); | 78 REPORTER_ASSERT(reporter, bm.allocPixels(NULL)); |
43 } | 79 } |
44 REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty()); | 80 REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty()); |
45 } | 81 } |
46 } | 82 } |
47 | 83 |
48 test_bigwidth(reporter); | 84 test_bigwidth(reporter); |
| 85 test_allocpixels(reporter); |
49 } | 86 } |
OLD | NEW |