OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/raster/task.h" | 5 #include "cc/raster/task.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace cc { | 9 namespace cc { |
10 | 10 |
11 Task::Task() : will_run_(false), did_run_(false) {} | 11 TaskState::TaskState() : value_(Value::NEW) {} |
12 | 12 |
13 Task::~Task() { | 13 TaskState::~TaskState() { |
14 DCHECK(!will_run_); | 14 DCHECK(value_ != Value::RUNNING) |
| 15 << "Running task should never get destroyed."; |
| 16 DCHECK(value_ == Value::NEW || value_ == Value::FINISHED || |
| 17 value_ == Value::CANCELED) |
| 18 << "Task, if scheduled, should get concluded either in FINISHED or " |
| 19 "CANCELED state."; |
15 } | 20 } |
16 | 21 |
17 void Task::WillRun() { | 22 bool TaskState::IsScheduled() const { |
18 DCHECK(!will_run_); | 23 return value_ == Value::SCHEDULED; |
19 DCHECK(!did_run_); | |
20 will_run_ = true; | |
21 } | 24 } |
22 | 25 |
23 void Task::DidRun() { | 26 bool TaskState::IsRunning() const { |
24 DCHECK(will_run_); | 27 return value_ == Value::RUNNING; |
25 will_run_ = false; | 28 } |
26 did_run_ = true; | 29 bool TaskState::IsFinished() const { |
| 30 return value_ == Value::FINISHED; |
| 31 } |
| 32 bool TaskState::IsCanceled() const { |
| 33 return value_ == Value::CANCELED; |
27 } | 34 } |
28 | 35 |
29 bool Task::HasFinishedRunning() const { | 36 void TaskState::Reset() { |
30 return did_run_; | 37 value_ = Value::NEW; |
31 } | 38 } |
32 | 39 |
| 40 void TaskState::DidSchedule() { |
| 41 DCHECK(value_ == Value::NEW) |
| 42 << "Task should be in NEW state to get scheduled."; |
| 43 value_ = Value::SCHEDULED; |
| 44 } |
| 45 |
| 46 void TaskState::DidStart() { |
| 47 DCHECK(value_ == Value::SCHEDULED) |
| 48 << "Task should be only in SCHEDULED state to start, that is it should " |
| 49 "not be started or finished."; |
| 50 value_ = Value::RUNNING; |
| 51 } |
| 52 |
| 53 void TaskState::DidFinish() { |
| 54 DCHECK(value_ == Value::RUNNING) |
| 55 << "Task should be running and not finished earlier."; |
| 56 value_ = Value::FINISHED; |
| 57 } |
| 58 |
| 59 void TaskState::DidCancel() { |
| 60 DCHECK(value_ == Value::NEW || value_ == Value::SCHEDULED) |
| 61 << "Task should be scheduled and not running to get canceled."; |
| 62 value_ = Value::CANCELED; |
| 63 } |
| 64 |
| 65 Task::Task() {} |
| 66 |
| 67 Task::~Task() {} |
| 68 |
33 TaskGraph::TaskGraph() {} | 69 TaskGraph::TaskGraph() {} |
34 | 70 |
35 TaskGraph::TaskGraph(const TaskGraph& other) = default; | 71 TaskGraph::TaskGraph(const TaskGraph& other) = default; |
36 | 72 |
37 TaskGraph::~TaskGraph() {} | 73 TaskGraph::~TaskGraph() {} |
38 | 74 |
39 void TaskGraph::Swap(TaskGraph* other) { | 75 void TaskGraph::Swap(TaskGraph* other) { |
40 nodes.swap(other->nodes); | 76 nodes.swap(other->nodes); |
41 edges.swap(other->edges); | 77 edges.swap(other->edges); |
42 } | 78 } |
43 | 79 |
44 void TaskGraph::Reset() { | 80 void TaskGraph::Reset() { |
45 nodes.clear(); | 81 nodes.clear(); |
46 edges.clear(); | 82 edges.clear(); |
47 } | 83 } |
48 | 84 |
49 } // namespace cc | 85 } // namespace cc |
OLD | NEW |