| 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/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 is_synchronous_single_threaded_(!task_runner_provider->HasImplThread() && | 229 is_synchronous_single_threaded_(!task_runner_provider->HasImplThread() && |
| 230 !settings.single_thread_proxy_scheduler), | 230 !settings.single_thread_proxy_scheduler), |
| 231 // Must be initialized after is_synchronous_single_threaded_ and | 231 // Must be initialized after is_synchronous_single_threaded_ and |
| 232 // task_runner_provider_. | 232 // task_runner_provider_. |
| 233 tile_manager_(this, | 233 tile_manager_(this, |
| 234 GetTaskRunner(), | 234 GetTaskRunner(), |
| 235 std::move(image_worker_task_runner), | 235 std::move(image_worker_task_runner), |
| 236 is_synchronous_single_threaded_ | 236 is_synchronous_single_threaded_ |
| 237 ? std::numeric_limits<size_t>::max() | 237 ? std::numeric_limits<size_t>::max() |
| 238 : settings.scheduled_raster_task_limit, | 238 : settings.scheduled_raster_task_limit, |
| 239 settings.use_partial_raster, | 239 settings.ToTileManagerSettings()), |
| 240 settings.check_tile_priority_inversion), | |
| 241 pinch_gesture_active_(false), | 240 pinch_gesture_active_(false), |
| 242 pinch_gesture_end_should_clear_scrolling_layer_(false), | 241 pinch_gesture_end_should_clear_scrolling_layer_(false), |
| 243 fps_counter_( | 242 fps_counter_( |
| 244 FrameRateCounter::Create(task_runner_provider_->HasImplThread())), | 243 FrameRateCounter::Create(task_runner_provider_->HasImplThread())), |
| 245 memory_history_(MemoryHistory::Create()), | 244 memory_history_(MemoryHistory::Create()), |
| 246 debug_rect_history_(DebugRectHistory::Create()), | 245 debug_rect_history_(DebugRectHistory::Create()), |
| 247 max_memory_needed_bytes_(0), | 246 max_memory_needed_bytes_(0), |
| 248 resourceless_software_draw_(false), | 247 resourceless_software_draw_(false), |
| 249 mutator_host_(std::move(mutator_host)), | 248 mutator_host_(std::move(mutator_host)), |
| 250 captured_scrollbar_animation_controller_(nullptr), | 249 captured_scrollbar_animation_controller_(nullptr), |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 if (compositor_frame_sink_) | 345 if (compositor_frame_sink_) |
| 347 compositor_frame_sink_->ForceReclaimResources(); | 346 compositor_frame_sink_->ForceReclaimResources(); |
| 348 | 347 |
| 349 if (!CommitToActiveTree()) | 348 if (!CommitToActiveTree()) |
| 350 CreatePendingTree(); | 349 CreatePendingTree(); |
| 351 } | 350 } |
| 352 | 351 |
| 353 void LayerTreeHostImpl::CommitComplete() { | 352 void LayerTreeHostImpl::CommitComplete() { |
| 354 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); | 353 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); |
| 355 | 354 |
| 355 UpdateSyncTreeAfterCommitOrImplSideInvalidation(); |
| 356 micro_benchmark_controller_.DidCompleteCommit(); |
| 357 } |
| 358 |
| 359 void LayerTreeHostImpl::UpdateSyncTreeAfterCommitOrImplSideInvalidation() { |
| 360 sync_tree()->InvalidateRegionForImages( |
| 361 tile_manager_.TakeImagesToInvalidateOnSyncTree()); |
| 362 |
| 356 if (CommitToActiveTree()) { | 363 if (CommitToActiveTree()) { |
| 357 // We have to activate animations here or "IsActive()" is true on the layers | 364 // We have to activate animations here or "IsActive()" is true on the layers |
| 358 // but the animations aren't activated yet so they get ignored by | 365 // but the animations aren't activated yet so they get ignored by |
| 359 // UpdateDrawProperties. | 366 // UpdateDrawProperties. |
| 360 ActivateAnimations(); | 367 ActivateAnimations(); |
| 361 } | 368 } |
| 362 | 369 |
| 363 // Start animations before UpdateDrawProperties and PrepareTiles, as they can | 370 // Start animations before UpdateDrawProperties and PrepareTiles, as they can |
| 364 // change the results. When doing commit to the active tree, this must happen | 371 // change the results. When doing commit to the active tree, this must happen |
| 365 // after ActivateAnimations() in order for this ticking to be propogated to | 372 // after ActivateAnimations() in order for this ticking to be propogated to |
| (...skipping 21 matching lines...) Expand all Loading... |
| 387 if (!did_prepare_tiles) { | 394 if (!did_prepare_tiles) { |
| 388 NotifyReadyToActivate(); | 395 NotifyReadyToActivate(); |
| 389 | 396 |
| 390 // Ensure we get ReadyToDraw signal even when PrepareTiles not run. This | 397 // Ensure we get ReadyToDraw signal even when PrepareTiles not run. This |
| 391 // is important for SingleThreadProxy and impl-side painting case. For | 398 // is important for SingleThreadProxy and impl-side painting case. For |
| 392 // STP, we commit to active tree and RequiresHighResToDraw, and set | 399 // STP, we commit to active tree and RequiresHighResToDraw, and set |
| 393 // Scheduler to wait for ReadyToDraw signal to avoid Checkerboard. | 400 // Scheduler to wait for ReadyToDraw signal to avoid Checkerboard. |
| 394 if (CommitToActiveTree()) | 401 if (CommitToActiveTree()) |
| 395 NotifyReadyToDraw(); | 402 NotifyReadyToDraw(); |
| 396 } | 403 } |
| 397 | |
| 398 micro_benchmark_controller_.DidCompleteCommit(); | |
| 399 } | 404 } |
| 400 | 405 |
| 401 bool LayerTreeHostImpl::CanDraw() const { | 406 bool LayerTreeHostImpl::CanDraw() const { |
| 402 // Note: If you are changing this function or any other function that might | 407 // Note: If you are changing this function or any other function that might |
| 403 // affect the result of CanDraw, make sure to call | 408 // affect the result of CanDraw, make sure to call |
| 404 // client_->OnCanDrawStateChanged in the proper places and update the | 409 // client_->OnCanDrawStateChanged in the proper places and update the |
| 405 // NotifyIfCanDrawChanged test. | 410 // NotifyIfCanDrawChanged test. |
| 406 | 411 |
| 407 if (!compositor_frame_sink_) { | 412 if (!compositor_frame_sink_) { |
| 408 TRACE_EVENT_INSTANT0("cc", | 413 TRACE_EVENT_INSTANT0("cc", |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 | 1053 |
| 1049 void LayerTreeHostImpl::DidAnimateScrollOffset() { | 1054 void LayerTreeHostImpl::DidAnimateScrollOffset() { |
| 1050 client_->SetNeedsCommitOnImplThread(); | 1055 client_->SetNeedsCommitOnImplThread(); |
| 1051 client_->RenewTreePriority(); | 1056 client_->RenewTreePriority(); |
| 1052 } | 1057 } |
| 1053 | 1058 |
| 1054 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { | 1059 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { |
| 1055 viewport_damage_rect_.Union(damage_rect); | 1060 viewport_damage_rect_.Union(damage_rect); |
| 1056 } | 1061 } |
| 1057 | 1062 |
| 1063 void LayerTreeHostImpl::InvalidateContentOnImplSide() { |
| 1064 DCHECK(!pending_tree_); |
| 1065 |
| 1066 if (!CommitToActiveTree()) |
| 1067 CreatePendingTree(); |
| 1068 UpdateSyncTreeAfterCommitOrImplSideInvalidation(); |
| 1069 } |
| 1070 |
| 1058 DrawResult LayerTreeHostImpl::PrepareToDraw(FrameData* frame) { | 1071 DrawResult LayerTreeHostImpl::PrepareToDraw(FrameData* frame) { |
| 1059 TRACE_EVENT1("cc", "LayerTreeHostImpl::PrepareToDraw", "SourceFrameNumber", | 1072 TRACE_EVENT1("cc", "LayerTreeHostImpl::PrepareToDraw", "SourceFrameNumber", |
| 1060 active_tree_->source_frame_number()); | 1073 active_tree_->source_frame_number()); |
| 1061 if (input_handler_client_) | 1074 if (input_handler_client_) |
| 1062 input_handler_client_->ReconcileElasticOverscrollAndRootScroll(); | 1075 input_handler_client_->ReconcileElasticOverscrollAndRootScroll(); |
| 1063 | 1076 |
| 1064 if (const char* client_name = GetClientNameForMetrics()) { | 1077 if (const char* client_name = GetClientNameForMetrics()) { |
| 1065 size_t total_memory = 0; | 1078 size_t total_memory = 0; |
| 1066 for (const PictureLayerImpl* layer : active_tree()->picture_layers()) | 1079 for (const PictureLayerImpl* layer : active_tree()->picture_layers()) |
| 1067 total_memory += layer->GetRasterSource()->GetMemoryUsage(); | 1080 total_memory += layer->GetRasterSource()->GetMemoryUsage(); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 // we intend to draw so it may make worse scheduling decisions. | 1318 // we intend to draw so it may make worse scheduling decisions. |
| 1306 is_likely_to_require_a_draw_ = is_likely_to_require_a_draw; | 1319 is_likely_to_require_a_draw_ = is_likely_to_require_a_draw; |
| 1307 } | 1320 } |
| 1308 | 1321 |
| 1309 gfx::ColorSpace LayerTreeHostImpl::GetTileColorSpace() const { | 1322 gfx::ColorSpace LayerTreeHostImpl::GetTileColorSpace() const { |
| 1310 if (!sync_tree()) | 1323 if (!sync_tree()) |
| 1311 return gfx::ColorSpace(); | 1324 return gfx::ColorSpace(); |
| 1312 return sync_tree()->device_color_space(); | 1325 return sync_tree()->device_color_space(); |
| 1313 } | 1326 } |
| 1314 | 1327 |
| 1328 void LayerTreeHostImpl::RequestImplSideInvalidation() { |
| 1329 client_->NeedsImplSideInvalidation(); |
| 1330 } |
| 1331 |
| 1315 void LayerTreeHostImpl::NotifyReadyToActivate() { | 1332 void LayerTreeHostImpl::NotifyReadyToActivate() { |
| 1316 client_->NotifyReadyToActivate(); | 1333 client_->NotifyReadyToActivate(); |
| 1317 } | 1334 } |
| 1318 | 1335 |
| 1319 void LayerTreeHostImpl::NotifyReadyToDraw() { | 1336 void LayerTreeHostImpl::NotifyReadyToDraw() { |
| 1320 // Tiles that are ready will cause NotifyTileStateChanged() to be called so we | 1337 // Tiles that are ready will cause NotifyTileStateChanged() to be called so we |
| 1321 // don't need to schedule a draw here. Just stop WillBeginImplFrame() from | 1338 // don't need to schedule a draw here. Just stop WillBeginImplFrame() from |
| 1322 // causing optimistic requests to draw a frame. | 1339 // causing optimistic requests to draw a frame. |
| 1323 is_likely_to_require_a_draw_ = false; | 1340 is_likely_to_require_a_draw_ = false; |
| 1324 | 1341 |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2022 | 2039 |
| 2023 UpdateViewportContainerSizes(); | 2040 UpdateViewportContainerSizes(); |
| 2024 | 2041 |
| 2025 active_tree_->DidBecomeActive(); | 2042 active_tree_->DidBecomeActive(); |
| 2026 client_->RenewTreePriority(); | 2043 client_->RenewTreePriority(); |
| 2027 // If we have any picture layers, then by activating we also modified tile | 2044 // If we have any picture layers, then by activating we also modified tile |
| 2028 // priorities. | 2045 // priorities. |
| 2029 if (!active_tree_->picture_layers().empty()) | 2046 if (!active_tree_->picture_layers().empty()) |
| 2030 DidModifyTilePriorities(); | 2047 DidModifyTilePriorities(); |
| 2031 | 2048 |
| 2049 tile_manager_.DidActivateSyncTree(); |
| 2032 client_->OnCanDrawStateChanged(CanDraw()); | 2050 client_->OnCanDrawStateChanged(CanDraw()); |
| 2033 client_->DidActivateSyncTree(); | 2051 client_->DidActivateSyncTree(); |
| 2034 if (!tree_activation_callback_.is_null()) | 2052 if (!tree_activation_callback_.is_null()) |
| 2035 tree_activation_callback_.Run(); | 2053 tree_activation_callback_.Run(); |
| 2036 | 2054 |
| 2037 std::unique_ptr<PendingPageScaleAnimation> pending_page_scale_animation = | 2055 std::unique_ptr<PendingPageScaleAnimation> pending_page_scale_animation = |
| 2038 active_tree_->TakePendingPageScaleAnimation(); | 2056 active_tree_->TakePendingPageScaleAnimation(); |
| 2039 if (pending_page_scale_animation) { | 2057 if (pending_page_scale_animation) { |
| 2040 StartPageScaleAnimation(pending_page_scale_animation->target_offset, | 2058 StartPageScaleAnimation(pending_page_scale_animation->target_offset, |
| 2041 pending_page_scale_animation->use_anchor, | 2059 pending_page_scale_animation->use_anchor, |
| (...skipping 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4090 worker_context_visibility_ = | 4108 worker_context_visibility_ = |
| 4091 worker_context->CacheController()->ClientBecameVisible(); | 4109 worker_context->CacheController()->ClientBecameVisible(); |
| 4092 } else { | 4110 } else { |
| 4093 worker_context->CacheController()->ClientBecameNotVisible( | 4111 worker_context->CacheController()->ClientBecameNotVisible( |
| 4094 std::move(worker_context_visibility_)); | 4112 std::move(worker_context_visibility_)); |
| 4095 } | 4113 } |
| 4096 } | 4114 } |
| 4097 } | 4115 } |
| 4098 | 4116 |
| 4099 } // namespace cc | 4117 } // namespace cc |
| OLD | NEW |