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 28 matching lines...) Expand all Loading... |
39 } | 39 } |
40 | 40 |
41 void Task::reallySpawnChild(CpuTask* task) { | 41 void Task::reallySpawnChild(CpuTask* task) { |
42 fTaskRunner->add(task); | 42 fTaskRunner->add(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 the task says skip, or if we're starting a top-level CPU task and we d
on't want to, skip. |
| 50 const bool skip = this->shouldSkip() || (this->depth() == 0 && !FLAGS_cpu); |
| 51 if (!skip) { |
50 this->start(); | 52 this->start(); |
51 if (!FLAGS_dryRun) this->draw(); | 53 if (!FLAGS_dryRun) this->draw(); |
52 this->finish(); | 54 this->finish(); |
53 } | 55 } |
54 SkDELETE(this); | 56 SkDELETE(this); |
55 } | 57 } |
56 | 58 |
57 void CpuTask::spawnChild(CpuTask* task) { | 59 void CpuTask::spawnChild(CpuTask* task) { |
58 // Run children serially on this (CPU) thread. This tends to save RAM and i
s usually no slower. | 60 // 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 | 61 // Calling reallySpawnChild() is nearly equivalent, but it'd pointlessly con
tend on the |
60 // threadpool; reallySpawnChild() is most useful when you want to change thr
eadpools. | 62 // threadpool; reallySpawnChild() is most useful when you want to change thr
eadpools. |
61 task->run(); | 63 task->run(); |
62 } | 64 } |
63 | 65 |
64 GpuTask::GpuTask(Reporter* reporter, TaskRunner* taskRunner) : Task(reporter, ta
skRunner) {} | 66 GpuTask::GpuTask(Reporter* reporter, TaskRunner* taskRunner) : Task(reporter, ta
skRunner) {} |
65 | 67 |
66 void GpuTask::run(GrContextFactory* factory) { | 68 void GpuTask::run(GrContextFactory* factory) { |
67 if (FLAGS_gpu && !this->shouldSkip()) { | 69 // If the task says skip, or if we're starting a top-level GPU task and we d
on't want to, skip. |
| 70 const bool skip = this->shouldSkip() || (this->depth() == 0 && !FLAGS_gpu); |
| 71 if (!skip) { |
68 this->start(); | 72 this->start(); |
69 if (!FLAGS_dryRun) this->draw(factory); | 73 if (!FLAGS_dryRun) this->draw(factory); |
70 this->finish(); | 74 this->finish(); |
71 if (FLAGS_abandonGpuContext) { | 75 if (FLAGS_abandonGpuContext) { |
72 factory->abandonContexts(); | 76 factory->abandonContexts(); |
73 } | 77 } |
74 if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { | 78 if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { |
75 factory->destroyContexts(); | 79 factory->destroyContexts(); |
76 } | 80 } |
77 } | 81 } |
78 SkDELETE(this); | 82 SkDELETE(this); |
79 } | 83 } |
80 | 84 |
81 void GpuTask::spawnChild(CpuTask* task) { | 85 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. | 86 // Spawn a new task so it runs on the CPU threadpool instead of the GPU 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. | 87 // It goes on the front of the queue to minimize the time we must hold refer
ence bitmaps in RAM. |
84 this->reallySpawnChild(task); | 88 this->reallySpawnChild(task); |
85 } | 89 } |
86 | 90 |
87 } // namespace DM | 91 } // namespace DM |
OLD | NEW |