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

Unified Diff: android_webview/browser/global_tile_manager.cc

Issue 643993005: Remove limit on number of resources in cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no cc change Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « android_webview/browser/global_tile_manager.h ('k') | android_webview/browser/global_tile_manager_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/browser/global_tile_manager.cc
diff --git a/android_webview/browser/global_tile_manager.cc b/android_webview/browser/global_tile_manager.cc
deleted file mode 100644
index 200a7ea68a942c2cd0b3867d3e8da51691bd6395..0000000000000000000000000000000000000000
--- a/android_webview/browser/global_tile_manager.cc
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "android_webview/browser/global_tile_manager.h"
-#include "android_webview/browser/global_tile_manager_client.h"
-#include "base/lazy_instance.h"
-
-using content::SynchronousCompositorMemoryPolicy;
-
-namespace android_webview {
-
-namespace {
-
-base::LazyInstance<GlobalTileManager>::Leaky g_tile_manager =
- LAZY_INSTANCE_INITIALIZER;
-
-// The soft limit of the number of file descriptors per process is 1024 on
-// Android and gralloc buffers may not be the only thing that uses file
-// descriptors. For each tile, there is a gralloc buffer backing it, which
-// uses 2 FDs.
-const size_t kNumTilesLimit = 450;
-
-} // namespace
-
-// static
-GlobalTileManager* GlobalTileManager::GetInstance() {
- return g_tile_manager.Pointer();
-}
-
-void GlobalTileManager::Remove(Key key) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- DCHECK(mru_list_.end() != key);
-
- total_allocated_tiles_ -= (*key)->GetMemoryPolicy().num_resources_limit;
- mru_list_.erase(key);
- DCHECK(IsConsistent());
-}
-
-size_t GlobalTileManager::Evict(size_t desired_num_tiles, Key key) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- size_t total_evicted_tiles = 0;
-
- // Evicts from the least recent drawn view, until the disired number of tiles
- // can be reclaimed, or until we've evicted all inactive views.
- ListType::reverse_iterator it;
- for (it = mru_list_.rbegin(); it != mru_list_.rend(); it++) {
- // key represents the view that requested the eviction, so we don't need to
- // evict the requester itself. And we only evict the inactive views,
- // which are all the views after the requester.
- if (*it == *key)
- break;
-
- size_t evicted_tiles = (*it)->GetMemoryPolicy().num_resources_limit;
- SynchronousCompositorMemoryPolicy zero_policy;
- (*it)->SetMemoryPolicy(zero_policy, true);
-
- total_evicted_tiles += evicted_tiles;
- if (total_evicted_tiles >= desired_num_tiles)
- break;
- }
-
- return total_evicted_tiles;
-}
-
-void GlobalTileManager::SetTileLimit(size_t num_tiles_limit) {
- num_tiles_limit_ = num_tiles_limit;
-}
-
-void GlobalTileManager::RequestTiles(
- SynchronousCompositorMemoryPolicy new_policy,
- Key key) {
- DCHECK(IsConsistent());
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- size_t new_num_of_tiles = new_policy.num_resources_limit;
- size_t old_num_of_tiles = (*key)->GetMemoryPolicy().num_resources_limit;
- size_t num_of_active_views = std::distance(mru_list_.begin(), key) + 1;
- size_t tiles_per_view_limit;
- if (num_of_active_views == 0)
- tiles_per_view_limit = num_tiles_limit_;
- else
- tiles_per_view_limit = num_tiles_limit_ / num_of_active_views;
- new_num_of_tiles = std::min(new_num_of_tiles, tiles_per_view_limit);
- size_t new_total_allocated_tiles =
- total_allocated_tiles_ - old_num_of_tiles + new_num_of_tiles;
- // Has enough tiles to satisfy the request.
- if (new_total_allocated_tiles <= num_tiles_limit_) {
- total_allocated_tiles_ = new_total_allocated_tiles;
- new_policy.num_resources_limit = new_num_of_tiles;
- (*key)->SetMemoryPolicy(new_policy, false);
- return;
- }
-
- // Does not have enough tiles. Now evict other clients' tiles.
- size_t tiles_left = num_tiles_limit_ - total_allocated_tiles_;
-
- size_t evicted_tiles =
- Evict(new_total_allocated_tiles - num_tiles_limit_, key);
- if (evicted_tiles >= new_total_allocated_tiles - num_tiles_limit_) {
- new_total_allocated_tiles -= evicted_tiles;
- total_allocated_tiles_ = new_total_allocated_tiles;
- new_policy.num_resources_limit = new_num_of_tiles;
- (*key)->SetMemoryPolicy(new_policy, false);
- return;
- } else {
- total_allocated_tiles_ = num_tiles_limit_;
- new_policy.num_resources_limit =
- tiles_left + old_num_of_tiles + evicted_tiles;
- (*key)->SetMemoryPolicy(new_policy, false);
- return;
- }
-}
-
-GlobalTileManager::Key GlobalTileManager::PushBack(
- GlobalTileManagerClient* client) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- DCHECK(mru_list_.end() ==
- std::find(mru_list_.begin(), mru_list_.end(), client));
- mru_list_.push_back(client);
- Key back = mru_list_.end();
- back--;
- return back;
-}
-
-void GlobalTileManager::DidUse(Key key) {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread());
- DCHECK(mru_list_.end() != key);
-
- mru_list_.splice(mru_list_.begin(), mru_list_, key);
-}
-
-GlobalTileManager::GlobalTileManager()
- : num_tiles_limit_(kNumTilesLimit), total_allocated_tiles_(0) {
-}
-
-GlobalTileManager::~GlobalTileManager() {
-}
-
-bool GlobalTileManager::IsConsistent() const {
- size_t total_tiles = 0;
- ListType::const_iterator it;
- for (it = mru_list_.begin(); it != mru_list_.end(); it++) {
- total_tiles += (*it)->GetMemoryPolicy().num_resources_limit;
- }
-
- bool is_consistent = (total_tiles <= num_tiles_limit_ &&
- total_tiles == total_allocated_tiles_);
-
- return is_consistent;
-}
-
-} // namespace webview
« no previous file with comments | « android_webview/browser/global_tile_manager.h ('k') | android_webview/browser/global_tile_manager_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698