blob: bd53ce615a61134271a1751add333c4eec480ff6 [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMTaskRunner.h"
2#include "DMTask.h"
3
4namespace DM {
5
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00006
7TaskRunner::TaskRunner(int cputhreads)
mtklein@google.comd36522d2013-10-16 13:02:15 +00008 : fMain(cputhreads)
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00009 , fGpu(1) {
10 // Enqueue a task on the GPU thread to create a GrContextFactory.
11 struct Create : public SkRunnable {
12 Create(GrContextFactory** ptr) : fPtr(ptr) {}
13 void run() SK_OVERRIDE {
14 *fPtr = SkNEW(GrContextFactory);
15 delete this;
16 }
17 GrContextFactory** fPtr;
18 };
19 fGpu.add(SkNEW_ARGS(Create, (&fGrContextFactory)));
20}
mtklein@google.comd36522d2013-10-16 13:02:15 +000021
22void TaskRunner::add(Task* task) {
23 if (task->usesGpu()) {
24 fGpu.add(task);
25 } else {
26 fMain.add(task);
27 }
28}
29
30void TaskRunner::wait() {
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000031 // Enqueue a task on the GPU thread to destroy the GrContextFactory.
32 struct Delete : public SkRunnable {
33 Delete(GrContextFactory* ptr) : fPtr(ptr) {}
34 void run() SK_OVERRIDE {
35 delete fPtr;
36 delete this;
37 }
38 GrContextFactory* fPtr;
39 };
40 fGpu.add(SkNEW_ARGS(Delete, (fGrContextFactory)));
41
mtklein@google.comd36522d2013-10-16 13:02:15 +000042 // These wait calls block until the threadpool is done. We don't allow
43 // children to spawn new GPU tasks so we can wait for that first knowing
44 // we'll never try to add to it later. Same can't be said of fMain: fGpu
45 // and fMain can both add tasks to fMain, so we have to wait for that last.
46 fGpu.wait();
47 fMain.wait();
48}
49
50} // namespace DM