From f0aed97aec3fa1c7f6460d8d6327358f3dcbabe6 Mon Sep 17 00:00:00 2001 From: reed Date: Tue, 1 Jul 2014 12:48:11 -0700 Subject: correctly plumb through explicit rowbytes for allocPixels BUG=skia: R=caryclark@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/357073003 --- tests/BitmapTest.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/BitmapTest.cpp') diff --git a/tests/BitmapTest.cpp b/tests/BitmapTest.cpp index ef560aa6d6..42ed8841b4 100644 --- a/tests/BitmapTest.cpp +++ b/tests/BitmapTest.cpp @@ -9,6 +9,42 @@ #include "Test.h" +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()); +} + static void test_bigwidth(skiatest::Reporter* reporter) { SkBitmap bm; int width = 1 << 29; // *4 will be the high-bit of 32bit int @@ -46,4 +82,5 @@ DEF_TEST(Bitmap, reporter) { } test_bigwidth(reporter); + test_allocpixels(reporter); } -- cgit v1.2.3