| Index: tests/ImageTest.cpp
|
| diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
|
| index d93815ba9c8900054f891a411faf426c83da694d..5da83429952294acaad611da34b45f1b918609d3 100644
|
| --- a/tests/ImageTest.cpp
|
| +++ b/tests/ImageTest.cpp
|
| @@ -165,3 +165,89 @@ DEF_TEST(Image_RetainSnapshot, reporter) {
|
| REPORTER_ASSERT(reporter, pixels[2] == green);
|
| REPORTER_ASSERT(reporter, pixels[3] == red);
|
| }
|
| +
|
| +/////////////////////////////////////////////////////////////////////////////////////////////////
|
| +#include "SkImageGenerator.h"
|
| +#include "SkData.h"
|
| +
|
| +const uint8_t tiny_png[] = {
|
| + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
|
| + 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x64,
|
| + 0x08, 0x06, 0x00, 0x00, 0x00, 0x70, 0xe2, 0x95, 0x54, 0x00, 0x00, 0x00,
|
| + 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00,
|
| + 0x01, 0x6b, 0x49, 0x44, 0x41, 0x54, 0x78, 0x01, 0xed, 0xd3, 0x41, 0x11,
|
| + 0x00, 0x20, 0x0c, 0xc4, 0x40, 0xc0, 0xbf, 0xe7, 0xc2, 0xa0, 0x22, 0x8f,
|
| + 0xad, 0x82, 0x4c, 0xd2, 0xdb, 0xf3, 0x6e, 0xb9, 0x8c, 0x81, 0x93, 0x21,
|
| + 0x01, 0xf2, 0x0d, 0x08, 0x12, 0x7b, 0x04, 0x41, 0x04, 0x89, 0x19, 0x88,
|
| + 0xe1, 0x58, 0x88, 0x20, 0x31, 0x03, 0x31, 0x1c, 0x0b, 0x11, 0x24, 0x66,
|
| + 0x20, 0x86, 0x63, 0x21, 0x82, 0xc4, 0x0c, 0xc4, 0x70, 0x2c, 0x44, 0x90,
|
| + 0x98, 0x81, 0x18, 0x8e, 0x85, 0x08, 0x12, 0x33, 0x10, 0xc3, 0xb1, 0x10,
|
| + 0x41, 0x62, 0x06, 0x62, 0x38, 0x16, 0x22, 0x48, 0xcc, 0x40, 0x0c, 0xc7,
|
| + 0x42, 0x04, 0x89, 0x19, 0x88, 0xe1, 0x58, 0x88, 0x20, 0x31, 0x03, 0x31,
|
| + 0x1c, 0x0b, 0x11, 0x24, 0x66, 0x20, 0x86, 0x63, 0x21, 0x82, 0xc4, 0x0c,
|
| + 0xc4, 0x70, 0x2c, 0x44, 0x90, 0x98, 0x81, 0x18, 0x8e, 0x85, 0x08, 0x12,
|
| + 0x33, 0x10, 0xc3, 0xb1, 0x10, 0x41, 0x62, 0x06, 0x62, 0x38, 0x16, 0x22,
|
| + 0x48, 0xcc, 0x40, 0x0c, 0xc7, 0x42, 0x04, 0x89, 0x19, 0x88, 0xe1, 0x58,
|
| + 0x88, 0x20, 0x31, 0x03, 0x31, 0x1c, 0x0b, 0x11, 0x24, 0x66, 0x20, 0x86,
|
| + 0x63, 0x21, 0x82, 0xc4, 0x0c, 0xc4, 0x70, 0x2c, 0x44, 0x90, 0x98, 0x81,
|
| + 0x18, 0x8e, 0x85, 0x08, 0x12, 0x33, 0x10, 0xc3, 0xb1, 0x10, 0x41, 0x62,
|
| + 0x06, 0x62, 0x38, 0x16, 0x22, 0x48, 0xcc, 0x40, 0x0c, 0xc7, 0x42, 0x04,
|
| + 0x89, 0x19, 0x88, 0xe1, 0x58, 0x88, 0x20, 0x31, 0x03, 0x31, 0x1c, 0x0b,
|
| + 0x11, 0x24, 0x66, 0x20, 0x86, 0x63, 0x21, 0x82, 0xc4, 0x0c, 0xc4, 0x70,
|
| + 0x2c, 0x44, 0x90, 0x98, 0x81, 0x18, 0x8e, 0x85, 0x08, 0x12, 0x33, 0x10,
|
| + 0xc3, 0xb1, 0x10, 0x41, 0x62, 0x06, 0x62, 0x38, 0x16, 0x22, 0x48, 0xcc,
|
| + 0x40, 0x0c, 0xc7, 0x42, 0x04, 0x89, 0x19, 0x88, 0xe1, 0x58, 0x88, 0x20,
|
| + 0x31, 0x03, 0x31, 0x1c, 0x0b, 0x11, 0x24, 0x66, 0x20, 0x86, 0x63, 0x21,
|
| + 0x82, 0xc4, 0x0c, 0xc4, 0x70, 0x2c, 0x44, 0x90, 0x98, 0x81, 0x18, 0x8e,
|
| + 0x85, 0x08, 0x12, 0x33, 0x10, 0xc3, 0xb1, 0x10, 0x41, 0x62, 0x06, 0x62,
|
| + 0x38, 0x16, 0x22, 0x48, 0xcc, 0x40, 0x0c, 0xc7, 0x42, 0x04, 0x89, 0x19,
|
| + 0x88, 0xe1, 0x58, 0x88, 0x20, 0x31, 0x03, 0x31, 0x1c, 0x0b, 0x11, 0x24,
|
| + 0x66, 0x20, 0x86, 0x63, 0x21, 0x82, 0xc4, 0x0c, 0xc4, 0x70, 0x2c, 0x44,
|
| + 0x90, 0x98, 0x81, 0x18, 0x8e, 0x85, 0x08, 0x12, 0x33, 0x10, 0xc3, 0xb1,
|
| + 0x10, 0x41, 0x62, 0x06, 0x62, 0x38, 0x16, 0x22, 0x48, 0xcc, 0x40, 0x0c,
|
| + 0xc7, 0x42, 0x62, 0x41, 0x2e, 0x08, 0x60, 0x04, 0xc4, 0x4c, 0x5d, 0x6e,
|
| + 0xf2, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60,
|
| + 0x82
|
| +};
|
| +
|
| +static void make_bitmap_lazy(SkBitmap* bm) {
|
| + SkAutoTUnref<SkData> data(SkData::NewWithoutCopy(tiny_png, sizeof(tiny_png)));
|
| + SkInstallDiscardablePixelRef(data, bm);
|
| +}
|
| +
|
| +static void make_bitmap_mutable(SkBitmap* bm) {
|
| + bm->allocN32Pixels(10, 10);
|
| +}
|
| +
|
| +static void make_bitmap_immutable(SkBitmap* bm) {
|
| + bm->allocN32Pixels(10, 10);
|
| + bm->setImmutable();
|
| +}
|
| +
|
| +DEF_TEST(image_newfrombitmap, reporter) {
|
| + const struct {
|
| + void (*fMakeProc)(SkBitmap*);
|
| + bool fExpectPeekSuccess;
|
| + bool fExpectSharedID;
|
| + } rec[] = {
|
| + { make_bitmap_lazy, false, true },
|
| + { make_bitmap_mutable, true, false },
|
| + { make_bitmap_immutable, true, true },
|
| + };
|
| +
|
| + for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
|
| + SkBitmap bm;
|
| + rec[i].fMakeProc(&bm);
|
| +
|
| + SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bm));
|
| + SkPixmap pmap;
|
| +
|
| + const bool sharedID = (image->uniqueID() == bm.getGenerationID());
|
| + REPORTER_ASSERT(reporter, sharedID == rec[i].fExpectSharedID);
|
| +
|
| +#if 0 // TODO: fix so that peek will succeed in the immutable case
|
| + const bool peekSuccess = image->peekPixels(&pmap);
|
| + REPORTER_ASSERT(reporter, peekSuccess == rec[i].fExpectPeekSuccess);
|
| +#endif
|
| + }
|
| +}
|
|
|