Index: tests/ImageTest.cpp |
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp |
index dd40f3608939c8d7b100908c2cd08e5d5742d433..72dc9432e39981df1fd394fd576a433cc0b75d6c 100644 |
--- a/tests/ImageTest.cpp |
+++ b/tests/ImageTest.cpp |
@@ -17,6 +17,7 @@ |
#include "SkImageEncoder.h" |
#include "SkImageGenerator.h" |
#include "SkImage_Base.h" |
+#include "SkImagePriv.h" |
#include "SkPicture.h" |
#include "SkPictureRecorder.h" |
#include "SkPixelSerializer.h" |
@@ -194,6 +195,36 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageEncode_Gpu, reporter, ctxInfo) { |
} |
#endif |
+DEF_TEST(Image_MakeFromRasterBitmap, reporter) { |
+ const struct { |
+ ForceCopyMode fMode; |
+ bool fExpectSameAsMutable; |
+ bool fExpectSameAsImmutable; |
+ } recs[] = { |
+ { kNo_ForceCopyMode, false, true }, |
+ { kYes_ForceCopyMode, false, false }, |
+ { kNever_ForceCopyMode, true, true }, |
+ }; |
+ for (auto rec : recs) { |
+ SkPixmap pm; |
+ SkBitmap bm; |
+ bm.allocN32Pixels(100, 100); |
+ |
+ auto img = SkMakeImageFromRasterBitmap(bm, rec.fMode); |
+ REPORTER_ASSERT(reporter, img->peekPixels(&pm)); |
+ const bool sameMutable = pm.addr32(0, 0) == bm.getAddr32(0, 0); |
+ REPORTER_ASSERT(reporter, rec.fExpectSameAsMutable == sameMutable); |
+ |
+ bm.notifyPixelsChanged(); // force a new generation ID |
+ |
+ bm.setImmutable(); |
+ img = SkMakeImageFromRasterBitmap(bm, rec.fMode); |
+ REPORTER_ASSERT(reporter, img->peekPixels(&pm)); |
+ const bool sameImmutable = pm.addr32(0, 0) == bm.getAddr32(0, 0); |
+ REPORTER_ASSERT(reporter, rec.fExpectSameAsImmutable == sameImmutable); |
+ } |
+} |
+ |
namespace { |
const char* kSerializedData = "serialized"; |