blob: cad8234c05b5047c3c31ddff642d2ab7c210c9cf [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#ifndef DMTask_DEFINED
2#define DMTask_DEFINED
3
4#include "DMReporter.h"
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00005#include "GrContextFactory.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00006#include "SkRunnable.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00007
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +00008// DM will run() these tasks on one of two threadpools.
9// Subclasses can call fail() to mark this task as failed, or make any number of spawnChild() calls
10// to kick off dependent tasks.
mtklein@google.comd36522d2013-10-16 13:02:15 +000011//
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000012// Tasks delete themselves when run.
mtklein@google.comd36522d2013-10-16 13:02:15 +000013
14namespace DM {
15
16class TaskRunner;
17
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000018class CpuTask;
19
20class Task {
mtklein@google.comd36522d2013-10-16 13:02:15 +000021public:
mtklein@google.comd36522d2013-10-16 13:02:15 +000022 virtual bool shouldSkip() const = 0;
23 virtual SkString name() const = 0;
24
rmistry@google.comd6bab022013-12-02 13:50:38 +000025 // Returns the number of parents above this task.
26 // Top-level tasks return 0, their children 1, and so on.
27 int depth() const { return fDepth; }
28
mtklein@google.comd36522d2013-10-16 13:02:15 +000029protected:
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000030 Task(Reporter* reporter, TaskRunner* taskRunner);
31 Task(const Task& parent);
32 virtual ~Task() {}
mtklein@google.comd36522d2013-10-16 13:02:15 +000033
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000034 void fail(const char* msg = NULL);
35 void finish();
36 void spawnChild(CpuTask* task); // For now we don't allow GPU child tasks.
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000037
mtklein@google.comd36522d2013-10-16 13:02:15 +000038private:
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000039 Reporter* fReporter; // Unowned.
40 TaskRunner* fTaskRunner; // Unowned.
rmistry@google.comd6bab022013-12-02 13:50:38 +000041 int fDepth;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000042};
scroggo@google.com1ecd9cf2013-11-20 16:44:59 +000043
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000044class CpuTask : public Task, public SkRunnable {
45public:
46 CpuTask(Reporter* reporter, TaskRunner* taskRunner);
47 CpuTask(const Task& parent);
48 virtual ~CpuTask() {}
49
50 void run() SK_OVERRIDE;
51 virtual void draw() = 0;
52};
53
54class GpuTask : public Task, public SkTRunnable<GrContextFactory> {
55 public:
56 GpuTask(Reporter* reporter, TaskRunner* taskRunner);
57 virtual ~GpuTask() {}
58
59 void run(GrContextFactory&) SK_OVERRIDE;
60 virtual void draw(GrContextFactory*) = 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +000061};
62
63} // namespace DM
64
65#endif // DMTask_DEFINED