From e190aa69756aecfaffabdd4c6d32cb6b3220d842 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Wed, 10 Nov 2010 19:01:29 -0800 Subject: [PATCH] Add new runtime debug flags. Change-Id: I07955de166a89b5053c6c13f250bb3e2936ca86e --- libs/hwui/Caches.cpp | 4 ++++ libs/hwui/Caches.h | 13 ++++++++++++- libs/hwui/OpenGLRenderer.cpp | 4 ++++ libs/hwui/PathCache.cpp | 8 ++++++++ libs/hwui/PathCache.h | 2 ++ libs/hwui/Properties.h | 23 +++++++++++++++++++++++ libs/hwui/TextureCache.cpp | 8 ++++++++ libs/hwui/TextureCache.h | 2 ++ 8 files changed, 63 insertions(+), 1 deletion(-) diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index 248e054b36554..2b498c67265f2 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -19,6 +19,7 @@ #include #include "Caches.h" +#include "Properties.h" namespace android { @@ -49,6 +50,9 @@ Caches::Caches(): Singleton(), blend(false), lastSrcMode(GL_ZERO), mCurrentBuffer = meshBuffer; mRegionMesh = NULL; + + mDebugLevel = readDebugLevel(); + LOGD("Enabling debug mode %d", mDebugLevel); } Caches::~Caches() { diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h index 77bbcd1a59050..2779dfdfed1c5 100644 --- a/libs/hwui/Caches.h +++ b/libs/hwui/Caches.h @@ -83,7 +83,7 @@ class Caches: public Singleton { friend class Singleton; - CacheLogger mlogger; + CacheLogger mLogger; GLuint mCurrentBuffer; @@ -92,6 +92,14 @@ class Caches: public Singleton { GLuint mRegionMeshIndices; public: + /** + * Indicates whether the renderer is in debug mode. + * This debug mode provides limited information to app developers. + */ + DebugLevel getDebugLevel() const { + return mDebugLevel; + } + /** * Binds the VBO used to render simple textured quads. */ @@ -145,6 +153,9 @@ public: ResourceCache resourceCache; Line line; + +private: + DebugLevel mDebugLevel; }; // class Caches }; // namespace uirenderer diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 19a597347cc2b..540f11580900a 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -163,6 +163,10 @@ void OpenGLRenderer::finish() { #endif #if DEBUG_MEMORY_USAGE mCaches.dumpMemoryUsage(); +#else + if (mCaches.getDebugLevel() & kDebugMemory) { + mCaches.dumpMemoryUsage(); + } #endif } diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp index 04d07dbbee8ab..7ff26dcaf080f 100644 --- a/libs/hwui/PathCache.cpp +++ b/libs/hwui/PathCache.cpp @@ -63,6 +63,8 @@ void PathCache::init() { GLint maxTextureSize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); mMaxTextureSize = maxTextureSize; + + mDebugEnabled = readDebugLevel() & kDebugCaches; } /////////////////////////////////////////////////////////////////////////////// @@ -98,6 +100,9 @@ void PathCache::operator()(PathCacheEntry& path, PathTexture*& texture) { PATH_LOGD("PathCache::callback: delete path: name, size, mSize = %d, %d, %d", texture->id, size, mSize); + if (mDebugEnabled) { + LOGD("Path deleted, size = %d", size); + } glDeleteTextures(1, &texture->id); delete texture; @@ -199,6 +204,9 @@ PathTexture* PathCache::addTexture(const PathCacheEntry& entry, mSize += size; PATH_LOGD("PathCache::get: create path: name, size, mSize = %d, %d, %d", texture->id, size, mSize); + if (mDebugEnabled) { + LOGD("Path created, size = %d", size); + } mCache.put(entry, texture); mLock.unlock(); } else { diff --git a/libs/hwui/PathCache.h b/libs/hwui/PathCache.h index 23aa7efecb4e6..0193f43d38e5a 100644 --- a/libs/hwui/PathCache.h +++ b/libs/hwui/PathCache.h @@ -176,6 +176,8 @@ private: uint32_t mMaxSize; GLuint mMaxTextureSize; + bool mDebugEnabled; + /** * Used to access mCache and mSize. All methods are accessed from a single * thread except for remove(). diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h index 813392bd9a83e..96d8b69075175 100644 --- a/libs/hwui/Properties.h +++ b/libs/hwui/Properties.h @@ -18,12 +18,27 @@ #define ANDROID_HWUI_PROPERTIES_H #include +#include /** * This file contains the list of system properties used to configure * the OpenGLRenderer. */ +/** + * Debug level for app developers. + */ +#define PROPERTY_DEBUG "hwui.debug_level" + +/** + * Debug levels. Debug levels are used as flags. + */ +enum DebugLevel { + kDebugDisabled = 0, + kDebugMemory = 1, + kDebugCaches = 2 +}; + // 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" @@ -56,4 +71,12 @@ #define DEFAULT_TEXT_BLACK_GAMMA_THRESHOLD 64 #define DEFAULT_TEXT_WHITE_GAMMA_THRESHOLD 192 +static DebugLevel readDebugLevel() { + char property[PROPERTY_VALUE_MAX]; + if (property_get(PROPERTY_DEBUG, property, NULL) > 0) { + return (DebugLevel) atoi(property); + } + return kDebugDisabled; +} + #endif // ANDROID_HWUI_PROPERTIES_H diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp index 2497925d66e16..1be6868cc0514 100644 --- a/libs/hwui/TextureCache.cpp +++ b/libs/hwui/TextureCache.cpp @@ -62,6 +62,8 @@ void TextureCache::init() { glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); LOGD(" Maximum texture dimension is %d pixels", mMaxTextureSize); + + mDebugEnabled = readDebugLevel() & kDebugCaches; } /////////////////////////////////////////////////////////////////////////////// @@ -96,6 +98,9 @@ void TextureCache::operator()(SkBitmap*& bitmap, Texture*& texture) { mSize -= texture->bitmapSize; TEXTURE_LOGD("TextureCache::callback: name, removed size, mSize = %d, %d, %d", texture->id, texture->bitmapSize, mSize); + if (mDebugEnabled) { + LOGD("Texture deleted, size = %d", texture->bitmapSize); + } glDeleteTextures(1, &texture->id); delete texture; } @@ -135,6 +140,9 @@ Texture* TextureCache::get(SkBitmap* bitmap) { mSize += size; TEXTURE_LOGD("TextureCache::get: create texture(%p): name, size, mSize = %d, %d, %d", bitmap, texture->id, size, mSize); + if (mDebugEnabled) { + LOGD("Texture created, size = %d", size); + } mCache.put(bitmap, texture); mLock.unlock(); } else { diff --git a/libs/hwui/TextureCache.h b/libs/hwui/TextureCache.h index 2ee88b1eff566..27693df99b0f9 100644 --- a/libs/hwui/TextureCache.h +++ b/libs/hwui/TextureCache.h @@ -107,6 +107,8 @@ private: uint32_t mMaxSize; GLint mMaxTextureSize; + bool mDebugEnabled; + /** * Used to access mCache and mSize. All methods are accessed from a single * thread except for remove().