| 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 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 params.client = this; | 186 params.client = this; |
| 184 params.shared_bitmap_manager = context_factory_->GetSharedBitmapManager(); | 187 params.shared_bitmap_manager = context_factory_->GetSharedBitmapManager(); |
| 185 params.gpu_memory_buffer_manager = | 188 params.gpu_memory_buffer_manager = |
| 186 context_factory_->GetGpuMemoryBufferManager(); | 189 context_factory_->GetGpuMemoryBufferManager(); |
| 187 params.task_graph_runner = context_factory_->GetTaskGraphRunner(); | 190 params.task_graph_runner = context_factory_->GetTaskGraphRunner(); |
| 188 params.settings = &settings; | 191 params.settings = &settings; |
| 189 params.main_task_runner = task_runner_; | 192 params.main_task_runner = task_runner_; |
| 190 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); | 193 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); |
| 191 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 194 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
| 192 base::TimeTicks::Now() - before_create); | 195 base::TimeTicks::Now() - before_create); |
| 196 |
| 197 if (settings.use_compositor_animation_timelines) { |
| 198 animation_timeline_ = cc::AnimationTimeline::Create( |
| 199 cc::AnimationIdProvider::NextTimelineId()); |
| 200 host_->animation_host()->AddAnimationTimeline(animation_timeline_.get()); |
| 201 } |
| 193 host_->SetRootLayer(root_web_layer_); | 202 host_->SetRootLayer(root_web_layer_); |
| 194 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); | 203 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); |
| 195 host_->SetVisible(true); | 204 host_->SetVisible(true); |
| 196 } | 205 } |
| 197 | 206 |
| 198 Compositor::~Compositor() { | 207 Compositor::~Compositor() { |
| 199 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 208 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
| 200 | 209 |
| 201 CancelCompositorLock(); | 210 CancelCompositorLock(); |
| 202 DCHECK(!compositor_lock_); | 211 DCHECK(!compositor_lock_); |
| 203 | 212 |
| 204 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 213 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
| 205 OnCompositingShuttingDown(this)); | 214 OnCompositingShuttingDown(this)); |
| 206 | 215 |
| 207 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, | 216 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, |
| 208 OnCompositingShuttingDown(this)); | 217 OnCompositingShuttingDown(this)); |
| 209 | 218 |
| 210 if (root_layer_) | 219 if (root_layer_) |
| 211 root_layer_->ResetCompositor(); | 220 root_layer_->ResetCompositor(); |
| 212 | 221 |
| 222 if (animation_timeline_) |
| 223 host_->animation_host()->RemoveAnimationTimeline(animation_timeline_.get()); |
| 224 |
| 213 // Stop all outstanding draws before telling the ContextFactory to tear | 225 // Stop all outstanding draws before telling the ContextFactory to tear |
| 214 // down any contexts that the |host_| may rely upon. | 226 // down any contexts that the |host_| may rely upon. |
| 215 host_.reset(); | 227 host_.reset(); |
| 216 | 228 |
| 217 context_factory_->RemoveCompositor(this); | 229 context_factory_->RemoveCompositor(this); |
| 218 } | 230 } |
| 219 | 231 |
| 220 void Compositor::SetOutputSurface( | 232 void Compositor::SetOutputSurface( |
| 221 scoped_ptr<cc::OutputSurface> output_surface) { | 233 scoped_ptr<cc::OutputSurface> output_surface) { |
| 222 output_surface_requested_ = false; | 234 output_surface_requested_ = false; |
| 223 host_->SetOutputSurface(std::move(output_surface)); | 235 host_->SetOutputSurface(std::move(output_surface)); |
| 224 } | 236 } |
| 225 | 237 |
| 226 void Compositor::ScheduleDraw() { | 238 void Compositor::ScheduleDraw() { |
| 227 host_->SetNeedsCommit(); | 239 host_->SetNeedsCommit(); |
| 228 } | 240 } |
| 229 | 241 |
| 230 void Compositor::SetRootLayer(Layer* root_layer) { | 242 void Compositor::SetRootLayer(Layer* root_layer) { |
| 231 if (root_layer_ == root_layer) | 243 if (root_layer_ == root_layer) |
| 232 return; | 244 return; |
| 233 if (root_layer_) | 245 if (root_layer_) |
| 234 root_layer_->ResetCompositor(); | 246 root_layer_->ResetCompositor(); |
| 235 root_layer_ = root_layer; | 247 root_layer_ = root_layer; |
| 236 root_web_layer_->RemoveAllChildren(); | 248 root_web_layer_->RemoveAllChildren(); |
| 237 if (root_layer_) | 249 if (root_layer_) |
| 238 root_layer_->SetCompositor(this, root_web_layer_); | 250 root_layer_->SetCompositor(this, root_web_layer_); |
| 239 } | 251 } |
| 240 | 252 |
| 253 cc::AnimationTimeline* Compositor::GetAnimationTimeline() const { |
| 254 return animation_timeline_.get(); |
| 255 } |
| 256 |
| 241 void Compositor::SetHostHasTransparentBackground( | 257 void Compositor::SetHostHasTransparentBackground( |
| 242 bool host_has_transparent_background) { | 258 bool host_has_transparent_background) { |
| 243 host_->set_has_transparent_background(host_has_transparent_background); | 259 host_->set_has_transparent_background(host_has_transparent_background); |
| 244 } | 260 } |
| 245 | 261 |
| 246 void Compositor::ScheduleFullRedraw() { | 262 void Compositor::ScheduleFullRedraw() { |
| 247 // TODO(enne): Some callers (mac) call this function expecting that it | 263 // TODO(enne): Some callers (mac) call this function expecting that it |
| 248 // will also commit. This should probably just redraw the screen | 264 // will also commit. This should probably just redraw the screen |
| 249 // from damage and not commit. ScheduleDraw/ScheduleRedraw need | 265 // from damage and not commit. ScheduleDraw/ScheduleRedraw need |
| 250 // better names. | 266 // better names. |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 observer_list_, | 519 observer_list_, |
| 504 OnCompositingLockStateChanged(this)); | 520 OnCompositingLockStateChanged(this)); |
| 505 } | 521 } |
| 506 | 522 |
| 507 void Compositor::CancelCompositorLock() { | 523 void Compositor::CancelCompositorLock() { |
| 508 if (compositor_lock_) | 524 if (compositor_lock_) |
| 509 compositor_lock_->CancelLock(); | 525 compositor_lock_->CancelLock(); |
| 510 } | 526 } |
| 511 | 527 |
| 512 } // namespace ui | 528 } // namespace ui |
| OLD | NEW |