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