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

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: Do BeginFrame stuff in BeginFrame, not lazily in commit 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 12 matching lines...) Expand all
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());
438 464
439 BeginFrameArgs begin_frame_args = BeginFrameArgs::Create( 465 BeginMainFrame();
440 frame_begin_time, base::TimeTicks(), BeginFrameArgs::DefaultInterval()); 466 DoCommit();
441 DoCommit(begin_frame_args); 467
468 DCHECK(!layer_tree_host_impl_->settings().impl_side_painting)
469 << "Impl-side painting and synchronous compositing are not supported.";
442 470
443 LayerTreeHostImpl::FrameData frame; 471 LayerTreeHostImpl::FrameData frame;
444 DoComposite(frame_begin_time, &frame); 472 DoComposite(frame_begin_time, &frame);
445 } 473 }
446 474
447 void SingleThreadProxy::AsValueInto(base::debug::TracedValue* state) const { 475 void SingleThreadProxy::AsValueInto(base::debug::TracedValue* state) const {
448 // The following line casts away const modifiers because it is just 476 // The following line casts away const modifiers because it is just
449 // setting debug state. We still want the AsValue() function and its 477 // setting debug state. We still want the AsValue() function and its
450 // call chain to be const throughout. 478 // call chain to be const throughout.
451 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); 479 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
(...skipping 27 matching lines...) Expand all
479 DCHECK(Proxy::IsImplThread()); 507 DCHECK(Proxy::IsImplThread());
480 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 508 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
481 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); 509 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer());
482 } 510 }
483 511
484 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, 512 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time,
485 LayerTreeHostImpl::FrameData* frame) { 513 LayerTreeHostImpl::FrameData* frame) {
486 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); 514 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
487 DCHECK(!layer_tree_host_->output_surface_lost()); 515 DCHECK(!layer_tree_host_->output_surface_lost());
488 516
517 DrawResult draw_result;
518 bool draw_frame;
489 { 519 {
490 DebugScopedSetImplThread impl(this); 520 DebugScopedSetImplThread impl(this);
491 base::AutoReset<bool> mark_inside(&inside_draw_, true); 521 base::AutoReset<bool> mark_inside(&inside_draw_, true);
492 522
493 // We guard PrepareToDraw() with CanDraw() because it always returns a valid 523 // 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 524 // 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 525 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
496 // CanDraw() as well. 526 // CanDraw() as well.
497 if (!ShouldComposite()) { 527 if (!ShouldComposite()) {
498 UpdateBackgroundAnimateTicking(); 528 UpdateBackgroundAnimateTicking();
499 return DRAW_ABORTED_CANT_DRAW; 529 return DRAW_ABORTED_CANT_DRAW;
500 } 530 }
501 531
502 timing_history_.DidStartDrawing(); 532 timing_history_.DidStartDrawing();
503 533
504 layer_tree_host_impl_->Animate( 534 layer_tree_host_impl_->Animate(
505 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); 535 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time);
506 UpdateBackgroundAnimateTicking(); 536 UpdateBackgroundAnimateTicking();
507 537
508 layer_tree_host_impl_->PrepareToDraw(frame); 538 draw_result = layer_tree_host_impl_->PrepareToDraw(frame);
danakj 2014/10/01 22:36:24 Question: Isn't sync composite supposed to wait fo
509 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); 539 draw_frame = draw_result == DRAW_SUCCESS;
540 if (draw_frame)
541 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time);
510 layer_tree_host_impl_->DidDrawAllLayers(*frame); 542 layer_tree_host_impl_->DidDrawAllLayers(*frame);
511 543
512 bool start_ready_animations = true; 544 bool start_ready_animations = draw_frame;
513 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); 545 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
514
515 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); 546 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame();
516 547
517 timing_history_.DidFinishDrawing(); 548 timing_history_.DidFinishDrawing();
518 } 549 }
519 550
520 { 551 if (draw_frame) {
521 DebugScopedSetImplThread impl(this); 552 DebugScopedSetImplThread impl(this);
522 553
523 // This CapturePostTasks should be destroyed before 554 // This CapturePostTasks should be destroyed before
524 // DidCommitAndDrawFrame() is called since that goes out to the 555 // DidCommitAndDrawFrame() is called since that goes out to the
525 // embedder, 556 // embedder,
526 // and we want the embedder to receive its callbacks before that. 557 // and we want the embedder to receive its callbacks before that.
527 // NOTE: This maintains consistent ordering with the ThreadProxy since 558 // NOTE: This maintains consistent ordering with the ThreadProxy since
528 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread 559 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
529 // there as the main thread is not blocked, so any posted tasks inside 560 // there as the main thread is not blocked, so any posted tasks inside
530 // the swap buffers will execute first. 561 // the swap buffers will execute first.
531 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 562 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
532 563
533 BlockingTaskRunner::CapturePostTasks blocked( 564 BlockingTaskRunner::CapturePostTasks blocked(
534 blocking_main_thread_task_runner()); 565 blocking_main_thread_task_runner());
535 layer_tree_host_impl_->SwapBuffers(*frame); 566 layer_tree_host_impl_->SwapBuffers(*frame);
536 } 567 }
537 DidCommitAndDrawFrame(); 568 DidCommitAndDrawFrame();
538 569
539 return DRAW_SUCCESS; 570 return draw_result;
540 } 571 }
541 572
542 void SingleThreadProxy::DidCommitAndDrawFrame() { 573 void SingleThreadProxy::DidCommitAndDrawFrame() {
543 if (next_frame_is_newly_committed_frame_) { 574 if (next_frame_is_newly_committed_frame_) {
544 DebugScopedSetMainThread main(this); 575 DebugScopedSetMainThread main(this);
545 next_frame_is_newly_committed_frame_ = false; 576 next_frame_is_newly_committed_frame_ = false;
546 layer_tree_host_->DidCommitAndDrawFrame(); 577 layer_tree_host_->DidCommitAndDrawFrame();
547 } 578 }
548 } 579 }
549 580
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 return; 622 return;
592 } 623 }
593 624
594 if (layer_tree_host_->output_surface_lost()) { 625 if (layer_tree_host_->output_surface_lost()) {
595 TRACE_EVENT_INSTANT0( 626 TRACE_EVENT_INSTANT0(
596 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); 627 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD);
597 BeginMainFrameAbortedOnImplThread(); 628 BeginMainFrameAbortedOnImplThread();
598 return; 629 return;
599 } 630 }
600 631
632 const BeginFrameArgs& begin_frame_args =
633 layer_tree_host_impl_->CurrentBeginFrameArgs();
634 layer_tree_host_->WillBeginMainFrame();
635 layer_tree_host_->BeginMainFrame(begin_frame_args);
636 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
637 layer_tree_host_->Layout();
638
639 if (PrioritizedResourceManager* contents_texture_manager =
640 layer_tree_host_->contents_texture_manager()) {
641 contents_texture_manager->UnlinkAndClearEvictedBackings();
642 contents_texture_manager->SetMaxMemoryLimitBytes(
643 layer_tree_host_impl_->memory_allocation_limit_bytes());
644 contents_texture_manager->SetExternalPriorityCutoff(
645 layer_tree_host_impl_->memory_allocation_priority_cutoff());
646 }
647
648 DCHECK(!queue_for_commit_);
649 queue_for_commit_ = make_scoped_ptr(new ResourceUpdateQueue);
650
651 layer_tree_host_->UpdateLayers(queue_for_commit_.get());
652
601 timing_history_.DidBeginMainFrame(); 653 timing_history_.DidBeginMainFrame();
602 654
603 DCHECK(scheduler_on_impl_thread_); 655 if (scheduler_on_impl_thread_) {
604 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); 656 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted();
605 scheduler_on_impl_thread_->NotifyReadyToCommit(); 657 scheduler_on_impl_thread_->NotifyReadyToCommit();
658 }
606 } 659 }
607 660
608 void SingleThreadProxy::BeginMainFrameAbortedOnImplThread() { 661 void SingleThreadProxy::BeginMainFrameAbortedOnImplThread() {
609 DebugScopedSetImplThread impl(this); 662 DebugScopedSetImplThread impl(this);
610 DCHECK(scheduler_on_impl_thread_->CommitPending()); 663 DCHECK(scheduler_on_impl_thread_->CommitPending());
611 DCHECK(!layer_tree_host_impl_->pending_tree()); 664 DCHECK(!layer_tree_host_impl_->pending_tree());
612 665
613 // TODO(enne): SingleThreadProxy does not support cancelling commits yet so 666 // TODO(enne): SingleThreadProxy does not support cancelling commits yet so
614 // did_handle is always false. 667 // did_handle is always false.
615 bool did_handle = false; 668 bool did_handle = false;
616 layer_tree_host_impl_->BeginMainFrameAborted(did_handle); 669 layer_tree_host_impl_->BeginMainFrameAborted(did_handle);
617 scheduler_on_impl_thread_->BeginMainFrameAborted(did_handle); 670 scheduler_on_impl_thread_->BeginMainFrameAborted(did_handle);
618 } 671 }
619 672
620 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { 673 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
621 DebugScopedSetImplThread impl(this); 674 DebugScopedSetImplThread impl(this);
622 LayerTreeHostImpl::FrameData frame; 675 LayerTreeHostImpl::FrameData frame;
623 return DoComposite(layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time, 676 return DoComposite(layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time,
624 &frame); 677 &frame);
625 } 678 }
626 679
627 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { 680 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() {
628 NOTREACHED(); 681 NOTREACHED();
629 return INVALID_RESULT; 682 return INVALID_RESULT;
630 } 683 }
631 684
632 void SingleThreadProxy::ScheduledActionCommit() { 685 void SingleThreadProxy::ScheduledActionCommit() {
633 DebugScopedSetMainThread main(this); 686 DebugScopedSetMainThread main(this);
634 DoCommit(layer_tree_host_impl_->CurrentBeginFrameArgs()); 687 DoCommit();
635 } 688 }
636 689
637 void SingleThreadProxy::ScheduledActionAnimate() { 690 void SingleThreadProxy::ScheduledActionAnimate() {
638 TRACE_EVENT0("cc", "ScheduledActionAnimate"); 691 TRACE_EVENT0("cc", "ScheduledActionAnimate");
639 layer_tree_host_impl_->Animate( 692 layer_tree_host_impl_->Animate(
640 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); 693 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time);
641 } 694 }
642 695
643 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() { 696 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() {
644 // Impl-side painting only. 697 DebugScopedSetImplThread impl(this);
645 NOTREACHED(); 698 layer_tree_host_impl_->UpdateVisibleTiles();
646 } 699 }
647 700
648 void SingleThreadProxy::ScheduledActionActivateSyncTree() { 701 void SingleThreadProxy::ScheduledActionActivateSyncTree() {
702 DebugScopedSetImplThread impl(this);
703 layer_tree_host_impl_->ActivateSyncTree();
649 } 704 }
650 705
651 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { 706 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
652 DebugScopedSetMainThread main(this); 707 DebugScopedSetMainThread main(this);
653 DCHECK(scheduler_on_impl_thread_); 708 DCHECK(scheduler_on_impl_thread_);
654 // If possible, create the output surface in a post task. Synchronously 709 // If possible, create the output surface in a post task. Synchronously
655 // creating the output surface makes tests more awkward since this differs 710 // creating the output surface makes tests more awkward since this differs
656 // from the ThreadProxy behavior. However, sometimes there is no 711 // from the ThreadProxy behavior. However, sometimes there is no
657 // task runner. 712 // task runner.
658 if (Proxy::MainThreadTaskRunner()) { 713 if (Proxy::MainThreadTaskRunner()) {
659 MainThreadTaskRunner()->PostTask( 714 MainThreadTaskRunner()->PostTask(
660 FROM_HERE, 715 FROM_HERE,
661 base::Bind(&SingleThreadProxy::RequestNewOutputSurface, 716 base::Bind(&SingleThreadProxy::RequestNewOutputSurface,
662 weak_factory_.GetWeakPtr())); 717 weak_factory_.GetWeakPtr()));
663 } else { 718 } else {
664 RequestNewOutputSurface(); 719 RequestNewOutputSurface();
665 } 720 }
666 } 721 }
667 722
668 void SingleThreadProxy::ScheduledActionManageTiles() { 723 void SingleThreadProxy::ScheduledActionManageTiles() {
669 // Impl-side painting only. 724 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionManageTiles");
670 NOTREACHED(); 725 DCHECK(layer_tree_host_impl_->settings().impl_side_painting);
726 DebugScopedSetImplThread impl(this);
727 layer_tree_host_impl_->ManageTiles();
671 } 728 }
672 729
673 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { 730 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) {
674 } 731 }
675 732
676 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() { 733 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() {
677 return timing_history_.DrawDurationEstimate(); 734 return timing_history_.DrawDurationEstimate();
678 } 735 }
679 736
680 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { 737 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() {
681 return timing_history_.BeginMainFrameToCommitDurationEstimate(); 738 return timing_history_.BeginMainFrameToCommitDurationEstimate();
682 } 739 }
683 740
684 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { 741 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() {
685 return timing_history_.CommitToActivateDurationEstimate(); 742 return timing_history_.CommitToActivateDurationEstimate();
686 } 743 }
687 744
688 void SingleThreadProxy::DidBeginImplFrameDeadline() { 745 void SingleThreadProxy::DidBeginImplFrameDeadline() {
689 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); 746 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame();
690 } 747 }
691 748
692 } // namespace cc 749 } // 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