Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Unified Diff: content/renderer/render_thread_impl.cc

Issue 1211153002: Expose a SequencedTaskRunner that runs tasks on raster threads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_thread_impl.cc
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index 2219b06f28332aecc0a8ab1c8dc23f0e97e3e2e1..9404d788d0384c28016bf33c54fea6590751335e 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -761,6 +761,9 @@ void RenderThreadImpl::Shutdown() {
compositor_thread_.reset();
+ DCHECK_IMPLIES(worker_task_runner_, worker_task_runner_->HasOneRef());
reveman 2015/06/26 21:13:56 I think we can remove this if we add a RasterWorke
Daniele Castagna 2015/06/29 23:30:49 Done.
+ worker_task_runner_ = nullptr;
+
// Shutdown raster threads.
compositor_task_graph_runner_->Shutdown();
while (!compositor_raster_threads_.empty()) {
@@ -1790,6 +1793,91 @@ RenderThreadImpl::GetMediaThreadTaskRunner() {
return media_thread_->task_runner();
}
+namespace {
reveman 2015/06/26 21:13:56 please move this to anonymous namespace at the top
Daniele Castagna 2015/06/29 23:30:49 Done.
+
+// Simple Task for the TaskGraphRunner that wraps a closure.
+class TaskGraphRunnerClosureTask : public cc::Task {
reveman 2015/06/26 21:13:56 Can we make this a private subclass of the class t
Daniele Castagna 2015/06/29 23:30:49 Sure. Also made CompositorRasterThread private si
+ public:
+ TaskGraphRunnerClosureTask(const base::Closure& closure)
+ : closure_(closure) {}
+ void RunOnWorkerThread() override { closure_.Run(); };
reveman 2015/06/26 21:13:56 should we drop the closure_ reference here on the
Daniele Castagna 2015/06/29 23:30:49 For the SequencedTaskRunner returned by the Sequen
+
+ protected:
+ ~TaskGraphRunnerClosureTask() override {}
+
+ private:
+ const base::Closure closure_;
+};
+
+// SequencedTaskRunner implementation that runs tasks on
+// |compositor_raster_threads_| using |task_graph_runner_|.
+class TaskGraphRunnerSequencedTaskRunner : public base::SequencedTaskRunner {
+ public:
+ TaskGraphRunnerSequencedTaskRunner(cc::TaskGraphRunner* task_graph_runner)
reveman 2015/06/26 21:13:56 explicit
Daniele Castagna 2015/06/29 23:30:49 This class owns TaskGraphRunner now, so the parame
+ : task_graph_runner_(task_graph_runner),
+ namespace_token_(task_graph_runner->GetNamespaceToken()) {}
+ bool PostDelayedTask(const tracked_objects::Location& from_here,
reveman 2015/06/26 21:13:57 please add a "// Overridden from base::TaskRunner:
Daniele Castagna 2015/06/29 23:30:49 Done.
+ const base::Closure& task,
+ base::TimeDelta delay) override {
+ DCHECK(task_graph_runner_);
+ PostNonNestableDelayedTask(from_here, task, delay);
+ return true;
+ }
+
+ bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
reveman 2015/06/26 21:13:56 // Overridden from base::SequencedTaskRunner:
Daniele Castagna 2015/06/29 23:30:49 Done.
+ const base::Closure& task,
+ base::TimeDelta delay) override {
reveman 2015/06/26 21:13:56 This function is currently not thread-safe but it
Daniele Castagna 2015/06/29 23:30:49 Done.
+ DCHECK(task_graph_runner_);
+ // Remove completed tasks.
+ TaskGraphRunnerClosureTask::Vector completed_tasks;
reveman 2015/06/26 21:13:56 Maybe make this a member variable to avoid unneces
Daniele Castagna 2015/06/29 23:30:49 Done.
+ task_graph_runner_->CollectCompletedTasks(namespace_token_,
+ &completed_tasks);
+ auto new_end = std::remove_if(
reveman 2015/06/26 21:13:57 as tasks are required to complete in a specific or
Daniele Castagna 2015/06/29 23:30:49 Added the DCHECKs. Using erase to avoid the quadra
+ tasks_.begin(), tasks_.end(),
+ [&completed_tasks](const scoped_refptr<cc::Task>& t) {
+ return std::find(completed_tasks.begin(), completed_tasks.end(), t) !=
+ completed_tasks.end();
+ });
+ tasks_.erase(new_end, tasks_.end());
+ tasks_.push_back(make_scoped_refptr(new TaskGraphRunnerClosureTask(task)));
+
+ // Rebuild graph_.
reveman 2015/06/26 21:13:56 not sure how useful this comment is
Daniele Castagna 2015/06/29 23:30:49 Removed.
+ graph_.Reset();
+ for (const auto& t : tasks_) {
reveman 2015/06/26 21:13:57 nit: s/t/task/
Daniele Castagna 2015/06/29 23:30:49 Done.
+ const auto& node = cc::TaskGraph::Node(t.get(), 0, graph_.nodes.size());
reveman 2015/06/26 21:13:57 nit: "cc::TaskGraph::Node node(t.get(), 0, graph_.
Daniele Castagna 2015/06/29 23:30:49 Done.
+ 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;
+ }
+
+ bool RunsTasksOnCurrentThread() const override { return true; }
+
+ protected:
+ ~TaskGraphRunnerSequencedTaskRunner() override{};
reveman 2015/06/26 21:13:56 s/override{};/override {}/
Daniele Castagna 2015/06/29 23:30:49 "git cl format" seems to disagree. :/
reveman 2015/06/30 04:47:51 because of the ";"?
+
+ private:
+ TaskGraphRunnerClosureTask::Vector tasks_;
+ cc::TaskGraph graph_;
+ cc::TaskGraphRunner* task_graph_runner_;
+ const cc::NamespaceToken namespace_token_;
+};
+}
+
+scoped_refptr<base::SequencedTaskRunner>
+RenderThreadImpl::GetWorkerSequencedTaskRunner() {
+ if (!worker_task_runner_) {
+ worker_task_runner_ = make_scoped_refptr(
+ new content::TaskGraphRunnerSequencedTaskRunner(GetTaskGraphRunner()));
+ }
+ return worker_task_runner_;
+}
+
void RenderThreadImpl::SampleGamepads(blink::WebGamepads* data) {
blink_platform_impl_->sampleGamepads(*data);
}
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698