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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 device_scale_factor_(0.0f), | 100 device_scale_factor_(0.0f), |
101 last_started_frame_(0), | 101 last_started_frame_(0), |
102 last_ended_frame_(0), | 102 last_ended_frame_(0), |
103 disable_schedule_composite_(false), | 103 disable_schedule_composite_(false), |
104 compositor_lock_(NULL), | 104 compositor_lock_(NULL), |
105 defer_draw_scheduling_(false), | 105 defer_draw_scheduling_(false), |
106 waiting_on_compositing_end_(false), | 106 waiting_on_compositing_end_(false), |
107 draw_on_compositing_end_(false), | 107 draw_on_compositing_end_(false), |
108 swap_state_(SWAP_NONE), | 108 swap_state_(SWAP_NONE), |
109 layer_animator_collection_(this), | 109 layer_animator_collection_(this), |
110 schedule_draw_factory_(this) { | 110 weak_ptr_factory_(this) { |
111 root_web_layer_ = cc::Layer::Create(); | 111 root_web_layer_ = cc::Layer::Create(); |
112 | 112 |
113 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 113 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
114 | 114 |
115 cc::LayerTreeSettings settings; | 115 cc::LayerTreeSettings settings; |
116 settings.refresh_rate = | 116 settings.refresh_rate = |
117 context_factory_->DoesCreateTestContexts() | 117 context_factory_->DoesCreateTestContexts() |
118 ? kTestRefreshRate | 118 ? kTestRefreshRate |
119 : kDefaultRefreshRate; | 119 : kDefaultRefreshRate; |
120 settings.main_frame_before_activation_enabled = false; | 120 settings.main_frame_before_activation_enabled = false; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 if (root_layer_) | 193 if (root_layer_) |
194 root_layer_->SetCompositor(NULL); | 194 root_layer_->SetCompositor(NULL); |
195 | 195 |
196 // Stop all outstanding draws before telling the ContextFactory to tear | 196 // Stop all outstanding draws before telling the ContextFactory to tear |
197 // down any contexts that the |host_| may rely upon. | 197 // down any contexts that the |host_| may rely upon. |
198 host_.reset(); | 198 host_.reset(); |
199 | 199 |
200 context_factory_->RemoveCompositor(this); | 200 context_factory_->RemoveCompositor(this); |
201 } | 201 } |
202 | 202 |
| 203 void Compositor::SetOutputSurface( |
| 204 scoped_ptr<cc::OutputSurface> output_surface) { |
| 205 host_->SetOutputSurface(output_surface.Pass()); |
| 206 } |
| 207 |
203 void Compositor::ScheduleDraw() { | 208 void Compositor::ScheduleDraw() { |
204 if (compositor_thread_loop_.get()) { | 209 if (compositor_thread_loop_.get()) { |
205 host_->SetNeedsCommit(); | 210 host_->SetNeedsCommit(); |
206 } else if (!defer_draw_scheduling_) { | 211 } else if (!defer_draw_scheduling_) { |
207 defer_draw_scheduling_ = true; | 212 defer_draw_scheduling_ = true; |
208 task_runner_->PostTask( | 213 task_runner_->PostTask( |
209 FROM_HERE, | 214 FROM_HERE, |
210 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); | 215 base::Bind(&Compositor::Draw, weak_ptr_factory_.GetWeakPtr())); |
211 } | 216 } |
212 } | 217 } |
213 | 218 |
214 void Compositor::SetRootLayer(Layer* root_layer) { | 219 void Compositor::SetRootLayer(Layer* root_layer) { |
215 if (root_layer_ == root_layer) | 220 if (root_layer_ == root_layer) |
216 return; | 221 return; |
217 if (root_layer_) | 222 if (root_layer_) |
218 root_layer_->SetCompositor(NULL); | 223 root_layer_->SetCompositor(NULL); |
219 root_layer_ = root_layer; | 224 root_layer_ = root_layer; |
220 if (root_layer_ && !root_layer_->GetCompositor()) | 225 if (root_layer_ && !root_layer_->GetCompositor()) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 void Compositor::Layout() { | 364 void Compositor::Layout() { |
360 // We're sending damage that will be addressed during this composite | 365 // We're sending damage that will be addressed during this composite |
361 // cycle, so we don't need to schedule another composite to address it. | 366 // cycle, so we don't need to schedule another composite to address it. |
362 disable_schedule_composite_ = true; | 367 disable_schedule_composite_ = true; |
363 if (root_layer_) | 368 if (root_layer_) |
364 root_layer_->SendDamagedRects(); | 369 root_layer_->SendDamagedRects(); |
365 disable_schedule_composite_ = false; | 370 disable_schedule_composite_ = false; |
366 } | 371 } |
367 | 372 |
368 void Compositor::RequestNewOutputSurface(bool fallback) { | 373 void Compositor::RequestNewOutputSurface(bool fallback) { |
369 host_->SetOutputSurface( | 374 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr(), |
370 context_factory_->CreateOutputSurface(this, fallback)); | 375 fallback); |
371 } | 376 } |
372 | 377 |
373 void Compositor::DidCommit() { | 378 void Compositor::DidCommit() { |
374 DCHECK(!IsLocked()); | 379 DCHECK(!IsLocked()); |
375 FOR_EACH_OBSERVER(CompositorObserver, | 380 FOR_EACH_OBSERVER(CompositorObserver, |
376 observer_list_, | 381 observer_list_, |
377 OnCompositingDidCommit(this)); | 382 OnCompositingDidCommit(this)); |
378 } | 383 } |
379 | 384 |
380 void Compositor::DidCommitAndDrawFrame() { | 385 void Compositor::DidCommitAndDrawFrame() { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 // Call ScheduleDraw() instead of Draw() in order to allow other | 483 // Call ScheduleDraw() instead of Draw() in order to allow other |
479 // CompositorObservers to be notified before starting another | 484 // CompositorObservers to be notified before starting another |
480 // draw cycle. | 485 // draw cycle. |
481 ScheduleDraw(); | 486 ScheduleDraw(); |
482 } | 487 } |
483 FOR_EACH_OBSERVER( | 488 FOR_EACH_OBSERVER( |
484 CompositorObserver, observer_list_, OnCompositingEnded(this)); | 489 CompositorObserver, observer_list_, OnCompositingEnded(this)); |
485 } | 490 } |
486 | 491 |
487 } // namespace ui | 492 } // namespace ui |
OLD | NEW |