| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 : context_factory_(context_factory), | 70 : context_factory_(context_factory), |
| 71 root_layer_(NULL), | 71 root_layer_(NULL), |
| 72 widget_(widget), | 72 widget_(widget), |
| 73 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()), | 73 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()), |
| 74 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), | 74 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), |
| 75 task_runner_(task_runner), | 75 task_runner_(task_runner), |
| 76 vsync_manager_(new CompositorVSyncManager()), | 76 vsync_manager_(new CompositorVSyncManager()), |
| 77 device_scale_factor_(0.0f), | 77 device_scale_factor_(0.0f), |
| 78 last_started_frame_(0), | 78 last_started_frame_(0), |
| 79 last_ended_frame_(0), | 79 last_ended_frame_(0), |
| 80 num_failed_recreate_attempts_(0), |
| 80 disable_schedule_composite_(false), | 81 disable_schedule_composite_(false), |
| 81 compositor_lock_(NULL), | 82 compositor_lock_(NULL), |
| 82 defer_draw_scheduling_(false), | 83 defer_draw_scheduling_(false), |
| 83 waiting_on_compositing_end_(false), | 84 waiting_on_compositing_end_(false), |
| 84 draw_on_compositing_end_(false), | 85 draw_on_compositing_end_(false), |
| 85 swap_state_(SWAP_NONE), | 86 swap_state_(SWAP_NONE), |
| 86 layer_animator_collection_(this), | 87 layer_animator_collection_(this), |
| 87 weak_ptr_factory_(this) { | 88 weak_ptr_factory_(this) { |
| 88 root_web_layer_ = cc::Layer::Create(); | 89 root_web_layer_ = cc::Layer::Create(); |
| 89 | 90 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 347 |
| 347 void Compositor::Layout() { | 348 void Compositor::Layout() { |
| 348 // We're sending damage that will be addressed during this composite | 349 // We're sending damage that will be addressed during this composite |
| 349 // cycle, so we don't need to schedule another composite to address it. | 350 // cycle, so we don't need to schedule another composite to address it. |
| 350 disable_schedule_composite_ = true; | 351 disable_schedule_composite_ = true; |
| 351 if (root_layer_) | 352 if (root_layer_) |
| 352 root_layer_->SendDamagedRects(); | 353 root_layer_->SendDamagedRects(); |
| 353 disable_schedule_composite_ = false; | 354 disable_schedule_composite_ = false; |
| 354 } | 355 } |
| 355 | 356 |
| 356 void Compositor::RequestNewOutputSurface(bool fallback) { | 357 void Compositor::RequestNewOutputSurface() { |
| 358 bool fallback = |
| 359 num_failed_recreate_attempts_ >= OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK; |
| 357 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr(), | 360 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr(), |
| 358 fallback); | 361 fallback); |
| 359 } | 362 } |
| 360 | 363 |
| 364 void Compositor::DidInitializeOutputSurface() { |
| 365 num_failed_recreate_attempts_ = 0; |
| 366 } |
| 367 |
| 368 void Compositor::DidFailToInitializeOutputSurface() { |
| 369 num_failed_recreate_attempts_++; |
| 370 |
| 371 // Tolerate a certain number of recreation failures to work around races |
| 372 // in the output-surface-lost machinery. |
| 373 if (num_failed_recreate_attempts_ >= MAX_OUTPUT_SURFACE_RETRIES) |
| 374 LOG(FATAL) << "Failed to create a fallback OutputSurface."; |
| 375 |
| 376 base::MessageLoop::current()->PostTask( |
| 377 FROM_HERE, base::Bind(&Compositor::RequestNewOutputSurface, |
| 378 weak_ptr_factory_.GetWeakPtr())); |
| 379 } |
| 380 |
| 361 void Compositor::DidCommit() { | 381 void Compositor::DidCommit() { |
| 362 DCHECK(!IsLocked()); | 382 DCHECK(!IsLocked()); |
| 363 FOR_EACH_OBSERVER(CompositorObserver, | 383 FOR_EACH_OBSERVER(CompositorObserver, |
| 364 observer_list_, | 384 observer_list_, |
| 365 OnCompositingDidCommit(this)); | 385 OnCompositingDidCommit(this)); |
| 366 } | 386 } |
| 367 | 387 |
| 368 void Compositor::DidCommitAndDrawFrame() { | 388 void Compositor::DidCommitAndDrawFrame() { |
| 369 base::TimeTicks start_time = gfx::FrameTime::Now(); | 389 base::TimeTicks start_time = gfx::FrameTime::Now(); |
| 370 FOR_EACH_OBSERVER(CompositorObserver, | 390 FOR_EACH_OBSERVER(CompositorObserver, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 // Call ScheduleDraw() instead of Draw() in order to allow other | 480 // Call ScheduleDraw() instead of Draw() in order to allow other |
| 461 // CompositorObservers to be notified before starting another | 481 // CompositorObservers to be notified before starting another |
| 462 // draw cycle. | 482 // draw cycle. |
| 463 ScheduleDraw(); | 483 ScheduleDraw(); |
| 464 } | 484 } |
| 465 FOR_EACH_OBSERVER( | 485 FOR_EACH_OBSERVER( |
| 466 CompositorObserver, observer_list_, OnCompositingEnded(this)); | 486 CompositorObserver, observer_list_, OnCompositingEnded(this)); |
| 467 } | 487 } |
| 468 | 488 |
| 469 } // namespace ui | 489 } // namespace ui |
| OLD | NEW |