2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
12 static void test_allocpixels(skiatest::Reporter* reporter) {
14 const int height = 10;
15 const SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
16 const size_t explicitRowBytes = info.minRowBytes() + 24;
20 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
22 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
25 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
27 bm.setInfo(info, explicitRowBytes);
28 REPORTER_ASSERT(reporter, explicitRowBytes == bm.rowBytes());
30 REPORTER_ASSERT(reporter, explicitRowBytes == bm.rowBytes());
32 bm.allocPixels(info, explicitRowBytes);
33 REPORTER_ASSERT(reporter, explicitRowBytes == bm.rowBytes());
37 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
39 bm.allocPixels(info, 0);
40 REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
43 bool success = bm.setInfo(info, info.minRowBytes() - 1); // invalid for 32bit
44 REPORTER_ASSERT(reporter, !success);
45 REPORTER_ASSERT(reporter, bm.isNull());
48 static void test_bigwidth(skiatest::Reporter* reporter) {
50 int width = 1 << 29; // *4 will be the high-bit of 32bit int
52 SkImageInfo info = SkImageInfo::MakeA8(width, 1);
53 REPORTER_ASSERT(reporter, bm.setInfo(info));
54 info.fColorType = kRGB_565_SkColorType;
55 REPORTER_ASSERT(reporter, bm.setInfo(info));
57 // for a 4-byte config, this width will compute a rowbytes of 0x80000000,
58 // which does not fit in a int32_t. setConfig should detect this, and fail.
60 // TODO: perhaps skia can relax this, and only require that rowBytes fit
61 // in a uint32_t (or larger), but for now this is the constraint.
63 info.fColorType = kN32_SkColorType;
64 REPORTER_ASSERT(reporter, !bm.setInfo(info));
68 * This test contains basic sanity checks concerning bitmaps.
70 DEF_TEST(Bitmap, reporter) {
71 // Zero-sized bitmaps are allowed
72 for (int width = 0; width < 2; ++width) {
73 for (int height = 0; height < 2; ++height) {
75 bool setConf = bm.setInfo(SkImageInfo::MakeN32Premul(width, height));
76 REPORTER_ASSERT(reporter, setConf);
78 REPORTER_ASSERT(reporter, bm.allocPixels(NULL));
80 REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty());
84 test_bigwidth(reporter);
85 test_allocpixels(reporter);