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

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

Issue 226363004: Global GPU memory manager for android webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 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_GPU_MEMORY_MANAGER_H_
6 #define ANDROID_WEBVIEW_BROWSER_GPU_MEMORY_MANAGER_H_
7
8 #include <list>
9 #include "android_webview/browser/shared_renderer_state.h"
10 #include "base/basictypes.h"
11 #include "base/synchronization/lock.h"
12 #include "content/public/browser/android/synchronous_compositor.h"
13
14 namespace android_webview {
15
16 namespace {
17 typedef content::SynchronousCompositorMemoryPolicy MemoryPolicy;
18 typedef GLViewRendererManager::Key Key;
19 } // namespace
20
21 // A global Gpu memory manager to keep track of gpu memory and number of tile
22 // resources. Each tile needs file descriptors (typically 2) and there is a soft
23 // limit of 1024 file descriptors per Android process. The GpuMemoryManger does
24 // not keep track of how much memory each individual view is using.
25 class GpuMemoryManager {
26 public:
27 static GpuMemoryManager* GetInstance();
28
29 // Updates the memory allocation in GpuMemoryManager. Evicts other views if
30 // memory allocation is over limit. |key| is the GLViewRendererManager key of
31 // the view that requests the resources.
32 void UpdateResources(MemoryPolicy& old_policy,
33 MemoryPolicy& new_policy,
34 Key key);
35
36 private:
37 friend struct base::DefaultLazyInstanceTraits<GpuMemoryManager>;
38 GpuMemoryManager();
39 ~GpuMemoryManager();
40
41 // Continues evicting the least recently drawn views until freeing up at least
42 // amount of memory specified by |desired_policy| to draw a view specified
43 // by |key|.
44 // Returns the amount of memory that was actually evicted.
45 MemoryPolicy EvictUntilSatisfied(MemoryPolicy desired_policy, Key key);
46
47 MemoryPolicy allocated_;
48 // Gpu Memory in bytes
49 const static size_t kGpuMemoryLimit;
50 // On Android webview, One resource has a gralloc buffer backing it and one
51 // gralloc buffer has two file descriptors
52 const static size_t kNumResourcesLimit;
53 mutable base::Lock lock_;
54
55 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager);
56 };
57 } // namespace android_webview
58
59 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698