Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: cc/trees/thread_proxy.cc

Issue 1357373002: Add basic framework for splitting thread proxy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor comment change. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/thread_proxy.h" 5 #include "cc/trees/thread_proxy.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 main_thread_only_vars_unsafe_(this, layer_tree_host->id()), 64 main_thread_only_vars_unsafe_(this, layer_tree_host->id()),
65 main_thread_or_blocked_vars_unsafe_(layer_tree_host), 65 main_thread_or_blocked_vars_unsafe_(layer_tree_host),
66 compositor_thread_vars_unsafe_( 66 compositor_thread_vars_unsafe_(
67 this, 67 this,
68 layer_tree_host->id(), 68 layer_tree_host->id(),
69 layer_tree_host->rendering_stats_instrumentation(), 69 layer_tree_host->rendering_stats_instrumentation(),
70 external_begin_frame_source.Pass()) { 70 external_begin_frame_source.Pass()) {
71 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); 71 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy");
72 DCHECK(IsMainThread()); 72 DCHECK(IsMainThread());
73 DCHECK(this->layer_tree_host()); 73 DCHECK(this->layer_tree_host());
74 // TODO(khushalsagar): Move this to LayerTreeHost#InitializeThreaded once
75 // ThreadProxy is split. LayerTreeHost creates the channel and passes it to
76 // ProxyMain#SetChannel.
77 SetChannel(ThreadedChannel::Create(this, main_task_runner, impl_task_runner));
74 } 78 }
75 79
76 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy, 80 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy,
77 int layer_tree_host_id) 81 int layer_tree_host_id)
78 : layer_tree_host_id(layer_tree_host_id), 82 : layer_tree_host_id(layer_tree_host_id),
79 max_requested_pipeline_stage(NO_PIPELINE_STAGE), 83 max_requested_pipeline_stage(NO_PIPELINE_STAGE),
80 current_pipeline_stage(NO_PIPELINE_STAGE), 84 current_pipeline_stage(NO_PIPELINE_STAGE),
81 final_pipeline_stage(NO_PIPELINE_STAGE), 85 final_pipeline_stage(NO_PIPELINE_STAGE),
82 started(false), 86 started(false),
83 prepare_tiles_pending(false), 87 prepare_tiles_pending(false),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 120 }
117 121
118 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} 122 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {}
119 123
120 ThreadProxy::~ThreadProxy() { 124 ThreadProxy::~ThreadProxy() {
121 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); 125 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy");
122 DCHECK(IsMainThread()); 126 DCHECK(IsMainThread());
123 DCHECK(!main().started); 127 DCHECK(!main().started);
124 } 128 }
125 129
130 void ThreadProxy::SetChannel(scoped_ptr<ThreadedChannel> threaded_channel) {
131 threaded_channel_ = threaded_channel.Pass();
132 main().channel_main = threaded_channel_.get();
133 }
134
126 void ThreadProxy::FinishAllRendering() { 135 void ThreadProxy::FinishAllRendering() {
127 DCHECK(Proxy::IsMainThread()); 136 DCHECK(Proxy::IsMainThread());
128 DCHECK(!main().defer_commits); 137 DCHECK(!main().defer_commits);
129 138
130 // Make sure all GL drawing is finished on the impl thread. 139 // Make sure all GL drawing is finished on the impl thread.
131 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 140 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
132 CompletionEvent completion; 141 CompletionEvent completion;
133 Proxy::ImplThreadTaskRunner()->PostTask( 142 Proxy::ImplThreadTaskRunner()->PostTask(
134 FROM_HERE, 143 FROM_HERE,
135 base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread, 144 base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread,
136 impl_thread_weak_ptr_, 145 impl_thread_weak_ptr_,
137 &completion)); 146 &completion));
138 completion.Wait(); 147 completion.Wait();
139 } 148 }
140 149
141 bool ThreadProxy::IsStarted() const { 150 bool ThreadProxy::IsStarted() const {
142 DCHECK(Proxy::IsMainThread()); 151 DCHECK(Proxy::IsMainThread());
143 return main().started; 152 return main().started;
144 } 153 }
145 154
146 bool ThreadProxy::CommitToActiveTree() const { 155 bool ThreadProxy::CommitToActiveTree() const {
147 // With ThreadProxy, we use a pending tree and activate it once it's ready to 156 // With ThreadProxy, we use a pending tree and activate it once it's ready to
148 // draw to allow input to modify the active tree and draw during raster. 157 // draw to allow input to modify the active tree and draw during raster.
149 return false; 158 return false;
150 } 159 }
151 160
152 void ThreadProxy::SetLayerTreeHostClientReady() { 161 void ThreadProxy::SetLayerTreeHostClientReady() {
153 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReady"); 162 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReady");
154 Proxy::ImplThreadTaskRunner()->PostTask( 163 main().channel_main->SetLayerTreeHostClientReadyOnImpl();
155 FROM_HERE,
156 base::Bind(&ThreadProxy::SetLayerTreeHostClientReadyOnImplThread,
157 impl_thread_weak_ptr_));
158 } 164 }
159 165
160 void ThreadProxy::SetLayerTreeHostClientReadyOnImplThread() { 166 void ThreadProxy::SetLayerTreeHostClientReadyOnImpl() {
161 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReadyOnImplThread"); 167 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReadyOnImplThread");
162 impl().scheduler->SetCanStart(); 168 impl().scheduler->SetCanStart();
163 } 169 }
164 170
165 void ThreadProxy::SetVisible(bool visible) { 171 void ThreadProxy::SetVisible(bool visible) {
166 TRACE_EVENT1("cc", "ThreadProxy::SetVisible", "visible", visible); 172 TRACE_EVENT1("cc", "ThreadProxy::SetVisible", "visible", visible);
167 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 173 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
168 174
169 CompletionEvent completion; 175 CompletionEvent completion;
170 Proxy::ImplThreadTaskRunner()->PostTask( 176 Proxy::ImplThreadTaskRunner()->PostTask(
171 FROM_HERE, 177 FROM_HERE,
172 base::Bind(&ThreadProxy::SetVisibleOnImplThread, 178 base::Bind(&ThreadProxy::SetVisibleOnImplThread,
173 impl_thread_weak_ptr_, 179 impl_thread_weak_ptr_,
174 &completion, 180 &completion,
175 visible)); 181 visible));
176 completion.Wait(); 182 completion.Wait();
177 } 183 }
178 184
179 void ThreadProxy::SetVisibleOnImplThread(CompletionEvent* completion, 185 void ThreadProxy::SetVisibleOnImplThread(CompletionEvent* completion,
180 bool visible) { 186 bool visible) {
181 TRACE_EVENT1("cc", "ThreadProxy::SetVisibleOnImplThread", "visible", visible); 187 TRACE_EVENT1("cc", "ThreadProxy::SetVisibleOnImplThread", "visible", visible);
182 impl().layer_tree_host_impl->SetVisible(visible); 188 impl().layer_tree_host_impl->SetVisible(visible);
183 impl().scheduler->SetVisible(visible); 189 impl().scheduler->SetVisible(visible);
184 completion->Signal(); 190 completion->Signal();
185 } 191 }
186 192
187 void ThreadProxy::SetThrottleFrameProduction(bool throttle) { 193 void ThreadProxy::SetThrottleFrameProduction(bool throttle) {
188 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProduction", "throttle", 194 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProduction", "throttle",
189 throttle); 195 throttle);
190 Proxy::ImplThreadTaskRunner()->PostTask( 196 main().channel_main->SetThrottleFrameProductionOnImpl(throttle);
191 FROM_HERE,
192 base::Bind(&ThreadProxy::SetThrottleFrameProductionOnImplThread,
193 impl_thread_weak_ptr_, throttle));
194 } 197 }
195 198
196 void ThreadProxy::SetThrottleFrameProductionOnImplThread(bool throttle) { 199 void ThreadProxy::SetThrottleFrameProductionOnImpl(bool throttle) {
197 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProductionOnImplThread", 200 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProductionOnImplThread",
198 "throttle", throttle); 201 "throttle", throttle);
199 impl().scheduler->SetThrottleFrameProduction(throttle); 202 impl().scheduler->SetThrottleFrameProduction(throttle);
200 } 203 }
201 204
202 void ThreadProxy::DidLoseOutputSurface() { 205 void ThreadProxy::DidLoseOutputSurface() {
203 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurface"); 206 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurface");
204 DCHECK(IsMainThread()); 207 DCHECK(IsMainThread());
205 layer_tree_host()->DidLoseOutputSurface(); 208 layer_tree_host()->DidLoseOutputSurface();
206 } 209 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 355
353 void ThreadProxy::DidSwapBuffersOnImplThread() { 356 void ThreadProxy::DidSwapBuffersOnImplThread() {
354 impl().scheduler->DidSwapBuffers(); 357 impl().scheduler->DidSwapBuffers();
355 } 358 }
356 359
357 void ThreadProxy::DidSwapBuffersCompleteOnImplThread() { 360 void ThreadProxy::DidSwapBuffersCompleteOnImplThread() {
358 TRACE_EVENT0("cc,benchmark", 361 TRACE_EVENT0("cc,benchmark",
359 "ThreadProxy::DidSwapBuffersCompleteOnImplThread"); 362 "ThreadProxy::DidSwapBuffersCompleteOnImplThread");
360 DCHECK(IsImplThread()); 363 DCHECK(IsImplThread());
361 impl().scheduler->DidSwapBuffersComplete(); 364 impl().scheduler->DidSwapBuffersComplete();
362 Proxy::MainThreadTaskRunner()->PostTask( 365 impl().channel_impl->DidCompleteSwapBuffers();
363 FROM_HERE,
364 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_));
365 } 366 }
366 367
367 void ThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { 368 void ThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) {
368 impl().layer_tree_host_impl->WillBeginImplFrame(args); 369 impl().layer_tree_host_impl->WillBeginImplFrame(args);
369 if (impl().last_processed_begin_main_frame_args.IsValid()) { 370 if (impl().last_processed_begin_main_frame_args.IsValid()) {
370 // Last processed begin main frame args records the frame args that we sent 371 // Last processed begin main frame args records the frame args that we sent
371 // to the main thread for the last frame that we've processed. If that is 372 // to the main thread for the last frame that we've processed. If that is
372 // set, that means the current frame is one past the frame in which we've 373 // set, that means the current frame is one past the frame in which we've
373 // finished the processing. 374 // finished the processing.
374 impl().layer_tree_host_impl->RecordMainFrameTiming( 375 impl().layer_tree_host_impl->RecordMainFrameTiming(
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 1014
1014 void ThreadProxy::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events) { 1015 void ThreadProxy::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events) {
1015 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents"); 1016 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents");
1016 DCHECK(IsMainThread()); 1017 DCHECK(IsMainThread());
1017 layer_tree_host()->SetAnimationEvents(events.Pass()); 1018 layer_tree_host()->SetAnimationEvents(events.Pass());
1018 } 1019 }
1019 1020
1020 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { 1021 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) {
1021 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); 1022 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread");
1022 DCHECK(IsImplThread()); 1023 DCHECK(IsImplThread());
1024
1025 // TODO(khushalsagar): ThreadedChannel will create ProxyImpl here and pass a
1026 // reference to itself.
1027 impl().channel_impl = threaded_channel_.get();
1028
1023 impl().layer_tree_host_impl = 1029 impl().layer_tree_host_impl =
1024 layer_tree_host()->CreateLayerTreeHostImpl(this); 1030 layer_tree_host()->CreateLayerTreeHostImpl(this);
1025 1031
1026 SchedulerSettings scheduler_settings( 1032 SchedulerSettings scheduler_settings(
1027 layer_tree_host()->settings().ToSchedulerSettings()); 1033 layer_tree_host()->settings().ToSchedulerSettings());
1028 1034
1029 scoped_ptr<CompositorTimingHistory> compositor_timing_history( 1035 scoped_ptr<CompositorTimingHistory> compositor_timing_history(
1030 new CompositorTimingHistory(CompositorTimingHistory::RENDERER_UMA, 1036 new CompositorTimingHistory(CompositorTimingHistory::RENDERER_UMA,
1031 impl().rendering_stats_instrumentation)); 1037 impl().rendering_stats_instrumentation));
1032 1038
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 } 1253 }
1248 1254
1249 void ThreadProxy::PostFrameTimingEvents( 1255 void ThreadProxy::PostFrameTimingEvents(
1250 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, 1256 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
1251 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { 1257 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
1252 DCHECK(IsMainThread()); 1258 DCHECK(IsMainThread());
1253 layer_tree_host()->RecordFrameTimingEvents(composite_events.Pass(), 1259 layer_tree_host()->RecordFrameTimingEvents(composite_events.Pass(),
1254 main_frame_events.Pass()); 1260 main_frame_events.Pass());
1255 } 1261 }
1256 1262
1263 base::WeakPtr<ProxyMain> ThreadProxy::GetMainWeakPtr() {
1264 return main_thread_weak_ptr_;
1265 }
1266
1267 base::WeakPtr<ProxyImpl> ThreadProxy::GetImplWeakPtr() {
1268 return impl_thread_weak_ptr_;
1269 }
1270
1257 } // namespace cc 1271 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698