summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cc/raster/task_graph_runner.cc12
-rw-r--r--cc/raster/task_graph_runner.h3
-rw-r--r--content/content_renderer.gypi2
-rw-r--r--content/content_tests.gypi1
-rw-r--r--content/renderer/raster_worker_pool.cc168
-rw-r--r--content/renderer/raster_worker_pool.h106
-rw-r--r--content/renderer/raster_worker_pool_unittest.cc71
-rw-r--r--content/renderer/render_thread_impl.cc122
-rw-r--r--content/renderer/render_thread_impl.h4
9 files changed, 122 insertions, 367 deletions
diff --git a/cc/raster/task_graph_runner.cc b/cc/raster/task_graph_runner.cc
index 4cc912f..c810aa5 100644
--- a/cc/raster/task_graph_runner.cc
+++ b/cc/raster/task_graph_runner.cc
@@ -349,18 +349,6 @@ void TaskGraphRunner::Shutdown() {
has_ready_to_run_tasks_cv_.Signal();
}
-void TaskGraphRunner::FlushForTesting() {
- base::AutoLock lock(lock_);
-
- while (std::find_if(namespaces_.begin(), namespaces_.end(),
- [](const TaskNamespaceMap::value_type& entry) {
- return !HasFinishedRunningTasksInNamespace(
- &entry.second);
- }) != namespaces_.end()) {
- has_namespaces_with_finished_running_tasks_cv_.Wait();
- }
-}
-
void TaskGraphRunner::Run() {
base::AutoLock lock(lock_);
diff --git a/cc/raster/task_graph_runner.h b/cc/raster/task_graph_runner.h
index d6d4191..bb55afc 100644
--- a/cc/raster/task_graph_runner.h
+++ b/cc/raster/task_graph_runner.h
@@ -137,9 +137,6 @@ class CC_EXPORT TaskGraphRunner {
// Warning: if the TaskGraphRunner remains busy, it may never quit.
void Shutdown();
- // Wait for all the tasks to finish running on all the namespaces.
- void FlushForTesting();
-
private:
struct PrioritizedTask {
typedef std::vector<PrioritizedTask> Vector;
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi
index 99108c3..d6f4c52 100644
--- a/content/content_renderer.gypi
+++ b/content/content_renderer.gypi
@@ -333,8 +333,6 @@
'renderer/presentation/presentation_session_client.h',
'renderer/push_messaging/push_messaging_dispatcher.cc',
'renderer/push_messaging/push_messaging_dispatcher.h',
- 'renderer/raster_worker_pool.cc',
- 'renderer/raster_worker_pool.h',
'renderer/render_font_warmup_win.cc',
'renderer/render_frame_impl.cc',
'renderer/render_frame_impl.h',
diff --git a/content/content_tests.gypi b/content/content_tests.gypi
index d5b601e..ed1a156 100644
--- a/content/content_tests.gypi
+++ b/content/content_tests.gypi
@@ -673,7 +673,6 @@
'renderer/media/video_capture_impl_manager_unittest.cc',
'renderer/media/video_capture_impl_unittest.cc',
'renderer/media/video_capture_message_filter_unittest.cc',
- 'renderer/raster_worker_pool_unittest.cc',
'renderer/render_thread_impl_unittest.cc',
'renderer/render_widget_unittest.cc',
'renderer/scheduler/resource_dispatch_throttler_unittest.cc',
diff --git a/content/renderer/raster_worker_pool.cc b/content/renderer/raster_worker_pool.cc
deleted file mode 100644
index 7abe255..0000000
--- a/content/renderer/raster_worker_pool.cc
+++ /dev/null
@@ -1,168 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "raster_worker_pool.h"
-
-#include "base/strings/stringprintf.h"
-
-namespace content {
-
-// A sequenced task runner which posts tasks to a RasterWorkerPool.
-class RasterWorkerPool::RasterWorkerPoolSequencedTaskRunner
- : public base::SequencedTaskRunner {
- public:
- RasterWorkerPoolSequencedTaskRunner(cc::TaskGraphRunner* task_graph_runner)
- : task_graph_runner_(task_graph_runner),
- namespace_token_(task_graph_runner->GetNamespaceToken()) {}
-
- // Overridden from base::TaskRunner:
- bool PostDelayedTask(const tracked_objects::Location& from_here,
- const base::Closure& task,
- base::TimeDelta delay) override {
- return PostNonNestableDelayedTask(from_here, task, delay);
- }
- bool RunsTasksOnCurrentThread() const override { return true; }
-
- // Overridden from base::SequencedTaskRunner:
- bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
- const base::Closure& task,
- base::TimeDelta delay) override {
- base::AutoLock lock(lock_);
-
- // Remove completed tasks.
- DCHECK(completed_tasks_.empty());
- task_graph_runner_->CollectCompletedTasks(namespace_token_,
- &completed_tasks_);
-
- tasks_.erase(tasks_.begin(), tasks_.begin() + completed_tasks_.size());
-
- tasks_.push_back(make_scoped_refptr(new ClosureTask(task)));
- graph_.Reset();
- for (const auto& task : tasks_) {
- int dependencies = 0;
- if (!graph_.nodes.empty())
- dependencies = 1;
-
- cc::TaskGraph::Node node(task.get(), 0, dependencies);
- if (dependencies) {
- graph_.edges.push_back(
- cc::TaskGraph::Edge(graph_.nodes.back().task, node.task));
- }
- graph_.nodes.push_back(node);
- }
- task_graph_runner_->ScheduleTasks(namespace_token_, &graph_);
- completed_tasks_.clear();
- return true;
- }
-
- private:
- ~RasterWorkerPoolSequencedTaskRunner() override {
- task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_);
- task_graph_runner_->CollectCompletedTasks(namespace_token_,
- &completed_tasks_);
- };
-
- cc::TaskGraphRunner* const task_graph_runner_;
-
- // Lock to exclusively access all the following members that are used to
- // implement the SequencedTaskRunner interfaces.
- base::Lock lock_;
- // Namespace used to schedule tasks in the task graph runner.
- cc::NamespaceToken namespace_token_;
- // List of tasks currently queued up for execution.
- cc::Task::Vector tasks_;
- // Graph object used for scheduling tasks.
- cc::TaskGraph graph_;
- // Cached vector to avoid allocation when getting the list of complete
- // tasks.
- cc::Task::Vector completed_tasks_;
-};
-
-RasterWorkerPool::RasterWorkerPool()
- : namespace_token_(task_graph_runner_.GetNamespaceToken()) {}
-
-void RasterWorkerPool::Start(
- int num_threads,
- const base::SimpleThread::Options& thread_options) {
- DCHECK(threads_.empty());
- while (threads_.size() < static_cast<size_t>(num_threads)) {
- scoped_ptr<base::DelegateSimpleThread> thread(
- new base::DelegateSimpleThread(
- this, base::StringPrintf("ComositorTileWorker%u",
- static_cast<unsigned>(threads_.size() + 1))
- .c_str(),
- thread_options));
- thread->Start();
- threads_.push_back(thread.Pass());
- }
-}
-
-void RasterWorkerPool::Shutdown() {
- task_graph_runner_.WaitForTasksToFinishRunning(namespace_token_);
- task_graph_runner_.CollectCompletedTasks(namespace_token_, &completed_tasks_);
- // Shutdown raster threads.
- task_graph_runner_.Shutdown();
- while (!threads_.empty()) {
- threads_.back()->Join();
- threads_.pop_back();
- }
-}
-
-// Overridden from base::TaskRunner:
-bool RasterWorkerPool::PostDelayedTask(
- const tracked_objects::Location& from_here,
- const base::Closure& task,
- base::TimeDelta delay) {
- base::AutoLock lock(lock_);
-
- // Remove completed tasks.
- DCHECK(completed_tasks_.empty());
- task_graph_runner_.CollectCompletedTasks(namespace_token_, &completed_tasks_);
-
- cc::Task::Vector::iterator end = std::remove_if(
- tasks_.begin(), tasks_.end(), [this](const scoped_refptr<cc::Task>& e) {
- return std::find(this->completed_tasks_.begin(),
- this->completed_tasks_.end(),
- e) != this->completed_tasks_.end();
- });
- tasks_.erase(end, tasks_.end());
-
- tasks_.push_back(make_scoped_refptr(new ClosureTask(task)));
- graph_.Reset();
- for (const auto& task : tasks_)
- graph_.nodes.push_back(cc::TaskGraph::Node(task.get(), 0, 0));
-
- task_graph_runner_.ScheduleTasks(namespace_token_, &graph_);
- completed_tasks_.clear();
- return true;
-}
-
-bool RasterWorkerPool::RunsTasksOnCurrentThread() const {
- return true;
-}
-
-// Overridden from base::DelegateSimpleThread::Delegate:
-void RasterWorkerPool::Run() {
- task_graph_runner_.Run();
-}
-
-scoped_refptr<base::SequencedTaskRunner>
-RasterWorkerPool::CreateSequencedTaskRunner() {
- return new RasterWorkerPoolSequencedTaskRunner(&task_graph_runner_);
-}
-
-RasterWorkerPool::~RasterWorkerPool() {}
-
-RasterWorkerPool::ClosureTask::ClosureTask(const base::Closure& closure)
- : closure_(closure) {}
-
-// Overridden from cc::Task:
-void RasterWorkerPool::ClosureTask::RunOnWorkerThread() {
- closure_.Run();
- closure_.Reset();
-};
-
-RasterWorkerPool::ClosureTask::~ClosureTask() {}
-
-} // namespace content
diff --git a/content/renderer/raster_worker_pool.h b/content/renderer/raster_worker_pool.h
deleted file mode 100644
index b8b4f35..0000000
--- a/content/renderer/raster_worker_pool.h
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_RENDERER_RASTER_WORKER_POOL_H_
-#define CONTENT_RENDERER_RASTER_WORKER_POOL_H_
-
-#include "base/callback.h"
-#include "base/containers/hash_tables.h"
-#include "base/memory/scoped_vector.h"
-#include "base/sequenced_task_runner.h"
-#include "base/task_runner.h"
-#include "base/threading/simple_thread.h"
-#include "cc/raster/task_graph_runner.h"
-#include "content/common/content_export.h"
-
-namespace content {
-
-// A pool of threads used to run raster work.
-// Work can be scheduled on the threads using different interfaces.
-// The pool itself implements TaskRunner interface and tasks posted via that
-// interface might run in parallel.
-// CreateSequencedTaskRunner creates a sequenced task runner that might run in
-// parallel with other instances of sequenced task runners.
-// It's also possible to get the underlying TaskGraphRunner to schedule a graph
-// of tasks with their dependencies.
-// TODO(reveman): make TaskGraphRunner an abstract interface and have this
-// WorkerPool class implement it.
-class CONTENT_EXPORT RasterWorkerPool
- : public base::TaskRunner,
- public base::DelegateSimpleThread::Delegate {
- public:
- RasterWorkerPool();
-
- // Overridden from base::TaskRunner:
- bool PostDelayedTask(const tracked_objects::Location& from_here,
- const base::Closure& task,
- base::TimeDelta delay) override;
- bool RunsTasksOnCurrentThread() const override;
-
- // Overridden from base::DelegateSimpleThread::Delegate:
- void Run() override;
-
- // Spawn |num_threads| number of threads and start running work on the
- // worker threads.
- void Start(int num_threads,
- const base::SimpleThread::Options& thread_options);
-
- // Finish running all the posted tasks (and nested task posted by those tasks)
- // of all the associated task runners.
- // Once all the tasks are executed the method blocks until the threads are
- // terminated.
- void Shutdown();
-
- cc::TaskGraphRunner* GetTaskGraphRunner() { return &task_graph_runner_; }
-
- // Create a new sequenced task graph runner.
- scoped_refptr<base::SequencedTaskRunner> CreateSequencedTaskRunner();
-
- protected:
- ~RasterWorkerPool() override;
-
- private:
- class RasterWorkerPoolSequencedTaskRunner;
- friend class RasterWorkerPoolSequencedTaskRunner;
-
- // Simple Task for the TaskGraphRunner that wraps a closure.
- // This class is used to schedule TaskRunner tasks on the
- // |task_graph_runner_|.
- class ClosureTask : public cc::Task {
- public:
- explicit ClosureTask(const base::Closure& closure);
-
- // Overridden from cc::Task:
- void RunOnWorkerThread() override;
-
- protected:
- ~ClosureTask() override;
-
- private:
- base::Closure closure_;
-
- DISALLOW_COPY_AND_ASSIGN(ClosureTask);
- };
-
- // The actual threads where work is done.
- ScopedVector<base::DelegateSimpleThread> threads_;
- cc::TaskGraphRunner task_graph_runner_;
-
- // Lock to exclusively access all the following members that are used to
- // implement the TaskRunner interfaces.
- base::Lock lock_;
- // Namespace used to schedule tasks in the task graph runner.
- cc::NamespaceToken namespace_token_;
- // List of tasks currently queued up for execution.
- cc::Task::Vector tasks_;
- // Graph object used for scheduling tasks.
- cc::TaskGraph graph_;
- // Cached vector to avoid allocation when getting the list of complete
- // tasks.
- cc::Task::Vector completed_tasks_;
-};
-
-} // namespace content
-
-#endif // CONTENT_RENDERER_RASTER_WORKER_POOL_H_
diff --git a/content/renderer/raster_worker_pool_unittest.cc b/content/renderer/raster_worker_pool_unittest.cc
deleted file mode 100644
index 926ba2b..0000000
--- a/content/renderer/raster_worker_pool_unittest.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/test/sequenced_task_runner_test_template.h"
-#include "base/test/task_runner_test_template.h"
-#include "base/threading/simple_thread.h"
-#include "content/renderer/raster_worker_pool.h"
-
-namespace base {
-namespace {
-
-// Number of threads spawned in tests.
-const int kNumThreads = 4;
-
-class RasterWorkerPoolTestDelegate {
- public:
- RasterWorkerPoolTestDelegate()
- : raster_worker_pool_(new content::RasterWorkerPool()) {}
-
- void StartTaskRunner() {
- raster_worker_pool_->Start(kNumThreads, SimpleThread::Options());
- }
-
- scoped_refptr<content::RasterWorkerPool> GetTaskRunner() {
- return raster_worker_pool_;
- }
-
- void StopTaskRunner() {
- raster_worker_pool_->GetTaskGraphRunner()->FlushForTesting();
- }
-
- ~RasterWorkerPoolTestDelegate() { raster_worker_pool_->Shutdown(); }
-
- private:
- scoped_refptr<content::RasterWorkerPool> raster_worker_pool_;
-};
-
-INSTANTIATE_TYPED_TEST_CASE_P(RasterWorkerPool,
- TaskRunnerTest,
- RasterWorkerPoolTestDelegate);
-
-class RasterWorkerPoolSequencedTestDelegate {
- public:
- RasterWorkerPoolSequencedTestDelegate()
- : raster_worker_pool_(new content::RasterWorkerPool()) {}
-
- void StartTaskRunner() {
- raster_worker_pool_->Start(kNumThreads, SimpleThread::Options());
- }
-
- scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() {
- return raster_worker_pool_->CreateSequencedTaskRunner();
- }
-
- void StopTaskRunner() {
- raster_worker_pool_->GetTaskGraphRunner()->FlushForTesting();
- }
-
- ~RasterWorkerPoolSequencedTestDelegate() { raster_worker_pool_->Shutdown(); }
-
- private:
- scoped_refptr<content::RasterWorkerPool> raster_worker_pool_;
-};
-
-INSTANTIATE_TYPED_TEST_CASE_P(RasterWorkerPool,
- SequencedTaskRunnerTest,
- RasterWorkerPoolSequencedTestDelegate);
-
-} // namespace
-} // namespace base
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index b96b775..0db0b29 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -107,7 +107,6 @@
#include "content/renderer/media/video_capture_message_filter.h"
#include "content/renderer/net_info_helper.h"
#include "content/renderer/p2p/socket_dispatcher.h"
-#include "content/renderer/raster_worker_pool.h"
#include "content/renderer/render_frame_proxy.h"
#include "content/renderer/render_process_impl.h"
#include "content/renderer/render_view_impl.h"
@@ -423,6 +422,125 @@ void CreateEmbeddedWorkerSetup(
} // namespace
+class RasterWorkerPool : public base::SequencedTaskRunner,
+ public base::DelegateSimpleThread::Delegate {
+ public:
+ RasterWorkerPool()
+ : namespace_token_(task_graph_runner_.GetNamespaceToken()) {}
+
+ void Start(int num_threads,
+ const base::SimpleThread::Options& thread_options) {
+ DCHECK(threads_.empty());
+ while (threads_.size() < static_cast<size_t>(num_threads)) {
+ scoped_ptr<base::DelegateSimpleThread> thread(
+ new base::DelegateSimpleThread(
+ this, base::StringPrintf(
+ "CompositorTileWorker%u",
+ static_cast<unsigned>(threads_.size() + 1)).c_str(),
+ thread_options));
+ thread->Start();
+ threads_.push_back(thread.Pass());
+ }
+ }
+
+ void Shutdown() {
+ // Shutdown raster threads.
+ task_graph_runner_.Shutdown();
+ while (!threads_.empty()) {
+ threads_.back()->Join();
+ threads_.pop_back();
+ }
+ }
+
+ // Overridden from base::TaskRunner:
+ bool PostDelayedTask(const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay) override {
+ return PostNonNestableDelayedTask(from_here, task, delay);
+ }
+
+ bool RunsTasksOnCurrentThread() const override { return true; }
+
+ // Overridden from base::SequencedTaskRunner:
+ bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay) override {
+ base::AutoLock lock(lock_);
+ DCHECK(!threads_.empty());
+
+ // Remove completed tasks.
+ DCHECK(completed_tasks_.empty());
+ task_graph_runner_.CollectCompletedTasks(namespace_token_,
+ &completed_tasks_);
+ DCHECK_LE(completed_tasks_.size(), tasks_.size());
+ DCHECK(std::equal(completed_tasks_.begin(), completed_tasks_.end(),
+ tasks_.begin()));
+ tasks_.erase(tasks_.begin(), tasks_.begin() + completed_tasks_.size());
+ completed_tasks_.clear();
+
+ tasks_.push_back(make_scoped_refptr(new ClosureTask(task)));
+
+ graph_.Reset();
+ for (const auto& task : tasks_) {
+ cc::TaskGraph::Node node(task.get(), 0, graph_.nodes.size());
+ if (graph_.nodes.size()) {
+ graph_.edges.push_back(
+ cc::TaskGraph::Edge(graph_.nodes.back().task, node.task));
+ }
+ graph_.nodes.push_back(node);
+ }
+
+ task_graph_runner_.ScheduleTasks(namespace_token_, &graph_);
+ return true;
+ }
+
+ // Overridden from base::DelegateSimpleThread::Delegate:
+ void Run() override { task_graph_runner_.Run(); }
+
+ cc::TaskGraphRunner* GetTaskGraphRunner() { return &task_graph_runner_; }
+
+ protected:
+ ~RasterWorkerPool() override {}
+
+ private:
+ // Simple Task for the TaskGraphRunner that wraps a closure.
+ class ClosureTask : public cc::Task {
+ public:
+ ClosureTask(const base::Closure& closure) : closure_(closure) {}
+
+ // Overridden from cc::Task:
+ void RunOnWorkerThread() override {
+ closure_.Run();
+ closure_.Reset();
+ };
+
+ protected:
+ ~ClosureTask() override {}
+
+ private:
+ base::Closure closure_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClosureTask);
+ };
+
+ // The actual threads where work is done.
+ ScopedVector<base::DelegateSimpleThread> threads_;
+ cc::TaskGraphRunner task_graph_runner_;
+
+ // Namespace where the SequencedTaskRunner tasks run.
+ const cc::NamespaceToken namespace_token_;
+
+ // Lock to exclusively access all the following members that are used to
+ // implement the SequencedTaskRunner interface.
+ base::Lock lock_;
+ // List of tasks currently queued up for execution.
+ ClosureTask::Vector tasks_;
+ // Cached vector to avoid allocation when getting the list of complete tasks.
+ ClosureTask::Vector completed_tasks_;
+ // Graph object used for scheduling tasks.
+ cc::TaskGraph graph_;
+};
+
// For measuring memory usage after each task. Behind a command line flag.
class MemoryObserver : public base::MessageLoop::TaskObserver {
public:
@@ -1836,7 +1954,7 @@ RenderThreadImpl::GetMediaThreadTaskRunner() {
return media_thread_->task_runner();
}
-base::TaskRunner* RenderThreadImpl::GetWorkerTaskRunner() {
+base::SequencedTaskRunner* RenderThreadImpl::GetWorkerSequencedTaskRunner() {
return raster_worker_pool_.get();
}
diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h
index eb6516e..8e99eaf 100644
--- a/content/renderer/render_thread_impl.h
+++ b/content/renderer/render_thread_impl.h
@@ -321,8 +321,8 @@ class CONTENT_EXPORT RenderThreadImpl
// on the renderer's main thread.
scoped_refptr<base::SingleThreadTaskRunner> GetMediaThreadTaskRunner();
- // A TaskRunner instance that runs tasks on the raster worker pool.
- base::TaskRunner* GetWorkerTaskRunner();
+ // A SequencedTaskRunner instance that runs tasks on the raster worker pool.
+ base::SequencedTaskRunner* GetWorkerSequencedTaskRunner();
// Causes the idle handler to skip sending idle notifications
// on the two next scheduled calls, so idle notifications are