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

Commit 0faa0556 authored by Chet Haase's avatar Chet Haase Committed by Android (Google) Code Review
Browse files

Merge "De-allocate caches for large glyphs when trimming memory"

parents f15784a5 9a824562
Loading
Loading
Loading
Loading
+39 −2
Original line number Diff line number Diff line
@@ -85,9 +85,12 @@ Font::~Font() {
    }
}

void Font::invalidateTextureCache() {
void Font::invalidateTextureCache(CacheTextureLine *cacheLine) {
    for (uint32_t i = 0; i < mCachedGlyphs.size(); i++) {
        mCachedGlyphs.valueAt(i)->mIsValid = false;
        CachedGlyphInfo* cachedGlyph = mCachedGlyphs.valueAt(i);
        if (cacheLine == NULL || cachedGlyph->mCachedTextureLine == cacheLine) {
            cachedGlyph->mIsValid = false;
        }
    }
}

@@ -414,6 +417,40 @@ void FontRenderer::flushAllAndInvalidate() {
    }
}

void FontRenderer::deallocateTextureMemory(CacheTexture *cacheTexture) {
    if (cacheTexture && cacheTexture->mTexture) {
        glDeleteTextures(1, &cacheTexture->mTextureId);
        delete cacheTexture->mTexture;
        cacheTexture->mTexture = NULL;
    }
}

void FontRenderer::flushLargeCaches() {
    if ((!mCacheTexture128 || !mCacheTexture128->mTexture) &&
            (!mCacheTexture256 || !mCacheTexture256->mTexture) &&
            (!mCacheTexture512 || !mCacheTexture512->mTexture)) {
        // Typical case; no large glyph caches allocated
        return;
    }

    for (uint32_t i = 0; i < mCacheLines.size(); i++) {
        CacheTextureLine* cacheLine = mCacheLines[i];
        if ((cacheLine->mCacheTexture == mCacheTexture128 ||
                cacheLine->mCacheTexture == mCacheTexture256 ||
                cacheLine->mCacheTexture == mCacheTexture512) &&
                cacheLine->mCacheTexture->mTexture != NULL) {
            cacheLine->mCurrentCol = 0;
            for (uint32_t i = 0; i < mActiveFonts.size(); i++) {
                mActiveFonts[i]->invalidateTextureCache(cacheLine);
            }
        }
    }

    deallocateTextureMemory(mCacheTexture128);
    deallocateTextureMemory(mCacheTexture256);
    deallocateTextureMemory(mCacheTexture512);
}

void FontRenderer::allocateTextureMemory(CacheTexture *cacheTexture) {
    int width = cacheTexture->mWidth;
    int height = cacheTexture->mHeight;
+3 −1
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ protected:
    // Cache of glyphs
    DefaultKeyedVector<glyph_t, CachedGlyphInfo*> mCachedGlyphs;

    void invalidateTextureCache();
    void invalidateTextureCache(CacheTextureLine *cacheLine = NULL);

    CachedGlyphInfo* cacheGlyph(SkPaint* paint, glyph_t glyph);
    void updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, CachedGlyphInfo *glyph);
@@ -219,6 +219,7 @@ public:

    void init();
    void deinit();
    void flushLargeCaches();

    void setGammaTable(const uint8_t* gammaTable) {
        mGammaTable = gammaTable;
@@ -286,6 +287,7 @@ protected:
    const uint8_t* mGammaTable;

    void allocateTextureMemory(CacheTexture* cacheTexture);
    void deallocateTextureMemory(CacheTexture* cacheTexture);
    void initTextTexture();
    CacheTexture *createCacheTexture(int width, int height, bool allocate);
    void cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyph,
+7 −0
Original line number Diff line number Diff line
@@ -113,6 +113,13 @@ void GammaFontRenderer::flush() {

    delete mRenderers[min];
    mRenderers[min] = NULL;

    // Also eliminate the caches for large glyphs, as they consume significant memory
    for (int i = 0; i < kGammaCount; ++i) {
        if (mRenderers[i]) {
            mRenderers[i]->flushLargeCaches();
        }
    }
}

FontRenderer* GammaFontRenderer::getRenderer(Gamma gamma) {