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 | |
| 13 | static uint32_t get_flags(bool crossProcess, bool sharedAddressSpace) { |
| 14 | SkASSERT(!(!crossProcess && sharedAddressSpace)); |
| 15 | uint32_t flags = 0; |
| 16 | if (crossProcess) { |
| 17 | flags |= SkGPipeWriter::kCrossProcess_Flag; |
| 18 | if (sharedAddressSpace) { |
| 19 | flags |= SkGPipeWriter::kSharedAddressSpace_Flag; |
| 20 | } |
| 21 | } |
| 22 | return flags; |
| 23 | } |
| 24 | |
| 25 | static const char* get_name(const uint32_t flags) { |
| 26 | if (flags & SkGPipeWriter::kCrossProcess_Flag && |
| 27 | flags & SkGPipeWriter::kSharedAddressSpace_Flag) { |
| 28 | return "cross_process_shared_address_space_pipe"; |
| 29 | } else if (flags & SkGPipeWriter::kCrossProcess_Flag) { |
| 30 | return "cross_process_pipe"; |
| 31 | } else { |
| 32 | return "pipe"; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | PipeTask::PipeTask(const Task& parent, |
| 37 | skiagm::GM* gm, |
| 38 | SkBitmap reference, |
| 39 | bool crossProcess, |
| 40 | bool sharedAddressSpace) |
| 41 | : Task(parent) |
| 42 | , fFlags(get_flags(crossProcess, sharedAddressSpace)) |
| 43 | , fName(UnderJoin(parent.name().c_str(), get_name(fFlags))) |
| 44 | , fGM(gm) |
| 45 | , fReference(reference) |
| 46 | {} |
| 47 | |
| 48 | void PipeTask::draw() { |
| 49 | SkBitmap bitmap; |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame^] | 50 | SetupBitmap(fReference.colorType(), fGM.get(), &bitmap); |
commit-bot@chromium.org | 2d3a789 | 2013-10-28 19:51:26 +0000 | [diff] [blame] | 51 | |
| 52 | SkCanvas canvas(bitmap); |
| 53 | PipeController pipeController(&canvas, &SkImageDecoder::DecodeMemory); |
| 54 | SkGPipeWriter writer; |
| 55 | |
| 56 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
| 57 | fFlags, |
| 58 | bitmap.width(), |
| 59 | bitmap.height()); |
| 60 | pipeCanvas->concat(fGM->getInitialTransform()); |
| 61 | fGM->draw(pipeCanvas); |
| 62 | writer.endRecording(); |
| 63 | |
| 64 | if (!BitmapsEqual(bitmap, fReference)) { |
| 65 | this->fail(); |
| 66 | this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | bool PipeTask::shouldSkip() const { |
| 71 | if (!FLAGS_pipe) { |
| 72 | return true; |
| 73 | } |
| 74 | if (fGM->getFlags() & skiagm::GM::kSkipPipe_Flag) { |
| 75 | return true; |
| 76 | } |
| 77 | if (fFlags == SkGPipeWriter::kCrossProcess_Flag && |
| 78 | fGM->getFlags() & skiagm::GM::kSkipPipeCrossProcess_Flag) { |
| 79 | return true; |
| 80 | } |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | } // namespace DM |