| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 device_scale_factor_(0.0f), | 101 device_scale_factor_(0.0f), |
| 102 last_started_frame_(0), | 102 last_started_frame_(0), |
| 103 last_ended_frame_(0), | 103 last_ended_frame_(0), |
| 104 disable_schedule_composite_(false), | 104 disable_schedule_composite_(false), |
| 105 compositor_lock_(NULL), | 105 compositor_lock_(NULL), |
| 106 defer_draw_scheduling_(false), | 106 defer_draw_scheduling_(false), |
| 107 waiting_on_compositing_end_(false), | 107 waiting_on_compositing_end_(false), |
| 108 draw_on_compositing_end_(false), | 108 draw_on_compositing_end_(false), |
| 109 swap_state_(SWAP_NONE), | 109 swap_state_(SWAP_NONE), |
| 110 layer_animator_collection_(this), | 110 layer_animator_collection_(this), |
| 111 schedule_draw_factory_(this) { | 111 weak_ptr_factory_(this) { |
| 112 root_web_layer_ = cc::Layer::Create(); | 112 root_web_layer_ = cc::Layer::Create(); |
| 113 | 113 |
| 114 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 114 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 115 | 115 |
| 116 cc::LayerTreeSettings settings; | 116 cc::LayerTreeSettings settings; |
| 117 settings.renderer_settings.refresh_rate = | 117 settings.renderer_settings.refresh_rate = |
| 118 context_factory_->DoesCreateTestContexts() | 118 context_factory_->DoesCreateTestContexts() |
| 119 ? kTestRefreshRate | 119 ? kTestRefreshRate |
| 120 : kDefaultRefreshRate; | 120 : kDefaultRefreshRate; |
| 121 settings.main_frame_before_activation_enabled = false; | 121 settings.main_frame_before_activation_enabled = false; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 context_factory_->RemoveCompositor(this); | 203 context_factory_->RemoveCompositor(this); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void Compositor::ScheduleDraw() { | 206 void Compositor::ScheduleDraw() { |
| 207 if (compositor_thread_loop_.get()) { | 207 if (compositor_thread_loop_.get()) { |
| 208 host_->SetNeedsCommit(); | 208 host_->SetNeedsCommit(); |
| 209 } else if (!defer_draw_scheduling_) { | 209 } else if (!defer_draw_scheduling_) { |
| 210 defer_draw_scheduling_ = true; | 210 defer_draw_scheduling_ = true; |
| 211 task_runner_->PostTask( | 211 task_runner_->PostTask( |
| 212 FROM_HERE, | 212 FROM_HERE, |
| 213 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); | 213 base::Bind(&Compositor::Draw, weak_ptr_factory_.GetWeakPtr())); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 void Compositor::DidInitializeOutputSurface() { |
| 218 num_failed_recreate_attempts_ = 0; |
| 219 } |
| 220 |
| 221 void Compositor::DidFailToInitializeOutputSurface() { |
| 222 num_failed_recreate_attempts_++; |
| 223 |
| 224 // Tolerate a certain number of recreation failures to work around races |
| 225 // in the output-surface-lost machinery. |
| 226 if (num_failed_recreate_attempts_ >= MAX_OUTPUT_SURFACE_RETRIES) |
| 227 LOG(FATAL) << "Failed to create a fallback OutputSurface."; |
| 228 |
| 229 base::MessageLoop::current()->PostTask( |
| 230 FROM_HERE, base::Bind(&Compositor::RequestNewOutputSurface, |
| 231 weak_ptr_factory_.GetWeakPtr())); |
| 232 } |
| 233 |
| 217 void Compositor::SetRootLayer(Layer* root_layer) { | 234 void Compositor::SetRootLayer(Layer* root_layer) { |
| 218 if (root_layer_ == root_layer) | 235 if (root_layer_ == root_layer) |
| 219 return; | 236 return; |
| 220 if (root_layer_) | 237 if (root_layer_) |
| 221 root_layer_->SetCompositor(NULL); | 238 root_layer_->SetCompositor(NULL); |
| 222 root_layer_ = root_layer; | 239 root_layer_ = root_layer; |
| 223 if (root_layer_ && !root_layer_->GetCompositor()) | 240 if (root_layer_ && !root_layer_->GetCompositor()) |
| 224 root_layer_->SetCompositor(this); | 241 root_layer_->SetCompositor(this); |
| 225 root_web_layer_->RemoveAllChildren(); | 242 root_web_layer_->RemoveAllChildren(); |
| 226 if (root_layer_) | 243 if (root_layer_) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 377 |
| 361 void Compositor::Layout() { | 378 void Compositor::Layout() { |
| 362 // We're sending damage that will be addressed during this composite | 379 // We're sending damage that will be addressed during this composite |
| 363 // cycle, so we don't need to schedule another composite to address it. | 380 // cycle, so we don't need to schedule another composite to address it. |
| 364 disable_schedule_composite_ = true; | 381 disable_schedule_composite_ = true; |
| 365 if (root_layer_) | 382 if (root_layer_) |
| 366 root_layer_->SendDamagedRects(); | 383 root_layer_->SendDamagedRects(); |
| 367 disable_schedule_composite_ = false; | 384 disable_schedule_composite_ = false; |
| 368 } | 385 } |
| 369 | 386 |
| 370 void Compositor::RequestNewOutputSurface(bool fallback) { | 387 void Compositor::RequestNewOutputSurface() { |
| 371 host_->SetOutputSurface( | 388 bool fallback = |
| 372 context_factory_->CreateOutputSurface(this, fallback)); | 389 num_failed_recreate_attempts_ >= OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK; |
| 390 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr().get(), |
| 391 fallback); |
| 373 } | 392 } |
| 374 | 393 |
| 375 void Compositor::DidCommit() { | 394 void Compositor::DidCommit() { |
| 376 DCHECK(!IsLocked()); | 395 DCHECK(!IsLocked()); |
| 377 FOR_EACH_OBSERVER(CompositorObserver, | 396 FOR_EACH_OBSERVER(CompositorObserver, |
| 378 observer_list_, | 397 observer_list_, |
| 379 OnCompositingDidCommit(this)); | 398 OnCompositingDidCommit(this)); |
| 380 } | 399 } |
| 381 | 400 |
| 382 void Compositor::DidCommitAndDrawFrame() { | 401 void Compositor::DidCommitAndDrawFrame() { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 // Call ScheduleDraw() instead of Draw() in order to allow other | 499 // Call ScheduleDraw() instead of Draw() in order to allow other |
| 481 // CompositorObservers to be notified before starting another | 500 // CompositorObservers to be notified before starting another |
| 482 // draw cycle. | 501 // draw cycle. |
| 483 ScheduleDraw(); | 502 ScheduleDraw(); |
| 484 } | 503 } |
| 485 FOR_EACH_OBSERVER( | 504 FOR_EACH_OBSERVER( |
| 486 CompositorObserver, observer_list_, OnCompositingEnded(this)); | 505 CompositorObserver, observer_list_, OnCompositingEnded(this)); |
| 487 } | 506 } |
| 488 | 507 |
| 489 } // namespace ui | 508 } // namespace ui |
| OLD | NEW |