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

Unified 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: address Bo's comments Created 6 years, 8 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
Index: android_webview/browser/global_tile_manager.h
diff --git a/android_webview/browser/global_tile_manager.h b/android_webview/browser/global_tile_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..718fc1c870037e1a414fbd4534152da4bb598fd6
--- /dev/null
+++ b/android_webview/browser/global_tile_manager.h
@@ -0,0 +1,73 @@
+// 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.
+
+#ifndef ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_H_
+#define ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_H_
+
+#include <list>
+#include "android_webview/browser/global_tile_manager_client.h"
+#include "base/basictypes.h"
+#include "base/lazy_instance.h"
+#include "base/synchronization/lock.h"
+
+namespace android_webview {
+
+// A global tile manager to keep track of the number of tile resources. Each
+// tile needs file descriptors (typically 2) and there is a soft limit of 1024
+// file descriptors per Android process. The GlobalTileManager does not keep
+// track of how many tiles each individual view is actually using. The purpose
+// of GlobalTileManager is to behave gracefully (as in not crashing) when the
+// embedder of webview creates a lot of webviews and draw them at the same time.
+class GlobalTileManager {
+ private:
+ typedef std::list<GlobalTileManagerClient*> ListType;
+
+ public:
+ typedef ListType::iterator Key;
+ static GlobalTileManager* GetInstance();
+
+ // Requests the |num_of_tiles| from the available global pool. Returns the
+ // actual number of tiles granted to the requester. If |needs_eviction| is
+ // true, the GlobalTileManager will evict tiles allocated to other
+ // requesters.
+ size_t RequestTiles(size_t old_num_of_tiles,
+ size_t new_num_of_tiles,
+ bool needs_eviction,
+ Key key);
+
+ Key PushBack(GlobalTileManagerClient* client);
+
+ // |key| must be already in manager. Move the tile manager client
+ // corresponding to |key| to most recent.
+ void DidUse(Key key);
+
+ void Remove(Key key);
+
+ private:
+ friend struct base::DefaultLazyInstanceTraits<GlobalTileManager>;
+ GlobalTileManager();
+ ~GlobalTileManager();
+
+ // Continues evicting the inactive views until freeing up at least amount of
+ // tiles specified by |desired_num_tiles| to draw a view specified by |key|,
+ // or until all inactive views have been evicted. Returns the amount of
+ // memory that was actually evicted. This function is called when a
+ // requester is starved.
+ size_t Evict(size_t desired_num_tiles, Key key);
+
+ // Check that the sum of all client's tiles is equal to
+ // total_allocated_tiles_. This is only called when DCHECK_IS_ON
+ bool CheckConsistency() const;
+
+ size_t total_allocated_tiles_;
+ ListType mru_list_;
+ // The list of inactive views is from inactive_views_ to mru_list_end().
+ Key inactive_views_;
+
+ DISALLOW_COPY_AND_ASSIGN(GlobalTileManager);
+};
+
+} // namespace android_webview
+
+#endif // ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698