OLD | NEW |
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/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 17 #include "cc/animation/animation_host.h" |
| 18 #include "cc/animation/animation_id_provider.h" |
| 19 #include "cc/animation/animation_timeline.h" |
17 #include "cc/base/switches.h" | 20 #include "cc/base/switches.h" |
18 #include "cc/input/input_handler.h" | 21 #include "cc/input/input_handler.h" |
19 #include "cc/layers/layer.h" | 22 #include "cc/layers/layer.h" |
20 #include "cc/output/begin_frame_args.h" | 23 #include "cc/output/begin_frame_args.h" |
21 #include "cc/output/context_provider.h" | 24 #include "cc/output/context_provider.h" |
22 #include "cc/output/latency_info_swap_promise.h" | 25 #include "cc/output/latency_info_swap_promise.h" |
23 #include "cc/scheduler/begin_frame_source.h" | 26 #include "cc/scheduler/begin_frame_source.h" |
24 #include "cc/surfaces/surface_id_allocator.h" | 27 #include "cc/surfaces/surface_id_allocator.h" |
25 #include "cc/trees/layer_tree_host.h" | 28 #include "cc/trees/layer_tree_host.h" |
26 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 params.client = this; | 187 params.client = this; |
185 params.shared_bitmap_manager = context_factory_->GetSharedBitmapManager(); | 188 params.shared_bitmap_manager = context_factory_->GetSharedBitmapManager(); |
186 params.gpu_memory_buffer_manager = | 189 params.gpu_memory_buffer_manager = |
187 context_factory_->GetGpuMemoryBufferManager(); | 190 context_factory_->GetGpuMemoryBufferManager(); |
188 params.task_graph_runner = context_factory_->GetTaskGraphRunner(); | 191 params.task_graph_runner = context_factory_->GetTaskGraphRunner(); |
189 params.settings = &settings; | 192 params.settings = &settings; |
190 params.main_task_runner = task_runner_; | 193 params.main_task_runner = task_runner_; |
191 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); | 194 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); |
192 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 195 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
193 base::TimeTicks::Now() - before_create); | 196 base::TimeTicks::Now() - before_create); |
| 197 |
| 198 if (settings.use_compositor_animation_timelines) { |
| 199 animation_timeline_ = cc::AnimationTimeline::Create( |
| 200 cc::AnimationIdProvider::NextTimelineId()); |
| 201 host_->animation_host()->AddAnimationTimeline(animation_timeline_.get()); |
| 202 } |
194 host_->SetRootLayer(root_web_layer_); | 203 host_->SetRootLayer(root_web_layer_); |
195 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); | 204 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); |
196 host_->SetVisible(true); | 205 host_->SetVisible(true); |
197 } | 206 } |
198 | 207 |
199 Compositor::~Compositor() { | 208 Compositor::~Compositor() { |
200 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 209 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
201 | 210 |
202 CancelCompositorLock(); | 211 CancelCompositorLock(); |
203 DCHECK(!compositor_lock_); | 212 DCHECK(!compositor_lock_); |
204 | 213 |
205 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 214 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
206 OnCompositingShuttingDown(this)); | 215 OnCompositingShuttingDown(this)); |
207 | 216 |
208 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, | 217 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, |
209 OnCompositingShuttingDown(this)); | 218 OnCompositingShuttingDown(this)); |
210 | 219 |
211 if (root_layer_) | 220 if (root_layer_) |
212 root_layer_->ResetCompositor(); | 221 root_layer_->ResetCompositor(); |
213 | 222 |
| 223 if (animation_timeline_) |
| 224 host_->animation_host()->RemoveAnimationTimeline(animation_timeline_.get()); |
| 225 |
214 // Stop all outstanding draws before telling the ContextFactory to tear | 226 // Stop all outstanding draws before telling the ContextFactory to tear |
215 // down any contexts that the |host_| may rely upon. | 227 // down any contexts that the |host_| may rely upon. |
216 host_.reset(); | 228 host_.reset(); |
217 | 229 |
218 context_factory_->RemoveCompositor(this); | 230 context_factory_->RemoveCompositor(this); |
219 } | 231 } |
220 | 232 |
221 void Compositor::SetOutputSurface( | 233 void Compositor::SetOutputSurface( |
222 scoped_ptr<cc::OutputSurface> output_surface) { | 234 scoped_ptr<cc::OutputSurface> output_surface) { |
223 output_surface_requested_ = false; | 235 output_surface_requested_ = false; |
224 host_->SetOutputSurface(output_surface.Pass()); | 236 host_->SetOutputSurface(output_surface.Pass()); |
225 } | 237 } |
226 | 238 |
227 void Compositor::ScheduleDraw() { | 239 void Compositor::ScheduleDraw() { |
228 host_->SetNeedsCommit(); | 240 host_->SetNeedsCommit(); |
229 } | 241 } |
230 | 242 |
231 void Compositor::SetRootLayer(Layer* root_layer) { | 243 void Compositor::SetRootLayer(Layer* root_layer) { |
232 if (root_layer_ == root_layer) | 244 if (root_layer_ == root_layer) |
233 return; | 245 return; |
234 if (root_layer_) | 246 if (root_layer_) |
235 root_layer_->ResetCompositor(); | 247 root_layer_->ResetCompositor(); |
236 root_layer_ = root_layer; | 248 root_layer_ = root_layer; |
237 root_web_layer_->RemoveAllChildren(); | 249 root_web_layer_->RemoveAllChildren(); |
238 if (root_layer_) | 250 if (root_layer_) |
239 root_layer_->SetCompositor(this, root_web_layer_); | 251 root_layer_->SetCompositor(this, root_web_layer_); |
240 } | 252 } |
241 | 253 |
| 254 cc::AnimationTimeline* Compositor::GetAnimationTimeline() const { |
| 255 return animation_timeline_.get(); |
| 256 } |
| 257 |
242 void Compositor::SetHostHasTransparentBackground( | 258 void Compositor::SetHostHasTransparentBackground( |
243 bool host_has_transparent_background) { | 259 bool host_has_transparent_background) { |
244 host_->set_has_transparent_background(host_has_transparent_background); | 260 host_->set_has_transparent_background(host_has_transparent_background); |
245 } | 261 } |
246 | 262 |
247 void Compositor::ScheduleFullRedraw() { | 263 void Compositor::ScheduleFullRedraw() { |
248 // TODO(enne): Some callers (mac) call this function expecting that it | 264 // TODO(enne): Some callers (mac) call this function expecting that it |
249 // will also commit. This should probably just redraw the screen | 265 // will also commit. This should probably just redraw the screen |
250 // from damage and not commit. ScheduleDraw/ScheduleRedraw need | 266 // from damage and not commit. ScheduleDraw/ScheduleRedraw need |
251 // better names. | 267 // better names. |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 | 494 |
479 void Compositor::SetLayerTreeDebugState( | 495 void Compositor::SetLayerTreeDebugState( |
480 const cc::LayerTreeDebugState& debug_state) { | 496 const cc::LayerTreeDebugState& debug_state) { |
481 host_->SetDebugState(debug_state); | 497 host_->SetDebugState(debug_state); |
482 } | 498 } |
483 | 499 |
484 const cc::RendererSettings& Compositor::GetRendererSettings() const { | 500 const cc::RendererSettings& Compositor::GetRendererSettings() const { |
485 return host_->settings().renderer_settings; | 501 return host_->settings().renderer_settings; |
486 } | 502 } |
487 | 503 |
| 504 const cc::LayerTreeHost& Compositor::GetLayerTreeHost() const { |
| 505 DCHECK(host_); |
| 506 return *host_.get(); |
| 507 } |
| 508 |
488 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { | 509 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { |
489 if (!compositor_lock_) { | 510 if (!compositor_lock_) { |
490 compositor_lock_ = new CompositorLock(this); | 511 compositor_lock_ = new CompositorLock(this); |
491 host_->SetDeferCommits(true); | 512 host_->SetDeferCommits(true); |
492 FOR_EACH_OBSERVER(CompositorObserver, | 513 FOR_EACH_OBSERVER(CompositorObserver, |
493 observer_list_, | 514 observer_list_, |
494 OnCompositingLockStateChanged(this)); | 515 OnCompositingLockStateChanged(this)); |
495 } | 516 } |
496 return compositor_lock_; | 517 return compositor_lock_; |
497 } | 518 } |
498 | 519 |
499 void Compositor::UnlockCompositor() { | 520 void Compositor::UnlockCompositor() { |
500 DCHECK(compositor_lock_); | 521 DCHECK(compositor_lock_); |
501 compositor_lock_ = NULL; | 522 compositor_lock_ = NULL; |
502 host_->SetDeferCommits(false); | 523 host_->SetDeferCommits(false); |
503 FOR_EACH_OBSERVER(CompositorObserver, | 524 FOR_EACH_OBSERVER(CompositorObserver, |
504 observer_list_, | 525 observer_list_, |
505 OnCompositingLockStateChanged(this)); | 526 OnCompositingLockStateChanged(this)); |
506 } | 527 } |
507 | 528 |
508 void Compositor::CancelCompositorLock() { | 529 void Compositor::CancelCompositorLock() { |
509 if (compositor_lock_) | 530 if (compositor_lock_) |
510 compositor_lock_->CancelLock(); | 531 compositor_lock_->CancelLock(); |
511 } | 532 } |
512 | 533 |
513 } // namespace ui | 534 } // namespace ui |
OLD | NEW |