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