blob: 316f3412c57cc38a17b41622ecf0eafa563f441a [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMCpuTask.h"
2#include "DMReplayTask.h"
3#include "DMUtil.h"
mtklein@google.coma7a9f372013-10-18 20:52:44 +00004#include "DMWriteTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00005#include "SkCommandLineFlags.h"
6
7DEFINE_bool(replay, false, "If true, run replay tests for each CpuTask.");
8// TODO(mtklein): add the other various options
9
10namespace DM {
11
12CpuTask::CpuTask(const char* name,
13 Reporter* reporter,
14 TaskRunner* taskRunner,
15 const skiagm::ExpectationsSource& expectations,
16 skiagm::GMRegistry::Factory gmFactory,
17 SkBitmap::Config config)
18 : Task(reporter, taskRunner)
19 , fGMFactory(gmFactory)
20 , fGM(fGMFactory(NULL))
21 , fName(underJoin(fGM->shortName(), name))
22 , fExpectations(expectations.get(png(fName).c_str()))
23 , fConfig(config)
24 {}
25
26void CpuTask::draw() {
27 SkBitmap bitmap;
commit-bot@chromium.org846872f2013-10-16 18:21:03 +000028 bitmap.setConfig(fConfig, SkScalarCeilToInt(fGM->width()), SkScalarCeilToInt(fGM->height()));
mtklein@google.comd36522d2013-10-16 13:02:15 +000029 bitmap.allocPixels();
30 bitmap.eraseColor(0x00000000);
31 SkCanvas canvas(bitmap);
32
33 canvas.concat(fGM->getInitialTransform());
34 fGM->draw(&canvas);
35 canvas.flush();
36
commit-bot@chromium.org66bb3d12013-10-16 19:13:38 +000037 if (!meetsExpectations(fExpectations, bitmap)) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000038 this->fail();
39 }
40
41 if (FLAGS_replay) {
42 this->spawnChild(SkNEW_ARGS(ReplayTask,
commit-bot@chromium.org66bb3d12013-10-16 19:13:38 +000043 ("replay", *this, fGMFactory(NULL), bitmap)));
mtklein@google.comd36522d2013-10-16 13:02:15 +000044 }
mtklein@google.coma7a9f372013-10-18 20:52:44 +000045 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
mtklein@google.comd36522d2013-10-16 13:02:15 +000046}
47
48bool CpuTask::shouldSkip() const {
49 if (SkBitmap::kRGB_565_Config == fConfig && (fGM->getFlags() & skiagm::GM::kSkip565_Flag)) {
50 return true;
51 }
52 if (fGM->getFlags() & skiagm::GM::kGPUOnly_Flag) {
53 return true;
54 }
55 return false;
56}
57
58} // namespace DM