aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-07-08 12:46:22 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-08 12:46:23 -0700
commit3c06511e910524bf9456c532fe20d1b2956e7d97 (patch)
treea9cccf8b4fd89c8ab68f486211f8590ef28a59da /tests
parent37fffc6e8fc1d7eaff7c1d977cfbc3a7e85e7fae (diff)
Add image->bitmap
BUG=skia: patch from issue 1212163012 at patchset 1 (http://crrev.com/1212163012#ps1) Review URL: https://codereview.chromium.org/1208993017
Diffstat (limited to 'tests')
-rw-r--r--tests/SurfaceTest.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index d78498f6b9..1b57b778f6 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -407,6 +407,33 @@ static void test_image_readpixels(skiatest::Reporter* reporter, SkImage* image,
REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected));
}
+static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* image) {
+ const SkImage::LegacyBitmapMode modes[] = {
+ SkImage::kRO_LegacyBitmapMode,
+ SkImage::kRW_LegacyBitmapMode,
+ };
+ for (size_t i = 0; i < SK_ARRAY_COUNT(modes); ++i) {
+ SkBitmap bitmap;
+ REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap, modes[i]));
+
+ REPORTER_ASSERT(reporter, image->width() == bitmap.width());
+ REPORTER_ASSERT(reporter, image->height() == bitmap.height());
+ REPORTER_ASSERT(reporter, image->isOpaque() == bitmap.isOpaque());
+
+ bitmap.lockPixels();
+ REPORTER_ASSERT(reporter, bitmap.getPixels());
+
+ const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType());
+ SkPMColor imageColor;
+ REPORTER_ASSERT(reporter, image->readPixels(info, &imageColor, sizeof(SkPMColor), 0, 0));
+ REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0));
+
+ if (SkImage::kRO_LegacyBitmapMode == modes[i]) {
+ REPORTER_ASSERT(reporter, bitmap.isImmutable());
+ }
+ }
+}
+
static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* factory) {
static const struct {
ImageType fType;
@@ -450,6 +477,8 @@ static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* facto
REPORTER_ASSERT(reporter, NULL == releaseCtx.fData); // we ignored the context
}
+ test_legacy_bitmap(reporter, image);
+
const void* addr = image->peekPixels(&info, &rowBytes);
bool success = SkToBool(addr);
REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);