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

Commit 21755bf5 authored by Chet Haase's avatar Chet Haase Committed by Android Git Automerger
Browse files

am 925b6a71: Merge "Optimize glyph cache texture uploads" into jb-mr1-dev

* commit '925b6a71':
  Optimize glyph cache texture uploads
parents e3089736 925b6a71
Loading
Loading
Loading
Loading
+10 −7
Original line number Original line Diff line number Diff line
@@ -331,10 +331,14 @@ void FontRenderer::checkTextureUpdate() {
    for (uint32_t i = 0; i < mCacheTextures.size(); i++) {
    for (uint32_t i = 0; i < mCacheTextures.size(); i++) {
        CacheTexture* cacheTexture = mCacheTextures[i];
        CacheTexture* cacheTexture = mCacheTextures[i];
        if (cacheTexture->isDirty() && cacheTexture->getTexture()) {
        if (cacheTexture->isDirty() && cacheTexture->getTexture()) {
            uint32_t xOffset = 0;
            // Can't copy inner rect; glTexSubimage expects pointer to deal with entire buffer
            // of data. So expand the dirty rect to the encompassing horizontal stripe.
            const Rect* dirtyRect = cacheTexture->getDirtyRect();
            uint32_t x = 0;
            uint32_t y = dirtyRect->top;
            uint32_t width = cacheTexture->getWidth();
            uint32_t width = cacheTexture->getWidth();
            uint32_t height = cacheTexture->getHeight();
            uint32_t height = dirtyRect->getHeight();
            void* textureData = cacheTexture->getTexture();
            void* textureData = cacheTexture->getTexture() + y * width;


            if (cacheTexture->getTextureId() != lastTextureId) {
            if (cacheTexture->getTextureId() != lastTextureId) {
                lastTextureId = cacheTexture->getTextureId();
                lastTextureId = cacheTexture->getTextureId();
@@ -342,12 +346,11 @@ void FontRenderer::checkTextureUpdate() {
                glBindTexture(GL_TEXTURE_2D, lastTextureId);
                glBindTexture(GL_TEXTURE_2D, lastTextureId);
            }
            }
#if DEBUG_FONT_RENDERER
#if DEBUG_FONT_RENDERER
            ALOGD("glTextSubimage for cacheTexture %d: xOff, width height = %d, %d, %d",
            ALOGD("glTexSubimage for cacheTexture %d: x, y, width height = %d, %d, %d, %d",
                    i, xOffset, width, height);
                    i, x, y, width, height);
#endif
#endif
            glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, 0, width, height,
            glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height,
                    GL_ALPHA, GL_UNSIGNED_BYTE, textureData);
                    GL_ALPHA, GL_UNSIGNED_BYTE, textureData);

            cacheTexture->setDirty(false);
            cacheTexture->setDirty(false);
        }
        }
    }
    }
+3 −0
Original line number Original line Diff line number Diff line
@@ -171,6 +171,9 @@ bool CacheTexture::fitBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_
            }
            }


            mDirty = true;
            mDirty = true;
            const Rect r(*retOriginX - TEXTURE_BORDER_SIZE, *retOriginY - TEXTURE_BORDER_SIZE,
                    *retOriginX + glyphW, *retOriginY + glyphH);
            mDirtyRect.unionWith(r);
            mNumGlyphs++;
            mNumGlyphs++;


#if DEBUG_FONT_RENDERER
#if DEBUG_FONT_RENDERER
+9 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@
#include <utils/Log.h>
#include <utils/Log.h>


#include "FontUtil.h"
#include "FontUtil.h"
#include "Rect.h"


namespace android {
namespace android {
namespace uirenderer {
namespace uirenderer {
@@ -149,6 +150,10 @@ public:
        return mHeight;
        return mHeight;
    }
    }


    inline const Rect* getDirtyRect() const {
        return &mDirtyRect;
    }

    inline uint8_t* getTexture() const {
    inline uint8_t* getTexture() const {
        return mTexture;
        return mTexture;
    }
    }
@@ -163,6 +168,9 @@ public:


    inline void setDirty(bool dirty) {
    inline void setDirty(bool dirty) {
        mDirty = dirty;
        mDirty = dirty;
        if (!dirty) {
            mDirtyRect.setEmpty();
        }
    }
    }


    inline bool getLinearFiltering() const {
    inline bool getLinearFiltering() const {
@@ -196,6 +204,7 @@ private:
    bool mDirty;
    bool mDirty;
    uint16_t mNumGlyphs;
    uint16_t mNumGlyphs;
    CacheBlock* mCacheBlocks;
    CacheBlock* mCacheBlocks;
    Rect mDirtyRect;
};
};


}; // namespace uirenderer
}; // namespace uirenderer