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/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/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 18 #include "cc/animation/animation_host.h" |
| 19 #include "cc/animation/animation_id_provider.h" |
| 20 #include "cc/animation/animation_timeline.h" |
18 #include "cc/base/switches.h" | 21 #include "cc/base/switches.h" |
19 #include "cc/input/input_handler.h" | 22 #include "cc/input/input_handler.h" |
20 #include "cc/layers/layer.h" | 23 #include "cc/layers/layer.h" |
21 #include "cc/output/begin_frame_args.h" | 24 #include "cc/output/begin_frame_args.h" |
22 #include "cc/output/context_provider.h" | 25 #include "cc/output/context_provider.h" |
23 #include "cc/output/latency_info_swap_promise.h" | 26 #include "cc/output/latency_info_swap_promise.h" |
24 #include "cc/scheduler/begin_frame_source.h" | 27 #include "cc/scheduler/begin_frame_source.h" |
25 #include "cc/surfaces/surface_id_allocator.h" | 28 #include "cc/surfaces/surface_id_allocator.h" |
26 #include "cc/trees/layer_tree_host.h" | 29 #include "cc/trees/layer_tree_host.h" |
27 #include "third_party/skia/include/core/SkBitmap.h" | 30 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 settings.use_compositor_animation_timelines = | 144 settings.use_compositor_animation_timelines = |
142 command_line->HasSwitch(switches::kUIEnableCompositorAnimationTimelines); | 145 command_line->HasSwitch(switches::kUIEnableCompositorAnimationTimelines); |
143 | 146 |
144 base::TimeTicks before_create = base::TimeTicks::Now(); | 147 base::TimeTicks before_create = base::TimeTicks::Now(); |
145 host_ = cc::LayerTreeHost::CreateSingleThreaded( | 148 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
146 this, this, context_factory_->GetSharedBitmapManager(), | 149 this, this, context_factory_->GetSharedBitmapManager(), |
147 context_factory_->GetGpuMemoryBufferManager(), | 150 context_factory_->GetGpuMemoryBufferManager(), |
148 context_factory_->GetTaskGraphRunner(), settings, task_runner_, nullptr); | 151 context_factory_->GetTaskGraphRunner(), settings, task_runner_, nullptr); |
149 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 152 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
150 base::TimeTicks::Now() - before_create); | 153 base::TimeTicks::Now() - before_create); |
| 154 |
| 155 if (settings.use_compositor_animation_timelines) { |
| 156 animation_timeline_ = cc::AnimationTimeline::Create( |
| 157 cc::AnimationIdProvider::NextTimelineId()); |
| 158 host_->animation_host()->AddAnimationTimeline(animation_timeline_.get()); |
| 159 } |
151 host_->SetRootLayer(root_web_layer_); | 160 host_->SetRootLayer(root_web_layer_); |
152 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); | 161 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); |
153 host_->SetLayerTreeHostClientReady(); | 162 host_->SetLayerTreeHostClientReady(); |
154 } | 163 } |
155 | 164 |
156 Compositor::~Compositor() { | 165 Compositor::~Compositor() { |
157 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 166 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
158 | 167 |
159 CancelCompositorLock(); | 168 CancelCompositorLock(); |
160 DCHECK(!compositor_lock_); | 169 DCHECK(!compositor_lock_); |
161 | 170 |
162 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 171 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
163 OnCompositingShuttingDown(this)); | 172 OnCompositingShuttingDown(this)); |
164 | 173 |
165 DCHECK(begin_frame_observer_list_.empty()); | 174 DCHECK(begin_frame_observer_list_.empty()); |
166 | 175 |
167 if (root_layer_) | 176 if (root_layer_) |
168 root_layer_->SetCompositor(NULL); | 177 root_layer_->SetCompositor(NULL); |
169 | 178 |
| 179 if (animation_timeline_) |
| 180 host_->animation_host()->RemoveAnimationTimeline(animation_timeline_.get()); |
| 181 |
170 // Stop all outstanding draws before telling the ContextFactory to tear | 182 // Stop all outstanding draws before telling the ContextFactory to tear |
171 // down any contexts that the |host_| may rely upon. | 183 // down any contexts that the |host_| may rely upon. |
172 host_.reset(); | 184 host_.reset(); |
173 | 185 |
174 context_factory_->RemoveCompositor(this); | 186 context_factory_->RemoveCompositor(this); |
175 } | 187 } |
176 | 188 |
177 void Compositor::SetOutputSurface( | 189 void Compositor::SetOutputSurface( |
178 scoped_ptr<cc::OutputSurface> output_surface) { | 190 scoped_ptr<cc::OutputSurface> output_surface) { |
179 host_->SetOutputSurface(output_surface.Pass()); | 191 host_->SetOutputSurface(output_surface.Pass()); |
180 } | 192 } |
181 | 193 |
182 void Compositor::ScheduleDraw() { | 194 void Compositor::ScheduleDraw() { |
183 host_->SetNeedsCommit(); | 195 host_->SetNeedsCommit(); |
184 } | 196 } |
185 | 197 |
186 void Compositor::SetRootLayer(Layer* root_layer) { | 198 void Compositor::SetRootLayer(Layer* root_layer) { |
187 if (root_layer_ == root_layer) | 199 if (root_layer_ == root_layer) |
188 return; | 200 return; |
189 if (root_layer_) | 201 if (root_layer_) |
190 root_layer_->SetCompositor(NULL); | 202 root_layer_->SetCompositor(NULL); |
191 root_layer_ = root_layer; | 203 root_layer_ = root_layer; |
192 if (root_layer_ && !root_layer_->GetCompositor()) | 204 if (root_layer_ && !root_layer_->GetCompositor()) |
193 root_layer_->SetCompositor(this); | 205 root_layer_->SetCompositor(this); |
194 root_web_layer_->RemoveAllChildren(); | 206 root_web_layer_->RemoveAllChildren(); |
195 if (root_layer_) | 207 if (root_layer_) |
196 root_web_layer_->AddChild(root_layer_->cc_layer()); | 208 root_web_layer_->AddChild(root_layer_->cc_layer()); |
197 } | 209 } |
198 | 210 |
| 211 cc::AnimationTimeline* Compositor::GetAnimationTimeline() const { |
| 212 DCHECK(animation_timeline_); |
| 213 return animation_timeline_.get(); |
| 214 } |
| 215 |
199 void Compositor::SetHostHasTransparentBackground( | 216 void Compositor::SetHostHasTransparentBackground( |
200 bool host_has_transparent_background) { | 217 bool host_has_transparent_background) { |
201 host_->set_has_transparent_background(host_has_transparent_background); | 218 host_->set_has_transparent_background(host_has_transparent_background); |
202 } | 219 } |
203 | 220 |
204 void Compositor::ScheduleFullRedraw() { | 221 void Compositor::ScheduleFullRedraw() { |
205 // TODO(enne): Some callers (mac) call this function expecting that it | 222 // TODO(enne): Some callers (mac) call this function expecting that it |
206 // will also commit. This should probably just redraw the screen | 223 // will also commit. This should probably just redraw the screen |
207 // from damage and not commit. ScheduleDraw/ScheduleRedraw need | 224 // from damage and not commit. ScheduleDraw/ScheduleRedraw need |
208 // better names. | 225 // better names. |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 411 |
395 void Compositor::SetLayerTreeDebugState( | 412 void Compositor::SetLayerTreeDebugState( |
396 const cc::LayerTreeDebugState& debug_state) { | 413 const cc::LayerTreeDebugState& debug_state) { |
397 host_->SetDebugState(debug_state); | 414 host_->SetDebugState(debug_state); |
398 } | 415 } |
399 | 416 |
400 const cc::RendererSettings& Compositor::GetRendererSettings() const { | 417 const cc::RendererSettings& Compositor::GetRendererSettings() const { |
401 return host_->settings().renderer_settings; | 418 return host_->settings().renderer_settings; |
402 } | 419 } |
403 | 420 |
| 421 const cc::LayerTreeHost& Compositor::GetLayerTreeHost() const { |
| 422 DCHECK(host_); |
| 423 return *host_.get(); |
| 424 } |
| 425 |
404 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { | 426 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { |
405 if (!compositor_lock_) { | 427 if (!compositor_lock_) { |
406 compositor_lock_ = new CompositorLock(this); | 428 compositor_lock_ = new CompositorLock(this); |
407 host_->SetDeferCommits(true); | 429 host_->SetDeferCommits(true); |
408 FOR_EACH_OBSERVER(CompositorObserver, | 430 FOR_EACH_OBSERVER(CompositorObserver, |
409 observer_list_, | 431 observer_list_, |
410 OnCompositingLockStateChanged(this)); | 432 OnCompositingLockStateChanged(this)); |
411 } | 433 } |
412 return compositor_lock_; | 434 return compositor_lock_; |
413 } | 435 } |
414 | 436 |
415 void Compositor::UnlockCompositor() { | 437 void Compositor::UnlockCompositor() { |
416 DCHECK(compositor_lock_); | 438 DCHECK(compositor_lock_); |
417 compositor_lock_ = NULL; | 439 compositor_lock_ = NULL; |
418 host_->SetDeferCommits(false); | 440 host_->SetDeferCommits(false); |
419 FOR_EACH_OBSERVER(CompositorObserver, | 441 FOR_EACH_OBSERVER(CompositorObserver, |
420 observer_list_, | 442 observer_list_, |
421 OnCompositingLockStateChanged(this)); | 443 OnCompositingLockStateChanged(this)); |
422 } | 444 } |
423 | 445 |
424 void Compositor::CancelCompositorLock() { | 446 void Compositor::CancelCompositorLock() { |
425 if (compositor_lock_) | 447 if (compositor_lock_) |
426 compositor_lock_->CancelLock(); | 448 compositor_lock_->CancelLock(); |
427 } | 449 } |
428 | 450 |
429 } // namespace ui | 451 } // namespace ui |
OLD | NEW |