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" |
| 5 | #include "SkRunnable.h" |
| 6 | #include "SkThreadPool.h" |
| 7 | |
| 8 | // DM will run() these tasks on one of two threadpools, depending on the result |
| 9 | // of usesGpu(). The subclasses can call fail() to mark this task as failed, |
| 10 | // or make any number of spawnChild() calls to kick off dependent tasks. |
| 11 | // |
| 12 | // Task deletes itself when run. |
| 13 | |
| 14 | namespace DM { |
| 15 | |
| 16 | class TaskRunner; |
| 17 | |
| 18 | class Task : public SkRunnable { |
| 19 | public: |
| 20 | Task(Reporter* reporter, TaskRunner* taskRunner); |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 21 | Task(const Task& parent); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 22 | virtual ~Task(); |
| 23 | |
scroggo@google.com | 1ecd9cf | 2013-11-20 16:44:59 +0000 | [diff] [blame] | 24 | void run() SK_OVERRIDE; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 25 | |
| 26 | virtual void draw() = 0; |
| 27 | virtual bool usesGpu() const = 0; |
| 28 | virtual bool shouldSkip() const = 0; |
| 29 | virtual SkString name() const = 0; |
| 30 | |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 31 | // Returns the number of parents above this task. |
| 32 | // Top-level tasks return 0, their children 1, and so on. |
| 33 | int depth() const { return fDepth; } |
| 34 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 35 | protected: |
| 36 | void spawnChild(Task* task); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame^] | 37 | void fail(const char* msg = NULL); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 38 | |
| 39 | private: |
| 40 | // Both unowned. |
| 41 | Reporter* fReporter; |
| 42 | TaskRunner* fTaskRunner; |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 43 | int fDepth; |
scroggo@google.com | 1ecd9cf | 2013-11-20 16:44:59 +0000 | [diff] [blame] | 44 | |
| 45 | typedef SkRunnable INHERITED; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | } // namespace DM |
| 49 | |
| 50 | #endif // DMTask_DEFINED |