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" |
| 11 #include "base/cancelable_callback.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/run_loop.h" |
14 #include "base/string_util.h" | 16 #include "base/string_util.h" |
15 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
16 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
17 #include "cc/base/switches.h" | 19 #include "cc/base/switches.h" |
18 #include "cc/base/thread_impl.h" | 20 #include "cc/base/thread_impl.h" |
19 #include "cc/input/input_handler.h" | 21 #include "cc/input/input_handler.h" |
20 #include "cc/layers/layer.h" | 22 #include "cc/layers/layer.h" |
21 #include "cc/output/context_provider.h" | 23 #include "cc/output/context_provider.h" |
22 #include "cc/output/output_surface.h" | 24 #include "cc/output/output_surface.h" |
23 #include "cc/trees/layer_tree_host.h" | 25 #include "cc/trees/layer_tree_host.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 CancelLock(); | 330 CancelLock(); |
329 } | 331 } |
330 | 332 |
331 void CompositorLock::CancelLock() { | 333 void CompositorLock::CancelLock() { |
332 if (!compositor_) | 334 if (!compositor_) |
333 return; | 335 return; |
334 compositor_->UnlockCompositor(); | 336 compositor_->UnlockCompositor(); |
335 compositor_ = NULL; | 337 compositor_ = NULL; |
336 } | 338 } |
337 | 339 |
| 340 // static |
| 341 bool DrawWaiterForTest::Wait(Compositor* compositor) { |
| 342 DrawWaiterForTest waiter; |
| 343 return waiter.WaitImpl(compositor); |
| 344 } |
| 345 |
| 346 DrawWaiterForTest::DrawWaiterForTest() |
| 347 : kDrawWaitTimeOutMs(1000), |
| 348 did_draw_(false) { |
| 349 } |
| 350 |
| 351 DrawWaiterForTest::~DrawWaiterForTest() { |
| 352 } |
| 353 |
| 354 bool DrawWaiterForTest::WaitImpl(Compositor* compositor) { |
| 355 did_draw_ = false; |
| 356 compositor->AddObserver(this); |
| 357 wait_run_loop_.reset(new base::RunLoop()); |
| 358 base::CancelableClosure timeout( |
| 359 base::Bind(&DrawWaiterForTest::TimedOutWhileWaiting, |
| 360 base::Unretained(this))); |
| 361 MessageLoop::current()->PostDelayedTask( |
| 362 FROM_HERE, timeout.callback(), |
| 363 base::TimeDelta::FromMilliseconds(kDrawWaitTimeOutMs)); |
| 364 wait_run_loop_->Run(); |
| 365 compositor->RemoveObserver(this); |
| 366 return did_draw_; |
| 367 } |
| 368 |
| 369 void DrawWaiterForTest::TimedOutWhileWaiting() { |
| 370 LOG(ERROR) << "Timed out waiting for draw."; |
| 371 wait_run_loop_->Quit(); |
| 372 } |
| 373 |
| 374 void DrawWaiterForTest::OnCompositingDidCommit(Compositor* compositor) { |
| 375 } |
| 376 |
| 377 void DrawWaiterForTest::OnCompositingStarted(Compositor* compositor, |
| 378 base::TimeTicks start_time) { |
| 379 } |
| 380 |
| 381 void DrawWaiterForTest::OnCompositingEnded(Compositor* compositor) { |
| 382 did_draw_ = true; |
| 383 wait_run_loop_->Quit(); |
| 384 } |
| 385 |
| 386 void DrawWaiterForTest::OnCompositingAborted(Compositor* compositor) { |
| 387 } |
| 388 |
| 389 void DrawWaiterForTest::OnCompositingLockStateChanged(Compositor* compositor) { |
| 390 } |
| 391 |
| 392 void DrawWaiterForTest::OnUpdateVSyncParameters(Compositor* compositor, |
| 393 base::TimeTicks timebase, |
| 394 base::TimeDelta interval) { |
| 395 } |
| 396 |
338 class PostedSwapQueue { | 397 class PostedSwapQueue { |
339 public: | 398 public: |
340 PostedSwapQueue() : pending_swap_(NULL) { | 399 PostedSwapQueue() : pending_swap_(NULL) { |
341 } | 400 } |
342 | 401 |
343 ~PostedSwapQueue() { | 402 ~PostedSwapQueue() { |
344 DCHECK(!pending_swap_); | 403 DCHECK(!pending_swap_); |
345 } | 404 } |
346 | 405 |
347 SwapType NextPostedSwap() const { | 406 SwapType NextPostedSwap() const { |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 COMPOSITOR_EXPORT void DisableTestCompositor() { | 810 COMPOSITOR_EXPORT void DisableTestCompositor() { |
752 ResetImplicitFactory(); | 811 ResetImplicitFactory(); |
753 g_test_compositor_enabled = false; | 812 g_test_compositor_enabled = false; |
754 } | 813 } |
755 | 814 |
756 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 815 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
757 return g_test_compositor_enabled; | 816 return g_test_compositor_enabled; |
758 } | 817 } |
759 | 818 |
760 } // namespace ui | 819 } // namespace ui |
OLD | NEW |