Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(758)

Unified Diff: tests/ImageTest.cpp

Issue 1310633006: Add a SkPixelSerializer SkImage encode variant (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: moar comment tweaks Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkImage.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageTest.cpp
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index bbf6682084b4e6c4cf6f2c6d123e9790d60db6f0..d271966979a036325841658011bf5ca18e706edc 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -10,6 +10,7 @@
#include "SkDevice.h"
#include "SkImageEncoder.h"
#include "SkImage_Base.h"
+#include "SkPixelSerializer.h"
#include "SkRRect.h"
#include "SkSurface.h"
#include "SkUtils.h"
@@ -104,6 +105,36 @@ DEF_GPUTEST(Image_Encode_Gpu, reporter, factory) {
}
#endif
+namespace {
+
+const char* kSerializedData = "serialized";
+
+class MockSerializer : public SkPixelSerializer {
+protected:
+ bool onUseEncodedData(const void*, size_t) override {
+ return false;
+ }
+
+ SkData* onEncodePixels(const SkImageInfo&, const void*, size_t) override {
+ return SkData::NewWithCString(kSerializedData);
+ }
+};
+
+} // anonymous namespace
+
+// Test that SkImage encoding observes custom pixel serializers.
+DEF_TEST(Image_Encode_Serializer, reporter) {
+ MockSerializer serializer;
+ const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10);
+ SkAutoTUnref<SkImage> image(make_image(nullptr, 20, 20, ir));
+ SkAutoTUnref<SkData> encoded(image->encode(&serializer));
+ SkAutoTUnref<SkData> reference(SkData::NewWithCString(kSerializedData));
+
+ REPORTER_ASSERT(reporter, encoded);
+ REPORTER_ASSERT(reporter, encoded->size() > 0);
+ REPORTER_ASSERT(reporter, encoded->equals(reference));
+}
+
DEF_TEST(Image_NewRasterCopy, reporter) {
const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0);
const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0);
« no previous file with comments | « src/image/SkImage.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698