blob: 8af1b63719af1ec23d639316c7ca20c4d7471b25 [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#ifndef DMTaskRunner_DEFINED
2#define DMTaskRunner_DEFINED
3
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00004#include "GrContextFactory.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00005#include "SkThreadPool.h"
6#include "SkTypes.h"
7
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00008// 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.comd36522d2013-10-16 13:02:15 +000010
11namespace DM {
12
13class Task;
14
15class TaskRunner : SkNoncopyable {
16public:
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000017 explicit TaskRunner(int cputhreads);
mtklein@google.comd36522d2013-10-16 13:02:15 +000018
19 void add(Task* task);
20 void wait();
21
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000022 // This can only be safely called from a GPU task's draw() method.
23 GrContextFactory* getGrContextFactory() const { return fGrContextFactory; }
24
mtklein@google.comd36522d2013-10-16 13:02:15 +000025private:
26 SkThreadPool fMain, fGpu;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000027 GrContextFactory* fGrContextFactory; // Created and destroyed on fGpu threadpool.
mtklein@google.comd36522d2013-10-16 13:02:15 +000028};
29
30} // namespace DM
31
32#endif // DMTaskRunner_DEFINED