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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/renderer/render_thread_impl.h" 5 #include "content/renderer/render_thread_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 } 754 }
755 755
756 media_thread_.reset(); 756 media_thread_.reset();
757 757
758 // AudioMessageFilter may be accessed on |media_thread_|, so shutdown after. 758 // AudioMessageFilter may be accessed on |media_thread_|, so shutdown after.
759 RemoveFilter(audio_message_filter_.get()); 759 RemoveFilter(audio_message_filter_.get());
760 audio_message_filter_ = NULL; 760 audio_message_filter_ = NULL;
761 761
762 compositor_thread_.reset(); 762 compositor_thread_.reset();
763 763
764 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.
765 worker_task_runner_ = nullptr;
766
764 // Shutdown raster threads. 767 // Shutdown raster threads.
765 compositor_task_graph_runner_->Shutdown(); 768 compositor_task_graph_runner_->Shutdown();
766 while (!compositor_raster_threads_.empty()) { 769 while (!compositor_raster_threads_.empty()) {
767 compositor_raster_threads_.back()->Join(); 770 compositor_raster_threads_.back()->Join();
768 compositor_raster_threads_.pop_back(); 771 compositor_raster_threads_.pop_back();
769 } 772 }
770 compositor_task_graph_runner_.reset(); 773 compositor_task_graph_runner_.reset();
771 774
772 main_input_callback_.Cancel(); 775 main_input_callback_.Cancel();
773 input_handler_manager_.reset(); 776 input_handler_manager_.reset();
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 media_thread_->Start(); 1786 media_thread_->Start();
1784 1787
1785 #if defined(OS_ANDROID) 1788 #if defined(OS_ANDROID)
1786 renderer_demuxer_ = new RendererDemuxerAndroid(); 1789 renderer_demuxer_ = new RendererDemuxerAndroid();
1787 AddFilter(renderer_demuxer_.get()); 1790 AddFilter(renderer_demuxer_.get());
1788 #endif 1791 #endif
1789 } 1792 }
1790 return media_thread_->task_runner(); 1793 return media_thread_->task_runner();
1791 } 1794 }
1792 1795
1796 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.
1797
1798 // Simple Task for the TaskGraphRunner that wraps a closure.
1799 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
1800 public:
1801 TaskGraphRunnerClosureTask(const base::Closure& closure)
1802 : closure_(closure) {}
1803 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
1804
1805 protected:
1806 ~TaskGraphRunnerClosureTask() override {}
1807
1808 private:
1809 const base::Closure closure_;
1810 };
1811
1812 // SequencedTaskRunner implementation that runs tasks on
1813 // |compositor_raster_threads_| using |task_graph_runner_|.
1814 class TaskGraphRunnerSequencedTaskRunner : public base::SequencedTaskRunner {
1815 public:
1816 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
1817 : task_graph_runner_(task_graph_runner),
1818 namespace_token_(task_graph_runner->GetNamespaceToken()) {}
1819 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.
1820 const base::Closure& task,
1821 base::TimeDelta delay) override {
1822 DCHECK(task_graph_runner_);
1823 PostNonNestableDelayedTask(from_here, task, delay);
1824 return true;
1825 }
1826
1827 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.
1828 const base::Closure& task,
1829 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.
1830 DCHECK(task_graph_runner_);
1831 // Remove completed tasks.
1832 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.
1833 task_graph_runner_->CollectCompletedTasks(namespace_token_,
1834 &completed_tasks);
1835 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
1836 tasks_.begin(), tasks_.end(),
1837 [&completed_tasks](const scoped_refptr<cc::Task>& t) {
1838 return std::find(completed_tasks.begin(), completed_tasks.end(), t) !=
1839 completed_tasks.end();
1840 });
1841 tasks_.erase(new_end, tasks_.end());
1842 tasks_.push_back(make_scoped_refptr(new TaskGraphRunnerClosureTask(task)));
1843
1844 // 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.
1845 graph_.Reset();
1846 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.
1847 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.
1848 if (graph_.nodes.size()) {
1849 graph_.edges.push_back(
1850 cc::TaskGraph::Edge(graph_.nodes.back().task, node.task));
1851 }
1852 graph_.nodes.push_back(node);
1853 }
1854
1855 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_);
1856 return true;
1857 }
1858
1859 bool RunsTasksOnCurrentThread() const override { return true; }
1860
1861 protected:
1862 ~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 ";"?
1863
1864 private:
1865 TaskGraphRunnerClosureTask::Vector tasks_;
1866 cc::TaskGraph graph_;
1867 cc::TaskGraphRunner* task_graph_runner_;
1868 const cc::NamespaceToken namespace_token_;
1869 };
1870 }
1871
1872 scoped_refptr<base::SequencedTaskRunner>
1873 RenderThreadImpl::GetWorkerSequencedTaskRunner() {
1874 if (!worker_task_runner_) {
1875 worker_task_runner_ = make_scoped_refptr(
1876 new content::TaskGraphRunnerSequencedTaskRunner(GetTaskGraphRunner()));
1877 }
1878 return worker_task_runner_;
1879 }
1880
1793 void RenderThreadImpl::SampleGamepads(blink::WebGamepads* data) { 1881 void RenderThreadImpl::SampleGamepads(blink::WebGamepads* data) {
1794 blink_platform_impl_->sampleGamepads(*data); 1882 blink_platform_impl_->sampleGamepads(*data);
1795 } 1883 }
1796 1884
1797 bool RenderThreadImpl::RendererIsHidden() const { 1885 bool RenderThreadImpl::RendererIsHidden() const {
1798 return widget_count_ > 0 && hidden_widget_count_ == widget_count_; 1886 return widget_count_ > 0 && hidden_widget_count_ == widget_count_;
1799 } 1887 }
1800 1888
1801 void RenderThreadImpl::WidgetCreated() { 1889 void RenderThreadImpl::WidgetCreated() {
1802 bool renderer_was_hidden = RendererIsHidden(); 1890 bool renderer_was_hidden = RendererIsHidden();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 } 1961 }
1874 1962
1875 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { 1963 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() {
1876 size_t erased = 1964 size_t erased =
1877 RenderThreadImpl::current()->pending_render_frame_connects_.erase( 1965 RenderThreadImpl::current()->pending_render_frame_connects_.erase(
1878 routing_id_); 1966 routing_id_);
1879 DCHECK_EQ(1u, erased); 1967 DCHECK_EQ(1u, erased);
1880 } 1968 }
1881 1969
1882 } // namespace content 1970 } // namespace content
OLDNEW
« 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