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

Side by Side Diff: android_webview/browser/global_tile_manager.h

Issue 226363004: Global GPU memory manager for android webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use command line switch and move that from HR to BVR. Created 6 years, 7 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
OLDNEW
(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 #ifndef ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_H_
6 #define ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_H_
7
8 #include <list>
9 #include "base/basictypes.h"
10 #include "base/lazy_instance.h"
11 #include "base/sequence_checker.h"
12 #include "base/synchronization/lock.h"
13
14 namespace android_webview {
15
16 class GlobalTileManagerClient;
17
18 // A global tile manager that keeps track of the number of tile resources. Each
19 // tile needs file descriptors (typically 2) and there is a soft limit of 1024
20 // file descriptors per Android process. The GlobalTileManager does not keep
21 // track of how many tiles each individual view is actually using. The purpose
22 // of GlobalTileManager is to behave gracefully (as in not crashing) when the
23 // embedder of webview creates a lot of webviews and draw them at the same time.
24 class GlobalTileManager {
25 private:
26 typedef std::list<GlobalTileManagerClient*> ListType;
27
28 public:
29 typedef ListType::iterator Key;
30 static GlobalTileManager* GetInstance();
31
32 // Requests the |num_of_tiles| from the available global pool. Calls
33 // GlobalTileManagerClient.SetNumTiles after the manager determines how many
34 // tiles are available for the client. The tile policy on the clients are not
35 // immediately enforced, unless |effective_immediately| is true. If the
36 // number of tiles left are not enough to satisfy the request, the manager
37 // will evict tiles allocated to other clients.
38 void RequestTiles(size_t new_num_of_tiles,
39 bool effective_immediately,
40 Key key);
41
42 Key PushBack(GlobalTileManagerClient* client);
43
44 // |key| must be already in manager. Move the tile manager client
45 // corresponding to |key| to most recent. This function should be called after
46 // RequestTiles.
47 void DidUse(Key key);
48
49 void Remove(Key key);
50
51 private:
52 friend struct base::DefaultLazyInstanceTraits<GlobalTileManager>;
53 GlobalTileManager();
54 ~GlobalTileManager();
55
56 // Continues evicting the inactive views until freeing up at least amount of
57 // tiles specified by |desired_num_tiles| to draw a view specified by |key|,
58 // or until all inactive views have been evicted. Returns the amount of
59 // memory that was actually evicted. This function is called when a
60 // request cannot be satisfied.
61 size_t Evict(size_t desired_num_tiles, Key key);
62
63 // Check that the sum of all client's tiles is equal to
64 // total_allocated_tiles_.
65 bool IsConsistent() const;
66
67 size_t total_allocated_tiles_;
68 ListType mru_list_;
69 base::SequenceChecker sequence_checker_;
70
71 DISALLOW_COPY_AND_ASSIGN(GlobalTileManager);
72 };
73
74 } // namespace android_webview
75
76 #endif // ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698