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 | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 5 | #include "DMGpuSupport.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 6 | #include "SkRunnable.h" |
commit-bot@chromium.org | a39874b | 2014-03-03 15:44:56 +0000 | [diff] [blame] | 7 | #include "SkTime.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 8 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 9 | // 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.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 12 | // |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 13 | // Tasks delete themselves when run. |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 14 | |
| 15 | namespace DM { |
| 16 | |
| 17 | class TaskRunner; |
| 18 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 19 | class CpuTask; |
| 20 | |
| 21 | class Task { |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 22 | public: |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 23 | virtual bool shouldSkip() const = 0; |
| 24 | virtual SkString name() const = 0; |
| 25 | |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 26 | // 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.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 30 | protected: |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 31 | Task(Reporter* reporter, TaskRunner* taskRunner); |
| 32 | Task(const Task& parent); |
| 33 | virtual ~Task() {} |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 34 | |
commit-bot@chromium.org | a39874b | 2014-03-03 15:44:56 +0000 | [diff] [blame] | 35 | void start(); |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 36 | void fail(const char* msg = NULL); |
| 37 | void finish(); |
commit-bot@chromium.org | a39874b | 2014-03-03 15:44:56 +0000 | [diff] [blame] | 38 | |
commit-bot@chromium.org | 3f03215 | 2014-05-01 17:41:32 +0000 | [diff] [blame] | 39 | void spawnChildNext(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] | 40 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 41 | private: |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 42 | Reporter* fReporter; // Unowned. |
| 43 | TaskRunner* fTaskRunner; // Unowned. |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 44 | int fDepth; |
commit-bot@chromium.org | a39874b | 2014-03-03 15:44:56 +0000 | [diff] [blame] | 45 | SkMSec fStart; |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 46 | }; |
scroggo@google.com | 1ecd9cf | 2013-11-20 16:44:59 +0000 | [diff] [blame] | 47 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 48 | class CpuTask : public Task, public SkRunnable { |
| 49 | public: |
| 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.org | b0c7156 | 2014-04-30 20:47:30 +0000 | [diff] [blame] | 56 | |
| 57 | void spawnChild(CpuTask* task); |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | class 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.org | b0c7156 | 2014-04-30 20:47:30 +0000 | [diff] [blame] | 67 | |
| 68 | void spawnChild(CpuTask* task); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace DM |
| 72 | |
| 73 | #endif // DMTask_DEFINED |