Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af102bee authored by sergeyv's avatar sergeyv
Browse files

HWUI: track upload & recent usage in font cache

FontCacheHistoryTracker should be turned off before shipping: b/31438876

bug:30427106
Change-Id: Ic26b25e790d4ee69e484ca0cb23dc9cc522b2ed3
parent baf29e7c
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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
+7 −0
Original line number Diff line number Diff line
@@ -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
}

///////////////////////////////////////////////////////////////////////////////
+14 −0
Original line number Diff line number Diff line
@@ -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,
+11 −0
Original line number Diff line number Diff line
@@ -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;
+7 −1
Original line number Diff line number Diff line
@@ -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++;
Loading