HWUI: track upload & recent usage in font cache
FontCacheHistoryTracker should be turned off before shipping: b/31438876 bug:30427106 Change-Id: Ic26b25e790d4ee69e484ca0cb23dc9cc522b2ed3
This commit is contained in:
@@ -3,6 +3,7 @@ include $(CLEAR_VARS)
|
||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
|
||||
|
||||
HWUI_NEW_OPS := true
|
||||
BUGREPORT_FONT_CACHE_USAGE := true
|
||||
|
||||
# Enables fine-grained GLES error checking
|
||||
# If set to true, every GLES call is wrapped & error checked
|
||||
@@ -135,6 +136,13 @@ ifeq (true, $(HWUI_NEW_OPS))
|
||||
|
||||
endif
|
||||
|
||||
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
|
||||
|
||||
@@ -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>
|
||||
@@ -212,6 +215,10 @@ void Caches::dumpMemoryUsage(String8 &log) {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -168,10 +168,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;
|
||||
@@ -183,6 +190,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);
|
||||
@@ -385,6 +395,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,
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#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>
|
||||
@@ -136,6 +139,10 @@ public:
|
||||
uint32_t getSize() const;
|
||||
void dumpMemoryUsage(String8& log) const;
|
||||
|
||||
#ifdef BUGREPORT_FONT_CACHE_USAGE
|
||||
FontCacheHistoryTracker& historyTracker() { return mHistoryTracker; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
friend class Font;
|
||||
|
||||
@@ -205,6 +212,10 @@ private:
|
||||
|
||||
bool mLinearFiltering;
|
||||
|
||||
#ifdef BUGREPORT_FONT_CACHE_USAGE
|
||||
FontCacheHistoryTracker mHistoryTracker;
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID_ENABLE_RENDERSCRIPT
|
||||
// RS constructs
|
||||
RSC::sp<RSC::RS> mRs;
|
||||
|
||||
@@ -408,9 +408,15 @@ void Font::render(const SkPaint* paint, const glyph_t* glyphs,
|
||||
if (cachedGlyph->mIsValid && cachedGlyph->mCacheTexture) {
|
||||
int penX = x + (int) roundf(positions[(glyphsCount << 1)]);
|
||||
int penY = y + (int) roundf(positions[(glyphsCount << 1) + 1]);
|
||||
|
||||
#ifdef BUGREPORT_FONT_CACHE_USAGE
|
||||
mState->historyTracker().glyphRendered(cachedGlyph, penX, penY);
|
||||
#endif
|
||||
(*this.*render)(cachedGlyph, penX, penY,
|
||||
bitmap, bitmapW, bitmapH, bounds, positions);
|
||||
} else {
|
||||
#ifdef BUGREPORT_FONT_CACHE_USAGE
|
||||
mState->historyTracker().glyphRendered(cachedGlyph, -1, -1);
|
||||
#endif
|
||||
}
|
||||
|
||||
glyphsCount++;
|
||||
|
||||
100
libs/hwui/font/FontCacheHistoryTracker.cpp
Normal file
100
libs/hwui/font/FontCacheHistoryTracker.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "FontCacheHistoryTracker.h"
|
||||
|
||||
#include "CachedGlyphInfo.h"
|
||||
#include "CacheTexture.h"
|
||||
|
||||
namespace android {
|
||||
namespace uirenderer {
|
||||
|
||||
void FontCacheHistoryTracker::dumpCachedGlyph(String8& log, const CachedGlyph& glyph) {
|
||||
log.appendFormat("glyph (texture %p, position: (%d, %d), size: %dx%d, gen: %d)", glyph.texture,
|
||||
glyph.startX, glyph.startY, glyph.bitmapW, glyph.bitmapH, glyph.generation);
|
||||
}
|
||||
|
||||
void FontCacheHistoryTracker::dumpRenderEntry(String8& log, const RenderEntry& entry) {
|
||||
if (entry.penX == -1 && entry.penY == -1) {
|
||||
log.appendFormat(" glyph skipped in gen: %d\n", entry.glyph.generation);
|
||||
} else {
|
||||
log.appendFormat(" rendered ");
|
||||
dumpCachedGlyph(log, entry.glyph);
|
||||
log.appendFormat(" at (%d, %d)\n", entry.penX, entry.penY);
|
||||
}
|
||||
}
|
||||
|
||||
void FontCacheHistoryTracker::dumpUploadEntry(String8& log, const CachedGlyph& glyph) {
|
||||
if (glyph.bitmapW == 0 && glyph.bitmapH == 0) {
|
||||
log.appendFormat(" cleared cachetexture %p in gen %d\n", glyph.texture,
|
||||
glyph.generation);
|
||||
} else {
|
||||
log.appendFormat(" uploaded ");
|
||||
dumpCachedGlyph(log, glyph);
|
||||
log.appendFormat("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void FontCacheHistoryTracker::dump(String8& log) const {
|
||||
log.appendFormat("FontCacheHistory: \n");
|
||||
log.appendFormat(" Upload history: \n");
|
||||
for (size_t i = 0; i < mUploadHistory.size(); i++) {
|
||||
dumpUploadEntry(log, mUploadHistory[i]);
|
||||
}
|
||||
log.appendFormat(" Render history: \n");
|
||||
for (size_t i = 0; i < mRenderHistory.size(); i++) {
|
||||
dumpRenderEntry(log, mRenderHistory[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void FontCacheHistoryTracker::glyphRendered(CachedGlyphInfo* glyphInfo, int penX, int penY) {
|
||||
RenderEntry& entry = mRenderHistory.next();
|
||||
entry.glyph.generation = generation;
|
||||
entry.glyph.texture = glyphInfo->mCacheTexture;
|
||||
entry.glyph.startX = glyphInfo->mStartX;
|
||||
entry.glyph.startY = glyphInfo->mStartY;
|
||||
entry.glyph.bitmapW = glyphInfo->mBitmapWidth;
|
||||
entry.glyph.bitmapH = glyphInfo->mBitmapHeight;
|
||||
entry.penX = penX;
|
||||
entry.penY = penY;
|
||||
}
|
||||
|
||||
void FontCacheHistoryTracker::glyphUploaded(CacheTexture* texture, uint32_t x, uint32_t y,
|
||||
uint16_t glyphW, uint16_t glyphH) {
|
||||
CachedGlyph& glyph = mUploadHistory.next();
|
||||
glyph.generation = generation;
|
||||
glyph.texture = texture;
|
||||
glyph.startX = x;
|
||||
glyph.startY = y;
|
||||
glyph.bitmapW = glyphW;
|
||||
glyph.bitmapH = glyphH;
|
||||
}
|
||||
|
||||
void FontCacheHistoryTracker::glyphsCleared(CacheTexture* texture) {
|
||||
CachedGlyph& glyph = mUploadHistory.next();
|
||||
glyph.generation = generation;
|
||||
glyph.texture = texture;
|
||||
glyph.startX = 0;
|
||||
glyph.startY = 0;
|
||||
glyph.bitmapW = 0;
|
||||
glyph.bitmapH = 0;
|
||||
}
|
||||
|
||||
void FontCacheHistoryTracker::frameCompleted() {
|
||||
generation++;
|
||||
}
|
||||
}; // namespace uirenderer
|
||||
}; // namespace android
|
||||
64
libs/hwui/font/FontCacheHistoryTracker.h
Normal file
64
libs/hwui/font/FontCacheHistoryTracker.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../utils/RingBuffer.h"
|
||||
|
||||
#include <utils/String8.h>
|
||||
|
||||
namespace android {
|
||||
namespace uirenderer {
|
||||
|
||||
class CacheTexture;
|
||||
struct CachedGlyphInfo;
|
||||
|
||||
// Tracks glyph uploads and recent rendered/skipped glyphs, so it can give an idea
|
||||
// what a missing character is: skipped glyph, wrong coordinates in cache texture etc.
|
||||
class FontCacheHistoryTracker {
|
||||
public:
|
||||
void glyphRendered(CachedGlyphInfo*, int penX, int penY);
|
||||
void glyphUploaded(CacheTexture*, uint32_t x, uint32_t y, uint16_t glyphW, uint16_t glyphH);
|
||||
void glyphsCleared(CacheTexture*);
|
||||
void frameCompleted();
|
||||
|
||||
void dump(String8& log) const;
|
||||
private:
|
||||
struct CachedGlyph {
|
||||
void* texture;
|
||||
uint16_t generation;
|
||||
uint16_t startX;
|
||||
uint16_t startY;
|
||||
uint16_t bitmapW;
|
||||
uint16_t bitmapH;
|
||||
};
|
||||
|
||||
struct RenderEntry {
|
||||
CachedGlyph glyph;
|
||||
int penX;
|
||||
int penY;
|
||||
};
|
||||
|
||||
static void dumpCachedGlyph(String8& log, const CachedGlyph& glyph);
|
||||
static void dumpRenderEntry(String8& log, const RenderEntry& entry);
|
||||
static void dumpUploadEntry(String8& log, const CachedGlyph& glyph);
|
||||
|
||||
RingBuffer<RenderEntry, 300> mRenderHistory;
|
||||
RingBuffer<CachedGlyph, 120> mUploadHistory;
|
||||
uint16_t generation = 0;
|
||||
};
|
||||
|
||||
}; // namespace uirenderer
|
||||
}; // namespace android
|
||||
@@ -608,6 +608,10 @@ void CanvasContext::draw() {
|
||||
}
|
||||
|
||||
GpuMemoryTracker::onFrameCompleted();
|
||||
#ifdef BUGREPORT_FONT_CACHE_USAGE
|
||||
caches.fontRenderer.getFontRenderer().historyTracker().frameCompleted();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
// Called by choreographer to do an RT-driven animation
|
||||
|
||||
Reference in New Issue
Block a user