halcanary@google.com | 4428734 | 2013-12-13 18:29:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkBitmap.h" |
| 9 | |
| 10 | #include "Test.h" |
halcanary@google.com | 4428734 | 2013-12-13 18:29:51 +0000 | [diff] [blame] | 11 | |
reed@google.com | 4856964 | 2013-12-30 19:21:22 +0000 | [diff] [blame] | 12 | static void test_bigwidth(skiatest::Reporter* reporter) { |
| 13 | SkBitmap bm; |
| 14 | int width = 1 << 29; // *4 will be the high-bit of 32bit int |
| 15 | |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 16 | SkImageInfo info = SkImageInfo::Make(width, 1, kAlpha_8_SkColorType, |
| 17 | kPremul_SkAlphaType); |
| 18 | REPORTER_ASSERT(reporter, bm.setConfig(info)); |
| 19 | info.fColorType = kRGB_565_SkColorType; |
| 20 | REPORTER_ASSERT(reporter, bm.setConfig(info)); |
skia.committer@gmail.com | f5e1f63 | 2013-12-31 07:01:36 +0000 | [diff] [blame] | 21 | |
reed@google.com | 4856964 | 2013-12-30 19:21:22 +0000 | [diff] [blame] | 22 | // for a 4-byte config, this width will compute a rowbytes of 0x80000000, |
| 23 | // which does not fit in a int32_t. setConfig should detect this, and fail. |
| 24 | |
| 25 | // TODO: perhaps skia can relax this, and only require that rowBytes fit |
| 26 | // in a uint32_t (or larger), but for now this is the constraint. |
| 27 | |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 28 | info.fColorType = kN32_SkColorType; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 29 | REPORTER_ASSERT(reporter, !bm.setConfig(info)); |
reed@google.com | 4856964 | 2013-12-30 19:21:22 +0000 | [diff] [blame] | 30 | } |
| 31 | |
halcanary@google.com | 4428734 | 2013-12-13 18:29:51 +0000 | [diff] [blame] | 32 | /** |
| 33 | * This test contains basic sanity checks concerning bitmaps. |
| 34 | */ |
| 35 | DEF_TEST(Bitmap, reporter) { |
halcanary@google.com | 4428734 | 2013-12-13 18:29:51 +0000 | [diff] [blame] | 36 | // Zero-sized bitmaps are allowed |
| 37 | for (int width = 0; width < 2; ++width) { |
| 38 | for (int height = 0; height < 2; ++height) { |
| 39 | SkBitmap bm; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 40 | bool setConf = bm.setConfig(SkImageInfo::MakeN32Premul(width, |
| 41 | height)); |
halcanary@google.com | 4428734 | 2013-12-13 18:29:51 +0000 | [diff] [blame] | 42 | REPORTER_ASSERT(reporter, setConf); |
| 43 | if (setConf) { |
| 44 | REPORTER_ASSERT(reporter, bm.allocPixels(NULL)); |
| 45 | } |
halcanary@google.com | 2af6c12 | 2013-12-13 19:25:21 +0000 | [diff] [blame] | 46 | REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty()); |
halcanary@google.com | 4428734 | 2013-12-13 18:29:51 +0000 | [diff] [blame] | 47 | } |
| 48 | } |
skia.committer@gmail.com | f5e1f63 | 2013-12-31 07:01:36 +0000 | [diff] [blame] | 49 | |
reed@google.com | 4856964 | 2013-12-30 19:21:22 +0000 | [diff] [blame] | 50 | test_bigwidth(reporter); |
halcanary@google.com | 4428734 | 2013-12-13 18:29:51 +0000 | [diff] [blame] | 51 | } |