OLD | NEW |
1 #include "DMTask.h" | 1 #include "DMTask.h" |
2 #include "DMTaskRunner.h" | 2 #include "DMTaskRunner.h" |
3 #include "SkCommandLineFlags.h" | 3 #include "SkCommandLineFlags.h" |
4 | 4 |
5 DEFINE_bool(cpu, true, "Master switch for running CPU-bound work."); | 5 DEFINE_bool(cpu, true, "Master switch for running CPU-bound work."); |
6 DEFINE_bool(gpu, true, "Master switch for running GPU-bound work."); | 6 DEFINE_bool(gpu, true, "Master switch for running GPU-bound work."); |
7 | 7 |
8 namespace DM { | 8 namespace DM { |
9 | 9 |
10 Task::Task(Reporter* reporter, TaskRunner* taskRunner) | 10 Task::Task(Reporter* reporter, TaskRunner* taskRunner) |
(...skipping 19 matching lines...) Expand all Loading... |
30 } | 30 } |
31 | 31 |
32 void Task::start() { | 32 void Task::start() { |
33 fStart = SkTime::GetMSecs(); | 33 fStart = SkTime::GetMSecs(); |
34 } | 34 } |
35 | 35 |
36 void Task::finish() { | 36 void Task::finish() { |
37 fReporter->finish(this->name(), SkTime::GetMSecs() - fStart); | 37 fReporter->finish(this->name(), SkTime::GetMSecs() - fStart); |
38 } | 38 } |
39 | 39 |
40 void Task::reallySpawnChild(CpuTask* task) { | 40 void Task::spawnChildNext(CpuTask* task) { |
41 fTaskRunner->add(task); | 41 fTaskRunner->addNext(task); |
42 } | 42 } |
43 | 43 |
44 CpuTask::CpuTask(Reporter* reporter, TaskRunner* taskRunner) : Task(reporter, ta
skRunner) {} | 44 CpuTask::CpuTask(Reporter* reporter, TaskRunner* taskRunner) : Task(reporter, ta
skRunner) {} |
45 CpuTask::CpuTask(const Task& parent) : Task(parent) {} | 45 CpuTask::CpuTask(const Task& parent) : Task(parent) {} |
46 | 46 |
47 void CpuTask::run() { | 47 void CpuTask::run() { |
48 this->start(); | 48 this->start(); |
49 if (FLAGS_cpu && !this->shouldSkip()) { | 49 if (FLAGS_cpu && !this->shouldSkip()) { |
50 this->draw(); | 50 this->draw(); |
51 } | 51 } |
52 this->finish(); | 52 this->finish(); |
53 SkDELETE(this); | 53 SkDELETE(this); |
54 } | 54 } |
55 | 55 |
56 void CpuTask::spawnChild(CpuTask* task) { | 56 void CpuTask::spawnChild(CpuTask* task) { |
57 // Run children serially on this (CPU) thread. This tends to save RAM and i
s usually no slower. | 57 // Run children serially on this (CPU) thread. This tends to save RAM and i
s usually no slower. |
| 58 // Calling spawnChildNext() is nearly equivalent, but it'd pointlessly conte
nd on the |
| 59 // threadpool; spawnChildNext() is most useful when you want to change threa
dpools. |
58 task->run(); | 60 task->run(); |
59 } | 61 } |
60 | 62 |
61 GpuTask::GpuTask(Reporter* reporter, TaskRunner* taskRunner) : Task(reporter, ta
skRunner) {} | 63 GpuTask::GpuTask(Reporter* reporter, TaskRunner* taskRunner) : Task(reporter, ta
skRunner) {} |
62 | 64 |
63 void GpuTask::run(GrContextFactory& factory) { | 65 void GpuTask::run(GrContextFactory& factory) { |
64 this->start(); | 66 this->start(); |
65 if (FLAGS_gpu && !this->shouldSkip()) { | 67 if (FLAGS_gpu && !this->shouldSkip()) { |
66 this->draw(&factory); | 68 this->draw(&factory); |
67 } | 69 } |
68 this->finish(); | 70 this->finish(); |
69 SkDELETE(this); | 71 SkDELETE(this); |
70 } | 72 } |
71 | 73 |
72 void GpuTask::spawnChild(CpuTask* task) { | 74 void GpuTask::spawnChild(CpuTask* task) { |
73 // Really spawn a new task so it runs on the CPU threadpool instead of the G
PU one we're on now. | 75 // Really spawn a new task so it runs on the CPU threadpool instead of the G
PU one we're on now. |
74 this->reallySpawnChild(task); | 76 // It goes on the front of the queue to minimize the time we must hold refer
ence bitmaps in RAM. |
| 77 this->spawnChildNext(task); |
75 } | 78 } |
76 | 79 |
77 } // namespace DM | 80 } // namespace DM |
OLD | NEW |