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