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."); |
mtklein | 7373456 | 2014-06-24 12:28:34 -0700 | [diff] [blame] | 10 | DECLARE_bool(skr); // in DMReplayTask.cpp |
| 11 | |
| 12 | static const char* kSuffixes[] = { "serialize", "serialize_skr" }; |
| 13 | static const bool* kEnabled[] = { &FLAGS_serialize, &FLAGS_skr }; |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 14 | |
| 15 | namespace DM { |
| 16 | |
| 17 | SerializeTask::SerializeTask(const Task& parent, |
| 18 | skiagm::GM* gm, |
mtklein | 7373456 | 2014-06-24 12:28:34 -0700 | [diff] [blame] | 19 | SkBitmap reference, |
| 20 | SerializeTask::Mode mode) |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 21 | : CpuTask(parent) |
mtklein | 7373456 | 2014-06-24 12:28:34 -0700 | [diff] [blame] | 22 | , fMode(mode) |
| 23 | , fName(UnderJoin(parent.name().c_str(), kSuffixes[mode])) |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 24 | , fGM(gm) |
| 25 | , fReference(reference) |
| 26 | {} |
| 27 | |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 28 | void SerializeTask::draw() { |
mtklein | 7373456 | 2014-06-24 12:28:34 -0700 | [diff] [blame] | 29 | SkAutoTUnref<SkPicture> recorded( |
| 30 | RecordPicture(fGM.get(), NULL/*no BBH*/, kSkRecord_Mode == fMode)); |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 31 | |
| 32 | SkDynamicMemoryWStream wStream; |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 33 | recorded->serialize(&wStream, NULL); |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 34 | SkAutoTUnref<SkStream> rStream(wStream.detachAsStream()); |
| 35 | SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream)); |
| 36 | |
| 37 | SkBitmap bitmap; |
commit-bot@chromium.org | 2664207 | 2014-05-15 17:33:31 +0000 | [diff] [blame] | 38 | AllocatePixels(fReference, &bitmap); |
mtklein | 7373456 | 2014-06-24 12:28:34 -0700 | [diff] [blame] | 39 | DrawPicture(*reconstructed, &bitmap); |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 40 | if (!BitmapsEqual(bitmap, fReference)) { |
| 41 | this->fail(); |
| 42 | this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | bool SerializeTask::shouldSkip() const { |
mtklein | 7373456 | 2014-06-24 12:28:34 -0700 | [diff] [blame] | 47 | if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) { |
| 48 | return true; |
| 49 | } |
| 50 | return !*kEnabled[fMode]; |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | } // namespace DM |