blob: 3f41b497ba6f6840c8292ebe54acf17f3e34c998 [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#ifndef DMTask_DEFINED
2#define DMTask_DEFINED
3
mtklein2460bbd2014-09-03 14:17:48 -07004#include "DMGpuSupport.h"
mtklein406654b2014-09-03 15:34:37 -07005#include "DMReporter.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00006#include "SkRunnable.h"
mtklein406654b2014-09-03 15:34:37 -07007#include "SkTaskGroup.h"
commit-bot@chromium.orga39874b2014-03-03 15:44:56 +00008#include "SkTime.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00009
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000010// DM will run() these tasks on one of two threadpools.
11// Subclasses can call fail() to mark this task as failed, or make any number of spawnChild() calls
12// to kick off dependent tasks.
mtklein@google.comd36522d2013-10-16 13:02:15 +000013//
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000014// Tasks delete themselves when run.
mtklein@google.comd36522d2013-10-16 13:02:15 +000015
16namespace DM {
17
18class TaskRunner;
19
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000020class CpuTask;
21
22class Task {
mtklein@google.comd36522d2013-10-16 13:02:15 +000023public:
mtklein@google.comd36522d2013-10-16 13:02:15 +000024 virtual bool shouldSkip() const = 0;
25 virtual SkString name() const = 0;
26
rmistry@google.comd6bab022013-12-02 13:50:38 +000027 // Returns the number of parents above this task.
28 // Top-level tasks return 0, their children 1, and so on.
29 int depth() const { return fDepth; }
30
mtklein@google.comd36522d2013-10-16 13:02:15 +000031protected:
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000032 Task(Reporter* reporter, TaskRunner* taskRunner);
33 Task(const Task& parent);
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000034 virtual ~Task();
mtklein@google.comd36522d2013-10-16 13:02:15 +000035
commit-bot@chromium.orga39874b2014-03-03 15:44:56 +000036 void start();
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000037 void fail(const char* msg = NULL);
38 void finish();
commit-bot@chromium.orga39874b2014-03-03 15:44:56 +000039
mtklein406654b2014-09-03 15:34:37 -070040 void reallySpawnChild(CpuTask* task); // For now we don't allow GPU child tasks.
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000041
mtklein@google.comd36522d2013-10-16 13:02:15 +000042private:
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000043 Reporter* fReporter; // Unowned.
44 TaskRunner* fTaskRunner; // Unowned.
rmistry@google.comd6bab022013-12-02 13:50:38 +000045 int fDepth;
commit-bot@chromium.orga39874b2014-03-03 15:44:56 +000046 SkMSec fStart;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000047};
scroggo@google.com1ecd9cf2013-11-20 16:44:59 +000048
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000049class CpuTask : public Task, public SkRunnable {
50public:
51 CpuTask(Reporter* reporter, TaskRunner* taskRunner);
52 CpuTask(const Task& parent);
53 virtual ~CpuTask() {}
54
55 void run() SK_OVERRIDE;
56 virtual void draw() = 0;
commit-bot@chromium.orgb0c71562014-04-30 20:47:30 +000057
58 void spawnChild(CpuTask* task);
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000059};
60
mtklein406654b2014-09-03 15:34:37 -070061class GpuTask : public Task {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000062 public:
63 GpuTask(Reporter* reporter, TaskRunner* taskRunner);
64 virtual ~GpuTask() {}
65
mtklein406654b2014-09-03 15:34:37 -070066 void run(GrContextFactory*);
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000067 virtual void draw(GrContextFactory*) = 0;
commit-bot@chromium.orgb0c71562014-04-30 20:47:30 +000068
69 void spawnChild(CpuTask* task);
mtklein@google.comd36522d2013-10-16 13:02:15 +000070};
71
72} // namespace DM
73
74#endif // DMTask_DEFINED