blob: 1ffe3ca8fda50478a78b7cb18b0d94efb5144f77 [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
mtkleinc92e5502014-08-21 13:07:27 -07009DEFINE_bool(serialize, true, "If true, run picture serialization tests via SkPictureData.");
10DEFINE_bool(serialize_skr, true, "If true, run picture serialization tests via SkRecord.");
mtklein73734562014-06-24 12:28:34 -070011
12static const char* kSuffixes[] = { "serialize", "serialize_skr" };
mtkleinc92e5502014-08-21 13:07:27 -070013static const bool* kEnabled[] = { &FLAGS_serialize, &FLAGS_serialize_skr };
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000014
15namespace DM {
16
17SerializeTask::SerializeTask(const Task& parent,
18 skiagm::GM* gm,
mtklein73734562014-06-24 12:28:34 -070019 SkBitmap reference,
20 SerializeTask::Mode mode)
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000021 : CpuTask(parent)
mtklein73734562014-06-24 12:28:34 -070022 , fMode(mode)
23 , fName(UnderJoin(parent.name().c_str(), kSuffixes[mode]))
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000024 , fGM(gm)
25 , fReference(reference)
26 {}
27
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000028void SerializeTask::draw() {
mtklein73734562014-06-24 12:28:34 -070029 SkAutoTUnref<SkPicture> recorded(
30 RecordPicture(fGM.get(), NULL/*no BBH*/, kSkRecord_Mode == fMode));
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000031
32 SkDynamicMemoryWStream wStream;
robertphillips@google.com84b18c72014-04-13 19:09:42 +000033 recorded->serialize(&wStream, NULL);
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000034 SkAutoTUnref<SkStream> rStream(wStream.detachAsStream());
35 SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream));
36
37 SkBitmap bitmap;
commit-bot@chromium.org26642072014-05-15 17:33:31 +000038 AllocatePixels(fReference, &bitmap);
mtklein73734562014-06-24 12:28:34 -070039 DrawPicture(*reconstructed, &bitmap);
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000040 if (!BitmapsEqual(bitmap, fReference)) {
41 this->fail();
42 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
43 }
44}
45
46bool SerializeTask::shouldSkip() const {
mtklein73734562014-06-24 12:28:34 -070047 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
48 return true;
49 }
50 return !*kEnabled[fMode];
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000051}
52
53} // namespace DM