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" |
commit-bot@chromium.org | b17a24f | 2014-04-14 20:33:05 +0000 | [diff] [blame^] | 5 | #include "SkRecording.h" |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 6 | |
| 7 | DEFINE_bool(skr, false, "If true, run SKR tests."); |
| 8 | |
| 9 | namespace DM { |
| 10 | |
| 11 | RecordTask::RecordTask(const Task& parent, skiagm::GM* gm, SkBitmap reference) |
| 12 | : CpuTask(parent) |
| 13 | , fName(UnderJoin(parent.name().c_str(), "skr")) |
| 14 | , fGM(gm) |
| 15 | , fReference(reference) |
| 16 | {} |
| 17 | |
| 18 | void RecordTask::draw() { |
commit-bot@chromium.org | b17a24f | 2014-04-14 20:33:05 +0000 | [diff] [blame^] | 19 | using EXPERIMENTAL::SkRecording; |
| 20 | using EXPERIMENTAL::SkPlayback; |
| 21 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 22 | // Record the GM into an SkRecord. |
commit-bot@chromium.org | b17a24f | 2014-04-14 20:33:05 +0000 | [diff] [blame^] | 23 | SkRecording* recording = SkRecording::Create(fReference.width(), fReference.height()); |
| 24 | fGM->draw(recording->canvas()); |
| 25 | SkAutoTDelete<const SkPlayback> playback(SkRecording::Delete(recording)); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 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 | b17a24f | 2014-04-14 20:33:05 +0000 | [diff] [blame^] | 31 | playback->draw(&target); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 32 | |
| 33 | if (!BitmapsEqual(bitmap, fReference)) { |
| 34 | this->fail(); |
| 35 | this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | bool RecordTask::shouldSkip() const { |
| 40 | return !FLAGS_skr; |
| 41 | } |
| 42 | |
| 43 | } // namespace DM |