Loading libs/hwui/Android.mk +9 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk BUGREPORT_FONT_CACHE_USAGE := true # Enables fine-grained GLES error checking # If set to true, every GLES call is wrapped & error checked # Has moderate overhead Loading Loading @@ -135,6 +137,13 @@ hwui_cflags += -Wno-free-nonheap-object # clang's warning is broken, see: https://llvm.org/bugs/show_bug.cgi?id=21629 hwui_cflags += -Wno-missing-braces ifeq (true, $(BUGREPORT_FONT_CACHE_USAGE)) hwui_src_files += \ font/FontCacheHistoryTracker.cpp hwui_cflags += -DBUGREPORT_FONT_CACHE_USAGE endif ifndef HWUI_COMPILE_SYMBOLS hwui_cflags += -fvisibility=hidden endif Loading libs/hwui/Caches.cpp +9 −8 Original line number Diff line number Diff line Loading @@ -21,6 +21,9 @@ #include "Properties.h" #include "renderstate/RenderState.h" #include "ShadowTessellator.h" #ifdef BUGREPORT_FONT_CACHE_USAGE #include "font/FontCacheHistoryTracker.h" #endif #include "utils/GLUtils.h" #include <cutils/properties.h> Loading Loading @@ -191,12 +194,7 @@ void Caches::dumpMemoryUsage(String8 &log) { log.appendFormat(" PatchCache %8d / %8d\n", patchCache.getSize(), patchCache.getMaxSize()); const uint32_t sizeA8 = fontRenderer.getFontRendererSize(GL_ALPHA); const uint32_t sizeRGBA = fontRenderer.getFontRendererSize(GL_RGBA); log.appendFormat(" FontRenderer A8 %8d / %8d\n", sizeA8, sizeA8); log.appendFormat(" FontRenderer RGBA %8d / %8d\n", sizeRGBA, sizeRGBA); log.appendFormat(" FontRenderer total %8d / %8d\n", sizeA8 + sizeRGBA, sizeA8 + sizeRGBA); fontRenderer.dumpMemoryUsage(log); log.appendFormat("Other:\n"); log.appendFormat(" FboCache %8d / %8d\n", Loading @@ -209,11 +207,14 @@ void Caches::dumpMemoryUsage(String8 &log) { total += tessellationCache.getSize(); total += dropShadowCache.getSize(); total += patchCache.getSize(); total += fontRenderer.getFontRendererSize(GL_ALPHA); total += fontRenderer.getFontRendererSize(GL_RGBA); total += fontRenderer.getSize(); log.appendFormat("Total memory usage:\n"); log.appendFormat(" %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f); #ifdef BUGREPORT_FONT_CACHE_USAGE fontRenderer.getFontRenderer().historyTracker().dump(log); #endif } /////////////////////////////////////////////////////////////////////////////// Loading libs/hwui/FontRenderer.cpp +67 −4 Original line number Diff line number Diff line Loading @@ -151,10 +151,17 @@ void FontRenderer::flushAllAndInvalidate() { for (uint32_t i = 0; i < mACacheTextures.size(); i++) { mACacheTextures[i]->init(); #ifdef BUGREPORT_FONT_CACHE_USAGE mHistoryTracker.glyphsCleared(mACacheTextures[i]); #endif } for (uint32_t i = 0; i < mRGBACacheTextures.size(); i++) { mRGBACacheTextures[i]->init(); #ifdef BUGREPORT_FONT_CACHE_USAGE mHistoryTracker.glyphsCleared(mRGBACacheTextures[i]); #endif } mDrawn = false; Loading @@ -166,6 +173,9 @@ void FontRenderer::flushLargeCaches(std::vector<CacheTexture*>& cacheTextures) { CacheTexture* cacheTexture = cacheTextures[i]; if (cacheTexture->getPixelBuffer()) { cacheTexture->init(); #ifdef BUGREPORT_FONT_CACHE_USAGE mHistoryTracker.glyphsCleared(cacheTexture); #endif LruCache<Font::FontDescription, Font*>::Iterator it(mActiveFonts); while (it.next()) { it.value()->invalidateTextureCache(cacheTexture); Loading Loading @@ -368,6 +378,10 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp } cachedGlyph->mIsValid = true; #ifdef BUGREPORT_FONT_CACHE_USAGE mHistoryTracker.glyphUploaded(cacheTexture, startX, startY, glyph.fWidth, glyph.fHeight); #endif } CacheTexture* FontRenderer::createCacheTexture(int width, int height, GLenum format, Loading Loading @@ -730,19 +744,68 @@ static uint32_t calculateCacheSize(const std::vector<CacheTexture*>& cacheTextur return size; } uint32_t FontRenderer::getCacheSize(GLenum format) const { static uint32_t calculateFreeCacheSize(const std::vector<CacheTexture*>& cacheTextures) { uint32_t size = 0; for (uint32_t i = 0; i < cacheTextures.size(); i++) { CacheTexture* cacheTexture = cacheTextures[i]; if (cacheTexture && cacheTexture->getPixelBuffer()) { size += cacheTexture->calculateFreeMemory(); } } return size; } const std::vector<CacheTexture*>& FontRenderer::cacheTexturesForFormat(GLenum format) const { switch (format) { case GL_ALPHA: { return calculateCacheSize(mACacheTextures); return mACacheTextures; } case GL_RGBA: { return calculateCacheSize(mRGBACacheTextures); return mRGBACacheTextures; } default: { return 0; LOG_ALWAYS_FATAL("Unsupported format: %d", format); // Impossible to hit this, but the compiler doesn't know that return *(new std::vector<CacheTexture*>()); } } } static void dumpTextures(String8& log, const char* tag, const std::vector<CacheTexture*>& cacheTextures) { for (uint32_t i = 0; i < cacheTextures.size(); i++) { CacheTexture* cacheTexture = cacheTextures[i]; if (cacheTexture && cacheTexture->getPixelBuffer()) { uint32_t free = cacheTexture->calculateFreeMemory(); uint32_t total = cacheTexture->getPixelBuffer()->getSize(); log.appendFormat(" %-4s texture %d %8d / %8d\n", tag, i, total - free, total); } } } void FontRenderer::dumpMemoryUsage(String8& log) const { const uint32_t sizeA8 = getCacheSize(GL_ALPHA); const uint32_t usedA8 = sizeA8 - getFreeCacheSize(GL_ALPHA); const uint32_t sizeRGBA = getCacheSize(GL_RGBA); const uint32_t usedRGBA = sizeRGBA - getFreeCacheSize(GL_RGBA); log.appendFormat(" FontRenderer A8 %8d / %8d\n", usedA8, sizeA8); dumpTextures(log, "A8", cacheTexturesForFormat(GL_ALPHA)); log.appendFormat(" FontRenderer RGBA %8d / %8d\n", usedRGBA, sizeRGBA); dumpTextures(log, "RGBA", cacheTexturesForFormat(GL_RGBA)); log.appendFormat(" FontRenderer total %8d / %8d\n", usedA8 + usedRGBA, sizeA8 + sizeRGBA); } uint32_t FontRenderer::getCacheSize(GLenum format) const { return calculateCacheSize(cacheTexturesForFormat(format)); } uint32_t FontRenderer::getFreeCacheSize(GLenum format) const { return calculateFreeCacheSize(cacheTexturesForFormat(format)); } uint32_t FontRenderer::getSize() const { return getCacheSize(GL_ALPHA) + getCacheSize(GL_RGBA); } }; // namespace uirenderer }; // namespace android libs/hwui/FontRenderer.h +18 −1 Original line number Diff line number Diff line Loading @@ -20,8 +20,12 @@ #include "font/CacheTexture.h" #include "font/CachedGlyphInfo.h" #include "font/Font.h" #ifdef BUGREPORT_FONT_CACHE_USAGE #include "font/FontCacheHistoryTracker.h" #endif #include <utils/LruCache.h> #include <utils/String8.h> #include <utils/StrongPointer.h> #include <SkPaint.h> Loading Loading @@ -117,7 +121,12 @@ public: mLinearFiltering = linearFiltering; } uint32_t getCacheSize(GLenum format) const; uint32_t getSize() const; void dumpMemoryUsage(String8& log) const; #ifdef BUGREPORT_FONT_CACHE_USAGE FontCacheHistoryTracker& historyTracker() { return mHistoryTracker; } #endif private: friend class Font; Loading Loading @@ -160,6 +169,10 @@ private: mUploadTexture = true; } const std::vector<CacheTexture*>& cacheTexturesForFormat(GLenum format) const; uint32_t getCacheSize(GLenum format) const; uint32_t getFreeCacheSize(GLenum format) const; uint32_t mSmallCacheWidth; uint32_t mSmallCacheHeight; uint32_t mLargeCacheWidth; Loading @@ -184,6 +197,10 @@ private: bool mLinearFiltering; #ifdef BUGREPORT_FONT_CACHE_USAGE FontCacheHistoryTracker mHistoryTracker; #endif #ifdef ANDROID_ENABLE_RENDERSCRIPT // RS constructs RSC::sp<RSC::RS> mRs; Loading libs/hwui/GammaFontRenderer.h +12 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ #include <SkPaint.h> #include <utils/String8.h> namespace android { namespace uirenderer { Loading @@ -46,8 +48,16 @@ public: return *mRenderer; } uint32_t getFontRendererSize(GLenum format) const { return mRenderer ? mRenderer->getCacheSize(format) : 0; void dumpMemoryUsage(String8& log) const { if (mRenderer) { mRenderer->dumpMemoryUsage(log); } else { log.appendFormat("FontRenderer doesn't exist.\n"); } } uint32_t getSize() const { return mRenderer ? mRenderer->getSize() : 0; } void endPrecaching(); Loading Loading
libs/hwui/Android.mk +9 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk BUGREPORT_FONT_CACHE_USAGE := true # Enables fine-grained GLES error checking # If set to true, every GLES call is wrapped & error checked # Has moderate overhead Loading Loading @@ -135,6 +137,13 @@ hwui_cflags += -Wno-free-nonheap-object # clang's warning is broken, see: https://llvm.org/bugs/show_bug.cgi?id=21629 hwui_cflags += -Wno-missing-braces ifeq (true, $(BUGREPORT_FONT_CACHE_USAGE)) hwui_src_files += \ font/FontCacheHistoryTracker.cpp hwui_cflags += -DBUGREPORT_FONT_CACHE_USAGE endif ifndef HWUI_COMPILE_SYMBOLS hwui_cflags += -fvisibility=hidden endif Loading
libs/hwui/Caches.cpp +9 −8 Original line number Diff line number Diff line Loading @@ -21,6 +21,9 @@ #include "Properties.h" #include "renderstate/RenderState.h" #include "ShadowTessellator.h" #ifdef BUGREPORT_FONT_CACHE_USAGE #include "font/FontCacheHistoryTracker.h" #endif #include "utils/GLUtils.h" #include <cutils/properties.h> Loading Loading @@ -191,12 +194,7 @@ void Caches::dumpMemoryUsage(String8 &log) { log.appendFormat(" PatchCache %8d / %8d\n", patchCache.getSize(), patchCache.getMaxSize()); const uint32_t sizeA8 = fontRenderer.getFontRendererSize(GL_ALPHA); const uint32_t sizeRGBA = fontRenderer.getFontRendererSize(GL_RGBA); log.appendFormat(" FontRenderer A8 %8d / %8d\n", sizeA8, sizeA8); log.appendFormat(" FontRenderer RGBA %8d / %8d\n", sizeRGBA, sizeRGBA); log.appendFormat(" FontRenderer total %8d / %8d\n", sizeA8 + sizeRGBA, sizeA8 + sizeRGBA); fontRenderer.dumpMemoryUsage(log); log.appendFormat("Other:\n"); log.appendFormat(" FboCache %8d / %8d\n", Loading @@ -209,11 +207,14 @@ void Caches::dumpMemoryUsage(String8 &log) { total += tessellationCache.getSize(); total += dropShadowCache.getSize(); total += patchCache.getSize(); total += fontRenderer.getFontRendererSize(GL_ALPHA); total += fontRenderer.getFontRendererSize(GL_RGBA); total += fontRenderer.getSize(); log.appendFormat("Total memory usage:\n"); log.appendFormat(" %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f); #ifdef BUGREPORT_FONT_CACHE_USAGE fontRenderer.getFontRenderer().historyTracker().dump(log); #endif } /////////////////////////////////////////////////////////////////////////////// Loading
libs/hwui/FontRenderer.cpp +67 −4 Original line number Diff line number Diff line Loading @@ -151,10 +151,17 @@ void FontRenderer::flushAllAndInvalidate() { for (uint32_t i = 0; i < mACacheTextures.size(); i++) { mACacheTextures[i]->init(); #ifdef BUGREPORT_FONT_CACHE_USAGE mHistoryTracker.glyphsCleared(mACacheTextures[i]); #endif } for (uint32_t i = 0; i < mRGBACacheTextures.size(); i++) { mRGBACacheTextures[i]->init(); #ifdef BUGREPORT_FONT_CACHE_USAGE mHistoryTracker.glyphsCleared(mRGBACacheTextures[i]); #endif } mDrawn = false; Loading @@ -166,6 +173,9 @@ void FontRenderer::flushLargeCaches(std::vector<CacheTexture*>& cacheTextures) { CacheTexture* cacheTexture = cacheTextures[i]; if (cacheTexture->getPixelBuffer()) { cacheTexture->init(); #ifdef BUGREPORT_FONT_CACHE_USAGE mHistoryTracker.glyphsCleared(cacheTexture); #endif LruCache<Font::FontDescription, Font*>::Iterator it(mActiveFonts); while (it.next()) { it.value()->invalidateTextureCache(cacheTexture); Loading Loading @@ -368,6 +378,10 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp } cachedGlyph->mIsValid = true; #ifdef BUGREPORT_FONT_CACHE_USAGE mHistoryTracker.glyphUploaded(cacheTexture, startX, startY, glyph.fWidth, glyph.fHeight); #endif } CacheTexture* FontRenderer::createCacheTexture(int width, int height, GLenum format, Loading Loading @@ -730,19 +744,68 @@ static uint32_t calculateCacheSize(const std::vector<CacheTexture*>& cacheTextur return size; } uint32_t FontRenderer::getCacheSize(GLenum format) const { static uint32_t calculateFreeCacheSize(const std::vector<CacheTexture*>& cacheTextures) { uint32_t size = 0; for (uint32_t i = 0; i < cacheTextures.size(); i++) { CacheTexture* cacheTexture = cacheTextures[i]; if (cacheTexture && cacheTexture->getPixelBuffer()) { size += cacheTexture->calculateFreeMemory(); } } return size; } const std::vector<CacheTexture*>& FontRenderer::cacheTexturesForFormat(GLenum format) const { switch (format) { case GL_ALPHA: { return calculateCacheSize(mACacheTextures); return mACacheTextures; } case GL_RGBA: { return calculateCacheSize(mRGBACacheTextures); return mRGBACacheTextures; } default: { return 0; LOG_ALWAYS_FATAL("Unsupported format: %d", format); // Impossible to hit this, but the compiler doesn't know that return *(new std::vector<CacheTexture*>()); } } } static void dumpTextures(String8& log, const char* tag, const std::vector<CacheTexture*>& cacheTextures) { for (uint32_t i = 0; i < cacheTextures.size(); i++) { CacheTexture* cacheTexture = cacheTextures[i]; if (cacheTexture && cacheTexture->getPixelBuffer()) { uint32_t free = cacheTexture->calculateFreeMemory(); uint32_t total = cacheTexture->getPixelBuffer()->getSize(); log.appendFormat(" %-4s texture %d %8d / %8d\n", tag, i, total - free, total); } } } void FontRenderer::dumpMemoryUsage(String8& log) const { const uint32_t sizeA8 = getCacheSize(GL_ALPHA); const uint32_t usedA8 = sizeA8 - getFreeCacheSize(GL_ALPHA); const uint32_t sizeRGBA = getCacheSize(GL_RGBA); const uint32_t usedRGBA = sizeRGBA - getFreeCacheSize(GL_RGBA); log.appendFormat(" FontRenderer A8 %8d / %8d\n", usedA8, sizeA8); dumpTextures(log, "A8", cacheTexturesForFormat(GL_ALPHA)); log.appendFormat(" FontRenderer RGBA %8d / %8d\n", usedRGBA, sizeRGBA); dumpTextures(log, "RGBA", cacheTexturesForFormat(GL_RGBA)); log.appendFormat(" FontRenderer total %8d / %8d\n", usedA8 + usedRGBA, sizeA8 + sizeRGBA); } uint32_t FontRenderer::getCacheSize(GLenum format) const { return calculateCacheSize(cacheTexturesForFormat(format)); } uint32_t FontRenderer::getFreeCacheSize(GLenum format) const { return calculateFreeCacheSize(cacheTexturesForFormat(format)); } uint32_t FontRenderer::getSize() const { return getCacheSize(GL_ALPHA) + getCacheSize(GL_RGBA); } }; // namespace uirenderer }; // namespace android
libs/hwui/FontRenderer.h +18 −1 Original line number Diff line number Diff line Loading @@ -20,8 +20,12 @@ #include "font/CacheTexture.h" #include "font/CachedGlyphInfo.h" #include "font/Font.h" #ifdef BUGREPORT_FONT_CACHE_USAGE #include "font/FontCacheHistoryTracker.h" #endif #include <utils/LruCache.h> #include <utils/String8.h> #include <utils/StrongPointer.h> #include <SkPaint.h> Loading Loading @@ -117,7 +121,12 @@ public: mLinearFiltering = linearFiltering; } uint32_t getCacheSize(GLenum format) const; uint32_t getSize() const; void dumpMemoryUsage(String8& log) const; #ifdef BUGREPORT_FONT_CACHE_USAGE FontCacheHistoryTracker& historyTracker() { return mHistoryTracker; } #endif private: friend class Font; Loading Loading @@ -160,6 +169,10 @@ private: mUploadTexture = true; } const std::vector<CacheTexture*>& cacheTexturesForFormat(GLenum format) const; uint32_t getCacheSize(GLenum format) const; uint32_t getFreeCacheSize(GLenum format) const; uint32_t mSmallCacheWidth; uint32_t mSmallCacheHeight; uint32_t mLargeCacheWidth; Loading @@ -184,6 +197,10 @@ private: bool mLinearFiltering; #ifdef BUGREPORT_FONT_CACHE_USAGE FontCacheHistoryTracker mHistoryTracker; #endif #ifdef ANDROID_ENABLE_RENDERSCRIPT // RS constructs RSC::sp<RSC::RS> mRs; Loading
libs/hwui/GammaFontRenderer.h +12 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ #include <SkPaint.h> #include <utils/String8.h> namespace android { namespace uirenderer { Loading @@ -46,8 +48,16 @@ public: return *mRenderer; } uint32_t getFontRendererSize(GLenum format) const { return mRenderer ? mRenderer->getCacheSize(format) : 0; void dumpMemoryUsage(String8& log) const { if (mRenderer) { mRenderer->dumpMemoryUsage(log); } else { log.appendFormat("FontRenderer doesn't exist.\n"); } } uint32_t getSize() const { return mRenderer ? mRenderer->getSize() : 0; } void endPrecaching(); Loading