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

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

Issue 15058004: cc: Rename VSync to BeginFrame (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 7 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/thread_proxy.h ('k') | chrome/test/perf/rendering/latency_tests.cc » ('j') | 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/thread_proxy.h" 5 #include "cc/trees/thread_proxy.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "cc/base/thread.h" 10 #include "cc/base/thread.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 commit_requested_(false), 45 commit_requested_(false),
46 commit_request_sent_to_impl_thread_(false), 46 commit_request_sent_to_impl_thread_(false),
47 created_offscreen_context_provider_(false), 47 created_offscreen_context_provider_(false),
48 layer_tree_host_(layer_tree_host), 48 layer_tree_host_(layer_tree_host),
49 started_(false), 49 started_(false),
50 textures_acquired_(true), 50 textures_acquired_(true),
51 in_composite_and_readback_(false), 51 in_composite_and_readback_(false),
52 manage_tiles_pending_(false), 52 manage_tiles_pending_(false),
53 weak_factory_on_impl_thread_(this), 53 weak_factory_on_impl_thread_(this),
54 weak_factory_(this), 54 weak_factory_(this),
55 begin_frame_completion_event_on_impl_thread_(NULL), 55 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_(NULL),
56 readback_request_on_impl_thread_(NULL), 56 readback_request_on_impl_thread_(NULL),
57 commit_completion_event_on_impl_thread_(NULL), 57 commit_completion_event_on_impl_thread_(NULL),
58 completion_event_for_commit_held_on_tree_activation_(NULL), 58 completion_event_for_commit_held_on_tree_activation_(NULL),
59 texture_acquisition_completion_event_on_impl_thread_(NULL), 59 texture_acquisition_completion_event_on_impl_thread_(NULL),
60 next_frame_is_newly_committed_frame_on_impl_thread_(false), 60 next_frame_is_newly_committed_frame_on_impl_thread_(false),
61 render_vsync_enabled_(layer_tree_host->settings().render_vsync_enabled), 61 throttle_frame_production_(
62 render_vsync_notification_enabled_( 62 layer_tree_host->settings().throttle_frame_production),
63 layer_tree_host->settings().render_vsync_notification_enabled), 63 render_parent_drives_begin_frame__(
64 synchronously_disable_vsync_( 64 layer_tree_host->settings().render_parent_drives_begin_frame_),
65 layer_tree_host->settings().synchronously_disable_vsync), 65 using_synchronous_renderer_compositor_(
66 layer_tree_host->settings().using_synchronous_renderer_compositor),
66 vsync_client_(NULL), 67 vsync_client_(NULL),
67 inside_draw_(false), 68 inside_draw_(false),
68 defer_commits_(false), 69 defer_commits_(false),
69 renew_tree_priority_on_impl_thread_pending_(false) { 70 renew_tree_priority_on_impl_thread_pending_(false) {
70 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); 71 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy");
71 DCHECK(IsMainThread()); 72 DCHECK(IsMainThread());
72 DCHECK(layer_tree_host_); 73 DCHECK(layer_tree_host_);
73 } 74 }
74 75
75 ThreadProxy::~ThreadProxy() { 76 ThreadProxy::~ThreadProxy() {
76 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); 77 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy");
77 DCHECK(IsMainThread()); 78 DCHECK(IsMainThread());
78 DCHECK(!started_); 79 DCHECK(!started_);
79 } 80 }
80 81
81 bool ThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) { 82 bool ThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) {
82 TRACE_EVENT0("cc", "ThreadProxy::CompositeAndReadback"); 83 TRACE_EVENT0("cc", "ThreadProxy::CompositeAndReadback");
83 DCHECK(IsMainThread()); 84 DCHECK(IsMainThread());
84 DCHECK(layer_tree_host_); 85 DCHECK(layer_tree_host_);
85 DCHECK(!defer_commits_); 86 DCHECK(!defer_commits_);
86 87
87 if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded()) { 88 if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded()) {
88 TRACE_EVENT0("cc", "CompositeAndReadback_EarlyOut_LR_Uninitialized"); 89 TRACE_EVENT0("cc", "CompositeAndReadback_EarlyOut_LR_Uninitialized");
89 return false; 90 return false;
90 } 91 }
91 92
92 // Perform a synchronous commit. 93 // Perform a synchronous commit.
93 { 94 {
94 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 95 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
95 CompletionEvent begin_frame_completion; 96 CompletionEvent begin_frame_sent_to_main_thread_completion;
96 Proxy::ImplThread()->PostTask( 97 Proxy::ImplThread()->PostTask(
97 base::Bind(&ThreadProxy::ForceBeginFrameOnImplThread, 98 base::Bind(&ThreadProxy::ForceCommitOnImplThread,
98 impl_thread_weak_ptr_, 99 impl_thread_weak_ptr_,
99 &begin_frame_completion)); 100 &begin_frame_sent_to_main_thread_completion));
100 begin_frame_completion.Wait(); 101 begin_frame_sent_to_main_thread_completion.Wait();
101 } 102 }
102 in_composite_and_readback_ = true; 103 in_composite_and_readback_ = true;
103 BeginFrame(scoped_ptr<BeginFrameAndCommitState>()); 104 BeginFrameOnMainThread(scoped_ptr<BeginFrameAndCommitState>());
104 in_composite_and_readback_ = false; 105 in_composite_and_readback_ = false;
105 106
106 // Perform a synchronous readback. 107 // Perform a synchronous readback.
107 ReadbackRequest request; 108 ReadbackRequest request;
108 request.rect = rect; 109 request.rect = rect;
109 request.pixels = pixels; 110 request.pixels = pixels;
110 { 111 {
111 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 112 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
112 Proxy::ImplThread()->PostTask( 113 Proxy::ImplThread()->PostTask(
113 base::Bind(&ThreadProxy::RequestReadbackOnImplThread, 114 base::Bind(&ThreadProxy::RequestReadbackOnImplThread,
114 impl_thread_weak_ptr_, 115 impl_thread_weak_ptr_,
115 &request)); 116 &request));
116 request.completion.Wait(); 117 request.completion.Wait();
117 } 118 }
118 return request.success; 119 return request.success;
119 } 120 }
120 121
122 void ThreadProxy::ForceCommitOnImplThread(CompletionEvent* completion) {
123 TRACE_EVENT0("cc", "ThreadProxy::ForceCommitOnImplThread");
124 DCHECK(IsImplThread());
125 DCHECK(!begin_frame_sent_to_main_thread_completion_event_on_impl_thread_);
126
127 scheduler_on_impl_thread_->SetNeedsForcedCommit();
128 if (scheduler_on_impl_thread_->CommitPending()) {
129 completion->Signal();
130 return;
131 }
132
133 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_ = completion;
134 }
135
121 void ThreadProxy::RequestReadbackOnImplThread(ReadbackRequest* request) { 136 void ThreadProxy::RequestReadbackOnImplThread(ReadbackRequest* request) {
122 DCHECK(Proxy::IsImplThread()); 137 DCHECK(Proxy::IsImplThread());
123 DCHECK(!readback_request_on_impl_thread_); 138 DCHECK(!readback_request_on_impl_thread_);
124 if (!layer_tree_host_impl_) { 139 if (!layer_tree_host_impl_) {
125 request->success = false; 140 request->success = false;
126 request->completion.Signal(); 141 request->completion.Signal();
127 return; 142 return;
128 } 143 }
129 144
130 readback_request_on_impl_thread_ = request; 145 readback_request_on_impl_thread_ = request;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 DCHECK(IsImplThread()); 338 DCHECK(IsImplThread());
324 TRACE_EVENT2("cc", 339 TRACE_EVENT2("cc",
325 "ThreadProxy::OnVSyncParametersChanged", 340 "ThreadProxy::OnVSyncParametersChanged",
326 "timebase", 341 "timebase",
327 (timebase - base::TimeTicks()).InMilliseconds(), 342 (timebase - base::TimeTicks()).InMilliseconds(),
328 "interval", 343 "interval",
329 interval.InMilliseconds()); 344 interval.InMilliseconds());
330 scheduler_on_impl_thread_->SetTimebaseAndInterval(timebase, interval); 345 scheduler_on_impl_thread_->SetTimebaseAndInterval(timebase, interval);
331 } 346 }
332 347
333 void ThreadProxy::DidVSync(base::TimeTicks frame_time) { 348 void ThreadProxy::BeginFrameOnImplThread(base::TimeTicks frame_time) {
334 DCHECK(IsImplThread()); 349 DCHECK(IsImplThread());
335 TRACE_EVENT0("cc", "ThreadProxy::DidVSync"); 350 TRACE_EVENT0("cc", "ThreadProxy::OnBeginFrameOnImplThread");
336 if (vsync_client_) 351 if (vsync_client_)
337 vsync_client_->DidVSync(frame_time); 352 vsync_client_->DidVSync(frame_time);
338 } 353 }
339 354
340 void ThreadProxy::RequestVSyncNotification(VSyncClient* client) { 355 void ThreadProxy::RequestVSyncNotification(VSyncClient* client) {
341 DCHECK(IsImplThread()); 356 DCHECK(IsImplThread());
342 TRACE_EVENT1( 357 TRACE_EVENT1(
343 "cc", "ThreadProxy::RequestVSyncNotification", "enable", !!client); 358 "cc", "ThreadProxy::RequestVSyncNotification", "enable", !!client);
344 vsync_client_ = client; 359 vsync_client_ = client;
345 layer_tree_host_impl_->EnableVSyncNotification(!!client); 360 layer_tree_host_impl_->SetNeedsBeginFrame(!!client);
346 } 361 }
347 362
348 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { 363 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) {
349 DCHECK(IsImplThread()); 364 DCHECK(IsImplThread());
350 TRACE_EVENT1( 365 TRACE_EVENT1(
351 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); 366 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
352 scheduler_on_impl_thread_->SetCanDraw(can_draw); 367 scheduler_on_impl_thread_->SetCanDraw(can_draw);
353 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 368 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
354 !scheduler_on_impl_thread_->WillDrawIfNeeded()); 369 !scheduler_on_impl_thread_->WillDrawIfNeeded());
355 } 370 }
(...skipping 21 matching lines...) Expand all
377 manage_tiles_pending_ = true; 392 manage_tiles_pending_ = true;
378 } 393 }
379 394
380 void ThreadProxy::ManageTilesOnImplThread() { 395 void ThreadProxy::ManageTilesOnImplThread() {
381 // TODO(nduca): If needed, move this into CCSchedulerStateMachine. 396 // TODO(nduca): If needed, move this into CCSchedulerStateMachine.
382 manage_tiles_pending_ = false; 397 manage_tiles_pending_ = false;
383 if (layer_tree_host_impl_) 398 if (layer_tree_host_impl_)
384 layer_tree_host_impl_->ManageTiles(); 399 layer_tree_host_impl_->ManageTiles();
385 } 400 }
386 401
387 void ThreadProxy::SetNeedsForcedCommitOnImplThread() {
388 DCHECK(IsImplThread());
389 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsForcedCommitOnImplThread");
390 scheduler_on_impl_thread_->SetNeedsForcedCommit();
391 }
392
393 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( 402 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
394 scoped_ptr<AnimationEventsVector> events, 403 scoped_ptr<AnimationEventsVector> events,
395 base::Time wall_clock_time) { 404 base::Time wall_clock_time) {
396 DCHECK(IsImplThread()); 405 DCHECK(IsImplThread());
397 TRACE_EVENT0("cc", 406 TRACE_EVENT0("cc",
398 "ThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); 407 "ThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
399 Proxy::MainThread()->PostTask(base::Bind(&ThreadProxy::SetAnimationEvents, 408 Proxy::MainThread()->PostTask(base::Bind(&ThreadProxy::SetAnimationEvents,
400 main_thread_weak_ptr_, 409 main_thread_weak_ptr_,
401 base::Passed(&events), 410 base::Passed(&events),
402 wall_clock_time)); 411 wall_clock_time));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 DCHECK_NE(defer_commits_, defer_commits); 483 DCHECK_NE(defer_commits_, defer_commits);
475 defer_commits_ = defer_commits; 484 defer_commits_ = defer_commits;
476 485
477 if (defer_commits_) 486 if (defer_commits_)
478 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this); 487 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this);
479 else 488 else
480 TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::SetDeferCommits", this); 489 TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::SetDeferCommits", this);
481 490
482 if (!defer_commits_ && pending_deferred_commit_) 491 if (!defer_commits_ && pending_deferred_commit_)
483 Proxy::MainThread()->PostTask( 492 Proxy::MainThread()->PostTask(
484 base::Bind(&ThreadProxy::BeginFrame, 493 base::Bind(&ThreadProxy::BeginFrameOnMainThread,
485 main_thread_weak_ptr_, 494 main_thread_weak_ptr_,
486 base::Passed(&pending_deferred_commit_))); 495 base::Passed(&pending_deferred_commit_)));
487 } 496 }
488 497
489 bool ThreadProxy::CommitRequested() const { 498 bool ThreadProxy::CommitRequested() const {
490 DCHECK(IsMainThread()); 499 DCHECK(IsMainThread());
491 return commit_requested_; 500 return commit_requested_;
492 } 501 }
493 502
494 void ThreadProxy::SetNeedsRedrawOnImplThread() { 503 void ThreadProxy::SetNeedsRedrawOnImplThread() {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 completion->Signal(); 609 completion->Signal();
601 } 610 }
602 611
603 void ThreadProxy::FinishAllRenderingOnImplThread(CompletionEvent* completion) { 612 void ThreadProxy::FinishAllRenderingOnImplThread(CompletionEvent* completion) {
604 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread"); 613 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread");
605 DCHECK(IsImplThread()); 614 DCHECK(IsImplThread());
606 layer_tree_host_impl_->FinishAllRendering(); 615 layer_tree_host_impl_->FinishAllRendering();
607 completion->Signal(); 616 completion->Signal();
608 } 617 }
609 618
610 void ThreadProxy::ForceBeginFrameOnImplThread(CompletionEvent* completion) { 619 void ThreadProxy::ScheduledActionSendBeginFrameToMainThread() {
611 TRACE_EVENT0("cc", "ThreadProxy::ForceBeginFrameOnImplThread"); 620 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionSendBeginFrameToMainThread");
612 DCHECK(!begin_frame_completion_event_on_impl_thread_);
613
614 SetNeedsForcedCommitOnImplThread();
615 if (scheduler_on_impl_thread_->CommitPending()) {
616 completion->Signal();
617 return;
618 }
619
620 begin_frame_completion_event_on_impl_thread_ = completion;
621 }
622
623 void ThreadProxy::ScheduledActionBeginFrame() {
624 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginFrame");
625 scoped_ptr<BeginFrameAndCommitState> begin_frame_state( 621 scoped_ptr<BeginFrameAndCommitState> begin_frame_state(
626 new BeginFrameAndCommitState); 622 new BeginFrameAndCommitState);
627 begin_frame_state->monotonic_frame_begin_time = base::TimeTicks::Now(); 623 begin_frame_state->monotonic_frame_begin_time = base::TimeTicks::Now();
628 begin_frame_state->scroll_info = layer_tree_host_impl_->ProcessScrollDeltas(); 624 begin_frame_state->scroll_info =
625 layer_tree_host_impl_->ProcessScrollDeltas();
629 DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u); 626 DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u);
630 begin_frame_state->memory_allocation_limit_bytes = 627 begin_frame_state->memory_allocation_limit_bytes =
631 layer_tree_host_impl_->memory_allocation_limit_bytes(); 628 layer_tree_host_impl_->memory_allocation_limit_bytes();
632 Proxy::MainThread()->PostTask(base::Bind(&ThreadProxy::BeginFrame, 629 Proxy::MainThread()->PostTask(
633 main_thread_weak_ptr_, 630 base::Bind(&ThreadProxy::BeginFrameOnMainThread,
634 base::Passed(&begin_frame_state))); 631 main_thread_weak_ptr_,
632 base::Passed(&begin_frame_state)));
635 633
636 if (begin_frame_completion_event_on_impl_thread_) { 634 if (begin_frame_sent_to_main_thread_completion_event_on_impl_thread_) {
637 begin_frame_completion_event_on_impl_thread_->Signal(); 635 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_->Signal();
638 begin_frame_completion_event_on_impl_thread_ = NULL; 636 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_ = NULL;
639 } 637 }
640 } 638 }
641 639
642 void ThreadProxy::BeginFrame( 640 void ThreadProxy::BeginFrameOnMainThread(
643 scoped_ptr<BeginFrameAndCommitState> begin_frame_state) { 641 scoped_ptr<BeginFrameAndCommitState> begin_frame_state) {
644 TRACE_EVENT0("cc", "ThreadProxy::BeginFrame"); 642 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnMainThread");
645 DCHECK(IsMainThread()); 643 DCHECK(IsMainThread());
646 if (!layer_tree_host_) 644 if (!layer_tree_host_)
647 return; 645 return;
648 646
649 if (defer_commits_) { 647 if (defer_commits_) {
650 pending_deferred_commit_ = begin_frame_state.Pass(); 648 pending_deferred_commit_ = begin_frame_state.Pass();
651 layer_tree_host_->DidDeferCommit(); 649 layer_tree_host_->DidDeferCommit();
652 TRACE_EVENT0("cc", "EarlyOut_DeferCommits"); 650 TRACE_EVENT0("cc", "EarlyOut_DeferCommits");
653 return; 651 return;
654 } 652 }
(...skipping 13 matching lines...) Expand all
668 666
669 if (begin_frame_state) 667 if (begin_frame_state)
670 layer_tree_host_->ApplyScrollAndScale(*begin_frame_state->scroll_info); 668 layer_tree_host_->ApplyScrollAndScale(*begin_frame_state->scroll_info);
671 669
672 if (!in_composite_and_readback_ && !layer_tree_host_->visible()) { 670 if (!in_composite_and_readback_ && !layer_tree_host_->visible()) {
673 commit_requested_ = false; 671 commit_requested_ = false;
674 commit_request_sent_to_impl_thread_ = false; 672 commit_request_sent_to_impl_thread_ = false;
675 673
676 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); 674 TRACE_EVENT0("cc", "EarlyOut_NotVisible");
677 Proxy::ImplThread()->PostTask(base::Bind( 675 Proxy::ImplThread()->PostTask(base::Bind(
678 &ThreadProxy::BeginFrameAbortedOnImplThread, impl_thread_weak_ptr_)); 676 &ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread,
677 impl_thread_weak_ptr_));
679 return; 678 return;
680 } 679 }
681 680
682 layer_tree_host_->WillBeginFrame(); 681 layer_tree_host_->WillBeginFrame();
683 682
684 if (begin_frame_state) { 683 if (begin_frame_state) {
685 layer_tree_host_->UpdateClientAnimations( 684 layer_tree_host_->UpdateClientAnimations(
686 begin_frame_state->monotonic_frame_begin_time); 685 begin_frame_state->monotonic_frame_begin_time);
687 layer_tree_host_->AnimateLayers( 686 layer_tree_host_->AnimateLayers(
688 begin_frame_state->monotonic_frame_begin_time); 687 begin_frame_state->monotonic_frame_begin_time);
(...skipping 11 matching lines...) Expand all
700 // Clear the commit flag after updating animations and layout here --- objects 699 // Clear the commit flag after updating animations and layout here --- objects
701 // that only layout when painted will trigger another SetNeedsCommit inside 700 // that only layout when painted will trigger another SetNeedsCommit inside
702 // UpdateLayers. 701 // UpdateLayers.
703 commit_requested_ = false; 702 commit_requested_ = false;
704 commit_request_sent_to_impl_thread_ = false; 703 commit_request_sent_to_impl_thread_ = false;
705 704
706 scoped_ptr<ResourceUpdateQueue> queue = 705 scoped_ptr<ResourceUpdateQueue> queue =
707 make_scoped_ptr(new ResourceUpdateQueue); 706 make_scoped_ptr(new ResourceUpdateQueue);
708 layer_tree_host_->UpdateLayers( 707 layer_tree_host_->UpdateLayers(
709 queue.get(), 708 queue.get(),
710 begin_frame_state ? begin_frame_state->memory_allocation_limit_bytes 709 begin_frame_state ?
711 : 0u); 710 begin_frame_state->memory_allocation_limit_bytes : 0u);
712 711
713 // Once single buffered layers are committed, they cannot be modified until 712 // Once single buffered layers are committed, they cannot be modified until
714 // they are drawn by the impl thread. 713 // they are drawn by the impl thread.
715 textures_acquired_ = false; 714 textures_acquired_ = false;
716 715
717 layer_tree_host_->WillCommit(); 716 layer_tree_host_->WillCommit();
718 // Before applying scrolls and calling animate, we set animate_requested_ to 717 // Before applying scrolls and calling animate, we set animate_requested_ to
719 // false. If it is true now, it means SetNeedAnimate was called again, but 718 // false. If it is true now, it means SetNeedAnimate was called again, but
720 // during a state when commit_request_sent_to_impl_thread_ = true. We need to 719 // during a state when commit_request_sent_to_impl_thread_ = true. We need to
721 // force that call to happen again now so that the commit request is sent to 720 // force that call to happen again now so that the commit request is sent to
722 // the impl thread. 721 // the impl thread.
723 if (animate_requested_) { 722 if (animate_requested_) {
724 // Forces SetNeedsAnimate to consider posting a commit task. 723 // Forces SetNeedsAnimate to consider posting a commit task.
725 animate_requested_ = false; 724 animate_requested_ = false;
726 SetNeedsAnimate(); 725 SetNeedsAnimate();
727 } 726 }
728 727
729 scoped_refptr<cc::ContextProvider> offscreen_context_provider; 728 scoped_refptr<cc::ContextProvider> offscreen_context_provider;
730 if (renderer_capabilities_main_thread_copy_.using_offscreen_context3d && 729 if (renderer_capabilities_main_thread_copy_.using_offscreen_context3d &&
731 layer_tree_host_->needs_offscreen_context()) { 730 layer_tree_host_->needs_offscreen_context()) {
732 offscreen_context_provider = layer_tree_host_->client()-> 731 offscreen_context_provider = layer_tree_host_->client()->
733 OffscreenContextProviderForCompositorThread(); 732 OffscreenContextProviderForCompositorThread();
734 if (offscreen_context_provider) 733 if (offscreen_context_provider)
735 created_offscreen_context_provider_ = true; 734 created_offscreen_context_provider_ = true;
736 } 735 }
737 736
738 // Notify the impl thread that the BeginFrame has completed. This will 737 // Notify the impl thread that the main thread is ready to commit. This will
739 // begin the commit process, which is blocking from the main thread's 738 // begin the commit process, which is blocking from the main thread's
740 // point of view, but asynchronously performed on the impl thread, 739 // point of view, but asynchronously performed on the impl thread,
741 // coordinated by the Scheduler. 740 // coordinated by the Scheduler.
742 { 741 {
743 TRACE_EVENT0("cc", "ThreadProxy::BeginFrame::commit"); 742 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnMainThread::commit");
744 743
745 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 744 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
746 745
747 RenderingStatsInstrumentation* stats_instrumentation = 746 RenderingStatsInstrumentation* stats_instrumentation =
748 layer_tree_host_->rendering_stats_instrumentation(); 747 layer_tree_host_->rendering_stats_instrumentation();
749 base::TimeTicks start_time = stats_instrumentation->StartRecording(); 748 base::TimeTicks start_time = stats_instrumentation->StartRecording();
750 749
751 CompletionEvent completion; 750 CompletionEvent completion;
752 Proxy::ImplThread()->PostTask( 751 Proxy::ImplThread()->PostTask(
753 base::Bind(&ThreadProxy::BeginFrameCompleteOnImplThread, 752 base::Bind(&ThreadProxy::StartCommitOnImplThread,
754 impl_thread_weak_ptr_, 753 impl_thread_weak_ptr_,
755 &completion, 754 &completion,
756 queue.release(), 755 queue.release(),
757 offscreen_context_provider)); 756 offscreen_context_provider));
758 completion.Wait(); 757 completion.Wait();
759 758
760 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); 759 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time);
761 stats_instrumentation->AddCommit(duration); 760 stats_instrumentation->AddCommit(duration);
762 } 761 }
763 762
764 layer_tree_host_->CommitComplete(); 763 layer_tree_host_->CommitComplete();
765 layer_tree_host_->DidBeginFrame(); 764 layer_tree_host_->DidBeginFrame();
766 } 765 }
767 766
768 void ThreadProxy::BeginFrameCompleteOnImplThread( 767 void ThreadProxy::StartCommitOnImplThread(
769 CompletionEvent* completion, 768 CompletionEvent* completion,
770 ResourceUpdateQueue* raw_queue, 769 ResourceUpdateQueue* raw_queue,
771 scoped_refptr<cc::ContextProvider> offscreen_context_provider) { 770 scoped_refptr<cc::ContextProvider> offscreen_context_provider) {
772 scoped_ptr<ResourceUpdateQueue> queue(raw_queue); 771 scoped_ptr<ResourceUpdateQueue> queue(raw_queue);
773 772
774 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameCompleteOnImplThread"); 773 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread");
775 DCHECK(!commit_completion_event_on_impl_thread_); 774 DCHECK(!commit_completion_event_on_impl_thread_);
776 DCHECK(IsImplThread() && IsMainThreadBlocked()); 775 DCHECK(IsImplThread() && IsMainThreadBlocked());
777 DCHECK(scheduler_on_impl_thread_); 776 DCHECK(scheduler_on_impl_thread_);
778 DCHECK(scheduler_on_impl_thread_->CommitPending()); 777 DCHECK(scheduler_on_impl_thread_->CommitPending());
779 778
780 if (!layer_tree_host_impl_) { 779 if (!layer_tree_host_impl_) {
781 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); 780 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree");
782 completion->Signal(); 781 completion->Signal();
783 return; 782 return;
784 } 783 }
(...skipping 22 matching lines...) Expand all
807 if (layer_tree_host_impl_->resource_provider()) { 806 if (layer_tree_host_impl_->resource_provider()) {
808 current_resource_update_controller_on_impl_thread_ = 807 current_resource_update_controller_on_impl_thread_ =
809 ResourceUpdateController::Create( 808 ResourceUpdateController::Create(
810 this, 809 this,
811 Proxy::ImplThread(), 810 Proxy::ImplThread(),
812 queue.Pass(), 811 queue.Pass(),
813 layer_tree_host_impl_->resource_provider()); 812 layer_tree_host_impl_->resource_provider());
814 current_resource_update_controller_on_impl_thread_->PerformMoreUpdates( 813 current_resource_update_controller_on_impl_thread_->PerformMoreUpdates(
815 scheduler_on_impl_thread_->AnticipatedDrawTime()); 814 scheduler_on_impl_thread_->AnticipatedDrawTime());
816 } else { 815 } else {
817 // Normally the ResourceUpdateController notifies when begin frame has 816 // Normally the ResourceUpdateController notifies when commit should
818 // completed, but in tile-free software rendering there is no resource 817 // finish, but in tile-free software rendering there is no resource
819 // update step so jump straight to the notification. 818 // update step so jump straight to the notification.
820 scheduler_on_impl_thread_->BeginFrameComplete(); 819 scheduler_on_impl_thread_->FinishCommit();
821 } 820 }
822 } 821 }
823 822
824 void ThreadProxy::BeginFrameAbortedOnImplThread() { 823 void ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread() {
825 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameAbortedOnImplThread"); 824 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread");
826 DCHECK(IsImplThread()); 825 DCHECK(IsImplThread());
827 DCHECK(scheduler_on_impl_thread_); 826 DCHECK(scheduler_on_impl_thread_);
828 DCHECK(scheduler_on_impl_thread_->CommitPending()); 827 DCHECK(scheduler_on_impl_thread_->CommitPending());
829 828
830 scheduler_on_impl_thread_->BeginFrameAborted(); 829 scheduler_on_impl_thread_->BeginFrameAbortedByMainThread();
831 } 830 }
832 831
833 void ThreadProxy::ScheduledActionCommit() { 832 void ThreadProxy::ScheduledActionCommit() {
834 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionCommit"); 833 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionCommit");
835 DCHECK(IsImplThread()); 834 DCHECK(IsImplThread());
836 DCHECK(commit_completion_event_on_impl_thread_); 835 DCHECK(commit_completion_event_on_impl_thread_);
837 if (current_resource_update_controller_on_impl_thread_) { 836 if (current_resource_update_controller_on_impl_thread_) {
838 // Complete all remaining texture updates. 837 // Complete all remaining texture updates.
839 current_resource_update_controller_on_impl_thread_->Finalize(); 838 current_resource_update_controller_on_impl_thread_->Finalize();
840 current_resource_update_controller_on_impl_thread_.reset(); 839 current_resource_update_controller_on_impl_thread_.reset();
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 if (layer_tree_host_impl_->PrepareToDraw(&frame, readback_rect) || 942 if (layer_tree_host_impl_->PrepareToDraw(&frame, readback_rect) ||
944 forced_draw) 943 forced_draw)
945 draw_frame = true; 944 draw_frame = true;
946 else 945 else
947 start_ready_animations = false; 946 start_ready_animations = false;
948 } 947 }
949 948
950 if (draw_frame) { 949 if (draw_frame) {
951 layer_tree_host_impl_->DrawLayers( 950 layer_tree_host_impl_->DrawLayers(
952 &frame, 951 &frame,
953 scheduler_on_impl_thread_->LastVSyncTime()); 952 scheduler_on_impl_thread_->LastBeginFrameOnImplThreadTime());
954 result.did_draw = true; 953 result.did_draw = true;
955 } 954 }
956 layer_tree_host_impl_->DidDrawAllLayers(frame); 955 layer_tree_host_impl_->DidDrawAllLayers(frame);
957 956
958 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); 957 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
959 958
960 // Check for a pending CompositeAndReadback. 959 // Check for a pending CompositeAndReadback.
961 if (readback_request_on_impl_thread_) { 960 if (readback_request_on_impl_thread_) {
962 readback_request_on_impl_thread_->success = false; 961 readback_request_on_impl_thread_->success = false;
963 if (draw_frame) { 962 if (draw_frame) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 1038
1040 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { 1039 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) {
1041 if (current_resource_update_controller_on_impl_thread_) 1040 if (current_resource_update_controller_on_impl_thread_)
1042 current_resource_update_controller_on_impl_thread_ 1041 current_resource_update_controller_on_impl_thread_
1043 ->PerformMoreUpdates(time); 1042 ->PerformMoreUpdates(time);
1044 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); 1043 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
1045 } 1044 }
1046 1045
1047 void ThreadProxy::ReadyToFinalizeTextureUpdates() { 1046 void ThreadProxy::ReadyToFinalizeTextureUpdates() {
1048 DCHECK(IsImplThread()); 1047 DCHECK(IsImplThread());
1049 scheduler_on_impl_thread_->BeginFrameComplete(); 1048 scheduler_on_impl_thread_->FinishCommit();
1050 } 1049 }
1051 1050
1052 void ThreadProxy::DidCommitAndDrawFrame() { 1051 void ThreadProxy::DidCommitAndDrawFrame() {
1053 DCHECK(IsMainThread()); 1052 DCHECK(IsMainThread());
1054 if (!layer_tree_host_) 1053 if (!layer_tree_host_)
1055 return; 1054 return;
1056 layer_tree_host_->DidCommitAndDrawFrame(); 1055 layer_tree_host_->DidCommitAndDrawFrame();
1057 } 1056 }
1058 1057
1059 void ThreadProxy::DidCompleteSwapBuffers() { 1058 void ThreadProxy::DidCompleteSwapBuffers() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 1108
1110 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { 1109 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) {
1111 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); 1110 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread");
1112 DCHECK(IsImplThread()); 1111 DCHECK(IsImplThread());
1113 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); 1112 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
1114 const base::TimeDelta display_refresh_interval = 1113 const base::TimeDelta display_refresh_interval =
1115 base::TimeDelta::FromMicroseconds( 1114 base::TimeDelta::FromMicroseconds(
1116 base::Time::kMicrosecondsPerSecond / 1115 base::Time::kMicrosecondsPerSecond /
1117 layer_tree_host_->settings().refresh_rate); 1116 layer_tree_host_->settings().refresh_rate);
1118 scoped_ptr<FrameRateController> frame_rate_controller; 1117 scoped_ptr<FrameRateController> frame_rate_controller;
1119 if (render_vsync_enabled_) { 1118 if (throttle_frame_production_) {
1120 if (render_vsync_notification_enabled_) { 1119 if (render_parent_drives_begin_frame__) {
1121 frame_rate_controller.reset( 1120 frame_rate_controller.reset(
1122 new FrameRateController(VSyncTimeSource::Create( 1121 new FrameRateController(VSyncTimeSource::Create(
1123 this, 1122 this,
1124 synchronously_disable_vsync_ ? 1123 using_synchronous_renderer_compositor_ ?
1125 VSyncTimeSource::DISABLE_SYNCHRONOUSLY : 1124 VSyncTimeSource::DISABLE_SYNCHRONOUSLY :
1126 VSyncTimeSource::DISABLE_ON_NEXT_TICK))); 1125 VSyncTimeSource::DISABLE_ON_NEXT_TICK)));
1127 } else { 1126 } else {
1128 frame_rate_controller.reset( 1127 frame_rate_controller.reset(
1129 new FrameRateController(DelayBasedTimeSource::Create( 1128 new FrameRateController(DelayBasedTimeSource::Create(
1130 display_refresh_interval, Proxy::ImplThread()))); 1129 display_refresh_interval, Proxy::ImplThread())));
1131 } 1130 }
1132 } else { 1131 } else {
1133 frame_rate_controller.reset(new FrameRateController(Proxy::ImplThread())); 1132 frame_rate_controller.reset(new FrameRateController(Proxy::ImplThread()));
1134 } 1133 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 if (layer_tree_host_impl_->resource_provider()) 1199 if (layer_tree_host_impl_->resource_provider())
1201 layer_tree_host_impl_->resource_provider()->Finish(); 1200 layer_tree_host_impl_->resource_provider()->Finish();
1202 completion->Signal(); 1201 completion->Signal();
1203 } 1202 }
1204 1203
1205 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { 1204 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) {
1206 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); 1205 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread");
1207 DCHECK(IsImplThread()); 1206 DCHECK(IsImplThread());
1208 layer_tree_host_->DeleteContentsTexturesOnImplThread( 1207 layer_tree_host_->DeleteContentsTexturesOnImplThread(
1209 layer_tree_host_impl_->resource_provider()); 1208 layer_tree_host_impl_->resource_provider());
1210 layer_tree_host_impl_->EnableVSyncNotification(false); 1209 layer_tree_host_impl_->SetNeedsBeginFrame(false);
1211 scheduler_on_impl_thread_.reset(); 1210 scheduler_on_impl_thread_.reset();
1212 layer_tree_host_impl_.reset(); 1211 layer_tree_host_impl_.reset();
1213 weak_factory_on_impl_thread_.InvalidateWeakPtrs(); 1212 weak_factory_on_impl_thread_.InvalidateWeakPtrs();
1214 vsync_client_ = NULL; 1213 vsync_client_ = NULL;
1215 completion->Signal(); 1214 completion->Signal();
1216 } 1215 }
1217 1216
1218 size_t ThreadProxy::MaxPartialTextureUpdates() const { 1217 size_t ThreadProxy::MaxPartialTextureUpdates() const {
1219 return ResourceUpdateController::MaxPartialTextureUpdates(); 1218 return ResourceUpdateController::MaxPartialTextureUpdates();
1220 } 1219 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 base::Bind(&ThreadProxy::StartScrollbarAnimationOnImplThread, 1360 base::Bind(&ThreadProxy::StartScrollbarAnimationOnImplThread,
1362 impl_thread_weak_ptr_), 1361 impl_thread_weak_ptr_),
1363 delay); 1362 delay);
1364 } 1363 }
1365 1364
1366 void ThreadProxy::StartScrollbarAnimationOnImplThread() { 1365 void ThreadProxy::StartScrollbarAnimationOnImplThread() {
1367 layer_tree_host_impl_->StartScrollbarAnimation( 1366 layer_tree_host_impl_->StartScrollbarAnimation(
1368 layer_tree_host_impl_->CurrentFrameTimeTicks()); 1367 layer_tree_host_impl_->CurrentFrameTimeTicks());
1369 } 1368 }
1370 1369
1371 void ThreadProxy::DidReceiveLastInputEventForVSync( 1370 void ThreadProxy::DidReceiveLastInputEventForBeginFrameOnImplThread(
1372 base::TimeTicks frame_time) { 1371 base::TimeTicks frame_time) {
1373 if (render_vsync_notification_enabled_) { 1372 if (render_parent_drives_begin_frame__) {
1374 TRACE_EVENT0("cc", "ThreadProxy::DidReceiveLastInputEventForVSync"); 1373 TRACE_EVENT0("cc",
1375 DidVSync(frame_time); 1374 "ThreadProxy::DidReceiveLastInputEventForBeginFrameOnImplThread");
1375 BeginFrameOnImplThread(frame_time);
1376 } 1376 }
1377 } 1377 }
1378 1378
1379 void ThreadProxy::DidActivatePendingTree() { 1379 void ThreadProxy::DidActivatePendingTree() {
1380 DCHECK(IsImplThread()); 1380 DCHECK(IsImplThread());
1381 TRACE_EVENT0("cc", "ThreadProxy::DidActivatePendingTreeOnImplThread"); 1381 TRACE_EVENT0("cc", "ThreadProxy::DidActivatePendingTreeOnImplThread");
1382 1382
1383 if (completion_event_for_commit_held_on_tree_activation_ && 1383 if (completion_event_for_commit_held_on_tree_activation_ &&
1384 !layer_tree_host_impl_->pending_tree()) { 1384 !layer_tree_host_impl_->pending_tree()) {
1385 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", 1385 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation",
1386 TRACE_EVENT_SCOPE_THREAD); 1386 TRACE_EVENT_SCOPE_THREAD);
1387 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); 1387 DCHECK(layer_tree_host_impl_->settings().impl_side_painting);
1388 completion_event_for_commit_held_on_tree_activation_->Signal(); 1388 completion_event_for_commit_held_on_tree_activation_->Signal();
1389 completion_event_for_commit_held_on_tree_activation_ = NULL; 1389 completion_event_for_commit_held_on_tree_activation_ = NULL;
1390 } 1390 }
1391 } 1391 }
1392 1392
1393 } // namespace cc 1393 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/thread_proxy.h ('k') | chrome/test/perf/rendering/latency_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698