blob: 0167d52d02b2a261d11ff5af35cd3a84a8f12aa2 [file] [log] [blame]
halcanary@google.com44287342013-12-13 18:29:51 +00001/*
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.com44287342013-12-13 18:29:51 +000011
reed@google.com48569642013-12-30 19:21:22 +000012static 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.orgfa9e5fa2014-02-13 22:00:04 +000016 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.comf5e1f632013-12-31 07:01:36 +000021
reed@google.com48569642013-12-30 19:21:22 +000022 // 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.org757ebd22014-04-10 22:36:34 +000028 info.fColorType = kPMColor_SkColorType;
commit-bot@chromium.orgfa9e5fa2014-02-13 22:00:04 +000029 REPORTER_ASSERT(reporter, !bm.setConfig(info));
reed@google.com48569642013-12-30 19:21:22 +000030}
31
halcanary@google.com44287342013-12-13 18:29:51 +000032/**
33 * This test contains basic sanity checks concerning bitmaps.
34 */
35DEF_TEST(Bitmap, reporter) {
halcanary@google.com44287342013-12-13 18:29:51 +000036 // 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.orgfa9e5fa2014-02-13 22:00:04 +000040 bool setConf = bm.setConfig(SkImageInfo::MakeN32Premul(width,
41 height));
halcanary@google.com44287342013-12-13 18:29:51 +000042 REPORTER_ASSERT(reporter, setConf);
43 if (setConf) {
44 REPORTER_ASSERT(reporter, bm.allocPixels(NULL));
45 }
halcanary@google.com2af6c122013-12-13 19:25:21 +000046 REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty());
halcanary@google.com44287342013-12-13 18:29:51 +000047 }
48 }
skia.committer@gmail.comf5e1f632013-12-31 07:01:36 +000049
reed@google.com48569642013-12-30 19:21:22 +000050 test_bigwidth(reporter);
halcanary@google.com44287342013-12-13 18:29:51 +000051}