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 | |
| 16 | REPORTER_ASSERT(reporter, bm.setConfig(SkBitmap::kA8_Config, width, 1)); |
| 17 | REPORTER_ASSERT(reporter, bm.setConfig(SkBitmap::kRGB_565_Config, width, 1)); |
skia.committer@gmail.com | f5e1f63 | 2013-12-31 07:01:36 +0000 | [diff] [blame] | 18 | |
reed@google.com | 4856964 | 2013-12-30 19:21:22 +0000 | [diff] [blame] | 19 | // for a 4-byte config, this width will compute a rowbytes of 0x80000000, |
| 20 | // which does not fit in a int32_t. setConfig should detect this, and fail. |
| 21 | |
| 22 | // TODO: perhaps skia can relax this, and only require that rowBytes fit |
| 23 | // in a uint32_t (or larger), but for now this is the constraint. |
| 24 | |
| 25 | REPORTER_ASSERT(reporter, !bm.setConfig(SkBitmap::kARGB_8888_Config, width, 1)); |
| 26 | } |
| 27 | |
halcanary@google.com | 4428734 | 2013-12-13 18:29:51 +0000 | [diff] [blame] | 28 | /** |
| 29 | * This test contains basic sanity checks concerning bitmaps. |
| 30 | */ |
| 31 | DEF_TEST(Bitmap, reporter) { |
| 32 | const SkBitmap::Config conf = SkBitmap::kARGB_8888_Config; |
| 33 | // Zero-sized bitmaps are allowed |
| 34 | for (int width = 0; width < 2; ++width) { |
| 35 | for (int height = 0; height < 2; ++height) { |
| 36 | SkBitmap bm; |
| 37 | bool setConf = bm.setConfig(conf, width, height); |
| 38 | REPORTER_ASSERT(reporter, setConf); |
| 39 | if (setConf) { |
| 40 | REPORTER_ASSERT(reporter, bm.allocPixels(NULL)); |
| 41 | } |
halcanary@google.com | 2af6c12 | 2013-12-13 19:25:21 +0000 | [diff] [blame] | 42 | REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty()); |
halcanary@google.com | 4428734 | 2013-12-13 18:29:51 +0000 | [diff] [blame] | 43 | } |
| 44 | } |
skia.committer@gmail.com | f5e1f63 | 2013-12-31 07:01:36 +0000 | [diff] [blame] | 45 | |
reed@google.com | 4856964 | 2013-12-30 19:21:22 +0000 | [diff] [blame] | 46 | test_bigwidth(reporter); |
halcanary@google.com | 4428734 | 2013-12-13 18:29:51 +0000 | [diff] [blame] | 47 | } |