OLD | NEW |
| (Empty) |
1 #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 | |
9 DEFINE_bool(serialize, true, "If true, run picture serialization tests via SkPic
tureData."); | |
10 | |
11 namespace DM { | |
12 | |
13 SerializeTask::SerializeTask(const Task& parent, skiagm::GM* gm, SkBitmap refere
nce) | |
14 : CpuTask(parent) | |
15 , fName(UnderJoin(parent.name().c_str(), "serialize")) | |
16 , fGM(gm) | |
17 , fReference(reference) | |
18 {} | |
19 | |
20 void SerializeTask::draw() { | |
21 SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get(), NULL/*no BBH*/)); | |
22 | |
23 SkDynamicMemoryWStream wStream; | |
24 recorded->serialize(&wStream); | |
25 SkAutoTUnref<SkStream> rStream(wStream.detachAsStream()); | |
26 SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream)); | |
27 | |
28 SkBitmap bitmap; | |
29 AllocatePixels(fReference, &bitmap); | |
30 DrawPicture(*reconstructed, &bitmap); | |
31 if (!BitmapsEqual(bitmap, fReference)) { | |
32 this->fail(); | |
33 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "GM", bitmap))); | |
34 } | |
35 } | |
36 | |
37 bool SerializeTask::shouldSkip() const { | |
38 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) { | |
39 return true; | |
40 } | |
41 return !FLAGS_serialize; | |
42 } | |
43 | |
44 } // namespace DM | |
OLD | NEW |