Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "android_webview/browser/global_tile_manager.h" | |
| 6 #include "android_webview/browser/tile_resource_consumer.h" | |
| 7 #include "base/lazy_instance.h" | |
| 8 | |
| 9 namespace android_webview { | |
| 10 | |
| 11 namespace { | |
| 12 base::LazyInstance<GlobalTileManager>::Leaky g_tile_manager = | |
|
boliu
2014/04/28 22:22:15
no indent for namespace
hush (inactive)
2014/04/30 20:50:17
Done.
| |
| 13 LAZY_INSTANCE_INITIALIZER; | |
|
boliu
2014/04/28 22:22:15
blank line below
hush (inactive)
2014/04/30 20:50:17
Done.
| |
| 14 // The soft limit of the number of file descriptors per process is 1024 on | |
| 15 // Android and gralloc buffers may not be the only thing that uses file | |
| 16 // descriptors. For each tile, there is a gralloc buffer backing it, which | |
| 17 // uses 2 FDs. | |
| 18 const size_t kNumTilesLimit = 450; | |
| 19 } // namespace | |
| 20 | |
| 21 // static | |
| 22 GlobalTileManager* GlobalTileManager::GetInstance() { | |
| 23 return g_tile_manager.Pointer(); | |
| 24 } | |
| 25 | |
| 26 void GlobalTileManager::DidDrawGL(Key key) { | |
|
boliu
2014/04/28 22:22:15
Call this DidDraw, or DidUse. And group the code t
hush (inactive)
2014/04/30 20:50:17
Done.
| |
| 27 DCHECK(mru_list_.end() != key); | |
| 28 | |
| 29 inactive_views_ = key; | |
| 30 inactive_views_++; | |
|
boliu
2014/04/28 22:22:15
This is not what I described, you are only moving
hush (inactive)
2014/04/30 20:50:17
This is essentially the same. Talked in person
On
| |
| 31 mru_list_.splice(mru_list_.begin(), mru_list_, key); | |
| 32 } | |
| 33 | |
| 34 void GlobalTileManager::Remove(Key key) { | |
| 35 DCHECK(mru_list_.end() != key); | |
| 36 if (key == inactive_views_) | |
| 37 inactive_views_++; | |
| 38 mru_list_.erase(key); | |
| 39 } | |
| 40 | |
| 41 size_t GlobalTileManager::EvictUntilSatisfied( | |
| 42 size_t desired_num_tiles, Key key) { | |
| 43 size_t total_evicted_tiles = 0; | |
| 44 ListType::reverse_iterator it; | |
| 45 | |
| 46 // Evicts from the least recent drawn view, until the disired number of tiles | |
| 47 // can be reclaimed. | |
| 48 for (it = mru_list_.rbegin(); it != mru_list_.rend(); it++) { | |
|
boliu
2014/04/28 22:22:15
Shouldn't you begin at something like inactive_vie
hush (inactive)
2014/04/30 20:50:17
Yes.
On 2014/04/28 22:22:15, boliu wrote:
| |
| 49 // key represents the view that requested the eviction, so we don't need to | |
| 50 // evict the requester itself. | |
| 51 if (*it == *key) | |
| 52 continue; | |
| 53 | |
| 54 size_t evicted_tiles = (*it)->ForceDropTiles(); | |
| 55 total_evicted_tiles += evicted_tiles; | |
| 56 if (total_evicted_tiles >= desired_num_tiles) { | |
| 57 break; | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 return total_evicted_tiles; | |
| 62 } | |
| 63 | |
| 64 size_t GlobalTileManager::RequestTiles(size_t old_num_of_tiles, | |
| 65 size_t new_num_of_tiles, bool is_starved, Key key) { | |
|
boliu
2014/04/28 22:22:15
ditto on multi-line argument style
hush (inactive)
2014/04/30 20:50:17
Done.
| |
| 66 size_t num_of_active_views = | |
| 67 std::distance(mru_list_.begin(), inactive_views_); | |
| 68 size_t tiles_per_view_limit; | |
| 69 if (num_of_active_views == 0) | |
| 70 tiles_per_view_limit = kNumTilesLimit; | |
| 71 else | |
| 72 tiles_per_view_limit = kNumTilesLimit / num_of_active_views; | |
| 73 new_num_of_tiles = std::min(new_num_of_tiles, tiles_per_view_limit); | |
| 74 size_t tiles = allocated_tiles_ - old_num_of_tiles + new_num_of_tiles; | |
|
boliu
2014/04/28 22:22:15
s/tiles/new_total_allocated_tiles/
hush (inactive)
2014/04/30 20:50:17
Done.
| |
| 75 // Has enough tiles to satisfy the request. | |
| 76 if (tiles <= kNumTilesLimit) { | |
| 77 allocated_tiles_ = tiles; | |
|
boliu
2014/04/28 22:22:15
Because individual view policy is inside each view
hush (inactive)
2014/04/30 20:50:17
Done.
| |
| 78 return new_num_of_tiles; | |
| 79 } | |
| 80 | |
| 81 // Does not have enough tiles, but the request is not starved. Gives what's | |
| 82 // left to the requester. | |
| 83 if (!is_starved) { | |
|
boliu
2014/04/28 22:22:15
The staved concept does not help with stability at
hush (inactive)
2014/04/30 20:50:17
We talked about this in person...
On 2014/04/28 22
| |
| 84 size_t tiles_left = kNumTilesLimit - allocated_tiles_; | |
| 85 allocated_tiles_ = kNumTilesLimit; | |
| 86 return tiles_left + old_num_of_tiles; | |
| 87 } | |
| 88 | |
| 89 // Does not have enough tiles and the requester is starved. | |
| 90 size_t evicted_tiles = EvictUntilSatisfied(tiles - kNumTilesLimit, key); | |
| 91 tiles -= evicted_tiles; | |
| 92 allocated_tiles_ = tiles; | |
| 93 return new_num_of_tiles; | |
| 94 } | |
| 95 | |
| 96 GlobalTileManager::Key GlobalTileManager::PushBack( | |
| 97 TileResourceConsumer* tile_resource_consumer) { | |
| 98 DCHECK(mru_list_.end() == | |
| 99 std::find(mru_list_.begin(), mru_list_.end(), tile_resource_consumer)); | |
| 100 mru_list_.push_back(tile_resource_consumer); | |
| 101 Key back = mru_list_.end(); | |
| 102 back--; | |
| 103 return back; | |
| 104 } | |
| 105 | |
| 106 GlobalTileManager::GlobalTileManager() { | |
| 107 allocated_tiles_ = 0; | |
| 108 inactive_views_ = mru_list_.end(); | |
| 109 } | |
| 110 | |
| 111 GlobalTileManager::~GlobalTileManager() {} | |
| 112 | |
| 113 } // namespace webview | |
| OLD | NEW |