blob: 2f009f067028532e9fbf954164d9c489726feb97 [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMTask.h"
2
3#include "DMTaskRunner.h"
4#include "DMUtil.h"
5#include "SkBitmap.h"
6#include "SkCommandLineFlags.h"
7
8namespace DM {
9
10Task::Task(Reporter* reporter, TaskRunner* taskRunner)
rmistry@google.comd6bab022013-12-02 13:50:38 +000011 : fReporter(reporter), fTaskRunner(taskRunner), fDepth(0) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000012 fReporter->start();
13}
14
rmistry@google.comd6bab022013-12-02 13:50:38 +000015Task::Task(const Task& parent)
16 : INHERITED(parent)
17 , fReporter(parent.fReporter)
18 , fTaskRunner(parent.fTaskRunner)
19 , fDepth(parent.depth()+1) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000020 fReporter->start();
21}
22
23Task::~Task() {}
24
25void Task::run() {
26 if (!this->shouldSkip()) {
27 this->draw();
28 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000029 fReporter->finish(this->name());
mtklein@google.comd36522d2013-10-16 13:02:15 +000030 delete this;
31}
32
33void Task::spawnChild(Task* task) {
34 if (!task->usesGpu()) {
35 fTaskRunner->add(task);
36 } else {
37 SkDEBUGFAIL("Sorry, we can't spawn GPU tasks. :( See comment in TaskRunner::wait().");
38 }
39}
40
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000041void Task::fail(const char* msg) {
42 SkString failure(this->name());
43 if (msg) {
44 failure.appendf(": %s", msg);
45 }
46 fReporter->fail(failure);
mtklein@google.comd36522d2013-10-16 13:02:15 +000047}
48
49} // namespace DM