commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 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 | |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 9 | DEFINE_bool(serialize, true, "If true, run picture serialization tests."); |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 10 | |
| 11 | namespace DM { |
| 12 | |
| 13 | SerializeTask::SerializeTask(const Task& parent, |
| 14 | skiagm::GM* gm, |
| 15 | SkBitmap reference) |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 16 | : CpuTask(parent) |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 17 | , fName(UnderJoin(parent.name().c_str(), "serialize")) |
| 18 | , fGM(gm) |
| 19 | , fReference(reference) |
| 20 | {} |
| 21 | |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 22 | void SerializeTask::draw() { |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 23 | SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get())); |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 24 | |
| 25 | SkDynamicMemoryWStream wStream; |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 26 | recorded->serialize(&wStream, NULL); |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 27 | SkAutoTUnref<SkStream> rStream(wStream.detachAsStream()); |
| 28 | SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream)); |
| 29 | |
| 30 | SkBitmap bitmap; |
commit-bot@chromium.org | 2664207 | 2014-05-15 17:33:31 +0000 | [diff] [blame] | 31 | AllocatePixels(fReference, &bitmap); |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 32 | DrawPicture(reconstructed, &bitmap); |
| 33 | if (!BitmapsEqual(bitmap, fReference)) { |
| 34 | this->fail(); |
| 35 | this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | bool SerializeTask::shouldSkip() const { |
| 40 | return !FLAGS_serialize || fGM->getFlags() & skiagm::GM::kSkipPicture_Flag; |
| 41 | } |
| 42 | |
| 43 | } // namespace DM |