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

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

Issue 22926024: cc: Control activation from the Scheduler (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedOutputSurface4
Patch Set: BlockNotifyReadyToActivateForTesting Created 7 years, 3 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/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_impl_unittest.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/layer_tree_host_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // correct. In fact, setting fake thread id's interferes with the real 103 // correct. In fact, setting fake thread id's interferes with the real
104 // thread id's and causes breakage. 104 // thread id's and causes breakage.
105 scoped_ptr<DebugScopedSetImplThread> set_impl_thread; 105 scoped_ptr<DebugScopedSetImplThread> set_impl_thread;
106 if (!layer_tree_host_impl_->proxy()->HasImplThread()) { 106 if (!layer_tree_host_impl_->proxy()->HasImplThread()) {
107 set_impl_thread.reset( 107 set_impl_thread.reset(
108 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy())); 108 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy()));
109 } 109 }
110 110
111 // TODO(enne): This should probably happen post-animate. 111 // TODO(enne): This should probably happen post-animate.
112 if (layer_tree_host_impl_->pending_tree()) { 112 if (layer_tree_host_impl_->pending_tree()) {
113 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); 113 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties();
114 114 layer_tree_host_impl_->ManageTiles();
115 if (layer_tree_host_impl_->pending_tree()) {
116 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties();
117 layer_tree_host_impl_->ManageTiles();
118 }
119 } 115 }
120 116
121 layer_tree_host_impl_->Animate( 117 layer_tree_host_impl_->Animate(
122 layer_tree_host_impl_->CurrentFrameTimeTicks(), 118 layer_tree_host_impl_->CurrentFrameTimeTicks(),
123 layer_tree_host_impl_->CurrentFrameTime()); 119 layer_tree_host_impl_->CurrentFrameTime());
124 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); 120 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true);
125 bool start_ready_animations = true; 121 bool start_ready_animations = true;
126 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); 122 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
127 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); 123 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
128 } 124 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 LayerTreeHostImplClient* client, 165 LayerTreeHostImplClient* client,
170 Proxy* proxy, 166 Proxy* proxy,
171 RenderingStatsInstrumentation* rendering_stats_instrumentation) 167 RenderingStatsInstrumentation* rendering_stats_instrumentation)
172 : client_(client), 168 : client_(client),
173 proxy_(proxy), 169 proxy_(proxy),
174 input_handler_client_(NULL), 170 input_handler_client_(NULL),
175 did_lock_scrolling_layer_(false), 171 did_lock_scrolling_layer_(false),
176 should_bubble_scrolls_(false), 172 should_bubble_scrolls_(false),
177 wheel_scrolling_(false), 173 wheel_scrolling_(false),
178 manage_tiles_needed_(false), 174 manage_tiles_needed_(false),
175 block_notify_ready_to_activate_for_testing_(false),
enne (OOO) 2013/08/26 21:57:52 I kind of liked the previous interposer in that it
brianderson 2013/08/26 22:47:26 I will put the code into LayerTreeHostImplForTesti
176 notify_ready_to_activate_was_blocked_(false),
179 root_layer_scroll_offset_delegate_(NULL), 177 root_layer_scroll_offset_delegate_(NULL),
180 settings_(settings), 178 settings_(settings),
181 visible_(true), 179 visible_(true),
182 cached_managed_memory_policy_( 180 cached_managed_memory_policy_(
183 PrioritizedResourceManager::DefaultMemoryAllocationLimit(), 181 PrioritizedResourceManager::DefaultMemoryAllocationLimit(),
184 ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING, 182 ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING,
185 0, 183 0,
186 ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING, 184 ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING,
187 ManagedMemoryPolicy::kDefaultNumResourcesLimit), 185 ManagedMemoryPolicy::kDefaultNumResourcesLimit),
188 pinch_gesture_active_(false), 186 pinch_gesture_active_(false),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); 245 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete");
248 246
249 if (settings_.impl_side_painting) { 247 if (settings_.impl_side_painting) {
250 // Impl-side painting needs an update immediately post-commit to have the 248 // Impl-side painting needs an update immediately post-commit to have the
251 // opportunity to create tilings. Other paths can call UpdateDrawProperties 249 // opportunity to create tilings. Other paths can call UpdateDrawProperties
252 // more lazily when needed prior to drawing. 250 // more lazily when needed prior to drawing.
253 pending_tree()->ApplyScrollDeltasSinceBeginFrame(); 251 pending_tree()->ApplyScrollDeltasSinceBeginFrame();
254 pending_tree_->set_needs_update_draw_properties(); 252 pending_tree_->set_needs_update_draw_properties();
255 pending_tree_->UpdateDrawProperties(); 253 pending_tree_->UpdateDrawProperties();
256 // Start working on newly created tiles immediately if needed. 254 // Start working on newly created tiles immediately if needed.
257 ManageTiles(); 255 if (!manage_tiles_needed_)
256 NotifyReadyToActivate();
257 else
258 ManageTiles();
258 } else { 259 } else {
259 active_tree_->set_needs_update_draw_properties(); 260 active_tree_->set_needs_update_draw_properties();
260 } 261 }
261 262
262 client_->SendManagedMemoryStats(); 263 client_->SendManagedMemoryStats();
263 } 264 }
264 265
265 bool LayerTreeHostImpl::CanDraw() const { 266 bool LayerTreeHostImpl::CanDraw() const {
266 // Note: If you are changing this function or any other function that might 267 // Note: If you are changing this function or any other function that might
267 // affect the result of CanDraw, make sure to call 268 // affect the result of CanDraw, make sure to call
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 1020
1020 // If we return true, then we expect DrawLayers() to be called before this 1021 // If we return true, then we expect DrawLayers() to be called before this
1021 // function is called again. 1022 // function is called again.
1022 return true; 1023 return true;
1023 } 1024 }
1024 1025
1025 void LayerTreeHostImpl::EvictTexturesForTesting() { 1026 void LayerTreeHostImpl::EvictTexturesForTesting() {
1026 EnforceManagedMemoryPolicy(ManagedMemoryPolicy(0)); 1027 EnforceManagedMemoryPolicy(ManagedMemoryPolicy(0));
1027 } 1028 }
1028 1029
1030
1031 void LayerTreeHostImpl::BlockNotifyReadyToActivateForTesting(bool block) {
1032 UNSHIPPED_TRACE_EVENT1(
1033 "cc", "LayerTreeHostImpl::BlockNotifyReadyToActivateForTesting",
1034 "block", block);
1035 block_notify_ready_to_activate_for_testing_ = block;
1036 if (!block && notify_ready_to_activate_was_blocked_) {
1037 NotifyReadyToActivate();
1038 notify_ready_to_activate_was_blocked_ = false;
1039 }
1040 }
1041
1029 void LayerTreeHostImpl::EnforceManagedMemoryPolicy( 1042 void LayerTreeHostImpl::EnforceManagedMemoryPolicy(
1030 const ManagedMemoryPolicy& policy) { 1043 const ManagedMemoryPolicy& policy) {
1031 1044
1032 bool evicted_resources = client_->ReduceContentsTextureMemoryOnImplThread( 1045 bool evicted_resources = client_->ReduceContentsTextureMemoryOnImplThread(
1033 visible_ ? policy.bytes_limit_when_visible 1046 visible_ ? policy.bytes_limit_when_visible
1034 : policy.bytes_limit_when_not_visible, 1047 : policy.bytes_limit_when_not_visible,
1035 ManagedMemoryPolicy::PriorityCutoffToValue( 1048 ManagedMemoryPolicy::PriorityCutoffToValue(
1036 visible_ ? policy.priority_cutoff_when_visible 1049 visible_ ? policy.priority_cutoff_when_visible
1037 : policy.priority_cutoff_when_not_visible)); 1050 : policy.priority_cutoff_when_not_visible));
1038 if (evicted_resources) { 1051 if (evicted_resources) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 1091
1079 void LayerTreeHostImpl::DidInitializeVisibleTile() { 1092 void LayerTreeHostImpl::DidInitializeVisibleTile() {
1080 // TODO(reveman): Determine tiles that changed and only damage 1093 // TODO(reveman): Determine tiles that changed and only damage
1081 // what's necessary. 1094 // what's necessary.
1082 SetFullRootLayerDamage(); 1095 SetFullRootLayerDamage();
1083 if (client_) 1096 if (client_)
1084 client_->DidInitializeVisibleTileOnImplThread(); 1097 client_->DidInitializeVisibleTileOnImplThread();
1085 } 1098 }
1086 1099
1087 void LayerTreeHostImpl::NotifyReadyToActivate() { 1100 void LayerTreeHostImpl::NotifyReadyToActivate() {
1088 if (pending_tree_) { 1101 if (block_notify_ready_to_activate_for_testing_)
1089 need_to_update_visible_tiles_before_draw_ = true; 1102 notify_ready_to_activate_was_blocked_ = true;
1090 ActivatePendingTree(); 1103 else
1091 } 1104 client_->NotifyReadyToActivate();
1092 } 1105 }
1093 1106
1094 bool LayerTreeHostImpl::ShouldClearRootRenderPass() const { 1107 bool LayerTreeHostImpl::ShouldClearRootRenderPass() const {
1095 return settings_.should_clear_root_render_pass; 1108 return settings_.should_clear_root_render_pass;
1096 } 1109 }
1097 1110
1098 void LayerTreeHostImpl::SetMemoryPolicy(const ManagedMemoryPolicy& policy) { 1111 void LayerTreeHostImpl::SetMemoryPolicy(const ManagedMemoryPolicy& policy) {
1099 SetManagedMemoryPolicy(policy, zero_budget_); 1112 SetManagedMemoryPolicy(policy, zero_budget_);
1100 } 1113 }
1101 1114
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 return 0; 1439 return 0;
1427 } 1440 }
1428 1441
1429 void LayerTreeHostImpl::CreatePendingTree() { 1442 void LayerTreeHostImpl::CreatePendingTree() {
1430 CHECK(!pending_tree_); 1443 CHECK(!pending_tree_);
1431 if (recycle_tree_) 1444 if (recycle_tree_)
1432 recycle_tree_.swap(pending_tree_); 1445 recycle_tree_.swap(pending_tree_);
1433 else 1446 else
1434 pending_tree_ = LayerTreeImpl::create(this); 1447 pending_tree_ = LayerTreeImpl::create(this);
1435 client_->OnCanDrawStateChanged(CanDraw()); 1448 client_->OnCanDrawStateChanged(CanDraw());
1436 client_->OnHasPendingTreeStateChanged(pending_tree_);
1437 TRACE_EVENT_ASYNC_BEGIN0("cc", "PendingTree", pending_tree_.get()); 1449 TRACE_EVENT_ASYNC_BEGIN0("cc", "PendingTree", pending_tree_.get());
1438 TRACE_EVENT_ASYNC_STEP0("cc", 1450 TRACE_EVENT_ASYNC_STEP0("cc",
1439 "PendingTree", pending_tree_.get(), "waiting"); 1451 "PendingTree", pending_tree_.get(), "waiting");
1440 } 1452 }
1441 1453
1442 void LayerTreeHostImpl::UpdateVisibleTiles() { 1454 void LayerTreeHostImpl::UpdateVisibleTiles() {
1443 DCHECK(!client_->IsInsideDraw()) << 1455 DCHECK(!client_->IsInsideDraw()) <<
1444 "Updating visible tiles within a draw may trigger " 1456 "Updating visible tiles within a draw may trigger "
1445 "spurious redraws."; 1457 "spurious redraws.";
1446 if (tile_manager_ && tile_manager_->UpdateVisibleTiles()) 1458 if (tile_manager_ && tile_manager_->UpdateVisibleTiles())
1447 DidInitializeVisibleTile(); 1459 DidInitializeVisibleTile();
1448 1460
1449 need_to_update_visible_tiles_before_draw_ = false; 1461 need_to_update_visible_tiles_before_draw_ = false;
1450 } 1462 }
1451 1463
1452 void LayerTreeHostImpl::ActivatePendingTreeIfNeeded() {
1453 DCHECK(pending_tree_);
1454 CHECK(settings_.impl_side_painting);
1455
1456 if (!pending_tree_)
1457 return;
1458
1459 // The tile manager is usually responsible for notifying activation.
1460 // If there is no tile manager, then we need to manually activate.
1461 if (!tile_manager_ || tile_manager_->AreTilesRequiredForActivationReady()) {
1462 ActivatePendingTree();
1463 return;
1464 }
1465
1466 // Manage tiles in case state affecting tile priority has changed.
1467 ManageTiles();
1468
1469 TRACE_EVENT_ASYNC_STEP1(
1470 "cc",
1471 "PendingTree", pending_tree_.get(), "activate",
1472 "state", TracedValue::FromValue(ActivationStateAsValue().release()));
1473 }
1474
1475 void LayerTreeHostImpl::ActivatePendingTree() { 1464 void LayerTreeHostImpl::ActivatePendingTree() {
1476 CHECK(pending_tree_); 1465 CHECK(pending_tree_);
1477 TRACE_EVENT_ASYNC_END0("cc", "PendingTree", pending_tree_.get()); 1466 TRACE_EVENT_ASYNC_END0("cc", "PendingTree", pending_tree_.get());
1478 1467
1468 need_to_update_visible_tiles_before_draw_ = true;
1469
1479 active_tree_->SetRootLayerScrollOffsetDelegate(NULL); 1470 active_tree_->SetRootLayerScrollOffsetDelegate(NULL);
1480 active_tree_->PushPersistedState(pending_tree_.get()); 1471 active_tree_->PushPersistedState(pending_tree_.get());
1481 if (pending_tree_->needs_full_tree_sync()) { 1472 if (pending_tree_->needs_full_tree_sync()) {
1482 active_tree_->SetRootLayer( 1473 active_tree_->SetRootLayer(
1483 TreeSynchronizer::SynchronizeTrees(pending_tree_->root_layer(), 1474 TreeSynchronizer::SynchronizeTrees(pending_tree_->root_layer(),
1484 active_tree_->DetachLayerTree(), 1475 active_tree_->DetachLayerTree(),
1485 active_tree_.get())); 1476 active_tree_.get()));
1486 } 1477 }
1487 TreeSynchronizer::PushProperties(pending_tree_->root_layer(), 1478 TreeSynchronizer::PushProperties(pending_tree_->root_layer(),
1488 active_tree_->root_layer()); 1479 active_tree_->root_layer());
1489 DCHECK(!recycle_tree_); 1480 DCHECK(!recycle_tree_);
1490 1481
1491 // Process any requests in the UI resource queue. The request queue is given 1482 // Process any requests in the UI resource queue. The request queue is given
1492 // in LayerTreeHost::FinishCommitOnImplThread. This must take place before 1483 // in LayerTreeHost::FinishCommitOnImplThread. This must take place before
1493 // the swap. 1484 // the swap.
1494 pending_tree_->ProcessUIResourceRequestQueue(); 1485 pending_tree_->ProcessUIResourceRequestQueue();
1495 1486
1496 pending_tree_->PushPropertiesTo(active_tree_.get()); 1487 pending_tree_->PushPropertiesTo(active_tree_.get());
1497 1488
1498 // Now that we've synced everything from the pending tree to the active 1489 // Now that we've synced everything from the pending tree to the active
1499 // tree, rename the pending tree the recycle tree so we can reuse it on the 1490 // tree, rename the pending tree the recycle tree so we can reuse it on the
1500 // next sync. 1491 // next sync.
1501 pending_tree_.swap(recycle_tree_); 1492 pending_tree_.swap(recycle_tree_);
1502 1493
1503 active_tree_->SetRootLayerScrollOffsetDelegate( 1494 active_tree_->SetRootLayerScrollOffsetDelegate(
1504 root_layer_scroll_offset_delegate_); 1495 root_layer_scroll_offset_delegate_);
1505 active_tree_->DidBecomeActive(); 1496 active_tree_->DidBecomeActive();
1506 1497
1498 client_->DidActivatePendingTree();
1499 if (!tree_activation_callback_.is_null())
1500 tree_activation_callback_.Run();
1501
1507 // Reduce wasted memory now that unlinked resources are guaranteed not 1502 // Reduce wasted memory now that unlinked resources are guaranteed not
1508 // to be used. 1503 // to be used.
1509 client_->ReduceWastedContentsTextureMemoryOnImplThread(); 1504 client_->ReduceWastedContentsTextureMemoryOnImplThread();
1510 1505
1511 client_->OnCanDrawStateChanged(CanDraw()); 1506 client_->OnCanDrawStateChanged(CanDraw());
1512 client_->OnHasPendingTreeStateChanged(pending_tree_);
1513 client_->SetNeedsRedrawOnImplThread(); 1507 client_->SetNeedsRedrawOnImplThread();
1514 client_->RenewTreePriority(); 1508 client_->RenewTreePriority();
1515 1509
1516 if (debug_state_.continuous_painting) { 1510 if (debug_state_.continuous_painting) {
1517 const RenderingStats& stats = 1511 const RenderingStats& stats =
1518 rendering_stats_instrumentation_->GetRenderingStats(); 1512 rendering_stats_instrumentation_->GetRenderingStats();
1519 paint_time_counter_->SavePaintTime( 1513 paint_time_counter_->SavePaintTime(
1520 stats.main_stats.paint_time + stats.main_stats.record_time + 1514 stats.main_stats.paint_time + stats.main_stats.record_time +
1521 stats.impl_stats.rasterize_time_for_now_bins_on_pending_tree); 1515 stats.impl_stats.rasterize_time_for_now_bins_on_pending_tree);
1522 } 1516 }
1523
1524 client_->DidActivatePendingTree();
1525 if (!tree_activation_callback_.is_null())
1526 tree_activation_callback_.Run();
1527 } 1517 }
1528 1518
1529 void LayerTreeHostImpl::SetVisible(bool visible) { 1519 void LayerTreeHostImpl::SetVisible(bool visible) {
1530 DCHECK(proxy_->IsImplThread()); 1520 DCHECK(proxy_->IsImplThread());
1531 1521
1532 if (visible_ == visible) 1522 if (visible_ == visible)
1533 return; 1523 return;
1534 visible_ = visible; 1524 visible_ = visible;
1535 DidVisibilityChange(this, visible_); 1525 DidVisibilityChange(this, visible_);
1536 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); 1526 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy());
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 2525
2536 ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource( 2526 ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource(
2537 UIResourceId uid) const { 2527 UIResourceId uid) const {
2538 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid); 2528 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid);
2539 if (iter != ui_resource_map_.end()) 2529 if (iter != ui_resource_map_.end())
2540 return iter->second; 2530 return iter->second;
2541 return 0; 2531 return 0;
2542 } 2532 }
2543 2533
2544 } // namespace cc 2534 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698