blob: 4f55de57d5d7e46d7ab7450aefb99ee27e11d0f4 [file] [log] [blame]
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +00001#include "DMSerializeTask.h"
2#include "DMUtil.h"
3#include "DMWriteTask.h"
4
5#include "SkCommandLineFlags.h"
6#include "SkPicture.h"
7#include "SkPixelRef.h"
8
rmistry@google.comd6bab022013-12-02 13:50:38 +00009DEFINE_bool(serialize, true, "If true, run picture serialization tests.");
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000010
11namespace DM {
12
13SerializeTask::SerializeTask(const Task& parent,
14 skiagm::GM* gm,
15 SkBitmap reference)
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000016 : CpuTask(parent)
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000017 , fName(UnderJoin(parent.name().c_str(), "serialize"))
18 , fGM(gm)
19 , fReference(reference)
20 {}
21
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000022void SerializeTask::draw() {
23 SkPicture recorded;
24 RecordPicture(fGM.get(), &recorded);
25
26 SkDynamicMemoryWStream wStream;
reed@google.com672588b2014-01-08 15:42:01 +000027 recorded.serialize(&wStream, NULL);
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000028 SkAutoTUnref<SkStream> rStream(wStream.detachAsStream());
29 SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream));
30
31 SkBitmap bitmap;
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000032 SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000033 DrawPicture(reconstructed, &bitmap);
34 if (!BitmapsEqual(bitmap, fReference)) {
35 this->fail();
36 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
37 }
38}
39
40bool SerializeTask::shouldSkip() const {
41 return !FLAGS_serialize || fGM->getFlags() & skiagm::GM::kSkipPicture_Flag;
42}
43
44} // namespace DM