Chromium Code Reviews| 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..5b39316dee70d52e96fbbfeb376ea30f257f4bd0 |
| --- /dev/null |
| +++ b/android_webview/browser/global_tile_manager.h |
| @@ -0,0 +1,64 @@ |
| +// 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 "base/basictypes.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/synchronization/lock.h" |
| + |
| +namespace android_webview { |
| + |
| +class HardwareRenderer; |
| + |
| +// 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 { |
|
mkosiba (inactive)
2014/04/23 14:10:08
*cough* unittests *cough* :)
|
| + private: |
| + typedef std::list<HardwareRenderer*> 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 |is_starved| 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 is_starved, Key key); |
| + |
| + // Continues evicting the least recently drawn views until freeing up at least |
| + // amount of memory specified by |desired_policy| to draw a view specified |
| + // by |key|. |
| + // Returns the amount of memory that was actually evicted. |
| + // This function is called when a requester is starved. |
| + size_t EvictUntilSatisfied(size_t desired_num_tiles, Key key); |
| + |
| + Key PushBack(HardwareRenderer* hardware_renderer); |
| + |
| + // |key| must be already in manager. Move renderer corresponding to |key| to |
| + // most recent. |
| + void DidDrawGL(Key key); |
| + |
| + void Remove(Key key); |
| + private: |
| + friend struct base::DefaultLazyInstanceTraits<GlobalTileManager>; |
| + GlobalTileManager(); |
| + ~GlobalTileManager(); |
| + size_t 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 |