blob: 163f1e64db60df6d85d4f7a392107f875fc65fc2 [file] [log] [blame]
commit-bot@chromium.org2d3a7892013-10-28 19:51:26 +00001#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.comd6bab022013-12-02 13:50:38 +00009DEFINE_bool(pipe, true, "If true, check several pipe variants against the reference bitmap.");
commit-bot@chromium.org2d3a7892013-10-28 19:51:26 +000010
11namespace DM {
12
13static 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
25static 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
36PipeTask::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
48void PipeTask::draw() {
49 SkBitmap bitmap;
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000050 SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
commit-bot@chromium.org2d3a7892013-10-28 19:51:26 +000051
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
70bool 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