| OLD | NEW |
| 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/thread_proxy.h" | 5 #include "cc/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/context_provider.h" | 10 #include "cc/context_provider.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 weak_factory_on_impl_thread_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 53 weak_factory_on_impl_thread_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 54 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 54 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 55 begin_frame_completion_event_on_impl_thread_(NULL), | 55 begin_frame_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().renderVSyncEnabled), | 61 render_vsync_enabled_(layer_tree_host->settings().renderVSyncEnabled), |
| 62 inside_draw_(false), | 62 inside_draw_(false), |
| 63 total_commit_count_(0), | |
| 64 defer_commits_(false), | 63 defer_commits_(false), |
| 65 renew_tree_priority_on_impl_thread_pending_(false) { | 64 renew_tree_priority_on_impl_thread_pending_(false) { |
| 66 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); | 65 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); |
| 67 DCHECK(IsMainThread()); | 66 DCHECK(IsMainThread()); |
| 68 } | 67 } |
| 69 | 68 |
| 70 ThreadProxy::~ThreadProxy() { | 69 ThreadProxy::~ThreadProxy() { |
| 71 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); | 70 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); |
| 72 DCHECK(IsMainThread()); | 71 DCHECK(IsMainThread()); |
| 73 DCHECK(!started_); | 72 DCHECK(!started_); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 offscreen_context_provider, | 270 offscreen_context_provider, |
| 272 &recreate_succeeded, | 271 &recreate_succeeded, |
| 273 &capabilities)); | 272 &capabilities)); |
| 274 completion.wait(); | 273 completion.wait(); |
| 275 | 274 |
| 276 if (recreate_succeeded) | 275 if (recreate_succeeded) |
| 277 renderer_capabilities_main_thread_copy_ = capabilities; | 276 renderer_capabilities_main_thread_copy_ = capabilities; |
| 278 return recreate_succeeded; | 277 return recreate_succeeded; |
| 279 } | 278 } |
| 280 | 279 |
| 281 void ThreadProxy::CollectRenderingStats(RenderingStats* stats) { | |
| 282 DCHECK(IsMainThread()); | |
| 283 | |
| 284 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | |
| 285 CompletionEvent completion; | |
| 286 Proxy::ImplThread()->postTask( | |
| 287 base::Bind(&ThreadProxy::RenderingStatsOnImplThread, | |
| 288 impl_thread_weak_ptr_, | |
| 289 &completion, | |
| 290 stats)); | |
| 291 stats->totalCommitTime = total_commit_time_; | |
| 292 stats->totalCommitCount = total_commit_count_; | |
| 293 | |
| 294 completion.wait(); | |
| 295 } | |
| 296 | |
| 297 const RendererCapabilities& ThreadProxy::GetRendererCapabilities() const { | 280 const RendererCapabilities& ThreadProxy::GetRendererCapabilities() const { |
| 298 DCHECK(renderer_initialized_); | 281 DCHECK(renderer_initialized_); |
| 299 return renderer_capabilities_main_thread_copy_; | 282 return renderer_capabilities_main_thread_copy_; |
| 300 } | 283 } |
| 301 | 284 |
| 302 void ThreadProxy::SetNeedsAnimate() { | 285 void ThreadProxy::SetNeedsAnimate() { |
| 303 DCHECK(IsMainThread()); | 286 DCHECK(IsMainThread()); |
| 304 if (animate_requested_) | 287 if (animate_requested_) |
| 305 return; | 288 return; |
| 306 | 289 |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 offscreen_context_provider = NULL; | 719 offscreen_context_provider = NULL; |
| 737 } | 720 } |
| 738 | 721 |
| 739 // Notify the impl thread that the beginFrame has completed. This will | 722 // Notify the impl thread that the beginFrame has completed. This will |
| 740 // begin the commit process, which is blocking from the main thread's | 723 // begin the commit process, which is blocking from the main thread's |
| 741 // point of view, but asynchronously performed on the impl thread, | 724 // point of view, but asynchronously performed on the impl thread, |
| 742 // coordinated by the Scheduler. | 725 // coordinated by the Scheduler. |
| 743 { | 726 { |
| 744 TRACE_EVENT0("cc", "commit"); | 727 TRACE_EVENT0("cc", "commit"); |
| 745 | 728 |
| 746 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 729 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 747 | 730 |
| 748 base::TimeTicks start_time = base::TimeTicks::HighResNow(); | 731 RenderingStatsInstrumentation* stats_instrumentation = |
| 732 layer_tree_host_->rendering_stats_instrumentation(); |
| 733 base::TimeTicks start_time = stats_instrumentation->StartRecording(); |
| 734 |
| 749 CompletionEvent completion; | 735 CompletionEvent completion; |
| 750 Proxy::ImplThread()->postTask( | 736 Proxy::ImplThread()->postTask( |
| 751 base::Bind(&ThreadProxy::BeginFrameCompleteOnImplThread, | 737 base::Bind(&ThreadProxy::BeginFrameCompleteOnImplThread, |
| 752 impl_thread_weak_ptr_, | 738 impl_thread_weak_ptr_, |
| 753 &completion, | 739 &completion, |
| 754 queue.release(), | 740 queue.release(), |
| 755 offscreen_context_provider)); | 741 offscreen_context_provider)); |
| 756 completion.wait(); | 742 completion.wait(); |
| 757 | 743 |
| 758 base::TimeTicks end_time = base::TimeTicks::HighResNow(); | 744 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); |
| 759 total_commit_time_ += end_time - start_time; | 745 stats_instrumentation->AddCommit(duration); |
| 760 total_commit_count_++; | |
| 761 } | 746 } |
| 762 | 747 |
| 763 layer_tree_host_->CommitComplete(); | 748 layer_tree_host_->CommitComplete(); |
| 764 layer_tree_host_->DidBeginFrame(); | 749 layer_tree_host_->DidBeginFrame(); |
| 765 } | 750 } |
| 766 | 751 |
| 767 void ThreadProxy::BeginFrameCompleteOnImplThread( | 752 void ThreadProxy::BeginFrameCompleteOnImplThread( |
| 768 CompletionEvent* completion, | 753 CompletionEvent* completion, |
| 769 ResourceUpdateQueue* raw_queue, | 754 ResourceUpdateQueue* raw_queue, |
| 770 scoped_refptr<cc::ContextProvider> offscreen_context_provider) { | 755 scoped_refptr<cc::ContextProvider> offscreen_context_provider) { |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 *capabilities = layer_tree_host_impl_->GetRendererCapabilities(); | 1156 *capabilities = layer_tree_host_impl_->GetRendererCapabilities(); |
| 1172 layer_tree_host_impl_->resource_provider()-> | 1157 layer_tree_host_impl_->resource_provider()-> |
| 1173 SetOffscreenContextProvider(offscreen_context_provider); | 1158 SetOffscreenContextProvider(offscreen_context_provider); |
| 1174 scheduler_on_impl_thread_->didRecreateOutputSurface(); | 1159 scheduler_on_impl_thread_->didRecreateOutputSurface(); |
| 1175 } else if (offscreen_context_provider) { | 1160 } else if (offscreen_context_provider) { |
| 1176 offscreen_context_provider->VerifyContexts(); | 1161 offscreen_context_provider->VerifyContexts(); |
| 1177 } | 1162 } |
| 1178 completion->signal(); | 1163 completion->signal(); |
| 1179 } | 1164 } |
| 1180 | 1165 |
| 1181 void ThreadProxy::RenderingStatsOnImplThread(CompletionEvent* completion, | |
| 1182 RenderingStats* stats) { | |
| 1183 DCHECK(IsImplThread()); | |
| 1184 layer_tree_host_impl_->CollectRenderingStats(stats); | |
| 1185 completion->signal(); | |
| 1186 } | |
| 1187 | |
| 1188 ThreadProxy::BeginFrameAndCommitState::BeginFrameAndCommitState() | 1166 ThreadProxy::BeginFrameAndCommitState::BeginFrameAndCommitState() |
| 1189 : memory_allocation_limit_bytes(0) {} | 1167 : memory_allocation_limit_bytes(0) {} |
| 1190 | 1168 |
| 1191 ThreadProxy::BeginFrameAndCommitState::~BeginFrameAndCommitState() {} | 1169 ThreadProxy::BeginFrameAndCommitState::~BeginFrameAndCommitState() {} |
| 1192 | 1170 |
| 1193 scoped_ptr<base::Value> ThreadProxy::AsValue() const { | 1171 scoped_ptr<base::Value> ThreadProxy::AsValue() const { |
| 1194 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 1172 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 1195 | 1173 |
| 1196 CompletionEvent completion; | 1174 CompletionEvent completion; |
| 1197 { | 1175 { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1316 } | 1294 } |
| 1317 | 1295 |
| 1318 void ThreadProxy::RenewTreePriorityOnImplThread() { | 1296 void ThreadProxy::RenewTreePriorityOnImplThread() { |
| 1319 DCHECK(renew_tree_priority_on_impl_thread_pending_); | 1297 DCHECK(renew_tree_priority_on_impl_thread_pending_); |
| 1320 renew_tree_priority_on_impl_thread_pending_ = false; | 1298 renew_tree_priority_on_impl_thread_pending_ = false; |
| 1321 | 1299 |
| 1322 RenewTreePriority(); | 1300 RenewTreePriority(); |
| 1323 } | 1301 } |
| 1324 | 1302 |
| 1325 } // namespace cc | 1303 } // namespace cc |
| OLD | NEW |