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