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

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

Issue 508373002: cc: Single-threaded impl-side painting for unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also abort remaining swap promises for synchronous composite Created 6 years, 2 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
« no previous file with comments | « cc/trees/single_thread_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "cc/output/output_surface.h" 11 #include "cc/output/output_surface.h"
12 #include "cc/quads/draw_quad.h" 12 #include "cc/quads/draw_quad.h"
13 #include "cc/resources/prioritized_resource_manager.h" 13 #include "cc/resources/prioritized_resource_manager.h"
14 #include "cc/resources/resource_update_controller.h" 14 #include "cc/resources/resource_update_controller.h"
15 #include "cc/trees/blocking_task_runner.h"
16 #include "cc/trees/layer_tree_host.h" 15 #include "cc/trees/layer_tree_host.h"
17 #include "cc/trees/layer_tree_host_single_thread_client.h" 16 #include "cc/trees/layer_tree_host_single_thread_client.h"
18 #include "cc/trees/layer_tree_impl.h" 17 #include "cc/trees/layer_tree_impl.h"
19 #include "cc/trees/scoped_abort_remaining_swap_promises.h" 18 #include "cc/trees/scoped_abort_remaining_swap_promises.h"
20 #include "ui/gfx/frame_time.h" 19 #include "ui/gfx/frame_time.h"
21 20
22 namespace cc { 21 namespace cc {
23 22
24 scoped_ptr<Proxy> SingleThreadProxy::Create( 23 scoped_ptr<Proxy> SingleThreadProxy::Create(
25 LayerTreeHost* layer_tree_host, 24 LayerTreeHost* layer_tree_host,
(...skipping 13 matching lines...) Expand all
39 timing_history_(layer_tree_host->rendering_stats_instrumentation()), 38 timing_history_(layer_tree_host->rendering_stats_instrumentation()),
40 next_frame_is_newly_committed_frame_(false), 39 next_frame_is_newly_committed_frame_(false),
41 inside_draw_(false), 40 inside_draw_(false),
42 defer_commits_(false), 41 defer_commits_(false),
43 commit_was_deferred_(false), 42 commit_was_deferred_(false),
44 commit_requested_(false), 43 commit_requested_(false),
45 weak_factory_(this) { 44 weak_factory_(this) {
46 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); 45 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
47 DCHECK(Proxy::IsMainThread()); 46 DCHECK(Proxy::IsMainThread());
48 DCHECK(layer_tree_host); 47 DCHECK(layer_tree_host);
49
50 // Impl-side painting not supported without threaded compositing.
51 CHECK(!layer_tree_host->settings().impl_side_painting)
52 << "Threaded compositing must be enabled to use impl-side painting.";
53 } 48 }
54 49
55 void SingleThreadProxy::Start() { 50 void SingleThreadProxy::Start() {
56 DebugScopedSetImplThread impl(this); 51 DebugScopedSetImplThread impl(this);
57 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); 52 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
58 } 53 }
59 54
60 SingleThreadProxy::~SingleThreadProxy() { 55 SingleThreadProxy::~SingleThreadProxy() {
61 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); 56 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
62 DCHECK(Proxy::IsMainThread()); 57 DCHECK(Proxy::IsMainThread());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 client_->ScheduleAnimation(); 147 client_->ScheduleAnimation();
153 SetNeedsCommit(); 148 SetNeedsCommit();
154 } 149 }
155 150
156 void SingleThreadProxy::SetNeedsUpdateLayers() { 151 void SingleThreadProxy::SetNeedsUpdateLayers() {
157 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); 152 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers");
158 DCHECK(Proxy::IsMainThread()); 153 DCHECK(Proxy::IsMainThread());
159 SetNeedsCommit(); 154 SetNeedsCommit();
160 } 155 }
161 156
162 void SingleThreadProxy::DoCommit(const BeginFrameArgs& begin_frame_args) { 157 void SingleThreadProxy::DoCommit() {
163 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); 158 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit");
164 DCHECK(Proxy::IsMainThread()); 159 DCHECK(Proxy::IsMainThread());
165 layer_tree_host_->WillBeginMainFrame(); 160
166 layer_tree_host_->BeginMainFrame(begin_frame_args);
167 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
168 layer_tree_host_->Layout();
169 commit_requested_ = false; 161 commit_requested_ = false;
170
171 if (PrioritizedResourceManager* contents_texture_manager =
172 layer_tree_host_->contents_texture_manager()) {
173 contents_texture_manager->UnlinkAndClearEvictedBackings();
174 contents_texture_manager->SetMaxMemoryLimitBytes(
175 layer_tree_host_impl_->memory_allocation_limit_bytes());
176 contents_texture_manager->SetExternalPriorityCutoff(
177 layer_tree_host_impl_->memory_allocation_priority_cutoff());
178 }
179
180 scoped_ptr<ResourceUpdateQueue> queue =
181 make_scoped_ptr(new ResourceUpdateQueue);
182
183 layer_tree_host_->UpdateLayers(queue.get());
184
185 layer_tree_host_->WillCommit(); 162 layer_tree_host_->WillCommit();
186 163
187 // Commit immediately. 164 // Commit immediately.
188 { 165 {
189 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 166 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
190 DebugScopedSetImplThread impl(this); 167 DebugScopedSetImplThread impl(this);
191 168
192 // This CapturePostTasks should be destroyed before CommitComplete() is 169 // This CapturePostTasks should be destroyed before CommitComplete() is
193 // called since that goes out to the embedder, and we want the embedder 170 // called since that goes out to the embedder, and we want the embedder
194 // to receive its callbacks before that. 171 // to receive its callbacks before that.
195 BlockingTaskRunner::CapturePostTasks blocked( 172 commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks(
196 blocking_main_thread_task_runner()); 173 blocking_main_thread_task_runner()));
197 174
198 layer_tree_host_impl_->BeginCommit(); 175 layer_tree_host_impl_->BeginCommit();
199 176
200 if (PrioritizedResourceManager* contents_texture_manager = 177 if (PrioritizedResourceManager* contents_texture_manager =
201 layer_tree_host_->contents_texture_manager()) { 178 layer_tree_host_->contents_texture_manager()) {
202 contents_texture_manager->PushTexturePrioritiesToBackings(); 179 contents_texture_manager->PushTexturePrioritiesToBackings();
203 } 180 }
204 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); 181 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
205 182
206 scoped_ptr<ResourceUpdateController> update_controller = 183 scoped_ptr<ResourceUpdateController> update_controller =
207 ResourceUpdateController::Create( 184 ResourceUpdateController::Create(
208 NULL, 185 NULL,
209 MainThreadTaskRunner(), 186 MainThreadTaskRunner(),
210 queue.Pass(), 187 queue_for_commit_.Pass(),
211 layer_tree_host_impl_->resource_provider()); 188 layer_tree_host_impl_->resource_provider());
212 update_controller->Finalize(); 189 update_controller->Finalize();
213 190
214 if (layer_tree_host_impl_->EvictedUIResourcesExist()) 191 if (layer_tree_host_impl_->EvictedUIResourcesExist())
215 layer_tree_host_->RecreateUIResources(); 192 layer_tree_host_->RecreateUIResources();
216 193
217 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); 194 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
218 195
219 layer_tree_host_impl_->CommitComplete(); 196 layer_tree_host_impl_->CommitComplete();
220 197
221 UpdateBackgroundAnimateTicking(); 198 UpdateBackgroundAnimateTicking();
222 199
223 #if DCHECK_IS_ON 200 #if DCHECK_IS_ON
224 // In the single-threaded case, the scale and scroll deltas should never be 201 // In the single-threaded case, the scale and scroll deltas should never be
225 // touched on the impl layer tree. 202 // touched on the impl layer tree.
226 scoped_ptr<ScrollAndScaleSet> scroll_info = 203 scoped_ptr<ScrollAndScaleSet> scroll_info =
227 layer_tree_host_impl_->ProcessScrollDeltas(); 204 layer_tree_host_impl_->ProcessScrollDeltas();
228 DCHECK(!scroll_info->scrolls.size()); 205 DCHECK(!scroll_info->scrolls.size());
229 DCHECK_EQ(1.f, scroll_info->page_scale_delta); 206 DCHECK_EQ(1.f, scroll_info->page_scale_delta);
230 #endif 207 #endif
231 208
232 RenderingStatsInstrumentation* stats_instrumentation = 209 RenderingStatsInstrumentation* stats_instrumentation =
233 layer_tree_host_->rendering_stats_instrumentation(); 210 layer_tree_host_->rendering_stats_instrumentation();
234 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent( 211 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent(
235 stats_instrumentation->main_thread_rendering_stats()); 212 stats_instrumentation->main_thread_rendering_stats());
236 stats_instrumentation->AccumulateAndClearMainThreadStats(); 213 stats_instrumentation->AccumulateAndClearMainThreadStats();
237 } 214 }
215
216 if (layer_tree_host_->settings().impl_side_painting) {
217 // TODO(enne): just commit directly to the active tree.
218 //
219 // Synchronously activate during commit to satisfy any potential
220 // SetNextCommitWaitsForActivation calls. Unfortunately, the tree
221 // might not be ready to draw, so DidActivateSyncTree must set
222 // the flag to force the tree to not draw until textures are ready.
223 NotifyReadyToActivate();
224 } else {
225 CommitComplete();
226 }
227 }
228
229 void SingleThreadProxy::CommitComplete() {
230 DCHECK(!layer_tree_host_impl_->pending_tree())
231 << "Activation is expected to have synchronously occurred by now.";
232 DCHECK(commit_blocking_task_runner_);
233
234 DebugScopedSetMainThread main(this);
235 commit_blocking_task_runner_.reset();
238 layer_tree_host_->CommitComplete(); 236 layer_tree_host_->CommitComplete();
239 layer_tree_host_->DidBeginMainFrame(); 237 layer_tree_host_->DidBeginMainFrame();
240 timing_history_.DidCommit(); 238 timing_history_.DidCommit();
241 239
242 next_frame_is_newly_committed_frame_ = true; 240 next_frame_is_newly_committed_frame_ = true;
243 } 241 }
244 242
245 void SingleThreadProxy::SetNeedsCommit() { 243 void SingleThreadProxy::SetNeedsCommit() {
246 DCHECK(Proxy::IsMainThread()); 244 DCHECK(Proxy::IsMainThread());
247 DebugScopedSetImplThread impl(this); 245 DebugScopedSetImplThread impl(this);
248 client_->ScheduleComposite(); 246 client_->ScheduleComposite();
249 if (scheduler_on_impl_thread_) 247 if (scheduler_on_impl_thread_)
250 scheduler_on_impl_thread_->SetNeedsCommit(); 248 scheduler_on_impl_thread_->SetNeedsCommit();
251 commit_requested_ = true; 249 commit_requested_ = true;
252 } 250 }
253 251
254 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { 252 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
255 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); 253 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw");
256 DCHECK(Proxy::IsMainThread()); 254 DCHECK(Proxy::IsMainThread());
257 DebugScopedSetImplThread impl(this); 255 DebugScopedSetImplThread impl(this);
258 client_->ScheduleComposite(); 256 client_->ScheduleComposite();
259 SetNeedsRedrawRectOnImplThread(damage_rect); 257 SetNeedsRedrawRectOnImplThread(damage_rect);
260 } 258 }
261 259
262 void SingleThreadProxy::SetNextCommitWaitsForActivation() { 260 void SingleThreadProxy::SetNextCommitWaitsForActivation() {
263 // There is no activation here other than commit. So do nothing. 261 // Activation always forced in commit, so nothing to do.
264 DCHECK(Proxy::IsMainThread()); 262 DCHECK(Proxy::IsMainThread());
265 } 263 }
266 264
267 void SingleThreadProxy::SetDeferCommits(bool defer_commits) { 265 void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
268 DCHECK(Proxy::IsMainThread()); 266 DCHECK(Proxy::IsMainThread());
269 // Deferring commits only makes sense if there's a scheduler. 267 // Deferring commits only makes sense if there's a scheduler.
270 if (!scheduler_on_impl_thread_) 268 if (!scheduler_on_impl_thread_)
271 return; 269 return;
272 if (defer_commits_ == defer_commits) 270 if (defer_commits_ == defer_commits)
273 return; 271 return;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { 320 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
323 TRACE_EVENT1( 321 TRACE_EVENT1(
324 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); 322 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
325 DCHECK(Proxy::IsImplThread()); 323 DCHECK(Proxy::IsImplThread());
326 UpdateBackgroundAnimateTicking(); 324 UpdateBackgroundAnimateTicking();
327 if (scheduler_on_impl_thread_) 325 if (scheduler_on_impl_thread_)
328 scheduler_on_impl_thread_->SetCanDraw(can_draw); 326 scheduler_on_impl_thread_->SetCanDraw(can_draw);
329 } 327 }
330 328
331 void SingleThreadProxy::NotifyReadyToActivate() { 329 void SingleThreadProxy::NotifyReadyToActivate() {
332 // Impl-side painting only. 330 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate");
333 NOTREACHED(); 331 DebugScopedSetImplThread impl(this);
332 if (scheduler_on_impl_thread_)
333 scheduler_on_impl_thread_->NotifyReadyToActivate();
334 } 334 }
335 335
336 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { 336 void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
337 client_->ScheduleComposite(); 337 client_->ScheduleComposite();
338 if (scheduler_on_impl_thread_) 338 if (scheduler_on_impl_thread_)
339 scheduler_on_impl_thread_->SetNeedsRedraw(); 339 scheduler_on_impl_thread_->SetNeedsRedraw();
340 } 340 }
341 341
342 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { 342 void SingleThreadProxy::SetNeedsAnimateOnImplThread() {
343 SetNeedsRedrawOnImplThread(); 343 SetNeedsRedrawOnImplThread();
344 } 344 }
345 345
346 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { 346 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() {
347 // Impl-side painting only. 347 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsManageTilesOnImplThread");
348 NOTREACHED(); 348 if (scheduler_on_impl_thread_)
349 scheduler_on_impl_thread_->SetNeedsManageTiles();
349 } 350 }
350 351
351 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( 352 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(
352 const gfx::Rect& damage_rect) { 353 const gfx::Rect& damage_rect) {
353 layer_tree_host_impl_->SetViewportDamage(damage_rect); 354 layer_tree_host_impl_->SetViewportDamage(damage_rect);
354 SetNeedsRedrawOnImplThread(); 355 SetNeedsRedrawOnImplThread();
355 } 356 }
356 357
357 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { 358 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() {
358 // Impl-side painting only. 359 TRACE_EVENT0("cc", "SingleThreadProxy::DidInitializeVisibleTileOnImplThread");
359 NOTREACHED(); 360 if (scheduler_on_impl_thread_)
361 scheduler_on_impl_thread_->SetNeedsRedraw();
360 } 362 }
361 363
362 void SingleThreadProxy::SetNeedsCommitOnImplThread() { 364 void SingleThreadProxy::SetNeedsCommitOnImplThread() {
363 client_->ScheduleComposite(); 365 client_->ScheduleComposite();
364 if (scheduler_on_impl_thread_) 366 if (scheduler_on_impl_thread_)
365 scheduler_on_impl_thread_->SetNeedsCommit(); 367 scheduler_on_impl_thread_->SetNeedsCommit();
366 } 368 }
367 369
368 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( 370 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
369 scoped_ptr<AnimationEventsVector> events) { 371 scoped_ptr<AnimationEventsVector> events) {
(...skipping 16 matching lines...) Expand all
386 388
387 if (!contents_texture_manager || !resource_provider) 389 if (!contents_texture_manager || !resource_provider)
388 return false; 390 return false;
389 391
390 return contents_texture_manager->ReduceMemoryOnImplThread( 392 return contents_texture_manager->ReduceMemoryOnImplThread(
391 limit_bytes, priority_cutoff, resource_provider); 393 limit_bytes, priority_cutoff, resource_provider);
392 } 394 }
393 395
394 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } 396 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
395 397
398 void SingleThreadProxy::DidActivateSyncTree() {
399 // Non-impl-side painting finishes commit in DoCommit. Impl-side painting
400 // defers until here to simulate SetNextCommitWaitsForActivation.
401 if (layer_tree_host_impl_->settings().impl_side_painting) {
402 // This is required because NotifyReadyToActivate gets called when
403 // the pending tree is not actually ready in the SingleThreadProxy.
404 layer_tree_host_impl_->active_tree()->SetRequiresHighResToDraw();
405
406 // Since activation could cause tasks to run, post CommitComplete
407 // separately so that it runs after these tasks. This is the loose
408 // equivalent of blocking commit until activation and also running
409 // all tasks posted during commit/activation before CommitComplete.
410 MainThreadTaskRunner()->PostTask(
411 FROM_HERE,
412 base::Bind(&SingleThreadProxy::CommitComplete,
413 weak_factory_.GetWeakPtr()));
414 }
415
416 UpdateBackgroundAnimateTicking();
417 timing_history_.DidActivateSyncTree();
418 }
419
420 void SingleThreadProxy::DidManageTiles() {
421 DCHECK(layer_tree_host_impl_->settings().impl_side_painting);
422 DCHECK(Proxy::IsImplThread());
423 if (scheduler_on_impl_thread_)
424 scheduler_on_impl_thread_->DidManageTiles();
425 }
426
396 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { 427 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
397 DCHECK(IsImplThread()); 428 DCHECK(IsImplThread());
398 renderer_capabilities_for_main_thread_ = 429 renderer_capabilities_for_main_thread_ =
399 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); 430 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities();
400 } 431 }
401 432
402 void SingleThreadProxy::DidManageTiles() {
403 // Impl-side painting only.
404 NOTREACHED();
405 }
406
407 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { 433 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
408 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); 434 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread");
409 { 435 {
410 DebugScopedSetMainThread main(this); 436 DebugScopedSetMainThread main(this);
411 // This must happen before we notify the scheduler as it may try to recreate 437 // This must happen before we notify the scheduler as it may try to recreate
412 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. 438 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE.
413 layer_tree_host_->DidLoseOutputSurface(); 439 layer_tree_host_->DidLoseOutputSurface();
414 } 440 }
415 client_->DidAbortSwapBuffers(); 441 client_->DidAbortSwapBuffers();
416 if (scheduler_on_impl_thread_) 442 if (scheduler_on_impl_thread_)
(...skipping 11 matching lines...) Expand all
428 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); 454 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread");
429 if (scheduler_on_impl_thread_) 455 if (scheduler_on_impl_thread_)
430 scheduler_on_impl_thread_->DidSwapBuffersComplete(); 456 scheduler_on_impl_thread_->DidSwapBuffersComplete();
431 layer_tree_host_->DidCompleteSwapBuffers(); 457 layer_tree_host_->DidCompleteSwapBuffers();
432 } 458 }
433 459
434 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { 460 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
435 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); 461 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately");
436 DCHECK(Proxy::IsMainThread()); 462 DCHECK(Proxy::IsMainThread());
437 DCHECK(!layer_tree_host_->output_surface_lost()); 463 DCHECK(!layer_tree_host_->output_surface_lost());
464 DCHECK(!layer_tree_host_impl_->settings().impl_side_painting)
465 << "Impl-side painting and synchronous compositing are not supported.";
438 466
439 BeginFrameArgs begin_frame_args = BeginFrameArgs::Create( 467 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_);
danakj 2014/10/02 17:15:54 do you think we should unit test this?
440 frame_begin_time, base::TimeTicks(), BeginFrameArgs::DefaultInterval()); 468
441 DoCommit(begin_frame_args); 469 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create(
470 frame_begin_time, base::TimeTicks(), BeginFrameArgs::DefaultInterval()));
471 DoBeginMainFrame(begin_frame_args);
472 DoCommit();
442 473
443 LayerTreeHostImpl::FrameData frame; 474 LayerTreeHostImpl::FrameData frame;
444 DoComposite(frame_begin_time, &frame); 475 DoComposite(frame_begin_time, &frame);
445 } 476 }
446 477
447 void SingleThreadProxy::AsValueInto(base::debug::TracedValue* state) const { 478 void SingleThreadProxy::AsValueInto(base::debug::TracedValue* state) const {
448 // The following line casts away const modifiers because it is just 479 // The following line casts away const modifiers because it is just
449 // setting debug state. We still want the AsValue() function and its 480 // setting debug state. We still want the AsValue() function and its
450 // call chain to be const throughout. 481 // call chain to be const throughout.
451 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); 482 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
(...skipping 27 matching lines...) Expand all
479 DCHECK(Proxy::IsImplThread()); 510 DCHECK(Proxy::IsImplThread());
480 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 511 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
481 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); 512 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer());
482 } 513 }
483 514
484 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, 515 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time,
485 LayerTreeHostImpl::FrameData* frame) { 516 LayerTreeHostImpl::FrameData* frame) {
486 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); 517 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
487 DCHECK(!layer_tree_host_->output_surface_lost()); 518 DCHECK(!layer_tree_host_->output_surface_lost());
488 519
520 DrawResult draw_result;
521 bool draw_frame;
489 { 522 {
490 DebugScopedSetImplThread impl(this); 523 DebugScopedSetImplThread impl(this);
491 base::AutoReset<bool> mark_inside(&inside_draw_, true); 524 base::AutoReset<bool> mark_inside(&inside_draw_, true);
492 525
493 // We guard PrepareToDraw() with CanDraw() because it always returns a valid 526 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
494 // frame, so can only be used when such a frame is possible. Since 527 // frame, so can only be used when such a frame is possible. Since
495 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on 528 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
496 // CanDraw() as well. 529 // CanDraw() as well.
497 if (!ShouldComposite()) { 530 if (!ShouldComposite()) {
498 UpdateBackgroundAnimateTicking(); 531 UpdateBackgroundAnimateTicking();
499 return DRAW_ABORTED_CANT_DRAW; 532 return DRAW_ABORTED_CANT_DRAW;
500 } 533 }
501 534
502 timing_history_.DidStartDrawing(); 535 timing_history_.DidStartDrawing();
503 536
504 layer_tree_host_impl_->Animate( 537 layer_tree_host_impl_->Animate(
505 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); 538 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time);
506 UpdateBackgroundAnimateTicking(); 539 UpdateBackgroundAnimateTicking();
507 540
508 layer_tree_host_impl_->PrepareToDraw(frame); 541 draw_result = layer_tree_host_impl_->PrepareToDraw(frame);
509 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); 542 draw_frame = draw_result == DRAW_SUCCESS;
543 if (draw_frame)
544 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time);
510 layer_tree_host_impl_->DidDrawAllLayers(*frame); 545 layer_tree_host_impl_->DidDrawAllLayers(*frame);
511 546
512 bool start_ready_animations = true; 547 bool start_ready_animations = draw_frame;
513 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); 548 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
514
515 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); 549 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame();
516 550
517 timing_history_.DidFinishDrawing(); 551 timing_history_.DidFinishDrawing();
518 } 552 }
519 553
520 { 554 if (draw_frame) {
521 DebugScopedSetImplThread impl(this); 555 DebugScopedSetImplThread impl(this);
522 556
523 // This CapturePostTasks should be destroyed before 557 // This CapturePostTasks should be destroyed before
524 // DidCommitAndDrawFrame() is called since that goes out to the 558 // DidCommitAndDrawFrame() is called since that goes out to the
525 // embedder, 559 // embedder,
526 // and we want the embedder to receive its callbacks before that. 560 // and we want the embedder to receive its callbacks before that.
527 // NOTE: This maintains consistent ordering with the ThreadProxy since 561 // NOTE: This maintains consistent ordering with the ThreadProxy since
528 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread 562 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
529 // there as the main thread is not blocked, so any posted tasks inside 563 // there as the main thread is not blocked, so any posted tasks inside
530 // the swap buffers will execute first. 564 // the swap buffers will execute first.
531 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 565 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
532 566
533 BlockingTaskRunner::CapturePostTasks blocked( 567 BlockingTaskRunner::CapturePostTasks blocked(
534 blocking_main_thread_task_runner()); 568 blocking_main_thread_task_runner());
535 layer_tree_host_impl_->SwapBuffers(*frame); 569 layer_tree_host_impl_->SwapBuffers(*frame);
536 } 570 }
537 DidCommitAndDrawFrame(); 571 DidCommitAndDrawFrame();
538 572
539 return DRAW_SUCCESS; 573 return draw_result;
540 } 574 }
541 575
542 void SingleThreadProxy::DidCommitAndDrawFrame() { 576 void SingleThreadProxy::DidCommitAndDrawFrame() {
543 if (next_frame_is_newly_committed_frame_) { 577 if (next_frame_is_newly_committed_frame_) {
544 DebugScopedSetMainThread main(this); 578 DebugScopedSetMainThread main(this);
545 next_frame_is_newly_committed_frame_ = false; 579 next_frame_is_newly_committed_frame_ = false;
546 layer_tree_host_->DidCommitAndDrawFrame(); 580 layer_tree_host_->DidCommitAndDrawFrame();
547 } 581 }
548 } 582 }
549 583
(...skipping 25 matching lines...) Expand all
575 } 609 }
576 610
577 void SingleThreadProxy::BeginMainFrame() { 611 void SingleThreadProxy::BeginMainFrame() {
578 if (defer_commits_) { 612 if (defer_commits_) {
579 DCHECK(!commit_was_deferred_); 613 DCHECK(!commit_was_deferred_);
580 commit_was_deferred_ = true; 614 commit_was_deferred_ = true;
581 layer_tree_host_->DidDeferCommit(); 615 layer_tree_host_->DidDeferCommit();
582 return; 616 return;
583 } 617 }
584 618
585 // This checker assumes NotifyReadyToCommit below causes a synchronous commit. 619 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous
620 // commit.
586 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); 621 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_);
587 622
588 if (!layer_tree_host_->visible()) { 623 if (!layer_tree_host_->visible()) {
589 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); 624 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
590 BeginMainFrameAbortedOnImplThread(); 625 BeginMainFrameAbortedOnImplThread();
591 return; 626 return;
592 } 627 }
593 628
594 if (layer_tree_host_->output_surface_lost()) { 629 if (layer_tree_host_->output_surface_lost()) {
595 TRACE_EVENT_INSTANT0( 630 TRACE_EVENT_INSTANT0(
596 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); 631 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD);
597 BeginMainFrameAbortedOnImplThread(); 632 BeginMainFrameAbortedOnImplThread();
598 return; 633 return;
599 } 634 }
600 635
636 const BeginFrameArgs& begin_frame_args =
637 layer_tree_host_impl_->CurrentBeginFrameArgs();
638 DoBeginMainFrame(begin_frame_args);
639 }
640
641 void SingleThreadProxy::DoBeginMainFrame(
642 const BeginFrameArgs& begin_frame_args) {
643 layer_tree_host_->WillBeginMainFrame();
644 layer_tree_host_->BeginMainFrame(begin_frame_args);
645 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
646 layer_tree_host_->Layout();
647
648 if (PrioritizedResourceManager* contents_texture_manager =
649 layer_tree_host_->contents_texture_manager()) {
650 contents_texture_manager->UnlinkAndClearEvictedBackings();
651 contents_texture_manager->SetMaxMemoryLimitBytes(
652 layer_tree_host_impl_->memory_allocation_limit_bytes());
653 contents_texture_manager->SetExternalPriorityCutoff(
654 layer_tree_host_impl_->memory_allocation_priority_cutoff());
655 }
656
657 DCHECK(!queue_for_commit_);
658 queue_for_commit_ = make_scoped_ptr(new ResourceUpdateQueue);
659
660 layer_tree_host_->UpdateLayers(queue_for_commit_.get());
661
601 timing_history_.DidBeginMainFrame(); 662 timing_history_.DidBeginMainFrame();
602 663
603 DCHECK(scheduler_on_impl_thread_); 664 if (scheduler_on_impl_thread_) {
604 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); 665 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted();
605 scheduler_on_impl_thread_->NotifyReadyToCommit(); 666 scheduler_on_impl_thread_->NotifyReadyToCommit();
667 }
606 } 668 }
607 669
608 void SingleThreadProxy::BeginMainFrameAbortedOnImplThread() { 670 void SingleThreadProxy::BeginMainFrameAbortedOnImplThread() {
609 DebugScopedSetImplThread impl(this); 671 DebugScopedSetImplThread impl(this);
610 DCHECK(scheduler_on_impl_thread_->CommitPending()); 672 DCHECK(scheduler_on_impl_thread_->CommitPending());
611 DCHECK(!layer_tree_host_impl_->pending_tree()); 673 DCHECK(!layer_tree_host_impl_->pending_tree());
612 674
613 // TODO(enne): SingleThreadProxy does not support cancelling commits yet so 675 // TODO(enne): SingleThreadProxy does not support cancelling commits yet so
614 // did_handle is always false. 676 // did_handle is always false.
615 bool did_handle = false; 677 bool did_handle = false;
616 layer_tree_host_impl_->BeginMainFrameAborted(did_handle); 678 layer_tree_host_impl_->BeginMainFrameAborted(did_handle);
617 scheduler_on_impl_thread_->BeginMainFrameAborted(did_handle); 679 scheduler_on_impl_thread_->BeginMainFrameAborted(did_handle);
618 } 680 }
619 681
620 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { 682 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
621 DebugScopedSetImplThread impl(this); 683 DebugScopedSetImplThread impl(this);
622 LayerTreeHostImpl::FrameData frame; 684 LayerTreeHostImpl::FrameData frame;
623 return DoComposite(layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time, 685 return DoComposite(layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time,
624 &frame); 686 &frame);
625 } 687 }
626 688
627 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { 689 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() {
628 NOTREACHED(); 690 NOTREACHED();
629 return INVALID_RESULT; 691 return INVALID_RESULT;
630 } 692 }
631 693
632 void SingleThreadProxy::ScheduledActionCommit() { 694 void SingleThreadProxy::ScheduledActionCommit() {
633 DebugScopedSetMainThread main(this); 695 DebugScopedSetMainThread main(this);
634 DoCommit(layer_tree_host_impl_->CurrentBeginFrameArgs()); 696 DoCommit();
635 } 697 }
636 698
637 void SingleThreadProxy::ScheduledActionAnimate() { 699 void SingleThreadProxy::ScheduledActionAnimate() {
638 TRACE_EVENT0("cc", "ScheduledActionAnimate"); 700 TRACE_EVENT0("cc", "ScheduledActionAnimate");
639 layer_tree_host_impl_->Animate( 701 layer_tree_host_impl_->Animate(
640 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); 702 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time);
641 } 703 }
642 704
643 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() { 705 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() {
644 // Impl-side painting only. 706 DebugScopedSetImplThread impl(this);
645 NOTREACHED(); 707 layer_tree_host_impl_->UpdateVisibleTiles();
646 } 708 }
647 709
648 void SingleThreadProxy::ScheduledActionActivateSyncTree() { 710 void SingleThreadProxy::ScheduledActionActivateSyncTree() {
711 DebugScopedSetImplThread impl(this);
712 layer_tree_host_impl_->ActivateSyncTree();
649 } 713 }
650 714
651 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { 715 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
652 DebugScopedSetMainThread main(this); 716 DebugScopedSetMainThread main(this);
653 DCHECK(scheduler_on_impl_thread_); 717 DCHECK(scheduler_on_impl_thread_);
654 // If possible, create the output surface in a post task. Synchronously 718 // If possible, create the output surface in a post task. Synchronously
655 // creating the output surface makes tests more awkward since this differs 719 // creating the output surface makes tests more awkward since this differs
656 // from the ThreadProxy behavior. However, sometimes there is no 720 // from the ThreadProxy behavior. However, sometimes there is no
657 // task runner. 721 // task runner.
658 if (Proxy::MainThreadTaskRunner()) { 722 if (Proxy::MainThreadTaskRunner()) {
659 MainThreadTaskRunner()->PostTask( 723 MainThreadTaskRunner()->PostTask(
660 FROM_HERE, 724 FROM_HERE,
661 base::Bind(&SingleThreadProxy::RequestNewOutputSurface, 725 base::Bind(&SingleThreadProxy::RequestNewOutputSurface,
662 weak_factory_.GetWeakPtr())); 726 weak_factory_.GetWeakPtr()));
663 } else { 727 } else {
664 RequestNewOutputSurface(); 728 RequestNewOutputSurface();
665 } 729 }
666 } 730 }
667 731
668 void SingleThreadProxy::ScheduledActionManageTiles() { 732 void SingleThreadProxy::ScheduledActionManageTiles() {
669 // Impl-side painting only. 733 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionManageTiles");
670 NOTREACHED(); 734 DCHECK(layer_tree_host_impl_->settings().impl_side_painting);
735 DebugScopedSetImplThread impl(this);
736 layer_tree_host_impl_->ManageTiles();
671 } 737 }
672 738
673 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { 739 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) {
674 } 740 }
675 741
676 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() { 742 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() {
677 return timing_history_.DrawDurationEstimate(); 743 return timing_history_.DrawDurationEstimate();
678 } 744 }
679 745
680 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { 746 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() {
681 return timing_history_.BeginMainFrameToCommitDurationEstimate(); 747 return timing_history_.BeginMainFrameToCommitDurationEstimate();
682 } 748 }
683 749
684 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { 750 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() {
685 return timing_history_.CommitToActivateDurationEstimate(); 751 return timing_history_.CommitToActivateDurationEstimate();
686 } 752 }
687 753
688 void SingleThreadProxy::DidBeginImplFrameDeadline() { 754 void SingleThreadProxy::DidBeginImplFrameDeadline() {
689 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); 755 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame();
690 } 756 }
691 757
692 } // namespace cc 758 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/single_thread_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698