| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 recycle_tree_ = nullptr; | 282 recycle_tree_ = nullptr; |
| 283 pending_tree_ = nullptr; | 283 pending_tree_ = nullptr; |
| 284 active_tree_ = nullptr; | 284 active_tree_ = nullptr; |
| 285 DestroyTileManager(); | 285 DestroyTileManager(); |
| 286 } | 286 } |
| 287 | 287 |
| 288 void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) { | 288 void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) { |
| 289 // If the begin frame data was handled, then scroll and scale set was applied | 289 // If the begin frame data was handled, then scroll and scale set was applied |
| 290 // by the main thread, so the active tree needs to be updated as if these sent | 290 // by the main thread, so the active tree needs to be updated as if these sent |
| 291 // values were applied and committed. | 291 // values were applied and committed. |
| 292 if (CommitEarlyOutHandledCommit(reason)) { | 292 if (CommitEarlyOutHandledCommit(reason)) |
| 293 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); | 293 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); |
| 294 active_tree_->ResetContentsTexturesPurged(); | |
| 295 } | |
| 296 } | 294 } |
| 297 | 295 |
| 298 void LayerTreeHostImpl::BeginCommit() { | 296 void LayerTreeHostImpl::BeginCommit() { |
| 299 TRACE_EVENT0("cc", "LayerTreeHostImpl::BeginCommit"); | 297 TRACE_EVENT0("cc", "LayerTreeHostImpl::BeginCommit"); |
| 300 | 298 |
| 301 // Ensure all textures are returned so partial texture updates can happen | 299 // Ensure all textures are returned so partial texture updates can happen |
| 302 // during the commit. | 300 // during the commit. |
| 303 // TODO(ericrk): We should not need to ForceReclaimResources when using | 301 // TODO(ericrk): We should not need to ForceReclaimResources when using |
| 304 // Impl-side-painting as it doesn't upload during commits. However, | 302 // Impl-side-painting as it doesn't upload during commits. However, |
| 305 // Display::Draw currently relies on resource being reclaimed to block drawing | 303 // Display::Draw currently relies on resource being reclaimed to block drawing |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw empty viewport", | 377 TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw empty viewport", |
| 380 TRACE_EVENT_SCOPE_THREAD); | 378 TRACE_EVENT_SCOPE_THREAD); |
| 381 return false; | 379 return false; |
| 382 } | 380 } |
| 383 if (active_tree_->ViewportSizeInvalid()) { | 381 if (active_tree_->ViewportSizeInvalid()) { |
| 384 TRACE_EVENT_INSTANT0( | 382 TRACE_EVENT_INSTANT0( |
| 385 "cc", "LayerTreeHostImpl::CanDraw viewport size recently changed", | 383 "cc", "LayerTreeHostImpl::CanDraw viewport size recently changed", |
| 386 TRACE_EVENT_SCOPE_THREAD); | 384 TRACE_EVENT_SCOPE_THREAD); |
| 387 return false; | 385 return false; |
| 388 } | 386 } |
| 389 if (active_tree_->ContentsTexturesPurged()) { | |
| 390 TRACE_EVENT_INSTANT0( | |
| 391 "cc", "LayerTreeHostImpl::CanDraw contents textures purged", | |
| 392 TRACE_EVENT_SCOPE_THREAD); | |
| 393 return false; | |
| 394 } | |
| 395 if (EvictedUIResourcesExist()) { | 387 if (EvictedUIResourcesExist()) { |
| 396 TRACE_EVENT_INSTANT0( | 388 TRACE_EVENT_INSTANT0( |
| 397 "cc", "LayerTreeHostImpl::CanDraw UI resources evicted not recreated", | 389 "cc", "LayerTreeHostImpl::CanDraw UI resources evicted not recreated", |
| 398 TRACE_EVENT_SCOPE_THREAD); | 390 TRACE_EVENT_SCOPE_THREAD); |
| 399 return false; | 391 return false; |
| 400 } | 392 } |
| 401 return true; | 393 return true; |
| 402 } | 394 } |
| 403 | 395 |
| 404 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time) { | 396 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time) { |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 pass_references[quad->render_pass_id]--; | 1134 pass_references[quad->render_pass_id]--; |
| 1143 } | 1135 } |
| 1144 | 1136 |
| 1145 frame->render_passes_by_id.erase(pass->id); | 1137 frame->render_passes_by_id.erase(pass->id); |
| 1146 frame->render_passes.erase(frame->render_passes.end() - 2 - i); | 1138 frame->render_passes.erase(frame->render_passes.end() - 2 - i); |
| 1147 --i; | 1139 --i; |
| 1148 } | 1140 } |
| 1149 } | 1141 } |
| 1150 | 1142 |
| 1151 void LayerTreeHostImpl::EvictTexturesForTesting() { | 1143 void LayerTreeHostImpl::EvictTexturesForTesting() { |
| 1152 EnforceManagedMemoryPolicy(ManagedMemoryPolicy(0)); | 1144 UpdateTileManagerMemoryPolicy(ManagedMemoryPolicy(0)); |
| 1153 } | 1145 } |
| 1154 | 1146 |
| 1155 void LayerTreeHostImpl::BlockNotifyReadyToActivateForTesting(bool block) { | 1147 void LayerTreeHostImpl::BlockNotifyReadyToActivateForTesting(bool block) { |
| 1156 NOTREACHED(); | 1148 NOTREACHED(); |
| 1157 } | 1149 } |
| 1158 | 1150 |
| 1159 void LayerTreeHostImpl::ResetTreesForTesting() { | 1151 void LayerTreeHostImpl::ResetTreesForTesting() { |
| 1160 if (active_tree_) | 1152 if (active_tree_) |
| 1161 active_tree_->DetachLayerTree(); | 1153 active_tree_->DetachLayerTree(); |
| 1162 active_tree_ = | 1154 active_tree_ = |
| 1163 LayerTreeImpl::create(this, active_tree()->page_scale_factor(), | 1155 LayerTreeImpl::create(this, active_tree()->page_scale_factor(), |
| 1164 active_tree()->top_controls_shown_ratio(), | 1156 active_tree()->top_controls_shown_ratio(), |
| 1165 active_tree()->elastic_overscroll()); | 1157 active_tree()->elastic_overscroll()); |
| 1166 if (pending_tree_) | 1158 if (pending_tree_) |
| 1167 pending_tree_->DetachLayerTree(); | 1159 pending_tree_->DetachLayerTree(); |
| 1168 pending_tree_ = nullptr; | 1160 pending_tree_ = nullptr; |
| 1169 if (recycle_tree_) | 1161 if (recycle_tree_) |
| 1170 recycle_tree_->DetachLayerTree(); | 1162 recycle_tree_->DetachLayerTree(); |
| 1171 recycle_tree_ = nullptr; | 1163 recycle_tree_ = nullptr; |
| 1172 } | 1164 } |
| 1173 | 1165 |
| 1174 size_t LayerTreeHostImpl::SourceAnimationFrameNumberForTesting() const { | 1166 size_t LayerTreeHostImpl::SourceAnimationFrameNumberForTesting() const { |
| 1175 return fps_counter_->current_frame_number(); | 1167 return fps_counter_->current_frame_number(); |
| 1176 } | 1168 } |
| 1177 | 1169 |
| 1178 void LayerTreeHostImpl::EnforceManagedMemoryPolicy( | |
| 1179 const ManagedMemoryPolicy& policy) { | |
| 1180 | |
| 1181 bool evicted_resources = client_->ReduceContentsTextureMemoryOnImplThread( | |
| 1182 visible_ ? policy.bytes_limit_when_visible : 0, | |
| 1183 ManagedMemoryPolicy::PriorityCutoffToValue( | |
| 1184 visible_ ? policy.priority_cutoff_when_visible | |
| 1185 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING)); | |
| 1186 if (evicted_resources) { | |
| 1187 active_tree_->SetContentsTexturesPurged(); | |
| 1188 if (pending_tree_) | |
| 1189 pending_tree_->SetContentsTexturesPurged(); | |
| 1190 client_->SetNeedsCommitOnImplThread(); | |
| 1191 client_->OnCanDrawStateChanged(CanDraw()); | |
| 1192 client_->RenewTreePriority(); | |
| 1193 } | |
| 1194 | |
| 1195 UpdateTileManagerMemoryPolicy(policy); | |
| 1196 } | |
| 1197 | |
| 1198 void LayerTreeHostImpl::UpdateTileManagerMemoryPolicy( | 1170 void LayerTreeHostImpl::UpdateTileManagerMemoryPolicy( |
| 1199 const ManagedMemoryPolicy& policy) { | 1171 const ManagedMemoryPolicy& policy) { |
| 1200 if (!tile_manager_) | 1172 if (!tile_manager_) |
| 1201 return; | 1173 return; |
| 1202 | 1174 |
| 1203 global_tile_state_.hard_memory_limit_in_bytes = 0; | 1175 global_tile_state_.hard_memory_limit_in_bytes = 0; |
| 1204 global_tile_state_.soft_memory_limit_in_bytes = 0; | 1176 global_tile_state_.soft_memory_limit_in_bytes = 0; |
| 1205 if (visible_ && policy.bytes_limit_when_visible > 0) { | 1177 if (visible_ && policy.bytes_limit_when_visible > 0) { |
| 1206 global_tile_state_.hard_memory_limit_in_bytes = | 1178 global_tile_state_.hard_memory_limit_in_bytes = |
| 1207 policy.bytes_limit_when_visible; | 1179 policy.bytes_limit_when_visible; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 cached_managed_memory_policy_ = policy; | 1332 cached_managed_memory_policy_ = policy; |
| 1361 ManagedMemoryPolicy actual_policy = ActualManagedMemoryPolicy(); | 1333 ManagedMemoryPolicy actual_policy = ActualManagedMemoryPolicy(); |
| 1362 | 1334 |
| 1363 if (old_policy == actual_policy) | 1335 if (old_policy == actual_policy) |
| 1364 return; | 1336 return; |
| 1365 | 1337 |
| 1366 if (!proxy_->HasImplThread()) { | 1338 if (!proxy_->HasImplThread()) { |
| 1367 // In single-thread mode, this can be called on the main thread by | 1339 // In single-thread mode, this can be called on the main thread by |
| 1368 // GLRenderer::OnMemoryAllocationChanged. | 1340 // GLRenderer::OnMemoryAllocationChanged. |
| 1369 DebugScopedSetImplThread impl_thread(proxy_); | 1341 DebugScopedSetImplThread impl_thread(proxy_); |
| 1370 EnforceManagedMemoryPolicy(actual_policy); | 1342 UpdateTileManagerMemoryPolicy(actual_policy); |
| 1371 } else { | 1343 } else { |
| 1372 DCHECK(proxy_->IsImplThread()); | 1344 DCHECK(proxy_->IsImplThread()); |
| 1373 EnforceManagedMemoryPolicy(actual_policy); | 1345 UpdateTileManagerMemoryPolicy(actual_policy); |
| 1374 } | 1346 } |
| 1375 | 1347 |
| 1376 // If there is already enough memory to draw everything imaginable and the | 1348 // If there is already enough memory to draw everything imaginable and the |
| 1377 // new memory limit does not change this, then do not re-commit. Don't bother | 1349 // new memory limit does not change this, then do not re-commit. Don't bother |
| 1378 // skipping commits if this is not visible (commits don't happen when not | 1350 // skipping commits if this is not visible (commits don't happen when not |
| 1379 // visible, there will almost always be a commit when this becomes visible). | 1351 // visible, there will almost always be a commit when this becomes visible). |
| 1380 bool needs_commit = true; | 1352 bool needs_commit = true; |
| 1381 if (visible() && | 1353 if (visible() && |
| 1382 actual_policy.bytes_limit_when_visible >= max_memory_needed_bytes_ && | 1354 actual_policy.bytes_limit_when_visible >= max_memory_needed_bytes_ && |
| 1383 old_policy.bytes_limit_when_visible >= max_memory_needed_bytes_ && | 1355 old_policy.bytes_limit_when_visible >= max_memory_needed_bytes_ && |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1967 } | 1939 } |
| 1968 } | 1940 } |
| 1969 | 1941 |
| 1970 void LayerTreeHostImpl::SetVisible(bool visible) { | 1942 void LayerTreeHostImpl::SetVisible(bool visible) { |
| 1971 DCHECK(proxy_->IsImplThread()); | 1943 DCHECK(proxy_->IsImplThread()); |
| 1972 | 1944 |
| 1973 if (visible_ == visible) | 1945 if (visible_ == visible) |
| 1974 return; | 1946 return; |
| 1975 visible_ = visible; | 1947 visible_ = visible; |
| 1976 DidVisibilityChange(this, visible_); | 1948 DidVisibilityChange(this, visible_); |
| 1977 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); | 1949 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); |
| 1978 | 1950 |
| 1979 // If we just became visible, we have to ensure that we draw high res tiles, | 1951 // If we just became visible, we have to ensure that we draw high res tiles, |
| 1980 // to prevent checkerboard/low res flashes. | 1952 // to prevent checkerboard/low res flashes. |
| 1981 if (visible_) | 1953 if (visible_) |
| 1982 SetRequiresHighResToDraw(); | 1954 SetRequiresHighResToDraw(); |
| 1983 else | 1955 else |
| 1984 EvictAllUIResources(); | 1956 EvictAllUIResources(); |
| 1985 | 1957 |
| 1986 // Call PrepareTiles unconditionally on visibility change since this tab may | 1958 // Call PrepareTiles unconditionally on visibility change since this tab may |
| 1987 // never get another draw or timer tick. When becoming visible we care about | 1959 // never get another draw or timer tick. When becoming visible we care about |
| (...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3490 new_target.SetToMin(layer_impl->MaxScrollOffset()); | 3462 new_target.SetToMin(layer_impl->MaxScrollOffset()); |
| 3491 | 3463 |
| 3492 curve->UpdateTarget( | 3464 curve->UpdateTarget( |
| 3493 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) | 3465 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) |
| 3494 .InSecondsF(), | 3466 .InSecondsF(), |
| 3495 new_target); | 3467 new_target); |
| 3496 | 3468 |
| 3497 return true; | 3469 return true; |
| 3498 } | 3470 } |
| 3499 } // namespace cc | 3471 } // namespace cc |
| OLD | NEW |