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 | 93043bc | 2014-05-06 19:48:02 +0000 | [diff] [blame] | 5 | #include "SkRecord.h" |
| 6 | #include "SkRecordDraw.h" |
| 7 | #include "SkRecordOpts.h" |
| 8 | #include "SkRecorder.h" |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 9 | |
commit-bot@chromium.org | 5aacfe9 | 2014-05-02 21:23:52 +0000 | [diff] [blame] | 10 | DEFINE_bool(skr, true, "If true, run SKR tests."); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 11 | |
| 12 | namespace DM { |
| 13 | |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 14 | RecordTask::RecordTask(const Task& parent, skiagm::GM* gm, SkBitmap reference, Mode mode) |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 15 | : CpuTask(parent) |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 16 | , fOptimize(mode == kOptimize_Mode) |
| 17 | , fName(UnderJoin(parent.name().c_str(), fOptimize ? "skr" : "skr-noopt")) |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 18 | , fGM(gm) |
| 19 | , fReference(reference) |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 20 | {} |
| 21 | |
| 22 | RecordTask::RecordTask(const Task& parent, SkPicture* pic, SkBitmap reference, Mode mode) |
| 23 | : CpuTask(parent) |
| 24 | , fOptimize(mode == kOptimize_Mode) |
| 25 | , fName(UnderJoin(parent.name().c_str(), fOptimize ? "skr" : "skr-noopt")) |
| 26 | , fPicture(SkRef(pic)) |
| 27 | , fReference(reference) |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 28 | {} |
| 29 | |
| 30 | void RecordTask::draw() { |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 31 | // Record into an SkRecord. |
commit-bot@chromium.org | 93043bc | 2014-05-06 19:48:02 +0000 | [diff] [blame] | 32 | SkRecord record; |
commit-bot@chromium.org | a095041 | 2014-05-29 16:52:40 +0000 | [diff] [blame] | 33 | SkRecorder recorder(&record, fReference.width(), fReference.height()); |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 34 | |
| 35 | if (fGM.get()) { |
| 36 | recorder.concat(fGM->getInitialTransform()); |
| 37 | fGM->draw(&recorder); |
| 38 | } else { |
| 39 | fPicture->draw(&recorder); |
| 40 | } |
| 41 | |
commit-bot@chromium.org | 93043bc | 2014-05-06 19:48:02 +0000 | [diff] [blame] | 42 | |
| 43 | if (fOptimize) { |
| 44 | SkRecordOptimize(&record); |
| 45 | } |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 46 | |
| 47 | // Draw the SkRecord back into a bitmap. |
| 48 | SkBitmap bitmap; |
commit-bot@chromium.org | 2664207 | 2014-05-15 17:33:31 +0000 | [diff] [blame] | 49 | AllocatePixels(fReference, &bitmap); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 50 | SkCanvas target(bitmap); |
commit-bot@chromium.org | 93043bc | 2014-05-06 19:48:02 +0000 | [diff] [blame] | 51 | SkRecordDraw(record, &target); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 52 | |
| 53 | if (!BitmapsEqual(bitmap, fReference)) { |
| 54 | this->fail(); |
| 55 | this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | bool RecordTask::shouldSkip() const { |
| 60 | return !FLAGS_skr; |
| 61 | } |
| 62 | |
| 63 | } // namespace DM |