| Index: android_webview/browser/gpu_memory_manager.h
|
| diff --git a/android_webview/browser/gpu_memory_manager.h b/android_webview/browser/gpu_memory_manager.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e992100263fc66516b4bc5127eaa149a02d98a2d
|
| --- /dev/null
|
| +++ b/android_webview/browser/gpu_memory_manager.h
|
| @@ -0,0 +1,59 @@
|
| +// 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_GPU_MEMORY_MANAGER_H_
|
| +#define ANDROID_WEBVIEW_BROWSER_GPU_MEMORY_MANAGER_H_
|
| +
|
| +#include <list>
|
| +#include "android_webview/browser/shared_renderer_state.h"
|
| +#include "base/basictypes.h"
|
| +#include "base/synchronization/lock.h"
|
| +#include "content/public/browser/android/synchronous_compositor.h"
|
| +
|
| +namespace android_webview {
|
| +
|
| +namespace {
|
| + typedef content::SynchronousCompositorMemoryPolicy MemoryPolicy;
|
| + typedef GLViewRendererManager::Key Key;
|
| +} // namespace
|
| +
|
| +// A global Gpu memory manager to keep track of gpu memory and 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 GpuMemoryManger does
|
| +// not keep track of how much memory each individual view is using.
|
| +class GpuMemoryManager {
|
| + public:
|
| + static GpuMemoryManager* GetInstance();
|
| +
|
| + // Updates the memory allocation in GpuMemoryManager. Evicts other views if
|
| + // memory allocation is over limit. |key| is the GLViewRendererManager key of
|
| + // the view that requests the resources.
|
| + void UpdateResources(MemoryPolicy& old_policy,
|
| + MemoryPolicy& new_policy,
|
| + Key key);
|
| +
|
| + private:
|
| + friend struct base::DefaultLazyInstanceTraits<GpuMemoryManager>;
|
| + GpuMemoryManager();
|
| + ~GpuMemoryManager();
|
| +
|
| + // 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.
|
| + MemoryPolicy EvictUntilSatisfied(MemoryPolicy desired_policy, Key key);
|
| +
|
| + MemoryPolicy allocated_;
|
| + // Gpu Memory in bytes
|
| + const static size_t kGpuMemoryLimit;
|
| + // On Android webview, One resource has a gralloc buffer backing it and one
|
| + // gralloc buffer has two file descriptors
|
| + const static size_t kNumResourcesLimit;
|
| + mutable base::Lock lock_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager);
|
| +};
|
| +} // namespace android_webview
|
| +
|
| +#endif
|
|
|