| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1 | #include "DMReplayTask.h" |
| 2 | #include "DMUtil.h" |
| 3 | |
| 4 | #include "SkPicture.h" |
| 5 | |
| 6 | namespace DM { |
| 7 | |
| 8 | ReplayTask::ReplayTask(const char* suffix, |
| 9 | const Task& parent, |
| 10 | skiagm::GM* gm, |
| 11 | skiagm::GmResultDigest reference, |
| 12 | SkBitmap::Config config) |
| 13 | : Task(parent) |
| 14 | , fName(underJoin(parent.name().c_str(), suffix)) |
| 15 | , fGM(gm) |
| 16 | , fReference(reference) |
| 17 | , fConfig(config) |
| 18 | {} |
| 19 | |
| 20 | void ReplayTask::draw() { |
| 21 | SkPicture picture; |
| commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 22 | SkCanvas* canvas = picture.beginRecording(SkScalarCeilToInt(fGM->width()), |
| 23 | SkScalarCeilToInt(fGM->height()), |
| 24 | 0 /*flags*/); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 25 | |
| 26 | canvas->concat(fGM->getInitialTransform()); |
| 27 | fGM->draw(canvas); |
| 28 | canvas->flush(); |
| 29 | |
| 30 | picture.endRecording(); |
| 31 | |
| 32 | SkBitmap bitmap; |
| commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 33 | bitmap.setConfig(fConfig, SkScalarCeilToInt(fGM->width()), SkScalarCeilToInt(fGM->height())); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 34 | bitmap.allocPixels(); |
| 35 | bitmap.eraseColor(0x00000000); |
| 36 | |
| 37 | SkCanvas replay(bitmap); |
| 38 | replay.drawPicture(picture); |
| 39 | replay.flush(); |
| 40 | |
| 41 | const skiagm::GmResultDigest replayDigest(bitmap); |
| 42 | if (!replayDigest.equals(fReference)) { |
| 43 | this->fail(); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | bool ReplayTask::shouldSkip() const { |
| 48 | return fGM->getFlags() & skiagm::GM::kGPUOnly_Flag || |
| 49 | fGM->getFlags() & skiagm::GM::kSkipPicture_Flag; |
| 50 | } |
| 51 | |
| 52 | } // namespace |