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

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

Issue 134623005: Make SingleThreadProxy a SchedulerClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mac browser compositor fixes Created 6 years, 5 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 | Annotate | Revision Log
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/single_thread_proxy.h" 5 #include "cc/trees/single_thread_proxy.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "cc/debug/benchmark_instrumentation.h" 9 #include "cc/debug/benchmark_instrumentation.h"
10 #include "cc/output/context_provider.h" 10 #include "cc/output/context_provider.h"
(...skipping 18 matching lines...) Expand all
29 .PassAs<Proxy>(); 29 .PassAs<Proxy>();
30 } 30 }
31 31
32 SingleThreadProxy::SingleThreadProxy( 32 SingleThreadProxy::SingleThreadProxy(
33 LayerTreeHost* layer_tree_host, 33 LayerTreeHost* layer_tree_host,
34 LayerTreeHostSingleThreadClient* client, 34 LayerTreeHostSingleThreadClient* client,
35 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) 35 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner)
36 : Proxy(main_task_runner, NULL), 36 : Proxy(main_task_runner, NULL),
37 layer_tree_host_(layer_tree_host), 37 layer_tree_host_(layer_tree_host),
38 client_(client), 38 client_(client),
39 timing_history_(layer_tree_host->rendering_stats_instrumentation()),
39 next_frame_is_newly_committed_frame_(false), 40 next_frame_is_newly_committed_frame_(false),
40 inside_draw_(false) { 41 inside_draw_(false),
42 defer_commits_(false),
43 commit_was_deferred_(false),
44 commit_requested_(false),
45 weak_factory_(this) {
41 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); 46 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
42 DCHECK(Proxy::IsMainThread()); 47 DCHECK(Proxy::IsMainThread());
43 DCHECK(layer_tree_host); 48 DCHECK(layer_tree_host);
44 49
45 // Impl-side painting not supported without threaded compositing. 50 // Impl-side painting not supported without threaded compositing.
46 CHECK(!layer_tree_host->settings().impl_side_painting) 51 CHECK(!layer_tree_host->settings().impl_side_painting)
47 << "Threaded compositing must be enabled to use impl-side painting."; 52 << "Threaded compositing must be enabled to use impl-side painting.";
48 } 53 }
49 54
50 void SingleThreadProxy::Start() { 55 void SingleThreadProxy::Start() {
(...skipping 19 matching lines...) Expand all
70 75
71 bool SingleThreadProxy::IsStarted() const { 76 bool SingleThreadProxy::IsStarted() const {
72 DCHECK(Proxy::IsMainThread()); 77 DCHECK(Proxy::IsMainThread());
73 return layer_tree_host_impl_; 78 return layer_tree_host_impl_;
74 } 79 }
75 80
76 void SingleThreadProxy::SetLayerTreeHostClientReady() { 81 void SingleThreadProxy::SetLayerTreeHostClientReady() {
77 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); 82 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady");
78 // Scheduling is controlled by the embedder in the single thread case, so 83 // Scheduling is controlled by the embedder in the single thread case, so
79 // nothing to do. 84 // nothing to do.
85 DCHECK(Proxy::IsMainThread());
86 DebugScopedSetImplThread impl(this);
87 if (layer_tree_host_->settings().single_thread_proxy_scheduler &&
88 !scheduler_on_impl_thread_) {
89 SchedulerSettings scheduler_settings(layer_tree_host_->settings());
90 scheduler_on_impl_thread_ = Scheduler::Create(this,
91 scheduler_settings,
92 layer_tree_host_->id(),
93 MainThreadTaskRunner());
94 scheduler_on_impl_thread_->SetCanStart();
95 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
96 }
80 } 97 }
81 98
82 void SingleThreadProxy::SetVisible(bool visible) { 99 void SingleThreadProxy::SetVisible(bool visible) {
83 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible"); 100 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible");
84 DebugScopedSetImplThread impl(this); 101 DebugScopedSetImplThread impl(this);
85 layer_tree_host_impl_->SetVisible(visible); 102 layer_tree_host_impl_->SetVisible(visible);
86 103 if (scheduler_on_impl_thread_)
104 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
87 // Changing visibility could change ShouldComposite(). 105 // Changing visibility could change ShouldComposite().
88 UpdateBackgroundAnimateTicking(); 106 UpdateBackgroundAnimateTicking();
89 } 107 }
90 108
91 void SingleThreadProxy::CreateAndInitializeOutputSurface() { 109 void SingleThreadProxy::CreateAndInitializeOutputSurface() {
92 TRACE_EVENT0( 110 TRACE_EVENT0(
93 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface"); 111 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface");
94 DCHECK(Proxy::IsMainThread()); 112 DCHECK(Proxy::IsMainThread());
95 DCHECK(layer_tree_host_->output_surface_lost()); 113 DCHECK(layer_tree_host_->output_surface_lost());
96 114
97 scoped_ptr<OutputSurface> output_surface = 115 scoped_ptr<OutputSurface> output_surface =
98 layer_tree_host_->CreateOutputSurface(); 116 layer_tree_host_->CreateOutputSurface();
99 117
100 renderer_capabilities_for_main_thread_ = RendererCapabilities(); 118 renderer_capabilities_for_main_thread_ = RendererCapabilities();
101 119
102 bool success = !!output_surface; 120 bool success = !!output_surface;
103 if (success) { 121 if (success) {
104 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 122 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
105 DebugScopedSetImplThread impl(this); 123 DebugScopedSetImplThread impl(this);
106 layer_tree_host_->DeleteContentsTexturesOnImplThread( 124 layer_tree_host_->DeleteContentsTexturesOnImplThread(
107 layer_tree_host_impl_->resource_provider()); 125 layer_tree_host_impl_->resource_provider());
108 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); 126 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass());
109 } 127 }
110 128
111 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); 129 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success);
112 130
113 if (!success) { 131 if (success) {
114 // Force another recreation attempt to happen by requesting another commit. 132 if (scheduler_on_impl_thread_)
115 SetNeedsCommit(); 133 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface();
134 } else if (Proxy::MainThreadTaskRunner()) {
135 Proxy::MainThreadTaskRunner()->PostTask(
136 FROM_HERE,
137 base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface,
138 weak_factory_.GetWeakPtr()));
116 } 139 }
117 } 140 }
118 141
119 const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { 142 const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
120 DCHECK(Proxy::IsMainThread()); 143 DCHECK(Proxy::IsMainThread());
121 DCHECK(!layer_tree_host_->output_surface_lost()); 144 DCHECK(!layer_tree_host_->output_surface_lost());
122 return renderer_capabilities_for_main_thread_; 145 return renderer_capabilities_for_main_thread_;
123 } 146 }
124 147
125 void SingleThreadProxy::SetNeedsAnimate() { 148 void SingleThreadProxy::SetNeedsAnimate() {
126 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); 149 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate");
127 DCHECK(Proxy::IsMainThread()); 150 DCHECK(Proxy::IsMainThread());
128 client_->ScheduleAnimation(); 151 client_->ScheduleAnimation();
152 SetNeedsCommit();
129 } 153 }
130 154
131 void SingleThreadProxy::SetNeedsUpdateLayers() { 155 void SingleThreadProxy::SetNeedsUpdateLayers() {
132 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); 156 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers");
133 DCHECK(Proxy::IsMainThread()); 157 DCHECK(Proxy::IsMainThread());
134 client_->ScheduleComposite(); 158 SetNeedsCommit();
135 } 159 }
136 160
137 void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { 161 void SingleThreadProxy::DoCommit(base::TimeTicks frame_begin_time) {
138 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); 162 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit");
139 DCHECK(Proxy::IsMainThread()); 163 DCHECK(Proxy::IsMainThread());
164 layer_tree_host_->WillBeginMainFrame();
165 layer_tree_host_->UpdateClientAnimations(frame_begin_time);
166 layer_tree_host_->AnimateLayers(frame_begin_time);
167 layer_tree_host_->Layout();
168 commit_requested_ = false;
169
170 if (PrioritizedResourceManager* contents_texture_manager =
171 layer_tree_host_->contents_texture_manager()) {
172 contents_texture_manager->UnlinkAndClearEvictedBackings();
173 contents_texture_manager->SetMaxMemoryLimitBytes(
174 layer_tree_host_impl_->memory_allocation_limit_bytes());
175 contents_texture_manager->SetExternalPriorityCutoff(
176 layer_tree_host_impl_->memory_allocation_priority_cutoff());
177 }
178
179 scoped_ptr<ResourceUpdateQueue> queue =
180 make_scoped_ptr(new ResourceUpdateQueue);
181
182 layer_tree_host_->UpdateLayers(queue.get());
183
184 layer_tree_host_->WillCommit();
185
140 // Commit immediately. 186 // Commit immediately.
141 { 187 {
142 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 188 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
143 DebugScopedSetImplThread impl(this); 189 DebugScopedSetImplThread impl(this);
144 190
145 // This CapturePostTasks should be destroyed before CommitComplete() is 191 // This CapturePostTasks should be destroyed before CommitComplete() is
146 // called since that goes out to the embedder, and we want the embedder 192 // called since that goes out to the embedder, and we want the embedder
147 // to receive its callbacks before that. 193 // to receive its callbacks before that.
148 BlockingTaskRunner::CapturePostTasks blocked; 194 BlockingTaskRunner::CapturePostTasks blocked;
149 195
(...skipping 13 matching lines...) Expand all
163 layer_tree_host_impl_->resource_provider()); 209 layer_tree_host_impl_->resource_provider());
164 update_controller->Finalize(); 210 update_controller->Finalize();
165 211
166 if (layer_tree_host_impl_->EvictedUIResourcesExist()) 212 if (layer_tree_host_impl_->EvictedUIResourcesExist())
167 layer_tree_host_->RecreateUIResources(); 213 layer_tree_host_->RecreateUIResources();
168 214
169 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); 215 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
170 216
171 layer_tree_host_impl_->CommitComplete(); 217 layer_tree_host_impl_->CommitComplete();
172 218
219 UpdateBackgroundAnimateTicking();
220
173 #if DCHECK_IS_ON 221 #if DCHECK_IS_ON
174 // In the single-threaded case, the scale and scroll deltas should never be 222 // In the single-threaded case, the scale and scroll deltas should never be
175 // touched on the impl layer tree. 223 // touched on the impl layer tree.
176 scoped_ptr<ScrollAndScaleSet> scroll_info = 224 scoped_ptr<ScrollAndScaleSet> scroll_info =
177 layer_tree_host_impl_->ProcessScrollDeltas(); 225 layer_tree_host_impl_->ProcessScrollDeltas();
178 DCHECK(!scroll_info->scrolls.size()); 226 DCHECK(!scroll_info->scrolls.size());
179 DCHECK_EQ(1.f, scroll_info->page_scale_delta); 227 DCHECK_EQ(1.f, scroll_info->page_scale_delta);
180 #endif 228 #endif
181 229
182 RenderingStatsInstrumentation* stats_instrumentation = 230 RenderingStatsInstrumentation* stats_instrumentation =
183 layer_tree_host_->rendering_stats_instrumentation(); 231 layer_tree_host_->rendering_stats_instrumentation();
184 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent( 232 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent(
185 stats_instrumentation->main_thread_rendering_stats()); 233 stats_instrumentation->main_thread_rendering_stats());
186 stats_instrumentation->AccumulateAndClearMainThreadStats(); 234 stats_instrumentation->AccumulateAndClearMainThreadStats();
187 } 235 }
188 layer_tree_host_->CommitComplete(); 236 layer_tree_host_->CommitComplete();
237 layer_tree_host_->DidBeginMainFrame();
238 timing_history_.DidCommit();
239
189 next_frame_is_newly_committed_frame_ = true; 240 next_frame_is_newly_committed_frame_ = true;
190 } 241 }
191 242
192 void SingleThreadProxy::SetNeedsCommit() { 243 void SingleThreadProxy::SetNeedsCommit() {
193 DCHECK(Proxy::IsMainThread()); 244 DCHECK(Proxy::IsMainThread());
245 DebugScopedSetImplThread impl(this);
194 client_->ScheduleComposite(); 246 client_->ScheduleComposite();
247 if (scheduler_on_impl_thread_)
248 scheduler_on_impl_thread_->SetNeedsCommit();
249 commit_requested_ = true;
195 } 250 }
196 251
197 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { 252 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
198 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); 253 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw");
254 DCHECK(Proxy::IsMainThread());
255 DebugScopedSetImplThread impl(this);
256 client_->ScheduleComposite();
199 SetNeedsRedrawRectOnImplThread(damage_rect); 257 SetNeedsRedrawRectOnImplThread(damage_rect);
200 client_->ScheduleComposite();
201 } 258 }
202 259
203 void SingleThreadProxy::SetNextCommitWaitsForActivation() { 260 void SingleThreadProxy::SetNextCommitWaitsForActivation() {
204 // There is no activation here other than commit. So do nothing. 261 // There is no activation here other than commit. So do nothing.
262 DCHECK(Proxy::IsMainThread());
205 } 263 }
206 264
207 void SingleThreadProxy::SetDeferCommits(bool defer_commits) { 265 void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
266 DCHECK(Proxy::IsMainThread());
267 // Deferring commits only makes sense if there's a scheduler.
268 if (!scheduler_on_impl_thread_)
269 return;
270 if (defer_commits_ == defer_commits)
271 return;
272
273 if (defer_commits)
274 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this);
275 else
276 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this);
277
278 defer_commits_ = defer_commits;
279 if (!defer_commits_ && commit_was_deferred_) {
280 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted();
281 scheduler_on_impl_thread_->NotifyReadyToCommit();
282 commit_was_deferred_ = false;
283 }
208 } 284 }
209 285
210 bool SingleThreadProxy::CommitRequested() const { return false; } 286 bool SingleThreadProxy::CommitRequested() const {
287 DCHECK(Proxy::IsMainThread());
288 return commit_requested_;
289 }
211 290
212 bool SingleThreadProxy::BeginMainFrameRequested() const { return false; } 291 bool SingleThreadProxy::BeginMainFrameRequested() const {
292 DCHECK(Proxy::IsMainThread());
293 return commit_requested_;
294 }
213 295
214 size_t SingleThreadProxy::MaxPartialTextureUpdates() const { 296 size_t SingleThreadProxy::MaxPartialTextureUpdates() const {
215 return std::numeric_limits<size_t>::max(); 297 return std::numeric_limits<size_t>::max();
216 } 298 }
217 299
218 void SingleThreadProxy::Stop() { 300 void SingleThreadProxy::Stop() {
219 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); 301 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
220 DCHECK(Proxy::IsMainThread()); 302 DCHECK(Proxy::IsMainThread());
221 { 303 {
222 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 304 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
223 DebugScopedSetImplThread impl(this); 305 DebugScopedSetImplThread impl(this);
224 306
225 BlockingTaskRunner::CapturePostTasks blocked; 307 BlockingTaskRunner::CapturePostTasks blocked;
226 layer_tree_host_->DeleteContentsTexturesOnImplThread( 308 layer_tree_host_->DeleteContentsTexturesOnImplThread(
227 layer_tree_host_impl_->resource_provider()); 309 layer_tree_host_impl_->resource_provider());
310 scheduler_on_impl_thread_.reset();
228 layer_tree_host_impl_.reset(); 311 layer_tree_host_impl_.reset();
229 } 312 }
230 layer_tree_host_ = NULL; 313 layer_tree_host_ = NULL;
231 } 314 }
232 315
233 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { 316 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
234 TRACE_EVENT1( 317 TRACE_EVENT1(
235 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); 318 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
236 DCHECK(Proxy::IsImplThread()); 319 DCHECK(Proxy::IsImplThread());
237 UpdateBackgroundAnimateTicking(); 320 UpdateBackgroundAnimateTicking();
321 if (scheduler_on_impl_thread_)
322 scheduler_on_impl_thread_->SetCanDraw(can_draw);
238 } 323 }
239 324
240 void SingleThreadProxy::NotifyReadyToActivate() { 325 void SingleThreadProxy::NotifyReadyToActivate() {
241 // Thread-only feature. 326 // Impl-side painting only.
242 NOTREACHED(); 327 NOTREACHED();
243 } 328 }
244 329
245 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { 330 void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
246 client_->ScheduleComposite(); 331 client_->ScheduleComposite();
332 if (scheduler_on_impl_thread_)
333 scheduler_on_impl_thread_->SetNeedsRedraw();
247 } 334 }
248 335
249 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { 336 void SingleThreadProxy::SetNeedsAnimateOnImplThread() {
250 SetNeedsRedrawOnImplThread(); 337 SetNeedsRedrawOnImplThread();
251 } 338 }
252 339
253 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { 340 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() {
254 // Thread-only/Impl-side-painting-only feature. 341 // Impl-side painting only.
255 NOTREACHED(); 342 NOTREACHED();
256 } 343 }
257 344
258 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( 345 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(
259 const gfx::Rect& damage_rect) { 346 const gfx::Rect& damage_rect) {
260 // TODO(brianderson): Once we move render_widget scheduling into this class,
261 // we can treat redraw requests more efficiently than CommitAndRedraw
262 // requests.
263 layer_tree_host_impl_->SetViewportDamage(damage_rect); 347 layer_tree_host_impl_->SetViewportDamage(damage_rect);
264 SetNeedsCommit(); 348 SetNeedsRedrawOnImplThread();
265 } 349 }
266 350
267 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { 351 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() {
268 // Impl-side painting only. 352 // Impl-side painting only.
269 NOTREACHED(); 353 NOTREACHED();
270 } 354 }
271 355
272 void SingleThreadProxy::SetNeedsCommitOnImplThread() { 356 void SingleThreadProxy::SetNeedsCommitOnImplThread() {
273 client_->ScheduleComposite(); 357 client_->ScheduleComposite();
358 if (scheduler_on_impl_thread_)
359 scheduler_on_impl_thread_->SetNeedsCommit();
274 } 360 }
275 361
276 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( 362 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
277 scoped_ptr<AnimationEventsVector> events) { 363 scoped_ptr<AnimationEventsVector> events) {
278 TRACE_EVENT0( 364 TRACE_EVENT0(
279 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); 365 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
280 DCHECK(Proxy::IsImplThread()); 366 DCHECK(Proxy::IsImplThread());
281 DebugScopedSetMainThread main(this); 367 DebugScopedSetMainThread main(this);
282 layer_tree_host_->SetAnimationEvents(events.Pass()); 368 layer_tree_host_->SetAnimationEvents(events.Pass());
283 } 369 }
(...skipping 16 matching lines...) Expand all
300 } 386 }
301 387
302 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } 388 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
303 389
304 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { 390 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
305 DCHECK(IsImplThread()); 391 DCHECK(IsImplThread());
306 renderer_capabilities_for_main_thread_ = 392 renderer_capabilities_for_main_thread_ =
307 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); 393 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities();
308 } 394 }
309 395
396 void SingleThreadProxy::DidManageTiles() {
397 // Impl-side painting only.
398 NOTREACHED();
399 }
400
310 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { 401 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
311 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); 402 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread");
312 // Cause a commit so we can notice the lost context. 403 {
313 SetNeedsCommitOnImplThread(); 404 DebugScopedSetMainThread main(this);
405 // This must happen before we notify the scheduler as it may try to recreate
406 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE.
407 layer_tree_host_->DidLoseOutputSurface();
408 }
314 client_->DidAbortSwapBuffers(); 409 client_->DidAbortSwapBuffers();
410 if (scheduler_on_impl_thread_)
411 scheduler_on_impl_thread_->DidLoseOutputSurface();
315 } 412 }
316 413
317 void SingleThreadProxy::DidSwapBuffersOnImplThread() { 414 void SingleThreadProxy::DidSwapBuffersOnImplThread() {
415 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread");
416 if (scheduler_on_impl_thread_)
417 scheduler_on_impl_thread_->DidSwapBuffers();
318 client_->DidPostSwapBuffers(); 418 client_->DidPostSwapBuffers();
319 } 419 }
320 420
321 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { 421 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() {
322 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); 422 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread");
323 client_->DidCompleteSwapBuffers(); 423 if (scheduler_on_impl_thread_)
424 scheduler_on_impl_thread_->DidSwapBuffersComplete();
425 layer_tree_host_->DidCompleteSwapBuffers();
324 } 426 }
325 427
326 // Called by the legacy scheduling path (e.g. where render_widget does the 428 void SingleThreadProxy::BeginFrame(const BeginFrameArgs& args) {
327 // scheduling) 429 TRACE_EVENT0("cc", "SingleThreadProxy::BeginFrame");
430 if (scheduler_on_impl_thread_)
431 scheduler_on_impl_thread_->BeginImplFrame(args);
432 }
433
328 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { 434 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
329 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); 435 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately");
330 DCHECK(Proxy::IsMainThread()); 436 DCHECK(Proxy::IsMainThread());
331 DCHECK(!layer_tree_host_->output_surface_lost()); 437 DCHECK(!layer_tree_host_->output_surface_lost());
332 438
333 layer_tree_host_->AnimateLayers(frame_begin_time); 439 DoCommit(frame_begin_time);
334
335 if (PrioritizedResourceManager* contents_texture_manager =
336 layer_tree_host_->contents_texture_manager()) {
337 contents_texture_manager->UnlinkAndClearEvictedBackings();
338 contents_texture_manager->SetMaxMemoryLimitBytes(
339 layer_tree_host_impl_->memory_allocation_limit_bytes());
340 contents_texture_manager->SetExternalPriorityCutoff(
341 layer_tree_host_impl_->memory_allocation_priority_cutoff());
342 }
343
344 scoped_ptr<ResourceUpdateQueue> queue =
345 make_scoped_ptr(new ResourceUpdateQueue);
346 layer_tree_host_->UpdateLayers(queue.get());
347 layer_tree_host_->WillCommit();
348 DoCommit(queue.Pass());
349 layer_tree_host_->DidBeginMainFrame();
350 440
351 LayerTreeHostImpl::FrameData frame; 441 LayerTreeHostImpl::FrameData frame;
352 if (DoComposite(frame_begin_time, &frame)) { 442 DoComposite(frame_begin_time, &frame);
353 {
354 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
355 DebugScopedSetImplThread impl(this);
356
357 // This CapturePostTasks should be destroyed before
358 // DidCommitAndDrawFrame() is called since that goes out to the embedder,
359 // and we want the embedder to receive its callbacks before that.
360 // NOTE: This maintains consistent ordering with the ThreadProxy since
361 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
362 // there as the main thread is not blocked, so any posted tasks inside
363 // the swap buffers will execute first.
364 BlockingTaskRunner::CapturePostTasks blocked;
365
366 layer_tree_host_impl_->SwapBuffers(frame);
367 }
368 DidSwapFrame();
369 }
370 } 443 }
371 444
372 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { 445 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const {
373 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 446 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
374 { 447 {
375 // The following line casts away const modifiers because it is just 448 // The following line casts away const modifiers because it is just
376 // setting debug state. We still want the AsValue() function and its 449 // setting debug state. We still want the AsValue() function and its
377 // call chain to be const throughout. 450 // call chain to be const throughout.
378 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); 451 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
379 452
(...skipping 22 matching lines...) Expand all
402 return layer_tree_host_impl_->visible() && 475 return layer_tree_host_impl_->visible() &&
403 layer_tree_host_impl_->CanDraw(); 476 layer_tree_host_impl_->CanDraw();
404 } 477 }
405 478
406 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { 479 void SingleThreadProxy::UpdateBackgroundAnimateTicking() {
407 DCHECK(Proxy::IsImplThread()); 480 DCHECK(Proxy::IsImplThread());
408 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 481 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
409 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); 482 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer());
410 } 483 }
411 484
412 bool SingleThreadProxy::DoComposite( 485 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time,
413 base::TimeTicks frame_begin_time, 486 LayerTreeHostImpl::FrameData* frame) {
414 LayerTreeHostImpl::FrameData* frame) {
415 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); 487 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
416 DCHECK(!layer_tree_host_->output_surface_lost()); 488 DCHECK(!layer_tree_host_->output_surface_lost());
417 489
418 bool lost_output_surface = false;
419 { 490 {
420 DebugScopedSetImplThread impl(this); 491 DebugScopedSetImplThread impl(this);
421 base::AutoReset<bool> mark_inside(&inside_draw_, true); 492 base::AutoReset<bool> mark_inside(&inside_draw_, true);
422 493
423 // We guard PrepareToDraw() with CanDraw() because it always returns a valid 494 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
424 // frame, so can only be used when such a frame is possible. Since 495 // frame, so can only be used when such a frame is possible. Since
425 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on 496 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
426 // CanDraw() as well. 497 // CanDraw() as well.
427 if (!ShouldComposite()) { 498 if (!ShouldComposite()) {
428 UpdateBackgroundAnimateTicking(); 499 UpdateBackgroundAnimateTicking();
429 return false; 500 return DRAW_ABORTED_CANT_DRAW;
430 } 501 }
431 502
503 timing_history_.DidStartDrawing();
504
432 layer_tree_host_impl_->Animate( 505 layer_tree_host_impl_->Animate(
433 layer_tree_host_impl_->CurrentFrameTimeTicks()); 506 layer_tree_host_impl_->CurrentFrameTimeTicks());
434 UpdateBackgroundAnimateTicking(); 507 UpdateBackgroundAnimateTicking();
435 508
436 if (!layer_tree_host_impl_->IsContextLost()) { 509 if (!layer_tree_host_impl_->IsContextLost()) {
437 layer_tree_host_impl_->PrepareToDraw(frame); 510 layer_tree_host_impl_->PrepareToDraw(frame);
438 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); 511 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time);
439 layer_tree_host_impl_->DidDrawAllLayers(*frame); 512 layer_tree_host_impl_->DidDrawAllLayers(*frame);
440 } 513 }
441 lost_output_surface = layer_tree_host_impl_->IsContextLost();
442 514
443 bool start_ready_animations = true; 515 bool start_ready_animations = true;
444 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); 516 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
445 517
446 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); 518 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
519
520 timing_history_.DidFinishDrawing();
447 } 521 }
448 522
449 if (lost_output_surface) { 523 {
450 layer_tree_host_->DidLoseOutputSurface(); 524 DebugScopedSetImplThread impl(this);
451 return false; 525
526 if (layer_tree_host_impl_->IsContextLost()) {
527 DidLoseOutputSurfaceOnImplThread();
528 } else {
529 // This CapturePostTasks should be destroyed before
530 // DidCommitAndDrawFrame() is called since that goes out to the
531 // embedder,
532 // and we want the embedder to receive its callbacks before that.
533 // NOTE: This maintains consistent ordering with the ThreadProxy since
534 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
535 // there as the main thread is not blocked, so any posted tasks inside
536 // the swap buffers will execute first.
537 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
538
539 BlockingTaskRunner::CapturePostTasks blocked;
540 layer_tree_host_impl_->SwapBuffers(*frame);
541 }
452 } 542 }
543 DidCommitAndDrawFrame();
453 544
454 return true; 545 return DRAW_SUCCESS;
455 } 546 }
456 547
457 void SingleThreadProxy::DidSwapFrame() { 548 void SingleThreadProxy::DidCommitAndDrawFrame() {
458 if (next_frame_is_newly_committed_frame_) { 549 if (next_frame_is_newly_committed_frame_) {
550 DebugScopedSetMainThread main(this);
459 next_frame_is_newly_committed_frame_ = false; 551 next_frame_is_newly_committed_frame_ = false;
460 layer_tree_host_->DidCommitAndDrawFrame(); 552 layer_tree_host_->DidCommitAndDrawFrame();
461 } 553 }
462 } 554 }
463 555
464 bool SingleThreadProxy::CommitPendingForTesting() { return false; } 556 bool SingleThreadProxy::CommitPendingForTesting() { return false; }
465 557
558 scoped_ptr<base::Value> SingleThreadProxy::SchedulerAsValueForTesting() {
559 DebugScopedSetImplThread impl(this);
560 if (!scheduler_on_impl_thread_)
561 return make_scoped_ptr(base::Value::CreateNullValue()).Pass();
562 return scheduler_on_impl_thread_->AsValue().Pass();
563 }
564
565 void SingleThreadProxy::SetNeedsBeginFrame(bool enable) {
566 layer_tree_host_impl_->SetNeedsBeginFrame(enable);
567 }
568
569 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) {
570 layer_tree_host_impl_->WillBeginImplFrame(args);
571 }
572
573 void SingleThreadProxy::ScheduledActionSendBeginMainFrame() {
574 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame");
575 if (defer_commits_) {
576 DCHECK(!commit_was_deferred_);
577 commit_was_deferred_ = true;
578 layer_tree_host_->DidDeferCommit();
579 return;
580 }
581 timing_history_.DidBeginMainFrame();
582
583 DCHECK(scheduler_on_impl_thread_);
584 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted();
585 scheduler_on_impl_thread_->NotifyReadyToCommit();
586 }
587
588 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
589 DebugScopedSetImplThread impl(this);
590 if (layer_tree_host_impl_->IsContextLost()) {
591 DidCommitAndDrawFrame();
592 return DRAW_SUCCESS;
593 }
594
595 LayerTreeHostImpl::FrameData frame;
596 return DoComposite(layer_tree_host_impl_->CurrentFrameTimeTicks(), &frame);
597 }
598
599 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() {
600 NOTREACHED();
601 return INVALID_RESULT;
602 }
603
604 void SingleThreadProxy::ScheduledActionCommit() {
605 DebugScopedSetMainThread main(this);
606 DoCommit(layer_tree_host_impl_->CurrentFrameTimeTicks());
607 }
608
609 void SingleThreadProxy::ScheduledActionAnimate() {
610 TRACE_EVENT0("cc", "ScheduledActionAnimate");
611 layer_tree_host_impl_->Animate(
612 layer_tree_host_impl_->CurrentFrameTimeTicks());
613 }
614
615 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() {
616 // Impl-side painting only.
617 NOTREACHED();
618 }
619
620 void SingleThreadProxy::ScheduledActionActivateSyncTree() {
621 }
622
623 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
624 DebugScopedSetMainThread main(this);
625 DCHECK(scheduler_on_impl_thread_);
626 // If possible, create the output surface in a post task. Synchronously
627 // creating the output surface makes tests more awkward since this differs
628 // from the ThreadProxy behavior. However, sometimes there is no
629 // task runner.
630 if (Proxy::MainThreadTaskRunner()) {
631 Proxy::MainThreadTaskRunner()->PostTask(
632 FROM_HERE,
633 base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface,
634 weak_factory_.GetWeakPtr()));
635 } else {
636 CreateAndInitializeOutputSurface();
637 }
638 }
639
640 void SingleThreadProxy::ScheduledActionManageTiles() {
641 // Impl-side painting only.
642 NOTREACHED();
643 }
644
645 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) {
646 }
647
648 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() {
649 return timing_history_.DrawDurationEstimate();
650 }
651
652 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() {
653 return timing_history_.BeginMainFrameToCommitDurationEstimate();
654 }
655
656 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() {
657 return timing_history_.CommitToActivateDurationEstimate();
658 }
659
660 void SingleThreadProxy::DidBeginImplFrameDeadline() {
661 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
662 }
663
466 } // namespace cc 664 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698