| 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" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 return; | 61 return; |
| 62 compositor_->UnlockCompositor(); | 62 compositor_->UnlockCompositor(); |
| 63 compositor_ = NULL; | 63 compositor_ = NULL; |
| 64 } | 64 } |
| 65 | 65 |
| 66 Compositor::Compositor(ui::ContextFactory* context_factory, | 66 Compositor::Compositor(ui::ContextFactory* context_factory, |
| 67 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 67 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 68 : context_factory_(context_factory), | 68 : context_factory_(context_factory), |
| 69 root_layer_(NULL), | 69 root_layer_(NULL), |
| 70 widget_(gfx::kNullAcceleratedWidget), | 70 widget_(gfx::kNullAcceleratedWidget), |
| 71 widget_valid_(false), |
| 72 output_surface_requested_(false), |
| 71 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()), | 73 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()), |
| 72 task_runner_(task_runner), | 74 task_runner_(task_runner), |
| 73 vsync_manager_(new CompositorVSyncManager()), | 75 vsync_manager_(new CompositorVSyncManager()), |
| 74 device_scale_factor_(0.0f), | 76 device_scale_factor_(0.0f), |
| 75 last_started_frame_(0), | 77 last_started_frame_(0), |
| 76 last_ended_frame_(0), | 78 last_ended_frame_(0), |
| 77 locks_will_time_out_(true), | 79 locks_will_time_out_(true), |
| 78 compositor_lock_(NULL), | 80 compositor_lock_(NULL), |
| 79 layer_animator_collection_(this), | 81 layer_animator_collection_(this), |
| 80 weak_ptr_factory_(this) { | 82 weak_ptr_factory_(this) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 params.gpu_memory_buffer_manager = | 170 params.gpu_memory_buffer_manager = |
| 169 context_factory_->GetGpuMemoryBufferManager(); | 171 context_factory_->GetGpuMemoryBufferManager(); |
| 170 params.task_graph_runner = context_factory_->GetTaskGraphRunner(); | 172 params.task_graph_runner = context_factory_->GetTaskGraphRunner(); |
| 171 params.settings = &settings; | 173 params.settings = &settings; |
| 172 params.main_task_runner = task_runner_; | 174 params.main_task_runner = task_runner_; |
| 173 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); | 175 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); |
| 174 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 176 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
| 175 base::TimeTicks::Now() - before_create); | 177 base::TimeTicks::Now() - before_create); |
| 176 host_->SetRootLayer(root_web_layer_); | 178 host_->SetRootLayer(root_web_layer_); |
| 177 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); | 179 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); |
| 180 host_->SetLayerTreeHostClientReady(); |
| 178 } | 181 } |
| 179 | 182 |
| 180 Compositor::~Compositor() { | 183 Compositor::~Compositor() { |
| 181 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 184 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
| 182 | 185 |
| 183 CancelCompositorLock(); | 186 CancelCompositorLock(); |
| 184 DCHECK(!compositor_lock_); | 187 DCHECK(!compositor_lock_); |
| 185 | 188 |
| 186 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 189 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
| 187 OnCompositingShuttingDown(this)); | 190 OnCompositingShuttingDown(this)); |
| 188 | 191 |
| 189 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, | 192 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, |
| 190 OnCompositingShuttingDown(this)); | 193 OnCompositingShuttingDown(this)); |
| 191 | 194 |
| 192 DCHECK(begin_frame_observer_list_.empty()); | 195 DCHECK(begin_frame_observer_list_.empty()); |
| 193 | 196 |
| 194 if (root_layer_) | 197 if (root_layer_) |
| 195 root_layer_->ResetCompositor(); | 198 root_layer_->ResetCompositor(); |
| 196 | 199 |
| 197 // Stop all outstanding draws before telling the ContextFactory to tear | 200 // Stop all outstanding draws before telling the ContextFactory to tear |
| 198 // down any contexts that the |host_| may rely upon. | 201 // down any contexts that the |host_| may rely upon. |
| 199 host_.reset(); | 202 host_.reset(); |
| 200 | 203 |
| 201 context_factory_->RemoveCompositor(this); | 204 context_factory_->RemoveCompositor(this); |
| 202 } | 205 } |
| 203 | 206 |
| 204 void Compositor::SetOutputSurface( | 207 void Compositor::SetOutputSurface( |
| 205 scoped_ptr<cc::OutputSurface> output_surface) { | 208 scoped_ptr<cc::OutputSurface> output_surface) { |
| 209 output_surface_requested_ = false; |
| 206 host_->SetOutputSurface(output_surface.Pass()); | 210 host_->SetOutputSurface(output_surface.Pass()); |
| 207 } | 211 } |
| 208 | 212 |
| 209 void Compositor::ScheduleDraw() { | 213 void Compositor::ScheduleDraw() { |
| 210 host_->SetNeedsCommit(); | 214 host_->SetNeedsCommit(); |
| 211 } | 215 } |
| 212 | 216 |
| 213 void Compositor::SetRootLayer(Layer* root_layer) { | 217 void Compositor::SetRootLayer(Layer* root_layer) { |
| 214 if (root_layer_ == root_layer) | 218 if (root_layer_ == root_layer) |
| 215 return; | 219 return; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 const base::TimeDelta& interval) { | 293 const base::TimeDelta& interval) { |
| 290 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 294 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 291 cc::switches::kEnableBeginFrameScheduling)) { | 295 cc::switches::kEnableBeginFrameScheduling)) { |
| 292 host_->SetAuthoritativeVSyncInterval(interval); | 296 host_->SetAuthoritativeVSyncInterval(interval); |
| 293 return; | 297 return; |
| 294 } | 298 } |
| 295 | 299 |
| 296 vsync_manager_->SetAuthoritativeVSyncInterval(interval); | 300 vsync_manager_->SetAuthoritativeVSyncInterval(interval); |
| 297 } | 301 } |
| 298 | 302 |
| 299 void Compositor::SetAcceleratedWidgetAndStartCompositor( | 303 void Compositor::SetAcceleratedWidget(gfx::AcceleratedWidget widget) { |
| 300 gfx::AcceleratedWidget widget) { | |
| 301 // This function should only get called once. | 304 // This function should only get called once. |
| 302 DCHECK_EQ(gfx::kNullAcceleratedWidget, widget_); | 305 DCHECK(!widget_valid_); |
| 303 widget_ = widget; | 306 widget_ = widget; |
| 304 host_->SetLayerTreeHostClientReady(); | 307 widget_valid_ = true; |
| 308 if (output_surface_requested_) |
| 309 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr()); |
| 310 } |
| 311 |
| 312 gfx::AcceleratedWidget Compositor::widget() const { |
| 313 DCHECK(widget_valid_); |
| 314 return widget_; |
| 305 } | 315 } |
| 306 | 316 |
| 307 scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const { | 317 scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const { |
| 308 return vsync_manager_; | 318 return vsync_manager_; |
| 309 } | 319 } |
| 310 | 320 |
| 311 void Compositor::AddObserver(CompositorObserver* observer) { | 321 void Compositor::AddObserver(CompositorObserver* observer) { |
| 312 observer_list_.AddObserver(observer); | 322 observer_list_.AddObserver(observer); |
| 313 } | 323 } |
| 314 | 324 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 SendDamagedRectsRecursive(child); | 389 SendDamagedRectsRecursive(child); |
| 380 } | 390 } |
| 381 | 391 |
| 382 void Compositor::Layout() { | 392 void Compositor::Layout() { |
| 383 if (!root_layer()) | 393 if (!root_layer()) |
| 384 return; | 394 return; |
| 385 SendDamagedRectsRecursive(root_layer()); | 395 SendDamagedRectsRecursive(root_layer()); |
| 386 } | 396 } |
| 387 | 397 |
| 388 void Compositor::RequestNewOutputSurface() { | 398 void Compositor::RequestNewOutputSurface() { |
| 389 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr()); | 399 DCHECK(!output_surface_requested_); |
| 400 output_surface_requested_ = true; |
| 401 if (widget_valid_) |
| 402 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr()); |
| 390 } | 403 } |
| 391 | 404 |
| 392 void Compositor::DidInitializeOutputSurface() { | 405 void Compositor::DidInitializeOutputSurface() { |
| 393 } | 406 } |
| 394 | 407 |
| 395 void Compositor::DidFailToInitializeOutputSurface() { | 408 void Compositor::DidFailToInitializeOutputSurface() { |
| 396 // The OutputSurface should already be bound/initialized before being given to | 409 // The OutputSurface should already be bound/initialized before being given to |
| 397 // the Compositor. | 410 // the Compositor. |
| 398 NOTREACHED(); | 411 NOTREACHED(); |
| 399 } | 412 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 observer_list_, | 478 observer_list_, |
| 466 OnCompositingLockStateChanged(this)); | 479 OnCompositingLockStateChanged(this)); |
| 467 } | 480 } |
| 468 | 481 |
| 469 void Compositor::CancelCompositorLock() { | 482 void Compositor::CancelCompositorLock() { |
| 470 if (compositor_lock_) | 483 if (compositor_lock_) |
| 471 compositor_lock_->CancelLock(); | 484 compositor_lock_->CancelLock(); |
| 472 } | 485 } |
| 473 | 486 |
| 474 } // namespace ui | 487 } // namespace ui |
| OLD | NEW |