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

Unified Diff: dm/DMSerializeTask.cpp

Issue 32613003: DM: add --serialize (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: no-find-copies Created 7 years, 2 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 | « dm/DMSerializeTask.h ('k') | dm/DMUtil.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DMSerializeTask.cpp
diff --git a/dm/DMSerializeTask.cpp b/dm/DMSerializeTask.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d71dfdccfa2e03cc681716b66bb32dbba547648f
--- /dev/null
+++ b/dm/DMSerializeTask.cpp
@@ -0,0 +1,53 @@
+#include "DMSerializeTask.h"
+#include "DMUtil.h"
+#include "DMWriteTask.h"
+
+#include "SkCommandLineFlags.h"
+#include "SkPicture.h"
+#include "SkPixelRef.h"
+
+DEFINE_bool(serialize, false, "If true, run picture serialization tests.");
+
+namespace DM {
+
+SerializeTask::SerializeTask(const Task& parent,
+ skiagm::GM* gm,
+ SkBitmap reference)
+ : Task(parent)
+ , fName(UnderJoin(parent.name().c_str(), "serialize"))
+ , fGM(gm)
+ , fReference(reference)
+ {}
+
+static SkData* trivial_bitmap_encoder(size_t* pixelRefOffset, const SkBitmap& bitmap) {
+ if (NULL == bitmap.pixelRef()) {
+ return NULL;
+ }
+ SkData* data = bitmap.pixelRef()->refEncodedData();
+ *pixelRefOffset = bitmap.pixelRefOffset();
+ return data;
+}
+
+void SerializeTask::draw() {
+ SkPicture recorded;
+ RecordPicture(fGM.get(), &recorded);
+
+ SkDynamicMemoryWStream wStream;
+ recorded.serialize(&wStream, &trivial_bitmap_encoder);
+ SkAutoTUnref<SkStream> rStream(wStream.detachAsStream());
+ SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream));
+
+ SkBitmap bitmap;
+ SetupBitmap(fReference.config(), fGM.get(), &bitmap);
+ DrawPicture(reconstructed, &bitmap);
+ if (!BitmapsEqual(bitmap, fReference)) {
+ this->fail();
+ this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
+ }
+}
+
+bool SerializeTask::shouldSkip() const {
+ return !FLAGS_serialize || fGM->getFlags() & skiagm::GM::kSkipPicture_Flag;
+}
+
+} // namespace DM
« no previous file with comments | « dm/DMSerializeTask.h ('k') | dm/DMUtil.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698