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

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

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 #include "android_webview/browser/gl_view_renderer_manager.h"
6 #include "android_webview/browser/gpu_memory_manager.h"
7 #include "base/lazy_instance.h"
8
9 #include "base/logging.h"
10 using base::AutoLock;
11
12 namespace android_webview {
13
14 namespace {
15 base::LazyInstance<GpuMemoryManager>::Leaky g_gpu_memory_manager =
16 LAZY_INSTANCE_INITIALIZER;
17 } // namespace
18
19 // TODO(hush): need to scale up/down this number based on your devide
20 const size_t GpuMemoryManager::kGpuMemoryLimit = 256 * 1024 * 1024;
boliu 2014/04/08 03:06:45 how about assume the limiting resource is always f
21 const size_t GpuMemoryManager::kNumResourcesLimit = 512;
22
23 // static
24 GpuMemoryManager* GpuMemoryManager::GetInstance() {
25 return g_gpu_memory_manager.Pointer();
26 }
27
28 MemoryPolicy GpuMemoryManager::EvictUntilSatisfied(
29 MemoryPolicy desired_policy, Key key) {
30 lock_.AssertAcquired();
31 MemoryPolicy total_evicted =
32 GLViewRendererManager::GetInstance()->
33 EvictUntilSatisfied(desired_policy, key);
34
35 return total_evicted;
36 }
37
38 void GpuMemoryManager::UpdateResources(
39 MemoryPolicy& old_policy, MemoryPolicy& new_policy, Key key) {
40 AutoLock auto_lock(lock_);
41 size_t gpu_memory = allocated_.bytes_limit - old_policy.bytes_limit +
42 new_policy.bytes_limit;
43 size_t num_resources = allocated_.num_resources_limit -
44 old_policy.num_resources_limit + new_policy.num_resources_limit;
45
46 if (gpu_memory > kGpuMemoryLimit || num_resources > kNumResourcesLimit) {
47 MemoryPolicy memory_to_evict;
48 if (gpu_memory > kGpuMemoryLimit) {
49 memory_to_evict.bytes_limit = gpu_memory - kGpuMemoryLimit;
50 }
51
52 if (num_resources > kNumResourcesLimit) {
53 memory_to_evict.num_resources_limit = num_resources - kNumResourcesLimit;
54 }
55
56 MemoryPolicy total_evicted = EvictUntilSatisfied(memory_to_evict, key);
57 gpu_memory -= total_evicted.bytes_limit;
58 num_resources -= total_evicted.num_resources_limit;
59 }
60
61 allocated_.bytes_limit = gpu_memory;
62 allocated_.num_resources_limit = num_resources;
63 }
64
65 GpuMemoryManager::GpuMemoryManager() {}
66
67 GpuMemoryManager::~GpuMemoryManager() {}
68
69 } // namespace webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698