mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1 | #include "DMCpuTask.h" |
| 2 | #include "DMReplayTask.h" |
| 3 | #include "DMUtil.h" |
| 4 | #include "SkCommandLineFlags.h" |
| 5 | |
| 6 | DEFINE_bool(replay, false, "If true, run replay tests for each CpuTask."); |
| 7 | // TODO(mtklein): add the other various options |
| 8 | |
| 9 | namespace DM { |
| 10 | |
| 11 | CpuTask::CpuTask(const char* name, |
| 12 | Reporter* reporter, |
| 13 | TaskRunner* taskRunner, |
| 14 | const skiagm::ExpectationsSource& expectations, |
| 15 | skiagm::GMRegistry::Factory gmFactory, |
| 16 | SkBitmap::Config config) |
| 17 | : Task(reporter, taskRunner) |
| 18 | , fGMFactory(gmFactory) |
| 19 | , fGM(fGMFactory(NULL)) |
| 20 | , fName(underJoin(fGM->shortName(), name)) |
| 21 | , fExpectations(expectations.get(png(fName).c_str())) |
| 22 | , fConfig(config) |
| 23 | {} |
| 24 | |
| 25 | void CpuTask::draw() { |
| 26 | SkBitmap bitmap; |
commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 27 | bitmap.setConfig(fConfig, SkScalarCeilToInt(fGM->width()), SkScalarCeilToInt(fGM->height())); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 28 | bitmap.allocPixels(); |
| 29 | bitmap.eraseColor(0x00000000); |
| 30 | SkCanvas canvas(bitmap); |
| 31 | |
| 32 | canvas.concat(fGM->getInitialTransform()); |
| 33 | fGM->draw(&canvas); |
| 34 | canvas.flush(); |
| 35 | |
commit-bot@chromium.org | 66bb3d1 | 2013-10-16 19:13:38 +0000 | [diff] [blame^] | 36 | if (!meetsExpectations(fExpectations, bitmap)) { |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 37 | this->fail(); |
| 38 | } |
| 39 | |
| 40 | if (FLAGS_replay) { |
| 41 | this->spawnChild(SkNEW_ARGS(ReplayTask, |
commit-bot@chromium.org | 66bb3d1 | 2013-10-16 19:13:38 +0000 | [diff] [blame^] | 42 | ("replay", *this, fGMFactory(NULL), bitmap))); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | bool CpuTask::shouldSkip() const { |
| 47 | if (SkBitmap::kRGB_565_Config == fConfig && (fGM->getFlags() & skiagm::GM::kSkip565_Flag)) { |
| 48 | return true; |
| 49 | } |
| 50 | if (fGM->getFlags() & skiagm::GM::kGPUOnly_Flag) { |
| 51 | return true; |
| 52 | } |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | } // namespace DM |