summaryrefslogtreecommitdiff
path: root/libs/hwui/FontRenderer.cpp
diff options
context:
space:
mode:
author sergeyv <sergeyv@google.com> 2016-09-14 00:43:43 -0700
committer sergeyv <sergeyv@google.com> 2016-09-14 09:15:15 -0700
commitdcbc0e9e25bf99600d487f3c6f5e26487545cd9c (patch)
tree55e9803b11d2f1d153f6890c66e9d4a551a15362 /libs/hwui/FontRenderer.cpp
parent182f9abdf427996249cb953ffd6133fde3bbfba2 (diff)
parent0ec2fd7bc5f3c57f7783425608732d2f95f53c4a (diff)
resolve merge conflicts of 0ec2fd7 to master
Change-Id: I113ede26ab42e3f9a36a52a756c38d365731e16d
Diffstat (limited to 'libs/hwui/FontRenderer.cpp')
-rw-r--r--libs/hwui/FontRenderer.cpp71
1 files changed, 67 insertions, 4 deletions
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp
index 25dc92c8a8dc..9b60dfcb5867 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -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;
@@ -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);
@@ -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,
@@ -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