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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); | 132 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); |
133 | 133 |
134 settings.initial_debug_state.SetRecordRenderingStats( | 134 settings.initial_debug_state.SetRecordRenderingStats( |
135 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | 135 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
136 | 136 |
137 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); | 137 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); |
138 settings.use_zero_copy = IsUIZeroCopyEnabled(); | 138 settings.use_zero_copy = IsUIZeroCopyEnabled(); |
139 settings.single_thread_proxy_scheduler = false; | 139 settings.single_thread_proxy_scheduler = false; |
140 | 140 |
141 base::TimeTicks before_create = base::TimeTicks::Now(); | 141 base::TimeTicks before_create = base::TimeTicks::Now(); |
142 if (compositor_thread_loop_) { | 142 if (compositor_thread_loop_.get()) { |
143 host_ = cc::LayerTreeHost::CreateThreaded( | 143 host_ = cc::LayerTreeHost::CreateThreaded( |
144 this, | 144 this, |
145 context_factory_->GetSharedBitmapManager(), | 145 context_factory_->GetSharedBitmapManager(), |
146 settings, | 146 settings, |
147 task_runner_, | 147 task_runner_, |
148 compositor_thread_loop_); | 148 compositor_thread_loop_); |
149 } else { | 149 } else { |
150 host_ = cc::LayerTreeHost::CreateSingleThreaded( | 150 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
151 this, | 151 this, |
152 this, | 152 this, |
(...skipping 17 matching lines...) Expand all Loading... |
170 root_layer_->SetCompositor(NULL); | 170 root_layer_->SetCompositor(NULL); |
171 | 171 |
172 // Stop all outstanding draws before telling the ContextFactory to tear | 172 // Stop all outstanding draws before telling the ContextFactory to tear |
173 // down any contexts that the |host_| may rely upon. | 173 // down any contexts that the |host_| may rely upon. |
174 host_.reset(); | 174 host_.reset(); |
175 | 175 |
176 context_factory_->RemoveCompositor(this); | 176 context_factory_->RemoveCompositor(this); |
177 } | 177 } |
178 | 178 |
179 void Compositor::ScheduleDraw() { | 179 void Compositor::ScheduleDraw() { |
180 if (compositor_thread_loop_) { | 180 if (compositor_thread_loop_.get()) { |
181 host_->SetNeedsCommit(); | 181 host_->SetNeedsCommit(); |
182 } else if (!defer_draw_scheduling_) { | 182 } else if (!defer_draw_scheduling_) { |
183 defer_draw_scheduling_ = true; | 183 defer_draw_scheduling_ = true; |
184 task_runner_->PostTask( | 184 task_runner_->PostTask( |
185 FROM_HERE, | 185 FROM_HERE, |
186 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); | 186 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 void Compositor::SetRootLayer(Layer* root_layer) { | 190 void Compositor::SetRootLayer(Layer* root_layer) { |
191 if (root_layer_ == root_layer) | 191 if (root_layer_ == root_layer) |
192 return; | 192 return; |
193 if (root_layer_) | 193 if (root_layer_) |
194 root_layer_->SetCompositor(NULL); | 194 root_layer_->SetCompositor(NULL); |
195 root_layer_ = root_layer; | 195 root_layer_ = root_layer; |
196 if (root_layer_ && !root_layer_->GetCompositor()) | 196 if (root_layer_ && !root_layer_->GetCompositor()) |
197 root_layer_->SetCompositor(this); | 197 root_layer_->SetCompositor(this); |
198 root_web_layer_->RemoveAllChildren(); | 198 root_web_layer_->RemoveAllChildren(); |
199 if (root_layer_) | 199 if (root_layer_) |
200 root_web_layer_->AddChild(root_layer_->cc_layer()); | 200 root_web_layer_->AddChild(root_layer_->cc_layer()); |
201 } | 201 } |
202 | 202 |
203 void Compositor::SetHostHasTransparentBackground( | 203 void Compositor::SetHostHasTransparentBackground( |
204 bool host_has_transparent_background) { | 204 bool host_has_transparent_background) { |
205 host_->set_has_transparent_background(host_has_transparent_background); | 205 host_->set_has_transparent_background(host_has_transparent_background); |
206 } | 206 } |
207 | 207 |
208 void Compositor::Draw() { | 208 void Compositor::Draw() { |
209 DCHECK(!compositor_thread_loop_); | 209 DCHECK(!compositor_thread_loop_.get()); |
210 | 210 |
211 defer_draw_scheduling_ = false; | 211 defer_draw_scheduling_ = false; |
212 if (waiting_on_compositing_end_) { | 212 if (waiting_on_compositing_end_) { |
213 draw_on_compositing_end_ = true; | 213 draw_on_compositing_end_ = true; |
214 return; | 214 return; |
215 } | 215 } |
216 if (!root_layer_) | 216 if (!root_layer_) |
217 return; | 217 return; |
218 | 218 |
219 TRACE_EVENT_ASYNC_BEGIN0("ui", "Compositor::Draw", last_started_frame_ + 1); | 219 TRACE_EVENT_ASYNC_BEGIN0("ui", "Compositor::Draw", last_started_frame_ + 1); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 } | 350 } |
351 | 351 |
352 void Compositor::DidCommitAndDrawFrame() { | 352 void Compositor::DidCommitAndDrawFrame() { |
353 base::TimeTicks start_time = gfx::FrameTime::Now(); | 353 base::TimeTicks start_time = gfx::FrameTime::Now(); |
354 FOR_EACH_OBSERVER(CompositorObserver, | 354 FOR_EACH_OBSERVER(CompositorObserver, |
355 observer_list_, | 355 observer_list_, |
356 OnCompositingStarted(this, start_time)); | 356 OnCompositingStarted(this, start_time)); |
357 } | 357 } |
358 | 358 |
359 void Compositor::DidCompleteSwapBuffers() { | 359 void Compositor::DidCompleteSwapBuffers() { |
360 if (compositor_thread_loop_) { | 360 if (compositor_thread_loop_.get()) { |
361 NotifyEnd(); | 361 NotifyEnd(); |
362 } else { | 362 } else { |
363 DCHECK_EQ(swap_state_, SWAP_POSTED); | 363 DCHECK_EQ(swap_state_, SWAP_POSTED); |
364 NotifyEnd(); | 364 NotifyEnd(); |
365 swap_state_ = SWAP_COMPLETED; | 365 swap_state_ = SWAP_COMPLETED; |
366 } | 366 } |
367 } | 367 } |
368 | 368 |
369 void Compositor::ScheduleComposite() { | 369 void Compositor::ScheduleComposite() { |
370 if (!disable_schedule_composite_) | 370 if (!disable_schedule_composite_) |
371 ScheduleDraw(); | 371 ScheduleDraw(); |
372 } | 372 } |
373 | 373 |
374 void Compositor::ScheduleAnimation() { | 374 void Compositor::ScheduleAnimation() { |
375 ScheduleComposite(); | 375 ScheduleComposite(); |
376 } | 376 } |
377 | 377 |
378 void Compositor::DidPostSwapBuffers() { | 378 void Compositor::DidPostSwapBuffers() { |
379 DCHECK(!compositor_thread_loop_); | 379 DCHECK(!compositor_thread_loop_.get()); |
380 DCHECK_EQ(swap_state_, SWAP_NONE); | 380 DCHECK_EQ(swap_state_, SWAP_NONE); |
381 swap_state_ = SWAP_POSTED; | 381 swap_state_ = SWAP_POSTED; |
382 } | 382 } |
383 | 383 |
384 void Compositor::DidAbortSwapBuffers() { | 384 void Compositor::DidAbortSwapBuffers() { |
385 if (!compositor_thread_loop_) { | 385 if (!compositor_thread_loop_.get()) { |
386 if (swap_state_ == SWAP_POSTED) { | 386 if (swap_state_ == SWAP_POSTED) { |
387 NotifyEnd(); | 387 NotifyEnd(); |
388 swap_state_ = SWAP_COMPLETED; | 388 swap_state_ = SWAP_COMPLETED; |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 FOR_EACH_OBSERVER(CompositorObserver, | 392 FOR_EACH_OBSERVER(CompositorObserver, |
393 observer_list_, | 393 observer_list_, |
394 OnCompositingAborted(this)); | 394 OnCompositingAborted(this)); |
395 } | 395 } |
396 | 396 |
397 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 397 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { |
398 return host_->debug_state(); | 398 return host_->debug_state(); |
399 } | 399 } |
400 | 400 |
401 void Compositor::SetLayerTreeDebugState( | 401 void Compositor::SetLayerTreeDebugState( |
402 const cc::LayerTreeDebugState& debug_state) { | 402 const cc::LayerTreeDebugState& debug_state) { |
403 host_->SetDebugState(debug_state); | 403 host_->SetDebugState(debug_state); |
404 } | 404 } |
405 | 405 |
406 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { | 406 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { |
407 if (!compositor_lock_) { | 407 if (!compositor_lock_) { |
408 compositor_lock_ = new CompositorLock(this); | 408 compositor_lock_ = new CompositorLock(this); |
409 if (compositor_thread_loop_) | 409 if (compositor_thread_loop_.get()) |
410 host_->SetDeferCommits(true); | 410 host_->SetDeferCommits(true); |
411 FOR_EACH_OBSERVER(CompositorObserver, | 411 FOR_EACH_OBSERVER(CompositorObserver, |
412 observer_list_, | 412 observer_list_, |
413 OnCompositingLockStateChanged(this)); | 413 OnCompositingLockStateChanged(this)); |
414 } | 414 } |
415 return compositor_lock_; | 415 return compositor_lock_; |
416 } | 416 } |
417 | 417 |
418 void Compositor::UnlockCompositor() { | 418 void Compositor::UnlockCompositor() { |
419 DCHECK(compositor_lock_); | 419 DCHECK(compositor_lock_); |
420 compositor_lock_ = NULL; | 420 compositor_lock_ = NULL; |
421 if (compositor_thread_loop_) | 421 if (compositor_thread_loop_.get()) |
422 host_->SetDeferCommits(false); | 422 host_->SetDeferCommits(false); |
423 FOR_EACH_OBSERVER(CompositorObserver, | 423 FOR_EACH_OBSERVER(CompositorObserver, |
424 observer_list_, | 424 observer_list_, |
425 OnCompositingLockStateChanged(this)); | 425 OnCompositingLockStateChanged(this)); |
426 } | 426 } |
427 | 427 |
428 void Compositor::CancelCompositorLock() { | 428 void Compositor::CancelCompositorLock() { |
429 if (compositor_lock_) | 429 if (compositor_lock_) |
430 compositor_lock_->CancelLock(); | 430 compositor_lock_->CancelLock(); |
431 } | 431 } |
432 | 432 |
433 void Compositor::NotifyEnd() { | 433 void Compositor::NotifyEnd() { |
434 last_ended_frame_++; | 434 last_ended_frame_++; |
435 TRACE_EVENT_ASYNC_END0("ui", "Compositor::Draw", last_ended_frame_); | 435 TRACE_EVENT_ASYNC_END0("ui", "Compositor::Draw", last_ended_frame_); |
436 waiting_on_compositing_end_ = false; | 436 waiting_on_compositing_end_ = false; |
437 if (draw_on_compositing_end_) { | 437 if (draw_on_compositing_end_) { |
438 draw_on_compositing_end_ = false; | 438 draw_on_compositing_end_ = false; |
439 | 439 |
440 // Call ScheduleDraw() instead of Draw() in order to allow other | 440 // Call ScheduleDraw() instead of Draw() in order to allow other |
441 // CompositorObservers to be notified before starting another | 441 // CompositorObservers to be notified before starting another |
442 // draw cycle. | 442 // draw cycle. |
443 ScheduleDraw(); | 443 ScheduleDraw(); |
444 } | 444 } |
445 FOR_EACH_OBSERVER( | 445 FOR_EACH_OBSERVER( |
446 CompositorObserver, observer_list_, OnCompositingEnded(this)); | 446 CompositorObserver, observer_list_, OnCompositingEnded(this)); |
447 } | 447 } |
448 | 448 |
449 } // namespace ui | 449 } // namespace ui |
OLD | NEW |