commit-bot@chromium.org | 2d3a789 | 2013-10-28 19:51:26 +0000 | [diff] [blame] | 1 | #include "DMPipeTask.h" |
| 2 | #include "DMUtil.h" |
| 3 | #include "DMWriteTask.h" |
| 4 | |
| 5 | #include "SamplePipeControllers.h" |
| 6 | #include "SkCommandLineFlags.h" |
| 7 | #include "SkGPipe.h" |
| 8 | |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 9 | DEFINE_bool(pipe, true, "If true, check several pipe variants against the reference bitmap."); |
commit-bot@chromium.org | 2d3a789 | 2013-10-28 19:51:26 +0000 | [diff] [blame] | 10 | |
| 11 | namespace DM { |
| 12 | |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 13 | static uint32_t get_flags(PipeTask::Mode mode) { |
commit-bot@chromium.org | 2d3a789 | 2013-10-28 19:51:26 +0000 | [diff] [blame] | 14 | uint32_t flags = 0; |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 15 | if (mode != PipeTask::kInProcess_Mode) { |
commit-bot@chromium.org | 2d3a789 | 2013-10-28 19:51:26 +0000 | [diff] [blame] | 16 | flags |= SkGPipeWriter::kCrossProcess_Flag; |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 17 | } |
| 18 | if (mode == PipeTask::kSharedAddress_Mode) { |
| 19 | flags |= SkGPipeWriter::kSharedAddressSpace_Flag; |
commit-bot@chromium.org | 2d3a789 | 2013-10-28 19:51:26 +0000 | [diff] [blame] | 20 | } |
| 21 | return flags; |
| 22 | } |
| 23 | |
| 24 | static const char* get_name(const uint32_t flags) { |
| 25 | if (flags & SkGPipeWriter::kCrossProcess_Flag && |
| 26 | flags & SkGPipeWriter::kSharedAddressSpace_Flag) { |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 27 | return "shared_address_space_pipe"; |
commit-bot@chromium.org | 2d3a789 | 2013-10-28 19:51:26 +0000 | [diff] [blame] | 28 | } else if (flags & SkGPipeWriter::kCrossProcess_Flag) { |
| 29 | return "cross_process_pipe"; |
| 30 | } else { |
| 31 | return "pipe"; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | PipeTask::PipeTask(const Task& parent, |
| 36 | skiagm::GM* gm, |
| 37 | SkBitmap reference, |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 38 | Mode mode) |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 39 | : CpuTask(parent) |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 40 | , fFlags(get_flags(mode)) |
commit-bot@chromium.org | 2d3a789 | 2013-10-28 19:51:26 +0000 | [diff] [blame] | 41 | , fName(UnderJoin(parent.name().c_str(), get_name(fFlags))) |
| 42 | , fGM(gm) |
| 43 | , fReference(reference) |
| 44 | {} |
| 45 | |
| 46 | void PipeTask::draw() { |
| 47 | SkBitmap bitmap; |
commit-bot@chromium.org | 2664207 | 2014-05-15 17:33:31 +0000 | [diff] [blame] | 48 | AllocatePixels(fReference, &bitmap); |
commit-bot@chromium.org | 2d3a789 | 2013-10-28 19:51:26 +0000 | [diff] [blame] | 49 | |
| 50 | SkCanvas canvas(bitmap); |
| 51 | PipeController pipeController(&canvas, &SkImageDecoder::DecodeMemory); |
| 52 | SkGPipeWriter writer; |
| 53 | |
| 54 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
| 55 | fFlags, |
| 56 | bitmap.width(), |
| 57 | bitmap.height()); |
| 58 | pipeCanvas->concat(fGM->getInitialTransform()); |
| 59 | fGM->draw(pipeCanvas); |
| 60 | writer.endRecording(); |
| 61 | |
| 62 | if (!BitmapsEqual(bitmap, fReference)) { |
| 63 | this->fail(); |
| 64 | this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | bool PipeTask::shouldSkip() const { |
| 69 | if (!FLAGS_pipe) { |
| 70 | return true; |
| 71 | } |
| 72 | if (fGM->getFlags() & skiagm::GM::kSkipPipe_Flag) { |
| 73 | return true; |
| 74 | } |
| 75 | if (fFlags == SkGPipeWriter::kCrossProcess_Flag && |
| 76 | fGM->getFlags() & skiagm::GM::kSkipPipeCrossProcess_Flag) { |
| 77 | return true; |
| 78 | } |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | } // namespace DM |