blob: 96cf810b2962c854ed3c548c17244873e80d3aeb [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.org787227d2014-03-26 21:26:15 +00005#include "DMGpuSupport.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00006#include "SkRunnable.h"
commit-bot@chromium.orga39874b2014-03-03 15:44:56 +00007#include "SkTime.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00008
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +00009// DM will run() these tasks on one of two threadpools.
10// Subclasses can call fail() to mark this task as failed, or make any number of spawnChild() calls
11// to kick off dependent tasks.
mtklein@google.comd36522d2013-10-16 13:02:15 +000012//
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000013// Tasks delete themselves when run.
mtklein@google.comd36522d2013-10-16 13:02:15 +000014
15namespace DM {
16
17class TaskRunner;
18
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000019class CpuTask;
20
21class Task {
mtklein@google.comd36522d2013-10-16 13:02:15 +000022public:
mtklein@google.comd36522d2013-10-16 13:02:15 +000023 virtual bool shouldSkip() const = 0;
24 virtual SkString name() const = 0;
25
rmistry@google.comd6bab022013-12-02 13:50:38 +000026 // Returns the number of parents above this task.
27 // Top-level tasks return 0, their children 1, and so on.
28 int depth() const { return fDepth; }
29
mtklein@google.comd36522d2013-10-16 13:02:15 +000030protected:
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000031 Task(Reporter* reporter, TaskRunner* taskRunner);
32 Task(const Task& parent);
33 virtual ~Task() {}
mtklein@google.comd36522d2013-10-16 13:02:15 +000034
commit-bot@chromium.orga39874b2014-03-03 15:44:56 +000035 void start();
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000036 void fail(const char* msg = NULL);
37 void finish();
commit-bot@chromium.orga39874b2014-03-03 15:44:56 +000038
commit-bot@chromium.org3f032152014-05-01 17:41:32 +000039 void spawnChildNext(CpuTask* task); // For now we don't allow GPU child tasks.
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000040
mtklein@google.comd36522d2013-10-16 13:02:15 +000041private:
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000042 Reporter* fReporter; // Unowned.
43 TaskRunner* fTaskRunner; // Unowned.
rmistry@google.comd6bab022013-12-02 13:50:38 +000044 int fDepth;
commit-bot@chromium.orga39874b2014-03-03 15:44:56 +000045 SkMSec fStart;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000046};
scroggo@google.com1ecd9cf2013-11-20 16:44:59 +000047
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000048class CpuTask : public Task, public SkRunnable {
49public:
50 CpuTask(Reporter* reporter, TaskRunner* taskRunner);
51 CpuTask(const Task& parent);
52 virtual ~CpuTask() {}
53
54 void run() SK_OVERRIDE;
55 virtual void draw() = 0;
commit-bot@chromium.orgb0c71562014-04-30 20:47:30 +000056
57 void spawnChild(CpuTask* task);
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000058};
59
60class GpuTask : public Task, public SkTRunnable<GrContextFactory> {
61 public:
62 GpuTask(Reporter* reporter, TaskRunner* taskRunner);
63 virtual ~GpuTask() {}
64
65 void run(GrContextFactory&) SK_OVERRIDE;
66 virtual void draw(GrContextFactory*) = 0;
commit-bot@chromium.orgb0c71562014-04-30 20:47:30 +000067
68 void spawnChild(CpuTask* task);
mtklein@google.comd36522d2013-10-16 13:02:15 +000069};
70
71} // namespace DM
72
73#endif // DMTask_DEFINED