| 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/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 "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "cc/base/thread.h" | |
| 12 #include "cc/input/input_handler.h" | 11 #include "cc/input/input_handler.h" |
| 13 #include "cc/output/context_provider.h" | 12 #include "cc/output/context_provider.h" |
| 14 #include "cc/output/output_surface.h" | 13 #include "cc/output/output_surface.h" |
| 15 #include "cc/quads/draw_quad.h" | 14 #include "cc/quads/draw_quad.h" |
| 16 #include "cc/resources/prioritized_resource_manager.h" | 15 #include "cc/resources/prioritized_resource_manager.h" |
| 17 #include "cc/scheduler/delay_based_time_source.h" | 16 #include "cc/scheduler/delay_based_time_source.h" |
| 18 #include "cc/scheduler/frame_rate_controller.h" | 17 #include "cc/scheduler/frame_rate_controller.h" |
| 19 #include "cc/scheduler/scheduler.h" | 18 #include "cc/scheduler/scheduler.h" |
| 20 #include "cc/scheduler/vsync_time_source.h" | 19 #include "cc/scheduler/vsync_time_source.h" |
| 21 #include "cc/trees/layer_tree_host.h" | 20 #include "cc/trees/layer_tree_host.h" |
| 22 #include "cc/trees/layer_tree_impl.h" | 21 #include "cc/trees/layer_tree_impl.h" |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 // Measured in seconds. | 25 // Measured in seconds. |
| 27 const double kContextRecreationTickRate = 0.03; | 26 const double kContextRecreationTickRate = 0.03; |
| 28 | 27 |
| 29 // Measured in seconds. | 28 // Measured in seconds. |
| 30 const double kSmoothnessTakesPriorityExpirationDelay = 0.25; | 29 const double kSmoothnessTakesPriorityExpirationDelay = 0.25; |
| 31 | 30 |
| 32 const size_t kDrawDurationHistorySize = 60; | 31 const size_t kDrawDurationHistorySize = 60; |
| 33 const double kDrawDurationEstimationPercentile = 100.0; | 32 const double kDrawDurationEstimationPercentile = 100.0; |
| 34 const int kDrawDurationEstimatePaddingInMicroseconds = 0; | 33 const int kDrawDurationEstimatePaddingInMicroseconds = 0; |
| 35 | 34 |
| 36 } // namespace | 35 } // namespace |
| 37 | 36 |
| 38 namespace cc { | 37 namespace cc { |
| 39 | 38 |
| 40 scoped_ptr<Proxy> ThreadProxy::Create(LayerTreeHost* layer_tree_host, | 39 scoped_ptr<Proxy> ThreadProxy::Create( |
| 41 scoped_ptr<Thread> impl_thread) { | 40 LayerTreeHost* layer_tree_host, |
| 41 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
| 42 return make_scoped_ptr( | 42 return make_scoped_ptr( |
| 43 new ThreadProxy(layer_tree_host, impl_thread.Pass())).PassAs<Proxy>(); | 43 new ThreadProxy(layer_tree_host, impl_task_runner)).PassAs<Proxy>(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 ThreadProxy::ThreadProxy(LayerTreeHost* layer_tree_host, | 46 ThreadProxy::ThreadProxy( |
| 47 scoped_ptr<Thread> impl_thread) | 47 LayerTreeHost* layer_tree_host, |
| 48 : Proxy(impl_thread.Pass()), | 48 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) |
| 49 : Proxy(impl_task_runner), |
| 49 animate_requested_(false), | 50 animate_requested_(false), |
| 50 commit_requested_(false), | 51 commit_requested_(false), |
| 51 commit_request_sent_to_impl_thread_(false), | 52 commit_request_sent_to_impl_thread_(false), |
| 52 created_offscreen_context_provider_(false), | 53 created_offscreen_context_provider_(false), |
| 53 layer_tree_host_(layer_tree_host), | 54 layer_tree_host_(layer_tree_host), |
| 54 started_(false), | 55 started_(false), |
| 55 textures_acquired_(true), | 56 textures_acquired_(true), |
| 56 in_composite_and_readback_(false), | 57 in_composite_and_readback_(false), |
| 57 manage_tiles_pending_(false), | 58 manage_tiles_pending_(false), |
| 58 weak_factory_on_impl_thread_(this), | 59 weak_factory_on_impl_thread_(this), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 94 |
| 94 if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded()) { | 95 if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded()) { |
| 95 TRACE_EVENT0("cc", "CompositeAndReadback_EarlyOut_LR_Uninitialized"); | 96 TRACE_EVENT0("cc", "CompositeAndReadback_EarlyOut_LR_Uninitialized"); |
| 96 return false; | 97 return false; |
| 97 } | 98 } |
| 98 | 99 |
| 99 // Perform a synchronous commit. | 100 // Perform a synchronous commit. |
| 100 { | 101 { |
| 101 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 102 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 102 CompletionEvent begin_frame_sent_to_main_thread_completion; | 103 CompletionEvent begin_frame_sent_to_main_thread_completion; |
| 103 Proxy::ImplThread()->PostTask( | 104 Proxy::ImplThreadTaskRunner()->PostTask( |
| 105 FROM_HERE, |
| 104 base::Bind(&ThreadProxy::ForceCommitOnImplThread, | 106 base::Bind(&ThreadProxy::ForceCommitOnImplThread, |
| 105 impl_thread_weak_ptr_, | 107 impl_thread_weak_ptr_, |
| 106 &begin_frame_sent_to_main_thread_completion)); | 108 &begin_frame_sent_to_main_thread_completion)); |
| 107 begin_frame_sent_to_main_thread_completion.Wait(); | 109 begin_frame_sent_to_main_thread_completion.Wait(); |
| 108 } | 110 } |
| 109 in_composite_and_readback_ = true; | 111 in_composite_and_readback_ = true; |
| 110 BeginFrameOnMainThread(scoped_ptr<BeginFrameAndCommitState>()); | 112 BeginFrameOnMainThread(scoped_ptr<BeginFrameAndCommitState>()); |
| 111 in_composite_and_readback_ = false; | 113 in_composite_and_readback_ = false; |
| 112 | 114 |
| 113 // Perform a synchronous readback. | 115 // Perform a synchronous readback. |
| 114 ReadbackRequest request; | 116 ReadbackRequest request; |
| 115 request.rect = rect; | 117 request.rect = rect; |
| 116 request.pixels = pixels; | 118 request.pixels = pixels; |
| 117 { | 119 { |
| 118 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 120 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 119 Proxy::ImplThread()->PostTask( | 121 Proxy::ImplThreadTaskRunner()->PostTask( |
| 122 FROM_HERE, |
| 120 base::Bind(&ThreadProxy::RequestReadbackOnImplThread, | 123 base::Bind(&ThreadProxy::RequestReadbackOnImplThread, |
| 121 impl_thread_weak_ptr_, | 124 impl_thread_weak_ptr_, |
| 122 &request)); | 125 &request)); |
| 123 request.completion.Wait(); | 126 request.completion.Wait(); |
| 124 } | 127 } |
| 125 return request.success; | 128 return request.success; |
| 126 } | 129 } |
| 127 | 130 |
| 128 void ThreadProxy::ForceCommitOnImplThread(CompletionEvent* completion) { | 131 void ThreadProxy::ForceCommitOnImplThread(CompletionEvent* completion) { |
| 129 TRACE_EVENT0("cc", "ThreadProxy::ForceCommitOnImplThread"); | 132 TRACE_EVENT0("cc", "ThreadProxy::ForceCommitOnImplThread"); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 153 scheduler_on_impl_thread_->SetNeedsForcedRedraw(); | 156 scheduler_on_impl_thread_->SetNeedsForcedRedraw(); |
| 154 } | 157 } |
| 155 | 158 |
| 156 void ThreadProxy::FinishAllRendering() { | 159 void ThreadProxy::FinishAllRendering() { |
| 157 DCHECK(Proxy::IsMainThread()); | 160 DCHECK(Proxy::IsMainThread()); |
| 158 DCHECK(!defer_commits_); | 161 DCHECK(!defer_commits_); |
| 159 | 162 |
| 160 // Make sure all GL drawing is finished on the impl thread. | 163 // Make sure all GL drawing is finished on the impl thread. |
| 161 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 164 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 162 CompletionEvent completion; | 165 CompletionEvent completion; |
| 163 Proxy::ImplThread()->PostTask( | 166 Proxy::ImplThreadTaskRunner()->PostTask( |
| 167 FROM_HERE, |
| 164 base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread, | 168 base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread, |
| 165 impl_thread_weak_ptr_, | 169 impl_thread_weak_ptr_, |
| 166 &completion)); | 170 &completion)); |
| 167 completion.Wait(); | 171 completion.Wait(); |
| 168 } | 172 } |
| 169 | 173 |
| 170 bool ThreadProxy::IsStarted() const { | 174 bool ThreadProxy::IsStarted() const { |
| 171 DCHECK(Proxy::IsMainThread()); | 175 DCHECK(Proxy::IsMainThread()); |
| 172 return started_; | 176 return started_; |
| 173 } | 177 } |
| 174 | 178 |
| 175 void ThreadProxy::SetLayerTreeHostClientReady() { | 179 void ThreadProxy::SetLayerTreeHostClientReady() { |
| 176 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReady"); | 180 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReady"); |
| 177 Proxy::ImplThread()->PostTask(base::Bind( | 181 Proxy::ImplThreadTaskRunner()->PostTask( |
| 178 &ThreadProxy::SetLayerTreeHostClientReadyOnImplThread, | 182 FROM_HERE, |
| 179 impl_thread_weak_ptr_)); | 183 base::Bind(&ThreadProxy::SetLayerTreeHostClientReadyOnImplThread, |
| 184 impl_thread_weak_ptr_)); |
| 180 } | 185 } |
| 181 | 186 |
| 182 void ThreadProxy::SetLayerTreeHostClientReadyOnImplThread() { | 187 void ThreadProxy::SetLayerTreeHostClientReadyOnImplThread() { |
| 183 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReadyOnImplThread"); | 188 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReadyOnImplThread"); |
| 184 scheduler_on_impl_thread_->SetCanStart(); | 189 scheduler_on_impl_thread_->SetCanStart(); |
| 185 } | 190 } |
| 186 | 191 |
| 187 void ThreadProxy::SetVisible(bool visible) { | 192 void ThreadProxy::SetVisible(bool visible) { |
| 188 TRACE_EVENT0("cc", "ThreadProxy::SetVisible"); | 193 TRACE_EVENT0("cc", "ThreadProxy::SetVisible"); |
| 189 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 194 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 190 CompletionEvent completion; | 195 CompletionEvent completion; |
| 191 Proxy::ImplThread()->PostTask(base::Bind(&ThreadProxy::SetVisibleOnImplThread, | 196 Proxy::ImplThreadTaskRunner()->PostTask( |
| 192 impl_thread_weak_ptr_, | 197 FROM_HERE, |
| 193 &completion, | 198 base::Bind(&ThreadProxy::SetVisibleOnImplThread, |
| 194 visible)); | 199 impl_thread_weak_ptr_, |
| 200 &completion, |
| 201 visible)); |
| 195 completion.Wait(); | 202 completion.Wait(); |
| 196 } | 203 } |
| 197 | 204 |
| 198 void ThreadProxy::SetVisibleOnImplThread(CompletionEvent* completion, | 205 void ThreadProxy::SetVisibleOnImplThread(CompletionEvent* completion, |
| 199 bool visible) { | 206 bool visible) { |
| 200 TRACE_EVENT0("cc", "ThreadProxy::SetVisibleOnImplThread"); | 207 TRACE_EVENT0("cc", "ThreadProxy::SetVisibleOnImplThread"); |
| 201 layer_tree_host_impl_->SetVisible(visible); | 208 layer_tree_host_impl_->SetVisible(visible); |
| 202 scheduler_on_impl_thread_->SetVisible(visible); | 209 scheduler_on_impl_thread_->SetVisible(visible); |
| 203 completion->Signal(); | 210 completion->Signal(); |
| 204 } | 211 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 230 } | 237 } |
| 231 | 238 |
| 232 success = false; | 239 success = false; |
| 233 { | 240 { |
| 234 // Make a blocking call to InitializeOutputSurfaceOnImplThread. The results | 241 // Make a blocking call to InitializeOutputSurfaceOnImplThread. The results |
| 235 // of that call are pushed into the success and capabilities local | 242 // of that call are pushed into the success and capabilities local |
| 236 // variables. | 243 // variables. |
| 237 CompletionEvent completion; | 244 CompletionEvent completion; |
| 238 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 245 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 239 | 246 |
| 240 Proxy::ImplThread()->PostTask( | 247 Proxy::ImplThreadTaskRunner()->PostTask( |
| 248 FROM_HERE, |
| 241 base::Bind(&ThreadProxy::InitializeOutputSurfaceOnImplThread, | 249 base::Bind(&ThreadProxy::InitializeOutputSurfaceOnImplThread, |
| 242 impl_thread_weak_ptr_, | 250 impl_thread_weak_ptr_, |
| 243 &completion, | 251 &completion, |
| 244 base::Passed(&output_surface), | 252 base::Passed(&output_surface), |
| 245 offscreen_context_provider, | 253 offscreen_context_provider, |
| 246 &success, | 254 &success, |
| 247 &capabilities)); | 255 &capabilities)); |
| 248 completion.Wait(); | 256 completion.Wait(); |
| 249 } | 257 } |
| 250 | 258 |
| 251 OnOutputSurfaceInitializeAttempted(success, capabilities); | 259 OnOutputSurfaceInitializeAttempted(success, capabilities); |
| 252 } | 260 } |
| 253 | 261 |
| 254 void ThreadProxy::OnOutputSurfaceInitializeAttempted( | 262 void ThreadProxy::OnOutputSurfaceInitializeAttempted( |
| 255 bool success, | 263 bool success, |
| 256 const RendererCapabilities& capabilities) { | 264 const RendererCapabilities& capabilities) { |
| 257 DCHECK(IsMainThread()); | 265 DCHECK(IsMainThread()); |
| 258 DCHECK(layer_tree_host_); | 266 DCHECK(layer_tree_host_); |
| 259 | 267 |
| 260 if (success) { | 268 if (success) { |
| 261 renderer_capabilities_main_thread_copy_ = capabilities; | 269 renderer_capabilities_main_thread_copy_ = capabilities; |
| 262 } | 270 } |
| 263 | 271 |
| 264 LayerTreeHost::CreateResult result = | 272 LayerTreeHost::CreateResult result = |
| 265 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); | 273 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); |
| 266 if (result == LayerTreeHost::CreateFailedButTryAgain) { | 274 if (result == LayerTreeHost::CreateFailedButTryAgain) { |
| 267 if (!output_surface_creation_callback_.callback().is_null()) { | 275 if (!output_surface_creation_callback_.callback().is_null()) { |
| 268 Proxy::MainThread()->PostTask( | 276 Proxy::MainThreadTaskRunner()->PostTask( |
| 269 output_surface_creation_callback_.callback()); | 277 FROM_HERE, output_surface_creation_callback_.callback()); |
| 270 } | 278 } |
| 271 } else { | 279 } else { |
| 272 output_surface_creation_callback_.Cancel(); | 280 output_surface_creation_callback_.Cancel(); |
| 273 } | 281 } |
| 274 } | 282 } |
| 275 | 283 |
| 276 const RendererCapabilities& ThreadProxy::GetRendererCapabilities() const { | 284 const RendererCapabilities& ThreadProxy::GetRendererCapabilities() const { |
| 277 DCHECK(IsMainThread()); | 285 DCHECK(IsMainThread()); |
| 278 DCHECK(!layer_tree_host_->output_surface_lost()); | 286 DCHECK(!layer_tree_host_->output_surface_lost()); |
| 279 return renderer_capabilities_main_thread_copy_; | 287 return renderer_capabilities_main_thread_copy_; |
| 280 } | 288 } |
| 281 | 289 |
| 282 void ThreadProxy::SetNeedsAnimate() { | 290 void ThreadProxy::SetNeedsAnimate() { |
| 283 DCHECK(IsMainThread()); | 291 DCHECK(IsMainThread()); |
| 284 if (animate_requested_) | 292 if (animate_requested_) |
| 285 return; | 293 return; |
| 286 | 294 |
| 287 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimate"); | 295 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimate"); |
| 288 animate_requested_ = true; | 296 animate_requested_ = true; |
| 289 | 297 |
| 290 if (commit_request_sent_to_impl_thread_) | 298 if (commit_request_sent_to_impl_thread_) |
| 291 return; | 299 return; |
| 292 commit_request_sent_to_impl_thread_ = true; | 300 commit_request_sent_to_impl_thread_ = true; |
| 293 Proxy::ImplThread()->PostTask(base::Bind( | 301 Proxy::ImplThreadTaskRunner()->PostTask( |
| 294 &ThreadProxy::SetNeedsCommitOnImplThread, impl_thread_weak_ptr_)); | 302 FROM_HERE, |
| 303 base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread, |
| 304 impl_thread_weak_ptr_)); |
| 295 } | 305 } |
| 296 | 306 |
| 297 void ThreadProxy::SetNeedsCommit() { | 307 void ThreadProxy::SetNeedsCommit() { |
| 298 DCHECK(IsMainThread()); | 308 DCHECK(IsMainThread()); |
| 299 if (commit_requested_) | 309 if (commit_requested_) |
| 300 return; | 310 return; |
| 301 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommit"); | 311 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommit"); |
| 302 commit_requested_ = true; | 312 commit_requested_ = true; |
| 303 | 313 |
| 304 if (commit_request_sent_to_impl_thread_) | 314 if (commit_request_sent_to_impl_thread_) |
| 305 return; | 315 return; |
| 306 commit_request_sent_to_impl_thread_ = true; | 316 commit_request_sent_to_impl_thread_ = true; |
| 307 Proxy::ImplThread()->PostTask(base::Bind( | 317 Proxy::ImplThreadTaskRunner()->PostTask( |
| 308 &ThreadProxy::SetNeedsCommitOnImplThread, impl_thread_weak_ptr_)); | 318 FROM_HERE, |
| 319 base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread, |
| 320 impl_thread_weak_ptr_)); |
| 309 } | 321 } |
| 310 | 322 |
| 311 void ThreadProxy::DidLoseOutputSurfaceOnImplThread() { | 323 void ThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
| 312 DCHECK(IsImplThread()); | 324 DCHECK(IsImplThread()); |
| 313 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread"); | 325 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
| 314 Proxy::ImplThread()->PostTask( | 326 Proxy::ImplThreadTaskRunner()->PostTask( |
| 327 FROM_HERE, |
| 315 base::Bind(&ThreadProxy::CheckOutputSurfaceStatusOnImplThread, | 328 base::Bind(&ThreadProxy::CheckOutputSurfaceStatusOnImplThread, |
| 316 impl_thread_weak_ptr_)); | 329 impl_thread_weak_ptr_)); |
| 317 } | 330 } |
| 318 | 331 |
| 319 void ThreadProxy::CheckOutputSurfaceStatusOnImplThread() { | 332 void ThreadProxy::CheckOutputSurfaceStatusOnImplThread() { |
| 320 DCHECK(IsImplThread()); | 333 DCHECK(IsImplThread()); |
| 321 TRACE_EVENT0("cc", "ThreadProxy::CheckOutputSurfaceStatusOnImplThread"); | 334 TRACE_EVENT0("cc", "ThreadProxy::CheckOutputSurfaceStatusOnImplThread"); |
| 322 if (!layer_tree_host_impl_->IsContextLost()) | 335 if (!layer_tree_host_impl_->IsContextLost()) |
| 323 return; | 336 return; |
| 324 cc::ContextProvider* offscreen_contexts = | 337 cc::ContextProvider* offscreen_contexts = |
| 325 layer_tree_host_impl_->resource_provider() ? | 338 layer_tree_host_impl_->resource_provider() ? |
| 326 layer_tree_host_impl_->resource_provider()-> | 339 layer_tree_host_impl_->resource_provider()-> |
| 327 offscreen_context_provider() : NULL; | 340 offscreen_context_provider() : NULL; |
| 328 | 341 |
| 329 if (offscreen_contexts) | 342 if (offscreen_contexts) |
| 330 offscreen_contexts->VerifyContexts(); | 343 offscreen_contexts->VerifyContexts(); |
| 331 scheduler_on_impl_thread_->DidLoseOutputSurface(); | 344 scheduler_on_impl_thread_->DidLoseOutputSurface(); |
| 332 } | 345 } |
| 333 | 346 |
| 334 void ThreadProxy::OnSwapBuffersCompleteOnImplThread() { | 347 void ThreadProxy::OnSwapBuffersCompleteOnImplThread() { |
| 335 DCHECK(IsImplThread()); | 348 DCHECK(IsImplThread()); |
| 336 TRACE_EVENT0("cc", "ThreadProxy::OnSwapBuffersCompleteOnImplThread"); | 349 TRACE_EVENT0("cc", "ThreadProxy::OnSwapBuffersCompleteOnImplThread"); |
| 337 scheduler_on_impl_thread_->DidSwapBuffersComplete(); | 350 scheduler_on_impl_thread_->DidSwapBuffersComplete(); |
| 338 Proxy::MainThread()->PostTask( | 351 Proxy::MainThreadTaskRunner()->PostTask( |
| 352 FROM_HERE, |
| 339 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); | 353 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); |
| 340 } | 354 } |
| 341 | 355 |
| 342 void ThreadProxy::OnVSyncParametersChanged(base::TimeTicks timebase, | 356 void ThreadProxy::OnVSyncParametersChanged(base::TimeTicks timebase, |
| 343 base::TimeDelta interval) { | 357 base::TimeDelta interval) { |
| 344 DCHECK(IsImplThread()); | 358 DCHECK(IsImplThread()); |
| 345 TRACE_EVENT2("cc", | 359 TRACE_EVENT2("cc", |
| 346 "ThreadProxy::OnVSyncParametersChanged", | 360 "ThreadProxy::OnVSyncParametersChanged", |
| 347 "timebase", | 361 "timebase", |
| 348 (timebase - base::TimeTicks()).InMilliseconds(), | 362 (timebase - base::TimeTicks()).InMilliseconds(), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread"); | 403 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread"); |
| 390 scheduler_on_impl_thread_->SetNeedsCommit(); | 404 scheduler_on_impl_thread_->SetNeedsCommit(); |
| 391 } | 405 } |
| 392 | 406 |
| 393 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( | 407 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
| 394 scoped_ptr<AnimationEventsVector> events, | 408 scoped_ptr<AnimationEventsVector> events, |
| 395 base::Time wall_clock_time) { | 409 base::Time wall_clock_time) { |
| 396 DCHECK(IsImplThread()); | 410 DCHECK(IsImplThread()); |
| 397 TRACE_EVENT0("cc", | 411 TRACE_EVENT0("cc", |
| 398 "ThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); | 412 "ThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); |
| 399 Proxy::MainThread()->PostTask(base::Bind(&ThreadProxy::SetAnimationEvents, | 413 Proxy::MainThreadTaskRunner()->PostTask( |
| 400 main_thread_weak_ptr_, | 414 FROM_HERE, |
| 401 base::Passed(&events), | 415 base::Bind(&ThreadProxy::SetAnimationEvents, |
| 402 wall_clock_time)); | 416 main_thread_weak_ptr_, |
| 417 base::Passed(&events), |
| 418 wall_clock_time)); |
| 403 } | 419 } |
| 404 | 420 |
| 405 bool ThreadProxy::ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, | 421 bool ThreadProxy::ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, |
| 406 int priority_cutoff) { | 422 int priority_cutoff) { |
| 407 DCHECK(IsImplThread()); | 423 DCHECK(IsImplThread()); |
| 408 | 424 |
| 409 if (!layer_tree_host_->contents_texture_manager()) | 425 if (!layer_tree_host_->contents_texture_manager()) |
| 410 return false; | 426 return false; |
| 411 if (!layer_tree_host_impl_->resource_provider()) | 427 if (!layer_tree_host_impl_->resource_provider()) |
| 412 return false; | 428 return false; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 layer_tree_host_->contents_texture_manager()-> | 473 layer_tree_host_->contents_texture_manager()-> |
| 458 MemoryVisibleAndNearbyBytes(), | 474 MemoryVisibleAndNearbyBytes(), |
| 459 layer_tree_host_->contents_texture_manager()->MemoryUseBytes()); | 475 layer_tree_host_->contents_texture_manager()->MemoryUseBytes()); |
| 460 } | 476 } |
| 461 | 477 |
| 462 bool ThreadProxy::IsInsideDraw() { return inside_draw_; } | 478 bool ThreadProxy::IsInsideDraw() { return inside_draw_; } |
| 463 | 479 |
| 464 void ThreadProxy::SetNeedsRedraw(gfx::Rect damage_rect) { | 480 void ThreadProxy::SetNeedsRedraw(gfx::Rect damage_rect) { |
| 465 DCHECK(IsMainThread()); | 481 DCHECK(IsMainThread()); |
| 466 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedraw"); | 482 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedraw"); |
| 467 Proxy::ImplThread()->PostTask(base::Bind( | 483 Proxy::ImplThreadTaskRunner()->PostTask( |
| 468 &ThreadProxy::SetNeedsRedrawRectOnImplThread, | 484 FROM_HERE, |
| 469 impl_thread_weak_ptr_, damage_rect)); | 485 base::Bind(&ThreadProxy::SetNeedsRedrawRectOnImplThread, |
| 486 impl_thread_weak_ptr_, |
| 487 damage_rect)); |
| 470 } | 488 } |
| 471 | 489 |
| 472 void ThreadProxy::SetDeferCommits(bool defer_commits) { | 490 void ThreadProxy::SetDeferCommits(bool defer_commits) { |
| 473 DCHECK(IsMainThread()); | 491 DCHECK(IsMainThread()); |
| 474 DCHECK_NE(defer_commits_, defer_commits); | 492 DCHECK_NE(defer_commits_, defer_commits); |
| 475 defer_commits_ = defer_commits; | 493 defer_commits_ = defer_commits; |
| 476 | 494 |
| 477 if (defer_commits_) | 495 if (defer_commits_) |
| 478 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this); | 496 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this); |
| 479 else | 497 else |
| 480 TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::SetDeferCommits", this); | 498 TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::SetDeferCommits", this); |
| 481 | 499 |
| 482 if (!defer_commits_ && pending_deferred_commit_) | 500 if (!defer_commits_ && pending_deferred_commit_) |
| 483 Proxy::MainThread()->PostTask( | 501 Proxy::MainThreadTaskRunner()->PostTask( |
| 502 FROM_HERE, |
| 484 base::Bind(&ThreadProxy::BeginFrameOnMainThread, | 503 base::Bind(&ThreadProxy::BeginFrameOnMainThread, |
| 485 main_thread_weak_ptr_, | 504 main_thread_weak_ptr_, |
| 486 base::Passed(&pending_deferred_commit_))); | 505 base::Passed(&pending_deferred_commit_))); |
| 487 } | 506 } |
| 488 | 507 |
| 489 bool ThreadProxy::CommitRequested() const { | 508 bool ThreadProxy::CommitRequested() const { |
| 490 DCHECK(IsMainThread()); | 509 DCHECK(IsMainThread()); |
| 491 return commit_requested_; | 510 return commit_requested_; |
| 492 } | 511 } |
| 493 | 512 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 510 } | 529 } |
| 511 | 530 |
| 512 void ThreadProxy::DidInitializeVisibleTileOnImplThread() { | 531 void ThreadProxy::DidInitializeVisibleTileOnImplThread() { |
| 513 DCHECK(IsImplThread()); | 532 DCHECK(IsImplThread()); |
| 514 TRACE_EVENT0("cc", "ThreadProxy::DidInitializeVisibleTileOnImplThread"); | 533 TRACE_EVENT0("cc", "ThreadProxy::DidInitializeVisibleTileOnImplThread"); |
| 515 scheduler_on_impl_thread_->SetNeedsRedraw(); | 534 scheduler_on_impl_thread_->SetNeedsRedraw(); |
| 516 } | 535 } |
| 517 | 536 |
| 518 void ThreadProxy::MainThreadHasStoppedFlinging() { | 537 void ThreadProxy::MainThreadHasStoppedFlinging() { |
| 519 DCHECK(IsMainThread()); | 538 DCHECK(IsMainThread()); |
| 520 Proxy::ImplThread()->PostTask( | 539 Proxy::ImplThreadTaskRunner()->PostTask( |
| 540 FROM_HERE, |
| 521 base::Bind(&ThreadProxy::MainThreadHasStoppedFlingingOnImplThread, | 541 base::Bind(&ThreadProxy::MainThreadHasStoppedFlingingOnImplThread, |
| 522 impl_thread_weak_ptr_)); | 542 impl_thread_weak_ptr_)); |
| 523 } | 543 } |
| 524 | 544 |
| 525 void ThreadProxy::MainThreadHasStoppedFlingingOnImplThread() { | 545 void ThreadProxy::MainThreadHasStoppedFlingingOnImplThread() { |
| 526 DCHECK(IsImplThread()); | 546 DCHECK(IsImplThread()); |
| 527 layer_tree_host_impl_->MainThreadHasStoppedFlinging(); | 547 layer_tree_host_impl_->MainThreadHasStoppedFlinging(); |
| 528 } | 548 } |
| 529 | 549 |
| 530 void ThreadProxy::Start(scoped_ptr<OutputSurface> first_output_surface) { | 550 void ThreadProxy::Start(scoped_ptr<OutputSurface> first_output_surface) { |
| 531 DCHECK(IsMainThread()); | 551 DCHECK(IsMainThread()); |
| 532 DCHECK(Proxy::ImplThread()); | 552 DCHECK(Proxy::HasImplThread()); |
| 533 DCHECK(first_output_surface); | 553 DCHECK(first_output_surface); |
| 534 // Create LayerTreeHostImpl. | 554 // Create LayerTreeHostImpl. |
| 535 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 555 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 536 CompletionEvent completion; | 556 CompletionEvent completion; |
| 537 Proxy::ImplThread()->PostTask( | 557 Proxy::ImplThreadTaskRunner()->PostTask( |
| 558 FROM_HERE, |
| 538 base::Bind(&ThreadProxy::InitializeImplOnImplThread, | 559 base::Bind(&ThreadProxy::InitializeImplOnImplThread, |
| 539 base::Unretained(this), | 560 base::Unretained(this), |
| 540 &completion)); | 561 &completion)); |
| 541 completion.Wait(); | 562 completion.Wait(); |
| 542 | 563 |
| 543 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); | 564 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 544 first_output_surface_ = first_output_surface.Pass(); | 565 first_output_surface_ = first_output_surface.Pass(); |
| 545 | 566 |
| 546 started_ = true; | 567 started_ = true; |
| 547 } | 568 } |
| 548 | 569 |
| 549 void ThreadProxy::Stop() { | 570 void ThreadProxy::Stop() { |
| 550 TRACE_EVENT0("cc", "ThreadProxy::Stop"); | 571 TRACE_EVENT0("cc", "ThreadProxy::Stop"); |
| 551 DCHECK(IsMainThread()); | 572 DCHECK(IsMainThread()); |
| 552 DCHECK(started_); | 573 DCHECK(started_); |
| 553 | 574 |
| 554 // Synchronously finishes pending GL operations and deletes the impl. | 575 // Synchronously finishes pending GL operations and deletes the impl. |
| 555 // The two steps are done as separate post tasks, so that tasks posted | 576 // The two steps are done as separate post tasks, so that tasks posted |
| 556 // by the GL implementation due to the Finish can be executed by the | 577 // by the GL implementation due to the Finish can be executed by the |
| 557 // renderer before shutting it down. | 578 // renderer before shutting it down. |
| 558 { | 579 { |
| 559 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 580 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 560 | 581 |
| 561 CompletionEvent completion; | 582 CompletionEvent completion; |
| 562 Proxy::ImplThread()->PostTask( | 583 Proxy::ImplThreadTaskRunner()->PostTask( |
| 584 FROM_HERE, |
| 563 base::Bind(&ThreadProxy::FinishGLOnImplThread, | 585 base::Bind(&ThreadProxy::FinishGLOnImplThread, |
| 564 impl_thread_weak_ptr_, | 586 impl_thread_weak_ptr_, |
| 565 &completion)); | 587 &completion)); |
| 566 completion.Wait(); | 588 completion.Wait(); |
| 567 } | 589 } |
| 568 { | 590 { |
| 569 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 591 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 570 | 592 |
| 571 CompletionEvent completion; | 593 CompletionEvent completion; |
| 572 Proxy::ImplThread()->PostTask( | 594 Proxy::ImplThreadTaskRunner()->PostTask( |
| 595 FROM_HERE, |
| 573 base::Bind(&ThreadProxy::LayerTreeHostClosedOnImplThread, | 596 base::Bind(&ThreadProxy::LayerTreeHostClosedOnImplThread, |
| 574 impl_thread_weak_ptr_, | 597 impl_thread_weak_ptr_, |
| 575 &completion)); | 598 &completion)); |
| 576 completion.Wait(); | 599 completion.Wait(); |
| 577 } | 600 } |
| 578 | 601 |
| 579 weak_factory_.InvalidateWeakPtrs(); | 602 weak_factory_.InvalidateWeakPtrs(); |
| 580 | 603 |
| 581 DCHECK(!layer_tree_host_impl_.get()); // verify that the impl deleted. | 604 DCHECK(!layer_tree_host_impl_.get()); // verify that the impl deleted. |
| 582 layer_tree_host_ = NULL; | 605 layer_tree_host_ = NULL; |
| 583 started_ = false; | 606 started_ = false; |
| 584 } | 607 } |
| 585 | 608 |
| 586 void ThreadProxy::ForceSerializeOnSwapBuffers() { | 609 void ThreadProxy::ForceSerializeOnSwapBuffers() { |
| 587 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 610 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 588 CompletionEvent completion; | 611 CompletionEvent completion; |
| 589 Proxy::ImplThread()->PostTask( | 612 Proxy::ImplThreadTaskRunner()->PostTask( |
| 613 FROM_HERE, |
| 590 base::Bind(&ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread, | 614 base::Bind(&ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread, |
| 591 impl_thread_weak_ptr_, | 615 impl_thread_weak_ptr_, |
| 592 &completion)); | 616 &completion)); |
| 593 completion.Wait(); | 617 completion.Wait(); |
| 594 } | 618 } |
| 595 | 619 |
| 596 void ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread( | 620 void ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread( |
| 597 CompletionEvent* completion) { | 621 CompletionEvent* completion) { |
| 598 if (layer_tree_host_impl_->renderer()) | 622 if (layer_tree_host_impl_->renderer()) |
| 599 layer_tree_host_impl_->renderer()->DoNoOp(); | 623 layer_tree_host_impl_->renderer()->DoNoOp(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 611 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionSendBeginFrameToMainThread"); | 635 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionSendBeginFrameToMainThread"); |
| 612 scoped_ptr<BeginFrameAndCommitState> begin_frame_state( | 636 scoped_ptr<BeginFrameAndCommitState> begin_frame_state( |
| 613 new BeginFrameAndCommitState); | 637 new BeginFrameAndCommitState); |
| 614 begin_frame_state->monotonic_frame_begin_time = | 638 begin_frame_state->monotonic_frame_begin_time = |
| 615 layer_tree_host_impl_->CurrentPhysicalTimeTicks(); | 639 layer_tree_host_impl_->CurrentPhysicalTimeTicks(); |
| 616 begin_frame_state->scroll_info = | 640 begin_frame_state->scroll_info = |
| 617 layer_tree_host_impl_->ProcessScrollDeltas(); | 641 layer_tree_host_impl_->ProcessScrollDeltas(); |
| 618 DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u); | 642 DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u); |
| 619 begin_frame_state->memory_allocation_limit_bytes = | 643 begin_frame_state->memory_allocation_limit_bytes = |
| 620 layer_tree_host_impl_->memory_allocation_limit_bytes(); | 644 layer_tree_host_impl_->memory_allocation_limit_bytes(); |
| 621 Proxy::MainThread()->PostTask( | 645 Proxy::MainThreadTaskRunner()->PostTask( |
| 646 FROM_HERE, |
| 622 base::Bind(&ThreadProxy::BeginFrameOnMainThread, | 647 base::Bind(&ThreadProxy::BeginFrameOnMainThread, |
| 623 main_thread_weak_ptr_, | 648 main_thread_weak_ptr_, |
| 624 base::Passed(&begin_frame_state))); | 649 base::Passed(&begin_frame_state))); |
| 625 | 650 |
| 626 if (begin_frame_sent_to_main_thread_completion_event_on_impl_thread_) { | 651 if (begin_frame_sent_to_main_thread_completion_event_on_impl_thread_) { |
| 627 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_->Signal(); | 652 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_->Signal(); |
| 628 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_ = NULL; | 653 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_ = NULL; |
| 629 } | 654 } |
| 630 } | 655 } |
| 631 | 656 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 657 animate_requested_ = false; | 682 animate_requested_ = false; |
| 658 | 683 |
| 659 if (begin_frame_state) | 684 if (begin_frame_state) |
| 660 layer_tree_host_->ApplyScrollAndScale(*begin_frame_state->scroll_info); | 685 layer_tree_host_->ApplyScrollAndScale(*begin_frame_state->scroll_info); |
| 661 | 686 |
| 662 if (!in_composite_and_readback_ && !layer_tree_host_->visible()) { | 687 if (!in_composite_and_readback_ && !layer_tree_host_->visible()) { |
| 663 commit_requested_ = false; | 688 commit_requested_ = false; |
| 664 commit_request_sent_to_impl_thread_ = false; | 689 commit_request_sent_to_impl_thread_ = false; |
| 665 | 690 |
| 666 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); | 691 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); |
| 667 Proxy::ImplThread()->PostTask(base::Bind( | 692 Proxy::ImplThreadTaskRunner()->PostTask( |
| 668 &ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread, | 693 FROM_HERE, |
| 669 impl_thread_weak_ptr_)); | 694 base::Bind(&ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread, |
| 695 impl_thread_weak_ptr_)); |
| 670 return; | 696 return; |
| 671 } | 697 } |
| 672 | 698 |
| 673 layer_tree_host_->WillBeginFrame(); | 699 layer_tree_host_->WillBeginFrame(); |
| 674 | 700 |
| 675 if (begin_frame_state) { | 701 if (begin_frame_state) { |
| 676 layer_tree_host_->UpdateClientAnimations( | 702 layer_tree_host_->UpdateClientAnimations( |
| 677 begin_frame_state->monotonic_frame_begin_time); | 703 begin_frame_state->monotonic_frame_begin_time); |
| 678 layer_tree_host_->AnimateLayers( | 704 layer_tree_host_->AnimateLayers( |
| 679 begin_frame_state->monotonic_frame_begin_time); | 705 begin_frame_state->monotonic_frame_begin_time); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 { | 759 { |
| 734 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnMainThread::commit"); | 760 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnMainThread::commit"); |
| 735 | 761 |
| 736 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 762 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 737 | 763 |
| 738 RenderingStatsInstrumentation* stats_instrumentation = | 764 RenderingStatsInstrumentation* stats_instrumentation = |
| 739 layer_tree_host_->rendering_stats_instrumentation(); | 765 layer_tree_host_->rendering_stats_instrumentation(); |
| 740 base::TimeTicks start_time = stats_instrumentation->StartRecording(); | 766 base::TimeTicks start_time = stats_instrumentation->StartRecording(); |
| 741 | 767 |
| 742 CompletionEvent completion; | 768 CompletionEvent completion; |
| 743 Proxy::ImplThread()->PostTask( | 769 Proxy::ImplThreadTaskRunner()->PostTask( |
| 770 FROM_HERE, |
| 744 base::Bind(&ThreadProxy::StartCommitOnImplThread, | 771 base::Bind(&ThreadProxy::StartCommitOnImplThread, |
| 745 impl_thread_weak_ptr_, | 772 impl_thread_weak_ptr_, |
| 746 &completion, | 773 &completion, |
| 747 queue.release(), | 774 queue.release(), |
| 748 offscreen_context_provider)); | 775 offscreen_context_provider)); |
| 749 completion.Wait(); | 776 completion.Wait(); |
| 750 | 777 |
| 751 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); | 778 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); |
| 752 stats_instrumentation->AddCommit(duration); | 779 stats_instrumentation->AddCommit(duration); |
| 753 } | 780 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 | 821 |
| 795 layer_tree_host_->contents_texture_manager()-> | 822 layer_tree_host_->contents_texture_manager()-> |
| 796 PushTexturePrioritiesToBackings(); | 823 PushTexturePrioritiesToBackings(); |
| 797 } | 824 } |
| 798 | 825 |
| 799 commit_completion_event_on_impl_thread_ = completion; | 826 commit_completion_event_on_impl_thread_ = completion; |
| 800 if (layer_tree_host_impl_->resource_provider()) { | 827 if (layer_tree_host_impl_->resource_provider()) { |
| 801 current_resource_update_controller_on_impl_thread_ = | 828 current_resource_update_controller_on_impl_thread_ = |
| 802 ResourceUpdateController::Create( | 829 ResourceUpdateController::Create( |
| 803 this, | 830 this, |
| 804 Proxy::ImplThread()->TaskRunner(), | 831 Proxy::ImplThreadTaskRunner(), |
| 805 queue.Pass(), | 832 queue.Pass(), |
| 806 layer_tree_host_impl_->resource_provider()); | 833 layer_tree_host_impl_->resource_provider()); |
| 807 current_resource_update_controller_on_impl_thread_->PerformMoreUpdates( | 834 current_resource_update_controller_on_impl_thread_->PerformMoreUpdates( |
| 808 scheduler_on_impl_thread_->AnticipatedDrawTime()); | 835 scheduler_on_impl_thread_->AnticipatedDrawTime()); |
| 809 } else { | 836 } else { |
| 810 // Normally the ResourceUpdateController notifies when commit should | 837 // Normally the ResourceUpdateController notifies when commit should |
| 811 // finish, but in tile-free software rendering there is no resource | 838 // finish, but in tile-free software rendering there is no resource |
| 812 // update step so jump straight to the notification. | 839 // update step so jump straight to the notification. |
| 813 scheduler_on_impl_thread_->FinishCommit(); | 840 scheduler_on_impl_thread_->FinishCommit(); |
| 814 } | 841 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 } | 897 } |
| 871 | 898 |
| 872 void ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded() { | 899 void ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded() { |
| 873 DCHECK(IsImplThread()); | 900 DCHECK(IsImplThread()); |
| 874 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded"); | 901 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded"); |
| 875 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); | 902 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); |
| 876 } | 903 } |
| 877 | 904 |
| 878 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { | 905 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { |
| 879 DCHECK(IsImplThread()); | 906 DCHECK(IsImplThread()); |
| 880 Proxy::MainThread()->PostTask( | 907 Proxy::MainThreadTaskRunner()->PostTask( |
| 908 FROM_HERE, |
| 881 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, | 909 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, |
| 882 main_thread_weak_ptr_)); | 910 main_thread_weak_ptr_)); |
| 883 } | 911 } |
| 884 | 912 |
| 885 ScheduledActionDrawAndSwapResult | 913 ScheduledActionDrawAndSwapResult |
| 886 ThreadProxy::ScheduledActionDrawAndSwapInternal(bool forced_draw) { | 914 ThreadProxy::ScheduledActionDrawAndSwapInternal(bool forced_draw) { |
| 887 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); | 915 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); |
| 888 | 916 |
| 889 ScheduledActionDrawAndSwapResult result; | 917 ScheduledActionDrawAndSwapResult result; |
| 890 result.did_draw = false; | 918 result.did_draw = false; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 } else if (draw_frame) { | 1001 } else if (draw_frame) { |
| 974 result.did_swap = layer_tree_host_impl_->SwapBuffers(frame); | 1002 result.did_swap = layer_tree_host_impl_->SwapBuffers(frame); |
| 975 | 1003 |
| 976 if (frame.contains_incomplete_tile) | 1004 if (frame.contains_incomplete_tile) |
| 977 DidSwapUseIncompleteTileOnImplThread(); | 1005 DidSwapUseIncompleteTileOnImplThread(); |
| 978 } | 1006 } |
| 979 | 1007 |
| 980 // Tell the main thread that the the newly-commited frame was drawn. | 1008 // Tell the main thread that the the newly-commited frame was drawn. |
| 981 if (next_frame_is_newly_committed_frame_on_impl_thread_) { | 1009 if (next_frame_is_newly_committed_frame_on_impl_thread_) { |
| 982 next_frame_is_newly_committed_frame_on_impl_thread_ = false; | 1010 next_frame_is_newly_committed_frame_on_impl_thread_ = false; |
| 983 Proxy::MainThread()->PostTask( | 1011 Proxy::MainThreadTaskRunner()->PostTask( |
| 1012 FROM_HERE, |
| 984 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); | 1013 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); |
| 985 } | 1014 } |
| 986 | 1015 |
| 987 if (draw_frame) { | 1016 if (draw_frame) { |
| 988 CheckOutputSurfaceStatusOnImplThread(); | 1017 CheckOutputSurfaceStatusOnImplThread(); |
| 989 | 1018 |
| 990 base::TimeDelta draw_duration = base::TimeTicks::HighResNow() - start_time; | 1019 base::TimeDelta draw_duration = base::TimeTicks::HighResNow() - start_time; |
| 991 draw_duration_history_.InsertSample(draw_duration); | 1020 draw_duration_history_.InsertSample(draw_duration); |
| 992 base::TimeDelta draw_duration_overestimate; | 1021 base::TimeDelta draw_duration_overestimate; |
| 993 base::TimeDelta draw_duration_underestimate; | 1022 base::TimeDelta draw_duration_underestimate; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 // previously committed frame that is still undrawn. This is necessary to | 1057 // previously committed frame that is still undrawn. This is necessary to |
| 1029 // ensure that the main thread does not monopolize access to the textures. | 1058 // ensure that the main thread does not monopolize access to the textures. |
| 1030 DCHECK(IsMainThread()); | 1059 DCHECK(IsMainThread()); |
| 1031 | 1060 |
| 1032 if (textures_acquired_) | 1061 if (textures_acquired_) |
| 1033 return; | 1062 return; |
| 1034 | 1063 |
| 1035 TRACE_EVENT0("cc", "ThreadProxy::AcquireLayerTextures"); | 1064 TRACE_EVENT0("cc", "ThreadProxy::AcquireLayerTextures"); |
| 1036 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 1065 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 1037 CompletionEvent completion; | 1066 CompletionEvent completion; |
| 1038 Proxy::ImplThread()->PostTask( | 1067 Proxy::ImplThreadTaskRunner()->PostTask( |
| 1068 FROM_HERE, |
| 1039 base::Bind(&ThreadProxy::AcquireLayerTexturesForMainThreadOnImplThread, | 1069 base::Bind(&ThreadProxy::AcquireLayerTexturesForMainThreadOnImplThread, |
| 1040 impl_thread_weak_ptr_, | 1070 impl_thread_weak_ptr_, |
| 1041 &completion)); | 1071 &completion)); |
| 1042 // Block until it is safe to write to layer textures from the main thread. | 1072 // Block until it is safe to write to layer textures from the main thread. |
| 1043 completion.Wait(); | 1073 completion.Wait(); |
| 1044 | 1074 |
| 1045 textures_acquired_ = true; | 1075 textures_acquired_ = true; |
| 1046 } | 1076 } |
| 1047 | 1077 |
| 1048 void ThreadProxy::AcquireLayerTexturesForMainThreadOnImplThread( | 1078 void ThreadProxy::AcquireLayerTexturesForMainThreadOnImplThread( |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 | 1145 |
| 1116 void ThreadProxy::CreateAndInitializeOutputSurface() { | 1146 void ThreadProxy::CreateAndInitializeOutputSurface() { |
| 1117 TRACE_EVENT0("cc", "ThreadProxy::CreateAndInitializeOutputSurface"); | 1147 TRACE_EVENT0("cc", "ThreadProxy::CreateAndInitializeOutputSurface"); |
| 1118 DCHECK(IsMainThread()); | 1148 DCHECK(IsMainThread()); |
| 1119 | 1149 |
| 1120 // Check that output surface has not been recreated by CompositeAndReadback | 1150 // Check that output surface has not been recreated by CompositeAndReadback |
| 1121 // after this task is posted but before it is run. | 1151 // after this task is posted but before it is run. |
| 1122 bool has_initialized_output_surface_on_impl_thread = true; | 1152 bool has_initialized_output_surface_on_impl_thread = true; |
| 1123 { | 1153 { |
| 1124 CompletionEvent completion; | 1154 CompletionEvent completion; |
| 1125 Proxy::ImplThread()->PostTask( | 1155 Proxy::ImplThreadTaskRunner()->PostTask( |
| 1156 FROM_HERE, |
| 1126 base::Bind(&ThreadProxy::HasInitializedOutputSurfaceOnImplThread, | 1157 base::Bind(&ThreadProxy::HasInitializedOutputSurfaceOnImplThread, |
| 1127 impl_thread_weak_ptr_, | 1158 impl_thread_weak_ptr_, |
| 1128 &completion, | 1159 &completion, |
| 1129 &has_initialized_output_surface_on_impl_thread)); | 1160 &has_initialized_output_surface_on_impl_thread)); |
| 1130 completion.Wait(); | 1161 completion.Wait(); |
| 1131 } | 1162 } |
| 1132 if (has_initialized_output_surface_on_impl_thread) | 1163 if (has_initialized_output_surface_on_impl_thread) |
| 1133 return; | 1164 return; |
| 1134 | 1165 |
| 1135 layer_tree_host_->DidLoseOutputSurface(); | 1166 layer_tree_host_->DidLoseOutputSurface(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1161 if (begin_frame_scheduling_enabled_) { | 1192 if (begin_frame_scheduling_enabled_) { |
| 1162 frame_rate_controller.reset( | 1193 frame_rate_controller.reset( |
| 1163 new FrameRateController(VSyncTimeSource::Create( | 1194 new FrameRateController(VSyncTimeSource::Create( |
| 1164 this, | 1195 this, |
| 1165 using_synchronous_renderer_compositor_ ? | 1196 using_synchronous_renderer_compositor_ ? |
| 1166 VSyncTimeSource::DISABLE_SYNCHRONOUSLY : | 1197 VSyncTimeSource::DISABLE_SYNCHRONOUSLY : |
| 1167 VSyncTimeSource::DISABLE_ON_NEXT_TICK))); | 1198 VSyncTimeSource::DISABLE_ON_NEXT_TICK))); |
| 1168 } else { | 1199 } else { |
| 1169 frame_rate_controller.reset( | 1200 frame_rate_controller.reset( |
| 1170 new FrameRateController(DelayBasedTimeSource::Create( | 1201 new FrameRateController(DelayBasedTimeSource::Create( |
| 1171 display_refresh_interval, Proxy::ImplThread()->TaskRunner()))); | 1202 display_refresh_interval, Proxy::ImplThreadTaskRunner()))); |
| 1172 } | 1203 } |
| 1173 } else { | 1204 } else { |
| 1174 frame_rate_controller.reset( | 1205 frame_rate_controller.reset( |
| 1175 new FrameRateController(Proxy::ImplThread()->TaskRunner())); | 1206 new FrameRateController(Proxy::ImplThreadTaskRunner())); |
| 1176 } | 1207 } |
| 1177 const LayerTreeSettings& settings = layer_tree_host_->settings(); | 1208 const LayerTreeSettings& settings = layer_tree_host_->settings(); |
| 1178 SchedulerSettings scheduler_settings; | 1209 SchedulerSettings scheduler_settings; |
| 1179 scheduler_settings.impl_side_painting = settings.impl_side_painting; | 1210 scheduler_settings.impl_side_painting = settings.impl_side_painting; |
| 1180 scheduler_settings.timeout_and_draw_when_animation_checkerboards = | 1211 scheduler_settings.timeout_and_draw_when_animation_checkerboards = |
| 1181 settings.timeout_and_draw_when_animation_checkerboards; | 1212 settings.timeout_and_draw_when_animation_checkerboards; |
| 1182 scheduler_on_impl_thread_ = Scheduler::Create(this, | 1213 scheduler_on_impl_thread_ = Scheduler::Create(this, |
| 1183 frame_rate_controller.Pass(), | 1214 frame_rate_controller.Pass(), |
| 1184 scheduler_settings); | 1215 scheduler_settings); |
| 1185 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | 1216 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 | 1305 |
| 1275 ThreadProxy::BeginFrameAndCommitState::~BeginFrameAndCommitState() {} | 1306 ThreadProxy::BeginFrameAndCommitState::~BeginFrameAndCommitState() {} |
| 1276 | 1307 |
| 1277 scoped_ptr<base::Value> ThreadProxy::AsValue() const { | 1308 scoped_ptr<base::Value> ThreadProxy::AsValue() const { |
| 1278 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 1309 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 1279 | 1310 |
| 1280 CompletionEvent completion; | 1311 CompletionEvent completion; |
| 1281 { | 1312 { |
| 1282 DebugScopedSetMainThreadBlocked main_thread_blocked( | 1313 DebugScopedSetMainThreadBlocked main_thread_blocked( |
| 1283 const_cast<ThreadProxy*>(this)); | 1314 const_cast<ThreadProxy*>(this)); |
| 1284 Proxy::ImplThread()->PostTask(base::Bind(&ThreadProxy::AsValueOnImplThread, | 1315 Proxy::ImplThreadTaskRunner()->PostTask( |
| 1285 impl_thread_weak_ptr_, | 1316 FROM_HERE, |
| 1286 &completion, | 1317 base::Bind(&ThreadProxy::AsValueOnImplThread, |
| 1287 state.get())); | 1318 impl_thread_weak_ptr_, |
| 1319 &completion, |
| 1320 state.get())); |
| 1288 completion.Wait(); | 1321 completion.Wait(); |
| 1289 } | 1322 } |
| 1290 return state.PassAs<base::Value>(); | 1323 return state.PassAs<base::Value>(); |
| 1291 } | 1324 } |
| 1292 | 1325 |
| 1293 void ThreadProxy::AsValueOnImplThread(CompletionEvent* completion, | 1326 void ThreadProxy::AsValueOnImplThread(CompletionEvent* completion, |
| 1294 base::DictionaryValue* state) const { | 1327 base::DictionaryValue* state) const { |
| 1295 state->Set("layer_tree_host_impl", | 1328 state->Set("layer_tree_host_impl", |
| 1296 layer_tree_host_impl_->AsValue().release()); | 1329 layer_tree_host_impl_->AsValue().release()); |
| 1297 completion->Signal(); | 1330 completion->Signal(); |
| 1298 } | 1331 } |
| 1299 | 1332 |
| 1300 bool ThreadProxy::CommitPendingForTesting() { | 1333 bool ThreadProxy::CommitPendingForTesting() { |
| 1301 DCHECK(IsMainThread()); | 1334 DCHECK(IsMainThread()); |
| 1302 CommitPendingRequest commit_pending_request; | 1335 CommitPendingRequest commit_pending_request; |
| 1303 { | 1336 { |
| 1304 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 1337 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 1305 Proxy::ImplThread()->PostTask( | 1338 Proxy::ImplThreadTaskRunner()->PostTask( |
| 1339 FROM_HERE, |
| 1306 base::Bind(&ThreadProxy::CommitPendingOnImplThreadForTesting, | 1340 base::Bind(&ThreadProxy::CommitPendingOnImplThreadForTesting, |
| 1307 impl_thread_weak_ptr_, | 1341 impl_thread_weak_ptr_, |
| 1308 &commit_pending_request)); | 1342 &commit_pending_request)); |
| 1309 commit_pending_request.completion.Wait(); | 1343 commit_pending_request.completion.Wait(); |
| 1310 } | 1344 } |
| 1311 return commit_pending_request.commit_pending; | 1345 return commit_pending_request.commit_pending; |
| 1312 } | 1346 } |
| 1313 | 1347 |
| 1314 void ThreadProxy::CommitPendingOnImplThreadForTesting( | 1348 void ThreadProxy::CommitPendingOnImplThreadForTesting( |
| 1315 CommitPendingRequest* request) { | 1349 CommitPendingRequest* request) { |
| 1316 DCHECK(IsImplThread()); | 1350 DCHECK(IsImplThread()); |
| 1317 if (layer_tree_host_impl_->output_surface()) | 1351 if (layer_tree_host_impl_->output_surface()) |
| 1318 request->commit_pending = scheduler_on_impl_thread_->CommitPending(); | 1352 request->commit_pending = scheduler_on_impl_thread_->CommitPending(); |
| 1319 else | 1353 else |
| 1320 request->commit_pending = false; | 1354 request->commit_pending = false; |
| 1321 request->completion.Signal(); | 1355 request->completion.Signal(); |
| 1322 } | 1356 } |
| 1323 | 1357 |
| 1324 skia::RefPtr<SkPicture> ThreadProxy::CapturePicture() { | 1358 skia::RefPtr<SkPicture> ThreadProxy::CapturePicture() { |
| 1325 DCHECK(IsMainThread()); | 1359 DCHECK(IsMainThread()); |
| 1326 CompletionEvent completion; | 1360 CompletionEvent completion; |
| 1327 skia::RefPtr<SkPicture> picture; | 1361 skia::RefPtr<SkPicture> picture; |
| 1328 { | 1362 { |
| 1329 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 1363 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 1330 Proxy::ImplThread()->PostTask( | 1364 Proxy::ImplThreadTaskRunner()->PostTask( |
| 1365 FROM_HERE, |
| 1331 base::Bind(&ThreadProxy::CapturePictureOnImplThread, | 1366 base::Bind(&ThreadProxy::CapturePictureOnImplThread, |
| 1332 impl_thread_weak_ptr_, | 1367 impl_thread_weak_ptr_, |
| 1333 &completion, | 1368 &completion, |
| 1334 &picture)); | 1369 &picture)); |
| 1335 completion.Wait(); | 1370 completion.Wait(); |
| 1336 } | 1371 } |
| 1337 return picture; | 1372 return picture; |
| 1338 } | 1373 } |
| 1339 | 1374 |
| 1340 void ThreadProxy::CapturePictureOnImplThread(CompletionEvent* completion, | 1375 void ThreadProxy::CapturePictureOnImplThread(CompletionEvent* completion, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 | 1419 |
| 1385 base::TimeDelta delay = smoothness_takes_priority_expiration_time_ - now; | 1420 base::TimeDelta delay = smoothness_takes_priority_expiration_time_ - now; |
| 1386 | 1421 |
| 1387 // Need to make sure a delayed task is posted when we have smoothness | 1422 // Need to make sure a delayed task is posted when we have smoothness |
| 1388 // takes priority expiration time in the future. | 1423 // takes priority expiration time in the future. |
| 1389 if (delay <= base::TimeDelta()) | 1424 if (delay <= base::TimeDelta()) |
| 1390 return; | 1425 return; |
| 1391 if (renew_tree_priority_on_impl_thread_pending_) | 1426 if (renew_tree_priority_on_impl_thread_pending_) |
| 1392 return; | 1427 return; |
| 1393 | 1428 |
| 1394 Proxy::ImplThread()->PostDelayedTask( | 1429 Proxy::ImplThreadTaskRunner()->PostDelayedTask( |
| 1430 FROM_HERE, |
| 1395 base::Bind(&ThreadProxy::RenewTreePriorityOnImplThread, | 1431 base::Bind(&ThreadProxy::RenewTreePriorityOnImplThread, |
| 1396 weak_factory_on_impl_thread_.GetWeakPtr()), | 1432 weak_factory_on_impl_thread_.GetWeakPtr()), |
| 1397 delay); | 1433 delay); |
| 1398 | 1434 |
| 1399 renew_tree_priority_on_impl_thread_pending_ = true; | 1435 renew_tree_priority_on_impl_thread_pending_ = true; |
| 1400 } | 1436 } |
| 1401 | 1437 |
| 1402 void ThreadProxy::RenewTreePriorityOnImplThread() { | 1438 void ThreadProxy::RenewTreePriorityOnImplThread() { |
| 1403 DCHECK(renew_tree_priority_on_impl_thread_pending_); | 1439 DCHECK(renew_tree_priority_on_impl_thread_pending_); |
| 1404 renew_tree_priority_on_impl_thread_pending_ = false; | 1440 renew_tree_priority_on_impl_thread_pending_ = false; |
| 1405 | 1441 |
| 1406 RenewTreePriority(); | 1442 RenewTreePriority(); |
| 1407 } | 1443 } |
| 1408 | 1444 |
| 1409 void ThreadProxy::RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) { | 1445 void ThreadProxy::RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) { |
| 1410 Proxy::ImplThread()->PostDelayedTask( | 1446 Proxy::ImplThreadTaskRunner()->PostDelayedTask( |
| 1447 FROM_HERE, |
| 1411 base::Bind(&ThreadProxy::StartScrollbarAnimationOnImplThread, | 1448 base::Bind(&ThreadProxy::StartScrollbarAnimationOnImplThread, |
| 1412 impl_thread_weak_ptr_), | 1449 impl_thread_weak_ptr_), |
| 1413 delay); | 1450 delay); |
| 1414 } | 1451 } |
| 1415 | 1452 |
| 1416 void ThreadProxy::StartScrollbarAnimationOnImplThread() { | 1453 void ThreadProxy::StartScrollbarAnimationOnImplThread() { |
| 1417 layer_tree_host_impl_->StartScrollbarAnimation(); | 1454 layer_tree_host_impl_->StartScrollbarAnimation(); |
| 1418 } | 1455 } |
| 1419 | 1456 |
| 1420 void ThreadProxy::DidActivatePendingTree() { | 1457 void ThreadProxy::DidActivatePendingTree() { |
| 1421 DCHECK(IsImplThread()); | 1458 DCHECK(IsImplThread()); |
| 1422 TRACE_EVENT0("cc", "ThreadProxy::DidActivatePendingTreeOnImplThread"); | 1459 TRACE_EVENT0("cc", "ThreadProxy::DidActivatePendingTreeOnImplThread"); |
| 1423 | 1460 |
| 1424 if (completion_event_for_commit_held_on_tree_activation_ && | 1461 if (completion_event_for_commit_held_on_tree_activation_ && |
| 1425 !layer_tree_host_impl_->pending_tree()) { | 1462 !layer_tree_host_impl_->pending_tree()) { |
| 1426 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", | 1463 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", |
| 1427 TRACE_EVENT_SCOPE_THREAD); | 1464 TRACE_EVENT_SCOPE_THREAD); |
| 1428 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); | 1465 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); |
| 1429 completion_event_for_commit_held_on_tree_activation_->Signal(); | 1466 completion_event_for_commit_held_on_tree_activation_->Signal(); |
| 1430 completion_event_for_commit_held_on_tree_activation_ = NULL; | 1467 completion_event_for_commit_held_on_tree_activation_ = NULL; |
| 1431 } | 1468 } |
| 1432 } | 1469 } |
| 1433 | 1470 |
| 1434 } // namespace cc | 1471 } // namespace cc |
| OLD | NEW |