blob: aa0dabe0acfa1e625f82ae761f1802e8166cf702 [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() {
robertphillips@google.com84b18c72014-04-13 19:09:42 +000023 SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get()));
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000024
25 SkDynamicMemoryWStream wStream;
robertphillips@google.com84b18c72014-04-13 19:09:42 +000026 recorded->serialize(&wStream, NULL);
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000027 SkAutoTUnref<SkStream> rStream(wStream.detachAsStream());
28 SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream));
29
30 SkBitmap bitmap;
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000031 SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000032 DrawPicture(reconstructed, &bitmap);
33 if (!BitmapsEqual(bitmap, fReference)) {
34 this->fail();
35 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
36 }
37}
38
39bool SerializeTask::shouldSkip() const {
40 return !FLAGS_serialize || fGM->getFlags() & skiagm::GM::kSkipPicture_Flag;
41}
42
43} // namespace DM