| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/resources/task_graph_runner.h" | 5 #include "cc/resources/task_graph_runner.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 return run_task_ids_[namespace_index]; | 67 return run_task_ids_[namespace_index]; |
| 68 } | 68 } |
| 69 | 69 |
| 70 const std::vector<unsigned>& on_task_completed_ids(int namespace_index) { | 70 const std::vector<unsigned>& on_task_completed_ids(int namespace_index) { |
| 71 return on_task_completed_ids_[namespace_index]; | 71 return on_task_completed_ids_[namespace_index]; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void ScheduleTasks(int namespace_index, const std::vector<Task>& tasks) { | 74 void ScheduleTasks(int namespace_index, const std::vector<Task>& tasks) { |
| 75 internal::Task::Vector new_tasks; | 75 internal::Task::Vector new_tasks; |
| 76 internal::Task::Vector new_dependents; | 76 internal::Task::Vector new_dependents; |
| 77 internal::GraphNode::Map new_graph; | 77 internal::TaskGraph new_graph; |
| 78 | 78 |
| 79 for (std::vector<Task>::const_iterator it = tasks.begin(); | 79 for (std::vector<Task>::const_iterator it = tasks.begin(); |
| 80 it != tasks.end(); | 80 it != tasks.end(); |
| 81 ++it) { | 81 ++it) { |
| 82 scoped_refptr<FakeTaskImpl> new_task( | 82 scoped_refptr<FakeTaskImpl> new_task( |
| 83 new FakeTaskImpl(this, it->namespace_index, it->id)); | 83 new FakeTaskImpl(this, it->namespace_index, it->id)); |
| 84 scoped_ptr<internal::GraphNode> node( | 84 new_graph.nodes.push_back( |
| 85 new internal::GraphNode(new_task.get(), it->priority)); | 85 internal::TaskGraph::Node(new_task.get(), it->priority, 0u)); |
| 86 | |
| 87 for (unsigned i = 0; i < it->dependent_count; ++i) { | 86 for (unsigned i = 0; i < it->dependent_count; ++i) { |
| 88 scoped_refptr<FakeDependentTaskImpl> new_dependent_task( | 87 scoped_refptr<FakeDependentTaskImpl> new_dependent_task( |
| 89 new FakeDependentTaskImpl( | 88 new FakeDependentTaskImpl( |
| 90 this, it->namespace_index, it->dependent_id)); | 89 this, it->namespace_index, it->dependent_id)); |
| 91 scoped_ptr<internal::GraphNode> dependent_node( | 90 new_graph.nodes.push_back(internal::TaskGraph::Node( |
| 92 new internal::GraphNode(new_dependent_task.get(), it->priority)); | 91 new_dependent_task.get(), it->priority, 1u)); |
| 93 node->add_dependent(dependent_node.get()); | 92 new_graph.edges.push_back(internal::TaskGraph::Edge( |
| 94 dependent_node->add_dependency(); | 93 new_task.get(), new_dependent_task.get())); |
| 95 new_graph.set(new_dependent_task.get(), dependent_node.Pass()); | 94 |
| 96 new_dependents.push_back(new_dependent_task.get()); | 95 new_dependents.push_back(new_dependent_task.get()); |
| 97 } | 96 } |
| 98 | 97 |
| 99 new_graph.set(new_task.get(), node.Pass()); | |
| 100 new_tasks.push_back(new_task.get()); | 98 new_tasks.push_back(new_task.get()); |
| 101 } | 99 } |
| 102 | 100 |
| 103 task_graph_runner_->SetTaskGraph(namespace_token_[namespace_index], | 101 task_graph_runner_->SetTaskGraph(namespace_token_[namespace_index], |
| 104 &new_graph); | 102 &new_graph); |
| 105 | 103 |
| 106 dependents_[namespace_index].swap(new_dependents); | 104 dependents_[namespace_index].swap(new_dependents); |
| 107 tasks_[namespace_index].swap(new_tasks); | 105 tasks_[namespace_index].swap(new_tasks); |
| 108 } | 106 } |
| 109 | 107 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // Check if tasks ran in order of priority. | 280 // Check if tasks ran in order of priority. |
| 283 ASSERT_EQ(4u, run_task_ids(i).size()); | 281 ASSERT_EQ(4u, run_task_ids(i).size()); |
| 284 EXPECT_EQ(1u, run_task_ids(i)[0]); | 282 EXPECT_EQ(1u, run_task_ids(i)[0]); |
| 285 EXPECT_EQ(3u, run_task_ids(i)[1]); | 283 EXPECT_EQ(3u, run_task_ids(i)[1]); |
| 286 EXPECT_EQ(0u, run_task_ids(i)[2]); | 284 EXPECT_EQ(0u, run_task_ids(i)[2]); |
| 287 EXPECT_EQ(2u, run_task_ids(i)[3]); | 285 EXPECT_EQ(2u, run_task_ids(i)[3]); |
| 288 ASSERT_EQ(2u, on_task_completed_ids(i).size()); | 286 ASSERT_EQ(2u, on_task_completed_ids(i).size()); |
| 289 EXPECT_EQ(1u, on_task_completed_ids(i)[0]); | 287 EXPECT_EQ(1u, on_task_completed_ids(i)[0]); |
| 290 EXPECT_EQ(0u, on_task_completed_ids(i)[1]); | 288 EXPECT_EQ(0u, on_task_completed_ids(i)[1]); |
| 291 } | 289 } |
| 292 | |
| 293 for (int i = 0; i < kNamespaceCount; ++i) | |
| 294 ResetIds(i); | |
| 295 | |
| 296 for (int i = 0; i < kNamespaceCount; ++i) { | |
| 297 std::vector<Task> tasks; | |
| 298 tasks.push_back(Task(i, | |
| 299 0u, | |
| 300 3u, | |
| 301 1u, // 1 dependent | |
| 302 1u)); // Priority 1 | |
| 303 tasks.push_back(Task(i, | |
| 304 1u, | |
| 305 4u, | |
| 306 2u, // 2 dependents | |
| 307 1u)); // Priority 1 | |
| 308 tasks.push_back(Task(i, | |
| 309 2u, | |
| 310 5u, | |
| 311 1u, // 1 dependent | |
| 312 0u)); // Priority 0 | |
| 313 ScheduleTasks(i, tasks); | |
| 314 } | |
| 315 | |
| 316 for (int i = 0; i < kNamespaceCount; ++i) { | |
| 317 RunAllTasks(i); | |
| 318 | |
| 319 // Check if tasks ran in order of priority and that task with more | |
| 320 // dependents ran first when priority is the same. | |
| 321 ASSERT_LE(3u, run_task_ids(i).size()); | |
| 322 EXPECT_EQ(2u, run_task_ids(i)[0]); | |
| 323 EXPECT_EQ(5u, run_task_ids(i)[1]); | |
| 324 EXPECT_EQ(1u, run_task_ids(i)[2]); | |
| 325 ASSERT_EQ(3u, on_task_completed_ids(i).size()); | |
| 326 EXPECT_EQ(2u, on_task_completed_ids(i)[0]); | |
| 327 EXPECT_EQ(1u, on_task_completed_ids(i)[1]); | |
| 328 EXPECT_EQ(0u, on_task_completed_ids(i)[2]); | |
| 329 } | |
| 330 } | 290 } |
| 331 | 291 |
| 332 } // namespace | 292 } // namespace |
| 333 } // namespace cc | 293 } // namespace cc |
| OLD | NEW |