| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1 | #ifndef DMTaskRunner_DEFINED |
| 2 | #define DMTaskRunner_DEFINED |
| 3 | |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 4 | #include "GrContextFactory.h" |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 5 | #include "SkThreadPool.h" |
| 6 | #include "SkTypes.h" |
| 7 | |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 8 | // TaskRunner runs Tasks on one of two threadpools depending on the Task's usesGpu() method. This |
| 9 | // lets us drive the GPU from a single thread while parallelizing CPU-bound work. |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 10 | |
| 11 | namespace DM { |
| 12 | |
| 13 | class Task; |
| 14 | |
| 15 | class TaskRunner : SkNoncopyable { |
| 16 | public: |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 17 | explicit TaskRunner(int cputhreads); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 18 | |
| 19 | void add(Task* task); |
| 20 | void wait(); |
| 21 | |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 22 | // This can only be safely called from a GPU task's draw() method. |
| 23 | GrContextFactory* getGrContextFactory() const { return fGrContextFactory; } |
| 24 | |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 25 | private: |
| 26 | SkThreadPool fMain, fGpu; |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 27 | GrContextFactory* fGrContextFactory; // Created and destroyed on fGpu threadpool. |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | } // namespace DM |
| 31 | |
| 32 | #endif // DMTaskRunner_DEFINED |