diff options
| author | 2010-07-01 18:26:52 -0700 | |
|---|---|---|
| committer | 2010-07-01 18:26:52 -0700 | |
| commit | 121e2242565d5f09ad83a2d33ecd2225838802c5 (patch) | |
| tree | 9c87b01a24909f832e00e9448fc2feb8241e41d1 /libs/hwui/OpenGLRenderer.cpp | |
| parent | 37f447338e4633461253539e62c9b8eae04de3b3 (diff) | |
Track the size in memory of the texture cache.
The texture cache was previously checking the number of stored textures. This was
not very useful as this could easily lead to an abuse of memory. The new cache
instead tracks the total size occupied in RAM by the cached textures. When a new
texture is generated, older textures are kicked out as needed.
Change-Id: Ib27142f4a018d5bf84774c1fb6f45a67a85f20bc
Diffstat (limited to 'libs/hwui/OpenGLRenderer.cpp')
| -rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 8b4fb9bca24a..095d58b81a89 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -22,6 +22,7 @@ #include <SkCanvas.h> +#include <cutils/properties.h> #include <utils/Log.h> #include "OpenGLRenderer.h" @@ -33,7 +34,15 @@ namespace uirenderer { // Defines /////////////////////////////////////////////////////////////////////////////// -#define MAX_TEXTURE_COUNT 128 +// These properties are defined in mega-bytes +#define PROPERTY_TEXTURE_CACHE_SIZE "ro.hwui.texture_cache_size" +#define PROPERTY_LAYER_CACHE_SIZE "ro.hwui.layer_cache_size" + +// Converts a number of mega-bytes into bytes +#define MB(s) s * 1024 * 1024 + +#define DEFAULT_TEXTURE_CACHE_SIZE MB(20) +#define DEFAULT_LAYER_CACHE_SIZE MB(10) #define SV(x, y) { { x, y } } #define FV(x, y, u, v) { { x, y }, { u, v } } @@ -83,9 +92,14 @@ static const Blender gBlends[] = { // Constructors/destructor /////////////////////////////////////////////////////////////////////////////// -OpenGLRenderer::OpenGLRenderer(): mTextureCache(MAX_TEXTURE_COUNT) { +OpenGLRenderer::OpenGLRenderer(): mTextureCache(DEFAULT_TEXTURE_CACHE_SIZE) { LOGD("Create OpenGLRenderer"); + char property[PROPERTY_VALUE_MAX]; + if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, NULL) > 0) { + mTextureCache.setMaxSize(MB(atoi(property))); + } + mDrawColorShader = new DrawColorProgram; mDrawTextureShader = new DrawTextureProgram; @@ -397,6 +411,8 @@ bool OpenGLRenderer::clipRect(float left, float top, float right, float bottom) void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, const SkPaint* paint) { const Texture* texture = mTextureCache.get(bitmap); + LOGD("Texture cache size %d", mTextureCache.getSize()); + LOGD(" max size %d", mTextureCache.getMaxSize()); int alpha; SkXfermode::Mode mode; |