commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 1 | #include "DMRecordTask.h" |
| 2 | #include "DMUtil.h" |
| 3 | #include "DMWriteTask.h" |
| 4 | #include "SkCommandLineFlags.h" |
| 5 | #include "SkRecordDraw.h" |
| 6 | #include "SkRecorder.h" |
| 7 | |
| 8 | DEFINE_bool(skr, false, "If true, run SKR tests."); |
| 9 | |
| 10 | namespace DM { |
| 11 | |
| 12 | RecordTask::RecordTask(const Task& parent, skiagm::GM* gm, SkBitmap reference) |
| 13 | : CpuTask(parent) |
| 14 | , fName(UnderJoin(parent.name().c_str(), "skr")) |
| 15 | , fGM(gm) |
| 16 | , fReference(reference) |
| 17 | {} |
| 18 | |
| 19 | void RecordTask::draw() { |
| 20 | // Record the GM into an SkRecord. |
| 21 | SkRecord record; |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame^] | 22 | SkRecorder canvas(SkRecorder::kWriteOnly_Mode, &record, |
| 23 | fReference.width(), fReference.height()); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 24 | canvas.concat(fGM->getInitialTransform()); |
| 25 | fGM->draw(&canvas); |
| 26 | |
| 27 | // Draw the SkRecord back into a bitmap. |
| 28 | SkBitmap bitmap; |
| 29 | SetupBitmap(fReference.colorType(), fGM.get(), &bitmap); |
| 30 | SkCanvas target(bitmap); |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 31 | |
| 32 | SkRecordDraw(record, &target); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 33 | |
| 34 | if (!BitmapsEqual(bitmap, fReference)) { |
| 35 | this->fail(); |
| 36 | this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | bool RecordTask::shouldSkip() const { |
| 41 | return !FLAGS_skr; |
| 42 | } |
| 43 | |
| 44 | } // namespace DM |