From 121e2242565d5f09ad83a2d33ecd2225838802c5 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Thu, 1 Jul 2010 18:26:52 -0700 Subject: 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 --- libs/hwui/OpenGLRenderer.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'libs/hwui/OpenGLRenderer.cpp') diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 8b4fb9b..095d58b 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -22,6 +22,7 @@ #include +#include #include #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; -- cgit v1.1