| OLD | NEW |
| 1 #include "DMTaskRunner.h" | 1 #include "DMTaskRunner.h" |
| 2 #include "DMTask.h" | 2 #include "DMTask.h" |
| 3 | 3 |
| 4 namespace DM { | 4 namespace DM { |
| 5 | 5 |
| 6 TaskRunner::TaskRunner(int cpuThreads, int gpuThreads) : fCpu(cpuThreads), fGpu(
gpuThreads) {} |
| 6 | 7 |
| 7 TaskRunner::TaskRunner(int cputhreads) | 8 void TaskRunner::add(CpuTask* task) { fCpu.add(task); } |
| 8 : fMain(cputhreads) | |
| 9 , 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 } | |
| 21 | 9 |
| 22 void TaskRunner::add(Task* task) { | 10 void TaskRunner::add(GpuTask* task) { fGpu.add(task); } |
| 23 if (task->usesGpu()) { | |
| 24 fGpu.add(task); | |
| 25 } else { | |
| 26 fMain.add(task); | |
| 27 } | |
| 28 } | |
| 29 | 11 |
| 30 void TaskRunner::wait() { | 12 void TaskRunner::wait() { |
| 31 // Enqueue a task on the GPU thread to destroy the GrContextFactory. | 13 // These wait calls block until each threadpool is done. We don't allow |
| 32 struct Delete : public SkRunnable { | 14 // spawning new child GPU tasks, so we can wait for that first knowing |
| 33 Delete(GrContextFactory* ptr) : fPtr(ptr) {} | 15 // we'll never try to add to it later. Same can't be said of the CPU pool: |
| 34 void run() SK_OVERRIDE { | 16 // both CPU and GPU tasks can spawn off new CPU work, so we wait for that la
st. |
| 35 delete fPtr; | |
| 36 delete this; | |
| 37 } | |
| 38 GrContextFactory* fPtr; | |
| 39 }; | |
| 40 fGpu.add(SkNEW_ARGS(Delete, (fGrContextFactory))); | |
| 41 | |
| 42 // 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(); | 17 fGpu.wait(); |
| 47 fMain.wait(); | 18 fCpu.wait(); |
| 48 } | 19 } |
| 49 | 20 |
| 50 } // namespace DM | 21 } // namespace DM |
| OLD | NEW |