| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1 | #ifndef DMTask_DEFINED |
| 2 | #define DMTask_DEFINED |
| 3 | |
| 4 | #include "DMReporter.h" |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 5 | #include "GrContextFactory.h" |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 6 | #include "SkRunnable.h" |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 7 | |
| commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame^] | 8 | // 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.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 11 | // |
| commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame^] | 12 | // Tasks delete themselves when run. |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 13 | |
| 14 | namespace DM { |
| 15 | |
| 16 | class TaskRunner; |
| 17 | |
| commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame^] | 18 | class CpuTask; |
| 19 | |
| 20 | class Task { |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 21 | public: |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 22 | virtual bool shouldSkip() const = 0; |
| 23 | virtual SkString name() const = 0; |
| 24 | |
| rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 25 | // 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.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 29 | protected: |
| commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame^] | 30 | Task(Reporter* reporter, TaskRunner* taskRunner); |
| 31 | Task(const Task& parent); |
| 32 | virtual ~Task() {} |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 33 | |
| commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame^] | 34 | 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.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 37 | |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 38 | private: |
| commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame^] | 39 | Reporter* fReporter; // Unowned. |
| 40 | TaskRunner* fTaskRunner; // Unowned. |
| rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 41 | int fDepth; |
| commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame^] | 42 | }; |
| scroggo@google.com | 1ecd9cf | 2013-11-20 16:44:59 +0000 | [diff] [blame] | 43 | |
| commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame^] | 44 | class CpuTask : public Task, public SkRunnable { |
| 45 | public: |
| 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 | |
| 54 | class 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.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } // namespace DM |
| 64 | |
| 65 | #endif // DMTask_DEFINED |