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

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

Issue 23478004: UI resource are evicted when LTH is set to not visible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CanDraw returns false when UI resources are evicted 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 max_memory_needed_bytes_(0), 193 max_memory_needed_bytes_(0),
194 last_sent_memory_visible_bytes_(0), 194 last_sent_memory_visible_bytes_(0),
195 last_sent_memory_visible_and_nearby_bytes_(0), 195 last_sent_memory_visible_and_nearby_bytes_(0),
196 last_sent_memory_use_bytes_(0), 196 last_sent_memory_use_bytes_(0),
197 zero_budget_(false), 197 zero_budget_(false),
198 device_scale_factor_(1.f), 198 device_scale_factor_(1.f),
199 overdraw_bottom_height_(0.f), 199 overdraw_bottom_height_(0.f),
200 external_stencil_test_enabled_(false), 200 external_stencil_test_enabled_(false),
201 animation_registrar_(AnimationRegistrar::Create()), 201 animation_registrar_(AnimationRegistrar::Create()),
202 rendering_stats_instrumentation_(rendering_stats_instrumentation), 202 rendering_stats_instrumentation_(rendering_stats_instrumentation),
203 need_to_update_visible_tiles_before_draw_(false) { 203 need_to_update_visible_tiles_before_draw_(false),
204 ui_resources_evicted_(false) {
204 DCHECK(proxy_->IsImplThread()); 205 DCHECK(proxy_->IsImplThread());
205 DidVisibilityChange(this, visible_); 206 DidVisibilityChange(this, visible_);
206 207
207 SetDebugState(settings.initial_debug_state); 208 SetDebugState(settings.initial_debug_state);
208 209
209 if (settings.calculate_top_controls_position) { 210 if (settings.calculate_top_controls_position) {
210 top_controls_manager_ = 211 top_controls_manager_ =
211 TopControlsManager::Create(this, 212 TopControlsManager::Create(this,
212 settings.top_controls_height, 213 settings.top_controls_height,
213 settings.top_controls_show_threshold, 214 settings.top_controls_show_threshold,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 "cc", "LayerTreeHostImpl::CanDraw viewport size recently changed", 299 "cc", "LayerTreeHostImpl::CanDraw viewport size recently changed",
299 TRACE_EVENT_SCOPE_THREAD); 300 TRACE_EVENT_SCOPE_THREAD);
300 return false; 301 return false;
301 } 302 }
302 if (active_tree_->ContentsTexturesPurged()) { 303 if (active_tree_->ContentsTexturesPurged()) {
303 TRACE_EVENT_INSTANT0( 304 TRACE_EVENT_INSTANT0(
304 "cc", "LayerTreeHostImpl::CanDraw contents textures purged", 305 "cc", "LayerTreeHostImpl::CanDraw contents textures purged",
305 TRACE_EVENT_SCOPE_THREAD); 306 TRACE_EVENT_SCOPE_THREAD);
306 return false; 307 return false;
307 } 308 }
309
310 if (ui_resources_evicted_) {
311 TRACE_EVENT_INSTANT0(
312 "cc", "LayerTreeHostImpl::CanDraw ui resources evicted",
313 TRACE_EVENT_SCOPE_THREAD);
314 return false;
315 }
316
308 return true; 317 return true;
309 } 318 }
310 319
311 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time, 320 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time,
312 base::Time wall_clock_time) { 321 base::Time wall_clock_time) {
313 if (input_handler_client_) 322 if (input_handler_client_)
314 input_handler_client_->Animate(monotonic_time); 323 input_handler_client_->Animate(monotonic_time);
315 AnimatePageScale(monotonic_time); 324 AnimatePageScale(monotonic_time);
316 AnimateLayers(monotonic_time, wall_clock_time); 325 AnimateLayers(monotonic_time, wall_clock_time);
317 AnimateScrollbars(monotonic_time); 326 AnimateScrollbars(monotonic_time);
(...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 1538
1530 void LayerTreeHostImpl::SetVisible(bool visible) { 1539 void LayerTreeHostImpl::SetVisible(bool visible) {
1531 DCHECK(proxy_->IsImplThread()); 1540 DCHECK(proxy_->IsImplThread());
1532 1541
1533 if (visible_ == visible) 1542 if (visible_ == visible)
1534 return; 1543 return;
1535 visible_ = visible; 1544 visible_ = visible;
1536 DidVisibilityChange(this, visible_); 1545 DidVisibilityChange(this, visible_);
1537 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); 1546 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy());
1538 1547
1539 // Evict tiles immediately if invisible since this tab may never get another 1548 if (!visible_) {
1540 // draw or timer tick. 1549 // Evict tiles immediately if invisible since this tab may never get another
1541 if (!visible_) 1550 // draw or timer tick.
1542 ManageTiles(); 1551 ManageTiles();
1543 1552
1553 // Evict UI resources
1554 ui_resources_evicted_ = ui_resource_map_.size() > 0;
1555 ReleaseUIResources();
1556 }
1557
1544 if (!renderer_) 1558 if (!renderer_)
1545 return; 1559 return;
1546 1560
1547 renderer_->SetVisible(visible); 1561 renderer_->SetVisible(visible);
1548 } 1562 }
1549 1563
1550 ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const { 1564 ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const {
1551 ManagedMemoryPolicy actual = cached_managed_memory_policy_; 1565 ManagedMemoryPolicy actual = cached_managed_memory_policy_;
1552 if (debug_state_.rasterize_only_visible_content) { 1566 if (debug_state_.rasterize_only_visible_content) {
1553 actual.priority_cutoff_when_not_visible = 1567 actual.priority_cutoff_when_not_visible =
(...skipping 15 matching lines...) Expand all
1569 } 1583 }
1570 1584
1571 void LayerTreeHostImpl::ReleaseTreeResources() { 1585 void LayerTreeHostImpl::ReleaseTreeResources() {
1572 if (active_tree_->root_layer()) 1586 if (active_tree_->root_layer())
1573 SendReleaseResourcesRecursive(active_tree_->root_layer()); 1587 SendReleaseResourcesRecursive(active_tree_->root_layer());
1574 if (pending_tree_ && pending_tree_->root_layer()) 1588 if (pending_tree_ && pending_tree_->root_layer())
1575 SendReleaseResourcesRecursive(pending_tree_->root_layer()); 1589 SendReleaseResourcesRecursive(pending_tree_->root_layer());
1576 if (recycle_tree_ && recycle_tree_->root_layer()) 1590 if (recycle_tree_ && recycle_tree_->root_layer())
1577 SendReleaseResourcesRecursive(recycle_tree_->root_layer()); 1591 SendReleaseResourcesRecursive(recycle_tree_->root_layer());
1578 1592
1579 // Remove all existing maps from UIResourceId to ResourceId. 1593 ReleaseUIResources();
1580 ui_resource_map_.clear();
1581 } 1594 }
1582 1595
1583 void LayerTreeHostImpl::CreateAndSetRenderer( 1596 void LayerTreeHostImpl::CreateAndSetRenderer(
1584 OutputSurface* output_surface, 1597 OutputSurface* output_surface,
1585 ResourceProvider* resource_provider, 1598 ResourceProvider* resource_provider,
1586 bool skip_gl_renderer) { 1599 bool skip_gl_renderer) {
1587 DCHECK(!renderer_); 1600 DCHECK(!renderer_);
1588 if (output_surface->capabilities().delegated_rendering) { 1601 if (output_surface->capabilities().delegated_rendering) {
1589 renderer_ = 1602 renderer_ =
1590 DelegatingRenderer::Create(this, output_surface, resource_provider); 1603 DelegatingRenderer::Create(this, output_surface, resource_provider);
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
2523 bitmap->GetSize(), 2536 bitmap->GetSize(),
2524 resource_provider_->best_texture_format(), 2537 resource_provider_->best_texture_format(),
2525 ResourceProvider::TextureUsageAny); 2538 ResourceProvider::TextureUsageAny);
2526 2539
2527 ui_resource_map_[uid] = id; 2540 ui_resource_map_[uid] = id;
2528 resource_provider_->SetPixels(id, 2541 resource_provider_->SetPixels(id,
2529 reinterpret_cast<uint8_t*>(bitmap->GetPixels()), 2542 reinterpret_cast<uint8_t*>(bitmap->GetPixels()),
2530 gfx::Rect(bitmap->GetSize()), 2543 gfx::Rect(bitmap->GetSize()),
2531 gfx::Rect(bitmap->GetSize()), 2544 gfx::Rect(bitmap->GetSize()),
2532 gfx::Vector2d(0, 0)); 2545 gfx::Vector2d(0, 0));
2546
2547 // Once any UI resource creation has been completed, we can assume that the
2548 // evicted UI resources will have been recovered by the time CanDraw is
2549 // checked.
2550 ui_resources_evicted_ = false;
2533 } 2551 }
2534 2552
2535 void LayerTreeHostImpl::DeleteUIResource(UIResourceId uid) { 2553 void LayerTreeHostImpl::DeleteUIResource(UIResourceId uid) {
2536 ResourceProvider::ResourceId id = ResourceIdForUIResource(uid); 2554 ResourceProvider::ResourceId id = ResourceIdForUIResource(uid);
2537 if (id) { 2555 if (id) {
2538 resource_provider_->DeleteResource(id); 2556 resource_provider_->DeleteResource(id);
2539 ui_resource_map_.erase(uid); 2557 ui_resource_map_.erase(uid);
2540 } 2558 }
2541 } 2559 }
2542 2560
2543 ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource( 2561 ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource(
2544 UIResourceId uid) const { 2562 UIResourceId uid) const {
2545 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid); 2563 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid);
2546 if (iter != ui_resource_map_.end()) 2564 if (iter != ui_resource_map_.end())
2547 return iter->second; 2565 return iter->second;
2548 return 0; 2566 return 0;
2549 } 2567 }
2550 2568
2569 void LayerTreeHostImpl::ReleaseUIResources() {
2570 for (UIResourceMap::const_iterator iter = ui_resource_map_.begin();
2571 iter != ui_resource_map_.end();
2572 ++iter) {
2573 resource_provider_->DeleteResource(iter->second);
2574 }
2575 ui_resource_map_.clear();
2576 }
2577
2551 } // namespace cc 2578 } // 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