blob: a3e2503c6d52e407d66758588800dd0fbe87b803 [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
mtkleina9ceaf52014-09-29 08:44:46 -07009DEFINE_bool(serialize, true, "If true, run picture serialization tests via SkPictureData.");
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000010
11namespace DM {
12
mtkleina9ceaf52014-09-29 08:44:46 -070013SerializeTask::SerializeTask(const Task& parent, skiagm::GM* gm, SkBitmap reference)
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000014 : CpuTask(parent)
mtkleina9ceaf52014-09-29 08:44:46 -070015 , fName(UnderJoin(parent.name().c_str(), "serialize"))
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000016 , fGM(gm)
17 , fReference(reference)
18 {}
19
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000020void SerializeTask::draw() {
mtkleina9ceaf52014-09-29 08:44:46 -070021 SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get(), NULL/*no BBH*/));
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000022
23 SkDynamicMemoryWStream wStream;
scroggo895c43b2014-12-11 10:53:58 -080024 recorded->serialize(&wStream);
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000025 SkAutoTUnref<SkStream> rStream(wStream.detachAsStream());
26 SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream));
27
28 SkBitmap bitmap;
commit-bot@chromium.org26642072014-05-15 17:33:31 +000029 AllocatePixels(fReference, &bitmap);
mtklein73734562014-06-24 12:28:34 -070030 DrawPicture(*reconstructed, &bitmap);
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000031 if (!BitmapsEqual(bitmap, fReference)) {
32 this->fail();
mtkleinea65bfa2014-09-09 07:59:46 -070033 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "GM", bitmap)));
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000034 }
35}
36
37bool SerializeTask::shouldSkip() const {
mtklein73734562014-06-24 12:28:34 -070038 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
39 return true;
40 }
mtkleina9ceaf52014-09-29 08:44:46 -070041 return !FLAGS_serialize;
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000042}
43
44} // namespace DM