OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "cc/trees/threaded_channel.h" | 5 #include "cc/trees/threaded_channel.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 | 10 |
11 namespace cc { | 11 namespace cc { |
12 | 12 |
13 scoped_ptr<ThreadedChannel> ThreadedChannel::Create( | 13 scoped_ptr<ThreadedChannel> ThreadedChannel::Create( |
14 ThreadProxy* thread_proxy, | 14 ThreadProxy* thread_proxy, |
15 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 15 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
16 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 16 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
17 return make_scoped_ptr( | 17 return make_scoped_ptr( |
18 new ThreadedChannel(thread_proxy, main_task_runner, impl_task_runner)); | 18 new ThreadedChannel(thread_proxy, main_task_runner, impl_task_runner)); |
19 } | 19 } |
20 | 20 |
21 ThreadedChannel::ThreadedChannel( | 21 ThreadedChannel::ThreadedChannel( |
22 ThreadProxy* thread_proxy, | 22 ThreadProxy* thread_proxy, |
23 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 23 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
24 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) | 24 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) |
25 : proxy_main_(thread_proxy), | 25 : proxy_main_(thread_proxy), |
26 proxy_impl_(thread_proxy), | 26 proxy_impl_(thread_proxy), |
27 main_task_runner_(main_task_runner), | 27 main_task_runner_(main_task_runner), |
28 impl_task_runner_(impl_task_runner) {} | 28 impl_task_runner_(impl_task_runner), |
| 29 impl_weak_factory_(this) {} |
29 | 30 |
30 void ThreadedChannel::SetThrottleFrameProductionOnImpl(bool throttle) { | 31 void ThreadedChannel::SetThrottleFrameProductionOnImpl(bool throttle) { |
31 ImplThreadTaskRunner()->PostTask( | 32 ImplThreadTaskRunner()->PostTask( |
32 FROM_HERE, base::Bind(&ProxyImpl::SetThrottleFrameProductionOnImpl, | 33 FROM_HERE, base::Bind(&ProxyImpl::SetThrottleFrameProductionOnImpl, |
33 proxy_impl_->GetImplWeakPtr(), throttle)); | 34 proxy_impl_->GetImplWeakPtr(), throttle)); |
34 } | 35 } |
35 | 36 |
36 void ThreadedChannel::SetLayerTreeHostClientReadyOnImpl() { | 37 void ThreadedChannel::SetLayerTreeHostClientReadyOnImpl() { |
37 ImplThreadTaskRunner()->PostTask( | 38 ImplThreadTaskRunner()->PostTask( |
38 FROM_HERE, base::Bind(&ProxyImpl::SetLayerTreeHostClientReadyOnImpl, | 39 FROM_HERE, base::Bind(&ProxyImpl::SetLayerTreeHostClientReadyOnImpl, |
39 proxy_impl_->GetImplWeakPtr())); | 40 proxy_impl_->GetImplWeakPtr())); |
40 } | 41 } |
41 | 42 |
| 43 void ThreadedChannel::InitializeOutputSurfaceOnImpl( |
| 44 OutputSurface* output_surface) { |
| 45 ImplThreadTaskRunner()->PostTask( |
| 46 FROM_HERE, base::Bind(&ProxyImpl::InitializeOutputSurfaceOnImpl, |
| 47 proxy_impl_->GetImplWeakPtr(), output_surface)); |
| 48 } |
| 49 |
| 50 void ThreadedChannel::MainThreadHasStoppedFlingingOnImpl() { |
| 51 ImplThreadTaskRunner()->PostTask( |
| 52 FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl, |
| 53 proxy_impl_->GetImplWeakPtr())); |
| 54 } |
| 55 |
| 56 void ThreadedChannel::SetInputThrottledUntilCommitOnImpl(bool is_throttled) { |
| 57 ImplThreadTaskRunner()->PostTask( |
| 58 FROM_HERE, base::Bind(&ProxyImpl::SetInputThrottledUntilCommitOnImpl, |
| 59 proxy_impl_->GetImplWeakPtr(), is_throttled)); |
| 60 } |
| 61 |
| 62 void ThreadedChannel::SetDeferCommitsOnImpl(bool defer_commits) { |
| 63 ImplThreadTaskRunner()->PostTask( |
| 64 FROM_HERE, base::Bind(&ProxyImpl::SetDeferCommitsOnImpl, |
| 65 proxy_impl_->GetImplWeakPtr(), defer_commits)); |
| 66 } |
| 67 |
| 68 void ThreadedChannel::FinishAllRenderingOnImpl() { |
| 69 CompletionEvent completion; |
| 70 ImplThreadTaskRunner()->PostTask( |
| 71 FROM_HERE, base::Bind(&ThreadedChannel::BlockingFinishAllRenderingOnImpl, |
| 72 impl_thread_weak_ptr_, &completion)); |
| 73 completion.Wait(); |
| 74 } |
| 75 |
| 76 void ThreadedChannel::BlockingFinishAllRenderingOnImpl( |
| 77 CompletionEvent* completion) { |
| 78 proxy_impl_->FinishAllRenderingOnImpl(); |
| 79 completion->Signal(); |
| 80 } |
| 81 |
| 82 void ThreadedChannel::SetVisibleOnImpl(bool visible) { |
| 83 CompletionEvent completion; |
| 84 ImplThreadTaskRunner()->PostTask( |
| 85 FROM_HERE, base::Bind(&ThreadedChannel::BlockingSetVisibleOnImpl, |
| 86 impl_thread_weak_ptr_, &completion, visible)); |
| 87 completion.Wait(); |
| 88 } |
| 89 |
| 90 void ThreadedChannel::BlockingSetVisibleOnImpl(CompletionEvent* completion, |
| 91 bool visible) { |
| 92 proxy_impl_->SetVisibleOnImpl(visible); |
| 93 completion->Signal(); |
| 94 } |
| 95 |
| 96 void ThreadedChannel::ReleaseOutputSurfaceOnImpl() { |
| 97 CompletionEvent completion; |
| 98 ImplThreadTaskRunner()->PostTask( |
| 99 FROM_HERE, |
| 100 base::Bind(&ThreadedChannel::BlockingReleaseOutputSurfaceOnImpl, |
| 101 impl_thread_weak_ptr_, &completion)); |
| 102 completion.Wait(); |
| 103 } |
| 104 |
| 105 void ThreadedChannel::BlockingReleaseOutputSurfaceOnImpl( |
| 106 CompletionEvent* completion) { |
| 107 proxy_impl_->ReleaseOutputSurfaceOnImpl(); |
| 108 completion->Signal(); |
| 109 } |
| 110 |
| 111 void ThreadedChannel::FinishGLOnImpl() { |
| 112 CompletionEvent completion; |
| 113 ImplThreadTaskRunner()->PostTask( |
| 114 FROM_HERE, base::Bind(&ThreadedChannel::BlockingFinishGLOnImpl, |
| 115 impl_thread_weak_ptr_, &completion)); |
| 116 completion.Wait(); |
| 117 } |
| 118 |
| 119 void ThreadedChannel::BlockingFinishGLOnImpl(CompletionEvent* completion) { |
| 120 proxy_impl_->FinishGLOnImpl(); |
| 121 completion->Signal(); |
| 122 } |
| 123 |
| 124 void ThreadedChannel::MainFrameWillHappenOnImplForTesting( |
| 125 bool* main_frame_will_happen) { |
| 126 CompletionEvent completion; |
| 127 ImplThreadTaskRunner()->PostTask( |
| 128 FROM_HERE, |
| 129 base::Bind(&ThreadedChannel::BlockingMainFrameWillHappenOnImplForTesting, |
| 130 impl_thread_weak_ptr_, &completion, main_frame_will_happen)); |
| 131 completion.Wait(); |
| 132 } |
| 133 |
| 134 void ThreadedChannel::BlockingMainFrameWillHappenOnImplForTesting( |
| 135 CompletionEvent* completion, |
| 136 bool* main_frame_will_happen) { |
| 137 proxy_impl_->MainFrameWillHappenOnImplForTesting(main_frame_will_happen); |
| 138 completion->Signal(); |
| 139 } |
| 140 |
42 void ThreadedChannel::DidCompleteSwapBuffers() { | 141 void ThreadedChannel::DidCompleteSwapBuffers() { |
43 MainThreadTaskRunner()->PostTask( | 142 MainThreadTaskRunner()->PostTask( |
44 FROM_HERE, base::Bind(&ProxyMain::DidCompleteSwapBuffers, | 143 FROM_HERE, base::Bind(&ProxyMain::DidCompleteSwapBuffers, |
45 proxy_main_->GetMainWeakPtr())); | 144 proxy_main_->GetMainWeakPtr())); |
46 } | 145 } |
47 | 146 |
| 147 void ThreadedChannel::SetRendererCapabilitiesMainCopy( |
| 148 const RendererCapabilities& capabilities) { |
| 149 MainThreadTaskRunner()->PostTask( |
| 150 FROM_HERE, base::Bind(&ProxyMain::SetRendererCapabilitiesMainCopy, |
| 151 proxy_main_->GetMainWeakPtr(), capabilities)); |
| 152 } |
| 153 |
| 154 void ThreadedChannel::BeginMainFrameNotExpectedSoon() { |
| 155 MainThreadTaskRunner()->PostTask( |
| 156 FROM_HERE, base::Bind(&ProxyMain::BeginMainFrameNotExpectedSoon, |
| 157 proxy_main_->GetMainWeakPtr())); |
| 158 } |
| 159 |
| 160 void ThreadedChannel::DidCommitAndDrawFrame() { |
| 161 MainThreadTaskRunner()->PostTask(FROM_HERE, |
| 162 base::Bind(&ProxyMain::DidCommitAndDrawFrame, |
| 163 proxy_main_->GetMainWeakPtr())); |
| 164 } |
| 165 |
| 166 void ThreadedChannel::SetAnimationEvents( |
| 167 scoped_ptr<AnimationEventsVector> queue) { |
| 168 MainThreadTaskRunner()->PostTask( |
| 169 FROM_HERE, |
| 170 base::Bind(&ProxyMain::SetAnimationEvents, proxy_main_->GetMainWeakPtr(), |
| 171 base::Passed(&queue))); |
| 172 } |
| 173 |
| 174 void ThreadedChannel::DidLoseOutputSurface() { |
| 175 MainThreadTaskRunner()->PostTask(FROM_HERE, |
| 176 base::Bind(&ProxyMain::DidLoseOutputSurface, |
| 177 proxy_main_->GetMainWeakPtr())); |
| 178 } |
| 179 |
| 180 void ThreadedChannel::RequestNewOutputSurface() { |
| 181 MainThreadTaskRunner()->PostTask( |
| 182 FROM_HERE, base::Bind(&ProxyMain::RequestNewOutputSurface, |
| 183 proxy_main_->GetMainWeakPtr())); |
| 184 } |
| 185 |
| 186 void ThreadedChannel::DidInitializeOutputSurface( |
| 187 bool success, |
| 188 const RendererCapabilities& capabilities) { |
| 189 MainThreadTaskRunner()->PostTask( |
| 190 FROM_HERE, |
| 191 base::Bind(&ProxyMain::DidInitializeOutputSurface, |
| 192 proxy_main_->GetMainWeakPtr(), success, capabilities)); |
| 193 } |
| 194 |
| 195 void ThreadedChannel::DidCompletePageScaleAnimation() { |
| 196 MainThreadTaskRunner()->PostTask( |
| 197 FROM_HERE, base::Bind(&ProxyMain::DidCompletePageScaleAnimation, |
| 198 proxy_main_->GetMainWeakPtr())); |
| 199 } |
| 200 |
| 201 void ThreadedChannel::PostFrameTimingEventsToMain( |
| 202 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
| 203 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
| 204 MainThreadTaskRunner()->PostTask( |
| 205 FROM_HERE, base::Bind(&ProxyMain::PostFrameTimingEventsToMain, |
| 206 proxy_main_->GetMainWeakPtr(), |
| 207 base::Passed(composite_events.Pass()), |
| 208 base::Passed(main_frame_events.Pass()))); |
| 209 } |
| 210 |
48 ThreadedChannel::~ThreadedChannel() { | 211 ThreadedChannel::~ThreadedChannel() { |
49 TRACE_EVENT0("cc", "ThreadChannel::~ThreadChannel"); | 212 TRACE_EVENT0("cc", "ThreadChannel::~ThreadChannel"); |
50 } | 213 } |
51 | 214 |
52 base::SingleThreadTaskRunner* ThreadedChannel::MainThreadTaskRunner() const { | 215 base::SingleThreadTaskRunner* ThreadedChannel::MainThreadTaskRunner() const { |
53 return main_task_runner_.get(); | 216 return main_task_runner_.get(); |
54 } | 217 } |
55 | 218 |
56 base::SingleThreadTaskRunner* ThreadedChannel::ImplThreadTaskRunner() const { | 219 base::SingleThreadTaskRunner* ThreadedChannel::ImplThreadTaskRunner() const { |
57 return impl_task_runner_.get(); | 220 return impl_task_runner_.get(); |
58 } | 221 } |
59 | 222 |
| 223 void ThreadedChannel::InitImplThreadWeakPtr() { |
| 224 impl_thread_weak_ptr_ = impl_weak_factory_.GetWeakPtr(); |
| 225 } |
| 226 |
| 227 void ThreadedChannel::InvalidateImplThreadWeakPtr() { |
| 228 impl_weak_factory_.InvalidateWeakPtrs(); |
| 229 } |
| 230 |
60 } // namespace cc | 231 } // namespace cc |
OLD | NEW |