blob: 0d3ef74cc37c518b2c7a96f571ddae9b511b65ff [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#ifndef DMTask_DEFINED
2#define DMTask_DEFINED
3
4#include "DMReporter.h"
5#include "SkRunnable.h"
6#include "SkThreadPool.h"
7
8// DM will run() these tasks on one of two threadpools, depending on the result
9// of usesGpu(). The subclasses can call fail() to mark this task as failed,
10// or make any number of spawnChild() calls to kick off dependent tasks.
11//
12// Task deletes itself when run.
13
14namespace DM {
15
16class TaskRunner;
17
18class Task : public SkRunnable {
19public:
20 Task(Reporter* reporter, TaskRunner* taskRunner);
mtklein@google.comca5bb872013-11-26 22:06:12 +000021 Task(const Task& parent);
mtklein@google.comd36522d2013-10-16 13:02:15 +000022 virtual ~Task();
23
scroggo@google.com1ecd9cf2013-11-20 16:44:59 +000024 void run() SK_OVERRIDE;
mtklein@google.comd36522d2013-10-16 13:02:15 +000025
26 virtual void draw() = 0;
27 virtual bool usesGpu() const = 0;
28 virtual bool shouldSkip() const = 0;
29 virtual SkString name() const = 0;
30
mtklein@google.comca5bb872013-11-26 22:06:12 +000031 // Returns the number of parents above this task.
32 // Top-level tasks return 0, their children 1, and so on.
33 int depth() const { return fDepth; }
34
mtklein@google.comd36522d2013-10-16 13:02:15 +000035protected:
36 void spawnChild(Task* task);
37 void fail();
38
39private:
40 // Both unowned.
41 Reporter* fReporter;
42 TaskRunner* fTaskRunner;
mtklein@google.comca5bb872013-11-26 22:06:12 +000043 int fDepth;
scroggo@google.com1ecd9cf2013-11-20 16:44:59 +000044
45 typedef SkRunnable INHERITED;
mtklein@google.comd36522d2013-10-16 13:02:15 +000046};
47
48} // namespace DM
49
50#endif // DMTask_DEFINED