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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return; | 99 return; |
98 delete g_implicit_factory; | 100 delete g_implicit_factory; |
99 g_implicit_factory = NULL; | 101 g_implicit_factory = NULL; |
100 g_context_factory = NULL; | 102 g_context_factory = NULL; |
101 } | 103 } |
102 | 104 |
103 } // namespace | 105 } // namespace |
104 | 106 |
105 namespace ui { | 107 namespace ui { |
106 | 108 |
| 109 class DrawWaiter : public ui::CompositorObserver { |
| 110 public: |
| 111 DrawWaiter() : did_draw_(false) {} |
| 112 |
| 113 bool Wait(ui::Compositor* compositor) { |
| 114 did_draw_ = false; |
| 115 compositor->AddObserver(this); |
| 116 wait_run_loop_.reset(new base::RunLoop()); |
| 117 base::CancelableClosure timeout( |
| 118 base::Bind(&DrawWaiter::TimedOutWhileWaiting, |
| 119 base::Unretained(this))); |
| 120 MessageLoop::current()->PostDelayedTask( |
| 121 FROM_HERE, timeout.callback(), |
| 122 base::TimeDelta::FromMilliseconds(compositor->kDrawWaitTimeOutMs)); |
| 123 wait_run_loop_->Run(); |
| 124 compositor->RemoveObserver(this); |
| 125 return did_draw_; |
| 126 } |
| 127 |
| 128 private: |
| 129 void TimedOutWhileWaiting() { |
| 130 LOG(ERROR) << "Timed out waiting for draw."; |
| 131 wait_run_loop_->Quit(); |
| 132 } |
| 133 |
| 134 // ui::CompositorObserver implementation. |
| 135 virtual void OnCompositingDidCommit(Compositor* compositor) OVERRIDE {} |
| 136 virtual void OnCompositingStarted(Compositor* compositor, |
| 137 base::TimeTicks start_time) OVERRIDE {} |
| 138 virtual void OnCompositingEnded(Compositor* compositor) OVERRIDE { |
| 139 did_draw_ = true; |
| 140 wait_run_loop_->Quit(); |
| 141 } |
| 142 virtual void OnCompositingAborted(Compositor* compositor) OVERRIDE {} |
| 143 virtual void OnCompositingLockStateChanged(Compositor* compositor) OVERRIDE {} |
| 144 virtual void OnUpdateVSyncParameters(Compositor* compositor, |
| 145 base::TimeTicks timebase, |
| 146 base::TimeDelta interval) OVERRIDE {} |
| 147 |
| 148 scoped_ptr<base::RunLoop> wait_run_loop_; |
| 149 bool did_draw_; |
| 150 |
| 151 DISALLOW_COPY_AND_ASSIGN(DrawWaiter); |
| 152 }; |
| 153 |
107 // static | 154 // static |
108 ContextFactory* ContextFactory::GetInstance() { | 155 ContextFactory* ContextFactory::GetInstance() { |
109 if (!g_context_factory) | 156 if (!g_context_factory) |
110 SetupImplicitFactory(); | 157 SetupImplicitFactory(); |
111 return g_context_factory; | 158 return g_context_factory; |
112 } | 159 } |
113 | 160 |
114 // static | 161 // static |
115 void ContextFactory::SetInstance(ContextFactory* instance) { | 162 void ContextFactory::SetInstance(ContextFactory* instance) { |
116 g_context_factory = instance; | 163 g_context_factory = instance; |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 compositor_lock_ = new CompositorLock(this); | 737 compositor_lock_ = new CompositorLock(this); |
691 if (g_compositor_thread) | 738 if (g_compositor_thread) |
692 host_->SetDeferCommits(true); | 739 host_->SetDeferCommits(true); |
693 FOR_EACH_OBSERVER(CompositorObserver, | 740 FOR_EACH_OBSERVER(CompositorObserver, |
694 observer_list_, | 741 observer_list_, |
695 OnCompositingLockStateChanged(this)); | 742 OnCompositingLockStateChanged(this)); |
696 } | 743 } |
697 return compositor_lock_; | 744 return compositor_lock_; |
698 } | 745 } |
699 | 746 |
| 747 bool Compositor::WaitForDraw() { |
| 748 DrawWaiter draw_waiter; |
| 749 return draw_waiter.Wait(this); |
| 750 } |
| 751 |
700 void Compositor::UnlockCompositor() { | 752 void Compositor::UnlockCompositor() { |
701 DCHECK(compositor_lock_); | 753 DCHECK(compositor_lock_); |
702 compositor_lock_ = NULL; | 754 compositor_lock_ = NULL; |
703 if (g_compositor_thread) | 755 if (g_compositor_thread) |
704 host_->SetDeferCommits(false); | 756 host_->SetDeferCommits(false); |
705 FOR_EACH_OBSERVER(CompositorObserver, | 757 FOR_EACH_OBSERVER(CompositorObserver, |
706 observer_list_, | 758 observer_list_, |
707 OnCompositingLockStateChanged(this)); | 759 OnCompositingLockStateChanged(this)); |
708 } | 760 } |
709 | 761 |
(...skipping 26 matching lines...) Expand all Loading... |
736 COMPOSITOR_EXPORT void DisableTestCompositor() { | 788 COMPOSITOR_EXPORT void DisableTestCompositor() { |
737 ResetImplicitFactory(); | 789 ResetImplicitFactory(); |
738 g_test_compositor_enabled = false; | 790 g_test_compositor_enabled = false; |
739 } | 791 } |
740 | 792 |
741 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 793 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
742 return g_test_compositor_enabled; | 794 return g_test_compositor_enabled; |
743 } | 795 } |
744 | 796 |
745 } // namespace ui | 797 } // namespace ui |
OLD | NEW |