• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.");
10 
11 namespace DM {
12 
SerializeTask(const Task & parent,skiagm::GM * gm,SkBitmap reference)13 SerializeTask::SerializeTask(const Task& parent,
14                              skiagm::GM* gm,
15                              SkBitmap reference)
16     : CpuTask(parent)
17     , fName(UnderJoin(parent.name().c_str(), "serialize"))
18     , fGM(gm)
19     , fReference(reference)
20     {}
21 
draw()22 void SerializeTask::draw() {
23     SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get()));
24 
25     SkDynamicMemoryWStream wStream;
26     recorded->serialize(&wStream, NULL);
27     SkAutoTUnref<SkStream> rStream(wStream.detachAsStream());
28     SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream));
29 
30     SkBitmap bitmap;
31     AllocatePixels(fReference, &bitmap);
32     DrawPicture(reconstructed, &bitmap);
33     if (!BitmapsEqual(bitmap, fReference)) {
34         this->fail();
35         this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
36     }
37 }
38 
shouldSkip() const39 bool SerializeTask::shouldSkip() const {
40     return !FLAGS_serialize || fGM->getFlags() & skiagm::GM::kSkipPicture_Flag;
41 }
42 
43 }  // namespace DM
44