HWUI: calculate used memory in FontCache for gfxinfo
am: baf29e7cf4
Change-Id: I0e100f38166f191552172bef640f73157c45b714
This commit is contained in:
@@ -195,12 +195,7 @@ void Caches::dumpMemoryUsage(String8 &log) {
|
|||||||
log.appendFormat(" PatchCache %8d / %8d\n",
|
log.appendFormat(" PatchCache %8d / %8d\n",
|
||||||
patchCache.getSize(), patchCache.getMaxSize());
|
patchCache.getSize(), patchCache.getMaxSize());
|
||||||
|
|
||||||
const uint32_t sizeA8 = fontRenderer.getFontRendererSize(GL_ALPHA);
|
fontRenderer.dumpMemoryUsage(log);
|
||||||
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);
|
|
||||||
|
|
||||||
log.appendFormat("Other:\n");
|
log.appendFormat("Other:\n");
|
||||||
log.appendFormat(" FboCache %8d / %8d\n",
|
log.appendFormat(" FboCache %8d / %8d\n",
|
||||||
@@ -213,8 +208,7 @@ void Caches::dumpMemoryUsage(String8 &log) {
|
|||||||
total += tessellationCache.getSize();
|
total += tessellationCache.getSize();
|
||||||
total += dropShadowCache.getSize();
|
total += dropShadowCache.getSize();
|
||||||
total += patchCache.getSize();
|
total += patchCache.getSize();
|
||||||
total += fontRenderer.getFontRendererSize(GL_ALPHA);
|
total += fontRenderer.getSize();
|
||||||
total += fontRenderer.getFontRendererSize(GL_RGBA);
|
|
||||||
|
|
||||||
log.appendFormat("Total memory usage:\n");
|
log.appendFormat("Total memory usage:\n");
|
||||||
log.appendFormat(" %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f);
|
log.appendFormat(" %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f);
|
||||||
|
|||||||
@@ -747,19 +747,68 @@ static uint32_t calculateCacheSize(const std::vector<CacheTexture*>& cacheTextur
|
|||||||
return size;
|
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) {
|
switch (format) {
|
||||||
case GL_ALPHA: {
|
case GL_ALPHA: {
|
||||||
return calculateCacheSize(mACacheTextures);
|
return mACacheTextures;
|
||||||
}
|
}
|
||||||
case GL_RGBA: {
|
case GL_RGBA: {
|
||||||
return calculateCacheSize(mRGBACacheTextures);
|
return mRGBACacheTextures;
|
||||||
}
|
}
|
||||||
default: {
|
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 uirenderer
|
||||||
}; // namespace android
|
}; // namespace android
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "font/Font.h"
|
#include "font/Font.h"
|
||||||
|
|
||||||
#include <utils/LruCache.h>
|
#include <utils/LruCache.h>
|
||||||
|
#include <utils/String8.h>
|
||||||
#include <utils/StrongPointer.h>
|
#include <utils/StrongPointer.h>
|
||||||
|
|
||||||
#include <SkPaint.h>
|
#include <SkPaint.h>
|
||||||
@@ -132,7 +133,8 @@ public:
|
|||||||
mLinearFiltering = linearFiltering;
|
mLinearFiltering = linearFiltering;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getCacheSize(GLenum format) const;
|
uint32_t getSize() const;
|
||||||
|
void dumpMemoryUsage(String8& log) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class Font;
|
friend class Font;
|
||||||
@@ -175,6 +177,10 @@ private:
|
|||||||
mUploadTexture = true;
|
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 mSmallCacheWidth;
|
||||||
uint32_t mSmallCacheHeight;
|
uint32_t mSmallCacheHeight;
|
||||||
uint32_t mLargeCacheWidth;
|
uint32_t mLargeCacheWidth;
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include <SkPaint.h>
|
#include <SkPaint.h>
|
||||||
|
|
||||||
|
#include <utils/String8.h>
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
namespace uirenderer {
|
namespace uirenderer {
|
||||||
|
|
||||||
@@ -46,8 +48,16 @@ public:
|
|||||||
return *mRenderer;
|
return *mRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getFontRendererSize(GLenum format) const {
|
void dumpMemoryUsage(String8& log) const {
|
||||||
return mRenderer ? mRenderer->getCacheSize(format) : 0;
|
if (mRenderer) {
|
||||||
|
mRenderer->dumpMemoryUsage(log);
|
||||||
|
} else {
|
||||||
|
log.appendFormat("FontRenderer doesn't exist.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t getSize() const {
|
||||||
|
return mRenderer ? mRenderer->getSize() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void endPrecaching();
|
void endPrecaching();
|
||||||
|
|||||||
@@ -324,5 +324,17 @@ bool CacheTexture::fitBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t CacheTexture::calculateFreeMemory() const {
|
||||||
|
CacheBlock* cacheBlock = mCacheBlocks;
|
||||||
|
uint32_t free = 0;
|
||||||
|
// currently only two formats are supported: GL_ALPHA or GL_RGBA;
|
||||||
|
uint32_t bpp = mFormat == GL_RGBA ? 4 : 1;
|
||||||
|
while (cacheBlock) {
|
||||||
|
free += bpp * cacheBlock->mWidth * cacheBlock->mHeight;
|
||||||
|
cacheBlock = cacheBlock->mNext;
|
||||||
|
}
|
||||||
|
return free;
|
||||||
|
}
|
||||||
|
|
||||||
}; // namespace uirenderer
|
}; // namespace uirenderer
|
||||||
}; // namespace android
|
}; // namespace android
|
||||||
|
|||||||
@@ -178,6 +178,8 @@ public:
|
|||||||
return mCurrentQuad == mMaxQuadCount;
|
return mCurrentQuad == mMaxQuadCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t calculateFreeMemory() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setDirty(bool dirty);
|
void setDirty(bool dirty);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user