mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1 | #include "DMTask.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 2 | #include "DMTaskRunner.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 3 | #include "SkCommonFlags.h" |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 4 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 5 | namespace DM { |
| 6 | |
| 7 | Task::Task(Reporter* reporter, TaskRunner* taskRunner) |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 8 | : fReporter(reporter) |
| 9 | , fTaskRunner(taskRunner) |
| 10 | , fDepth(0) { |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 11 | fReporter->taskCreated(); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 12 | } |
| 13 | |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 14 | Task::Task(const Task& parent) |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 15 | : fReporter(parent.fReporter) |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 16 | , fTaskRunner(parent.fTaskRunner) |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 17 | , fDepth(parent.depth() + 1) { |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 18 | fReporter->taskCreated(); |
| 19 | } |
| 20 | |
| 21 | Task::~Task() { |
| 22 | fReporter->taskDestroyed(); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 23 | } |
| 24 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 25 | void Task::fail(const char* msg) { |
| 26 | SkString failure(this->name()); |
| 27 | if (msg) { |
| 28 | failure.appendf(": %s", msg); |
| 29 | } |
| 30 | fReporter->fail(failure); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 31 | } |
| 32 | |
commit-bot@chromium.org | a39874b | 2014-03-03 15:44:56 +0000 | [diff] [blame] | 33 | void Task::start() { |
| 34 | fStart = SkTime::GetMSecs(); |
| 35 | } |
| 36 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 37 | void Task::finish() { |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 38 | fReporter->printStatus(this->name(), SkTime::GetMSecs() - fStart); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 39 | } |
| 40 | |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame^] | 41 | void Task::reallySpawnChild(CpuTask* task) { |
| 42 | fTaskRunner->add(task); |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | CpuTask::CpuTask(Reporter* reporter, TaskRunner* taskRunner) : Task(reporter, taskRunner) {} |
| 46 | CpuTask::CpuTask(const Task& parent) : Task(parent) {} |
| 47 | |
| 48 | void CpuTask::run() { |
commit-bot@chromium.org | fa8cb1c | 2014-03-31 19:59:44 +0000 | [diff] [blame] | 49 | if (FLAGS_cpu && !this->shouldSkip()) { |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 50 | this->start(); |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 51 | if (!FLAGS_dryRun) this->draw(); |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 52 | this->finish(); |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 53 | } |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 54 | SkDELETE(this); |
| 55 | } |
| 56 | |
commit-bot@chromium.org | b0c7156 | 2014-04-30 20:47:30 +0000 | [diff] [blame] | 57 | void CpuTask::spawnChild(CpuTask* task) { |
| 58 | // Run children serially on this (CPU) thread. This tends to save RAM and is usually no slower. |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame^] | 59 | // Calling reallySpawnChild() is nearly equivalent, but it'd pointlessly contend on the |
| 60 | // threadpool; reallySpawnChild() is most useful when you want to change threadpools. |
commit-bot@chromium.org | b0c7156 | 2014-04-30 20:47:30 +0000 | [diff] [blame] | 61 | task->run(); |
| 62 | } |
| 63 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 64 | GpuTask::GpuTask(Reporter* reporter, TaskRunner* taskRunner) : Task(reporter, taskRunner) {} |
| 65 | |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame^] | 66 | void GpuTask::run(GrContextFactory* factory) { |
commit-bot@chromium.org | fa8cb1c | 2014-03-31 19:59:44 +0000 | [diff] [blame] | 67 | if (FLAGS_gpu && !this->shouldSkip()) { |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 68 | this->start(); |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame^] | 69 | if (!FLAGS_dryRun) this->draw(factory); |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 70 | this->finish(); |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 71 | if (FLAGS_abandonGpuContext) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame^] | 72 | factory->abandonContexts(); |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 73 | } |
| 74 | if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame^] | 75 | factory->destroyContexts(); |
Mike Klein | 18515cf | 2014-07-15 16:10:02 -0400 | [diff] [blame] | 76 | } |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 77 | } |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 78 | SkDELETE(this); |
| 79 | } |
| 80 | |
commit-bot@chromium.org | b0c7156 | 2014-04-30 20:47:30 +0000 | [diff] [blame] | 81 | void GpuTask::spawnChild(CpuTask* task) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame^] | 82 | // Spawn a new task so it runs on the CPU threadpool instead of the GPU one we're on now. |
commit-bot@chromium.org | 3f03215 | 2014-05-01 17:41:32 +0000 | [diff] [blame] | 83 | // It goes on the front of the queue to minimize the time we must hold reference bitmaps in RAM. |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame^] | 84 | this->reallySpawnChild(task); |
commit-bot@chromium.org | b0c7156 | 2014-04-30 20:47:30 +0000 | [diff] [blame] | 85 | } |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 86 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 87 | } // namespace DM |