2013-12-13 18:29:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkBitmap.h"
|
|
|
|
|
|
|
|
#include "Test.h"
|
|
|
|
|
2014-07-01 19:48:11 +00:00
|
|
|
static void test_allocpixels(skiatest::Reporter* reporter) {
|
|
|
|
const int width = 10;
|
|
|
|
const int height = 10;
|
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
|
|
|
const size_t explicitRowBytes = info.minRowBytes() + 24;
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.setInfo(info);
|
|
|
|
REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
|
|
|
|
bm.allocPixels();
|
|
|
|
REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
|
|
|
|
bm.reset();
|
|
|
|
bm.allocPixels(info);
|
|
|
|
REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
|
|
|
|
|
|
|
|
bm.setInfo(info, explicitRowBytes);
|
|
|
|
REPORTER_ASSERT(reporter, explicitRowBytes == bm.rowBytes());
|
|
|
|
bm.allocPixels();
|
|
|
|
REPORTER_ASSERT(reporter, explicitRowBytes == bm.rowBytes());
|
|
|
|
bm.reset();
|
|
|
|
bm.allocPixels(info, explicitRowBytes);
|
|
|
|
REPORTER_ASSERT(reporter, explicitRowBytes == bm.rowBytes());
|
|
|
|
|
|
|
|
bm.reset();
|
|
|
|
bm.setInfo(info, 0);
|
|
|
|
REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
|
|
|
|
bm.reset();
|
|
|
|
bm.allocPixels(info, 0);
|
|
|
|
REPORTER_ASSERT(reporter, info.minRowBytes() == bm.rowBytes());
|
|
|
|
|
|
|
|
bm.reset();
|
|
|
|
bool success = bm.setInfo(info, info.minRowBytes() - 1); // invalid for 32bit
|
|
|
|
REPORTER_ASSERT(reporter, !success);
|
|
|
|
REPORTER_ASSERT(reporter, bm.isNull());
|
|
|
|
}
|
|
|
|
|
2013-12-30 19:21:22 +00:00
|
|
|
static void test_bigwidth(skiatest::Reporter* reporter) {
|
|
|
|
SkBitmap bm;
|
|
|
|
int width = 1 << 29; // *4 will be the high-bit of 32bit int
|
|
|
|
|
2014-05-30 13:26:10 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeA8(width, 1);
|
|
|
|
REPORTER_ASSERT(reporter, bm.setInfo(info));
|
2014-02-13 22:00:04 +00:00
|
|
|
info.fColorType = kRGB_565_SkColorType;
|
2014-05-30 13:26:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, bm.setInfo(info));
|
2013-12-31 07:01:36 +00:00
|
|
|
|
2013-12-30 19:21:22 +00:00
|
|
|
// for a 4-byte config, this width will compute a rowbytes of 0x80000000,
|
|
|
|
// which does not fit in a int32_t. setConfig should detect this, and fail.
|
|
|
|
|
|
|
|
// TODO: perhaps skia can relax this, and only require that rowBytes fit
|
|
|
|
// in a uint32_t (or larger), but for now this is the constraint.
|
|
|
|
|
2014-04-11 17:15:40 +00:00
|
|
|
info.fColorType = kN32_SkColorType;
|
2014-05-30 13:26:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, !bm.setInfo(info));
|
2013-12-30 19:21:22 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 18:29:51 +00:00
|
|
|
/**
|
|
|
|
* This test contains basic sanity checks concerning bitmaps.
|
|
|
|
*/
|
|
|
|
DEF_TEST(Bitmap, reporter) {
|
|
|
|
// Zero-sized bitmaps are allowed
|
|
|
|
for (int width = 0; width < 2; ++width) {
|
|
|
|
for (int height = 0; height < 2; ++height) {
|
|
|
|
SkBitmap bm;
|
2014-05-30 13:26:10 +00:00
|
|
|
bool setConf = bm.setInfo(SkImageInfo::MakeN32Premul(width, height));
|
2013-12-13 18:29:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, setConf);
|
|
|
|
if (setConf) {
|
|
|
|
REPORTER_ASSERT(reporter, bm.allocPixels(NULL));
|
|
|
|
}
|
2013-12-13 19:25:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty());
|
2013-12-13 18:29:51 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-31 07:01:36 +00:00
|
|
|
|
2013-12-30 19:21:22 +00:00
|
|
|
test_bigwidth(reporter);
|
2014-07-01 19:48:11 +00:00
|
|
|
test_allocpixels(reporter);
|
2013-12-13 18:29:51 +00:00
|
|
|
}
|