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