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

Side by Side Diff: ui/compositor/compositor.cc

Issue 999173004: cc: Move worker threads to content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: some cleanup Created 5 years, 9 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 | « ui/compositor/compositor.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 "ui/compositor/compositor.h" 5 #include "ui/compositor/compositor.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/profiler/scoped_tracker.h" 14 #include "base/profiler/scoped_tracker.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/sys_info.h" 16 #include "base/sys_info.h"
17 #include "base/threading/simple_thread.h"
17 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
18 #include "cc/base/switches.h" 19 #include "cc/base/switches.h"
19 #include "cc/input/input_handler.h" 20 #include "cc/input/input_handler.h"
20 #include "cc/layers/layer.h" 21 #include "cc/layers/layer.h"
21 #include "cc/output/begin_frame_args.h" 22 #include "cc/output/begin_frame_args.h"
22 #include "cc/output/context_provider.h" 23 #include "cc/output/context_provider.h"
23 #include "cc/output/latency_info_swap_promise.h" 24 #include "cc/output/latency_info_swap_promise.h"
25 #include "cc/resources/task_graph_runner.h"
24 #include "cc/scheduler/begin_frame_source.h" 26 #include "cc/scheduler/begin_frame_source.h"
25 #include "cc/surfaces/surface_id_allocator.h" 27 #include "cc/surfaces/surface_id_allocator.h"
26 #include "cc/trees/layer_tree_host.h" 28 #include "cc/trees/layer_tree_host.h"
27 #include "third_party/skia/include/core/SkBitmap.h" 29 #include "third_party/skia/include/core/SkBitmap.h"
28 #include "ui/compositor/compositor_observer.h" 30 #include "ui/compositor/compositor_observer.h"
29 #include "ui/compositor/compositor_switches.h" 31 #include "ui/compositor/compositor_switches.h"
30 #include "ui/compositor/compositor_vsync_manager.h" 32 #include "ui/compositor/compositor_vsync_manager.h"
31 #include "ui/compositor/dip_util.h" 33 #include "ui/compositor/dip_util.h"
32 #include "ui/compositor/layer.h" 34 #include "ui/compositor/layer.h"
33 #include "ui/compositor/layer_animator_collection.h" 35 #include "ui/compositor/layer_animator_collection.h"
34 #include "ui/gfx/frame_time.h" 36 #include "ui/gfx/frame_time.h"
35 #include "ui/gl/gl_context.h" 37 #include "ui/gl/gl_context.h"
36 #include "ui/gl/gl_switches.h" 38 #include "ui/gl/gl_switches.h"
37 39
38 namespace { 40 namespace {
39 41
42 class RasterThread : public base::SimpleThread {
43 public:
44 RasterThread(cc::TaskGraphRunner* task_graph_runner)
45 : base::SimpleThread("UICompositorWorker"),
46 task_graph_runner_(task_graph_runner) {}
47
48 // Overridden from base::SimpleThread:
49 void Run() override { task_graph_runner_->Run(); }
50
51 private:
52 cc::TaskGraphRunner* task_graph_runner_;
53
54 DISALLOW_COPY_AND_ASSIGN(RasterThread);
55 };
56
40 const double kDefaultRefreshRate = 60.0; 57 const double kDefaultRefreshRate = 60.0;
41 const double kTestRefreshRate = 200.0; 58 const double kTestRefreshRate = 200.0;
42 59
43 const int kCompositorLockTimeoutMs = 67; 60 const int kCompositorLockTimeoutMs = 67;
44 61
45 } // namespace 62 } // namespace
46 63
47 namespace ui { 64 namespace ui {
48 65
49 CompositorLock::CompositorLock(Compositor* compositor) 66 CompositorLock::CompositorLock(Compositor* compositor)
(...skipping 18 matching lines...) Expand all
68 } 85 }
69 86
70 Compositor::Compositor(gfx::AcceleratedWidget widget, 87 Compositor::Compositor(gfx::AcceleratedWidget widget,
71 ui::ContextFactory* context_factory, 88 ui::ContextFactory* context_factory,
72 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 89 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
73 : context_factory_(context_factory), 90 : context_factory_(context_factory),
74 root_layer_(NULL), 91 root_layer_(NULL),
75 widget_(widget), 92 widget_(widget),
76 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()), 93 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()),
77 task_runner_(task_runner), 94 task_runner_(task_runner),
95 task_graph_runner_(new cc::TaskGraphRunner),
96 raster_thread_(new RasterThread(task_graph_runner_.get())),
piman 2015/03/20 06:28:35 We wouldn't want one raster thread per compositor.
reveman 2015/03/20 07:42:02 Makes sense. Done.
78 vsync_manager_(new CompositorVSyncManager()), 97 vsync_manager_(new CompositorVSyncManager()),
79 device_scale_factor_(0.0f), 98 device_scale_factor_(0.0f),
80 last_started_frame_(0), 99 last_started_frame_(0),
81 last_ended_frame_(0), 100 last_ended_frame_(0),
82 locks_will_time_out_(true), 101 locks_will_time_out_(true),
83 compositor_lock_(NULL), 102 compositor_lock_(NULL),
84 layer_animator_collection_(this), 103 layer_animator_collection_(this),
85 weak_ptr_factory_(this) { 104 weak_ptr_factory_(this) {
86 root_web_layer_ = cc::Layer::Create(); 105 root_web_layer_ = cc::Layer::Create();
87 106
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 command_line->HasSwitch(cc::switches::kUIShowReplicaScreenSpaceRects); 147 command_line->HasSwitch(cc::switches::kUIShowReplicaScreenSpaceRects);
129 148
130 settings.initial_debug_state.SetRecordRenderingStats( 149 settings.initial_debug_state.SetRecordRenderingStats(
131 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); 150 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking));
132 151
133 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); 152 settings.impl_side_painting = IsUIImplSidePaintingEnabled();
134 settings.use_zero_copy = IsUIZeroCopyEnabled(); 153 settings.use_zero_copy = IsUIZeroCopyEnabled();
135 settings.use_one_copy = IsUIOneCopyEnabled(); 154 settings.use_one_copy = IsUIOneCopyEnabled();
136 settings.use_image_texture_target = context_factory_->GetImageTextureTarget(); 155 settings.use_image_texture_target = context_factory_->GetImageTextureTarget();
137 156
157 raster_thread_->Start();
158
138 base::TimeTicks before_create = base::TimeTicks::Now(); 159 base::TimeTicks before_create = base::TimeTicks::Now();
139 host_ = cc::LayerTreeHost::CreateSingleThreaded( 160 host_ = cc::LayerTreeHost::CreateSingleThreaded(
140 this, this, context_factory_->GetSharedBitmapManager(), 161 this, this, context_factory_->GetSharedBitmapManager(),
141 context_factory_->GetGpuMemoryBufferManager(), settings, task_runner_, 162 context_factory_->GetGpuMemoryBufferManager(), task_graph_runner_.get(),
142 nullptr); 163 settings, task_runner_, nullptr);
143 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", 164 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor",
144 base::TimeTicks::Now() - before_create); 165 base::TimeTicks::Now() - before_create);
145 host_->SetRootLayer(root_web_layer_); 166 host_->SetRootLayer(root_web_layer_);
146 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); 167 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace());
147 host_->SetLayerTreeHostClientReady(); 168 host_->SetLayerTreeHostClientReady();
148 } 169 }
149 170
150 Compositor::~Compositor() { 171 Compositor::~Compositor() {
151 TRACE_EVENT0("shutdown", "Compositor::destructor"); 172 TRACE_EVENT0("shutdown", "Compositor::destructor");
152 173
153 CancelCompositorLock(); 174 CancelCompositorLock();
154 DCHECK(!compositor_lock_); 175 DCHECK(!compositor_lock_);
155 176
156 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, 177 FOR_EACH_OBSERVER(CompositorObserver, observer_list_,
157 OnCompositingShuttingDown(this)); 178 OnCompositingShuttingDown(this));
158 179
159 if (root_layer_) 180 if (root_layer_)
160 root_layer_->SetCompositor(NULL); 181 root_layer_->SetCompositor(NULL);
161 182
162 // Stop all outstanding draws before telling the ContextFactory to tear 183 // Stop all outstanding draws before telling the ContextFactory to tear
163 // down any contexts that the |host_| may rely upon. 184 // down any contexts that the |host_| may rely upon.
164 host_.reset(); 185 host_.reset();
165 186
187 task_graph_runner_->Shutdown();
188 raster_thread_->Join();
189
166 context_factory_->RemoveCompositor(this); 190 context_factory_->RemoveCompositor(this);
167 } 191 }
168 192
169 void Compositor::SetOutputSurface( 193 void Compositor::SetOutputSurface(
170 scoped_ptr<cc::OutputSurface> output_surface) { 194 scoped_ptr<cc::OutputSurface> output_surface) {
171 host_->SetOutputSurface(output_surface.Pass()); 195 host_->SetOutputSurface(output_surface.Pass());
172 } 196 }
173 197
174 void Compositor::ScheduleDraw() { 198 void Compositor::ScheduleDraw() {
175 host_->SetNeedsCommit(); 199 host_->SetNeedsCommit();
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 observer_list_, 401 observer_list_,
378 OnCompositingLockStateChanged(this)); 402 OnCompositingLockStateChanged(this));
379 } 403 }
380 404
381 void Compositor::CancelCompositorLock() { 405 void Compositor::CancelCompositorLock() {
382 if (compositor_lock_) 406 if (compositor_lock_)
383 compositor_lock_->CancelLock(); 407 compositor_lock_->CancelLock();
384 } 408 }
385 409
386 } // namespace ui 410 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/compositor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698