diff options
Diffstat (limited to 'libs/hwui/font')
| -rw-r--r-- | libs/hwui/font/CacheTexture.cpp | 80 | ||||
| -rw-r--r-- | libs/hwui/font/CacheTexture.h | 52 | ||||
| -rw-r--r-- | libs/hwui/font/CachedGlyphInfo.h | 4 | ||||
| -rw-r--r-- | libs/hwui/font/Font.cpp | 29 | ||||
| -rw-r--r-- | libs/hwui/font/Font.h | 8 | ||||
| -rw-r--r-- | libs/hwui/font/FontUtil.h | 11 |
6 files changed, 93 insertions, 91 deletions
diff --git a/libs/hwui/font/CacheTexture.cpp b/libs/hwui/font/CacheTexture.cpp index 24ffb80..845cf30 100644 --- a/libs/hwui/font/CacheTexture.cpp +++ b/libs/hwui/font/CacheTexture.cpp @@ -17,6 +17,7 @@ #include <SkGlyph.h> #include "CacheTexture.h" +#include "FontUtil.h" #include "../Caches.h" #include "../Debug.h" #include "../Extensions.h" @@ -42,7 +43,7 @@ CacheBlock* CacheBlock::insertBlock(CacheBlock* head, CacheBlock* newBlock) { #endif CacheBlock* currBlock = head; - CacheBlock* prevBlock = NULL; + CacheBlock* prevBlock = nullptr; while (currBlock && currBlock->mY != TEXTURE_BORDER_SIZE) { if (newBlock->mWidth < currBlock->mWidth) { @@ -108,29 +109,33 @@ CacheBlock* CacheBlock::removeBlock(CacheBlock* head, CacheBlock* blockToRemove) // CacheTexture /////////////////////////////////////////////////////////////////////////////// -CacheTexture::CacheTexture(uint16_t width, uint16_t height, GLenum format, uint32_t maxQuadCount) : - mTexture(NULL), mTextureId(0), mWidth(width), mHeight(height), mFormat(format), - mLinearFiltering(false), mDirty(false), mNumGlyphs(0), - mMesh(NULL), mCurrentQuad(0), mMaxQuadCount(maxQuadCount), - mCaches(Caches::getInstance()) { +CacheTexture::CacheTexture(uint16_t width, uint16_t height, GLenum format, uint32_t maxQuadCount) + : mTexture(Caches::getInstance()) + , mFormat(format) + , mMaxQuadCount(maxQuadCount) + , mCaches(Caches::getInstance()) { + mTexture.width = width; + mTexture.height = height; + mTexture.blend = true; + mCacheBlocks = new CacheBlock(TEXTURE_BORDER_SIZE, TEXTURE_BORDER_SIZE, - mWidth - TEXTURE_BORDER_SIZE, mHeight - TEXTURE_BORDER_SIZE); + getWidth() - TEXTURE_BORDER_SIZE, getHeight() - TEXTURE_BORDER_SIZE); // OpenGL ES 3.0+ lets us specify the row length for unpack operations such // as glTexSubImage2D(). This allows us to upload a sub-rectangle of a texture. // With OpenGL ES 2.0 we have to upload entire stripes instead. - mHasUnpackRowLength = Extensions::getInstance().hasUnpackRowLength(); + mHasUnpackRowLength = mCaches.extensions().hasUnpackRowLength(); } CacheTexture::~CacheTexture() { releaseMesh(); - releaseTexture(); + releasePixelBuffer(); reset(); } void CacheTexture::reset() { // Delete existing cache blocks - while (mCacheBlocks != NULL) { + while (mCacheBlocks != nullptr) { CacheBlock* tmpBlock = mCacheBlocks; mCacheBlocks = mCacheBlocks->mNext; delete tmpBlock; @@ -143,35 +148,28 @@ void CacheTexture::init() { // reset, then create a new remainder space to start again reset(); mCacheBlocks = new CacheBlock(TEXTURE_BORDER_SIZE, TEXTURE_BORDER_SIZE, - mWidth - TEXTURE_BORDER_SIZE, mHeight - TEXTURE_BORDER_SIZE); + getWidth() - TEXTURE_BORDER_SIZE, getHeight() - TEXTURE_BORDER_SIZE); } void CacheTexture::releaseMesh() { delete[] mMesh; } -void CacheTexture::releaseTexture() { - if (mTexture) { - delete mTexture; - mTexture = NULL; +void CacheTexture::releasePixelBuffer() { + if (mPixelBuffer) { + delete mPixelBuffer; + mPixelBuffer = nullptr; } - if (mTextureId) { - mCaches.deleteTexture(mTextureId); - mTextureId = 0; + if (mTexture.id) { + mCaches.textureState().deleteTexture(mTexture.id); + mTexture.id = 0; } mDirty = false; mCurrentQuad = 0; } -void CacheTexture::setLinearFiltering(bool linearFiltering, bool bind) { - if (linearFiltering != mLinearFiltering) { - mLinearFiltering = linearFiltering; - - const GLenum filtering = linearFiltering ? GL_LINEAR : GL_NEAREST; - if (bind) mCaches.bindTexture(getTextureId()); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); - } +void CacheTexture::setLinearFiltering(bool linearFiltering) { + mTexture.setFilter(linearFiltering ? GL_LINEAR : GL_NEAREST); } void CacheTexture::allocateMesh() { @@ -180,19 +178,19 @@ void CacheTexture::allocateMesh() { } } -void CacheTexture::allocateTexture() { - if (!mTexture) { - mTexture = PixelBuffer::create(mFormat, mWidth, mHeight); +void CacheTexture::allocatePixelBuffer() { + if (!mPixelBuffer) { + mPixelBuffer = PixelBuffer::create(mFormat, getWidth(), getHeight()); } - if (!mTextureId) { - glGenTextures(1, &mTextureId); + if (!mTexture.id) { + glGenTextures(1, &mTexture.id); - mCaches.bindTexture(mTextureId); + mCaches.textureState().bindTexture(mTexture.id); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Initialize texture dimensions - glTexImage2D(GL_TEXTURE_2D, 0, mFormat, mWidth, mHeight, 0, - mFormat, GL_UNSIGNED_BYTE, 0); + glTexImage2D(GL_TEXTURE_2D, 0, mFormat, getWidth(), getHeight(), 0, + mFormat, GL_UNSIGNED_BYTE, nullptr); const GLenum filtering = getLinearFiltering() ? GL_LINEAR : GL_NEAREST; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); @@ -208,16 +206,16 @@ bool CacheTexture::upload() { uint32_t x = mHasUnpackRowLength ? dirtyRect.left : 0; uint32_t y = dirtyRect.top; - uint32_t width = mHasUnpackRowLength ? dirtyRect.getWidth() : mWidth; + uint32_t width = mHasUnpackRowLength ? dirtyRect.getWidth() : getWidth(); uint32_t height = dirtyRect.getHeight(); // The unpack row length only needs to be specified when a new // texture is bound if (mHasUnpackRowLength) { - glPixelStorei(GL_UNPACK_ROW_LENGTH, mWidth); + glPixelStorei(GL_UNPACK_ROW_LENGTH, getWidth()); } - mTexture->upload(x, y, width, height); + mPixelBuffer->upload(x, y, width, height); setDirty(false); return mHasUnpackRowLength; @@ -257,7 +255,7 @@ bool CacheTexture::fitBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_ return false; } - if (glyph.fHeight + TEXTURE_BORDER_SIZE * 2 > mHeight) { + if (glyph.fHeight + TEXTURE_BORDER_SIZE * 2 > getHeight()) { return false; } @@ -294,10 +292,10 @@ bool CacheTexture::fitBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_ cacheBlock->mWidth -= roundedUpW; cacheBlock->mX += roundedUpW; - if (mHeight - glyphH >= glyphH) { + if (getHeight() - glyphH >= glyphH) { // There's enough height left over to create a new CacheBlock CacheBlock* newBlock = new CacheBlock(oldX, glyphH + TEXTURE_BORDER_SIZE, - roundedUpW, mHeight - glyphH - TEXTURE_BORDER_SIZE); + roundedUpW, getHeight() - glyphH - TEXTURE_BORDER_SIZE); #if DEBUG_FONT_RENDERER ALOGD("fitBitmap: Created new block: this, x, y, w, h = %p, %d, %d, %d, %d", newBlock, newBlock->mX, newBlock->mY, diff --git a/libs/hwui/font/CacheTexture.h b/libs/hwui/font/CacheTexture.h index 4cc4f22..6dabc76 100644 --- a/libs/hwui/font/CacheTexture.h +++ b/libs/hwui/font/CacheTexture.h @@ -17,16 +17,15 @@ #ifndef ANDROID_HWUI_CACHE_TEXTURE_H #define ANDROID_HWUI_CACHE_TEXTURE_H -#include <GLES3/gl3.h> +#include "PixelBuffer.h" +#include "Rect.h" +#include "Texture.h" +#include "Vertex.h" +#include <GLES3/gl3.h> #include <SkScalerContext.h> - #include <utils/Log.h> -#include "FontUtil.h" -#include "../PixelBuffer.h" -#include "../Rect.h" -#include "../Vertex.h" namespace android { namespace uirenderer { @@ -55,7 +54,7 @@ struct CacheBlock { CacheBlock* mPrev; CacheBlock(uint16_t x, uint16_t y, uint16_t width, uint16_t height): - mX(x), mY(y), mWidth(width), mHeight(height), mNext(NULL), mPrev(NULL) { + mX(x), mY(y), mWidth(width), mHeight(height), mNext(nullptr), mPrev(nullptr) { } static CacheBlock* insertBlock(CacheBlock* head, CacheBlock* newBlock); @@ -81,9 +80,9 @@ public: void init(); void releaseMesh(); - void releaseTexture(); + void releasePixelBuffer(); - void allocateTexture(); + void allocatePixelBuffer(); void allocateMesh(); // Returns true if glPixelStorei(GL_UNPACK_ROW_LENGTH) must be reset @@ -93,11 +92,11 @@ public: bool fitBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_t* retOriginY); inline uint16_t getWidth() const { - return mWidth; + return mTexture.width; } inline uint16_t getHeight() const { - return mHeight; + return mTexture.height; } inline GLenum getFormat() const { @@ -105,7 +104,7 @@ public: } inline uint32_t getOffset(uint16_t x, uint16_t y) const { - return (y * mWidth + x) * PixelBuffer::formatSize(mFormat); + return (y * getWidth() + x) * PixelBuffer::formatSize(mFormat); } inline const Rect* getDirtyRect() const { @@ -113,12 +112,17 @@ public: } inline PixelBuffer* getPixelBuffer() const { + return mPixelBuffer; + } + + Texture& getTexture() { + allocatePixelBuffer(); return mTexture; } GLuint getTextureId() { - allocateTexture(); - return mTextureId; + allocatePixelBuffer(); + return mTexture.id; } inline bool isDirty() const { @@ -132,7 +136,7 @@ public: /** * This method assumes that the proper texture unit is active. */ - void setLinearFiltering(bool linearFiltering, bool bind = true); + void setLinearFiltering(bool linearFiltering); inline uint16_t getGlyphCount() const { return mNumGlyphs; @@ -147,7 +151,7 @@ public: } uint16_t* indices() const { - return (uint16_t*) 0; + return (uint16_t*) nullptr; } void resetMesh() { @@ -177,16 +181,14 @@ public: private: void setDirty(bool dirty); - PixelBuffer* mTexture; - GLuint mTextureId; - uint16_t mWidth; - uint16_t mHeight; + PixelBuffer* mPixelBuffer = nullptr; + Texture mTexture; GLenum mFormat; - bool mLinearFiltering; - bool mDirty; - uint16_t mNumGlyphs; - TextureVertex* mMesh; - uint32_t mCurrentQuad; + bool mLinearFiltering = false; + bool mDirty = false; + uint16_t mNumGlyphs = 0; + TextureVertex* mMesh = nullptr; + uint32_t mCurrentQuad = 0; uint32_t mMaxQuadCount; Caches& mCaches; CacheBlock* mCacheBlocks; diff --git a/libs/hwui/font/CachedGlyphInfo.h b/libs/hwui/font/CachedGlyphInfo.h index 6680a00..0642d59 100644 --- a/libs/hwui/font/CachedGlyphInfo.h +++ b/libs/hwui/font/CachedGlyphInfo.h @@ -19,11 +19,11 @@ #include <SkFixed.h> -#include "CacheTexture.h" - namespace android { namespace uirenderer { +class CacheTexture; + struct CachedGlyphInfo { // Has the cache been invalidated? bool mIsValid; diff --git a/libs/hwui/font/Font.cpp b/libs/hwui/font/Font.cpp index af39f16..b07a3c8 100644 --- a/libs/hwui/font/Font.cpp +++ b/libs/hwui/font/Font.cpp @@ -22,6 +22,7 @@ #include <utils/JenkinsHash.h> #include <utils/Trace.h> +#include <SkDeviceProperties.h> #include <SkGlyph.h> #include <SkGlyphCache.h> #include <SkUtils.h> @@ -41,9 +42,7 @@ namespace uirenderer { /////////////////////////////////////////////////////////////////////////////// Font::Font(FontRenderer* state, const Font::FontDescription& desc) : - mState(state), mDescription(desc) { - mDeviceProperties = SkDeviceProperties::Make(SkDeviceProperties::Geometry::MakeDefault(), 1.0f); -} + mState(state), mDescription(desc) { } Font::FontDescription::FontDescription(const SkPaint* paint, const SkMatrix& rasterMatrix) : mLookupTransform(rasterMatrix) { @@ -285,7 +284,8 @@ CachedGlyphInfo* Font::getCachedGlyph(const SkPaint* paint, glyph_t textUnit, bo if (cachedGlyph) { // Is the glyph still in texture cache? if (!cachedGlyph->mIsValid) { - SkAutoGlyphCache autoCache(*paint, &mDeviceProperties, &mDescription.mLookupTransform); + SkDeviceProperties deviceProperties(kUnknown_SkPixelGeometry, 1.0f); + SkAutoGlyphCache autoCache(*paint, &deviceProperties, &mDescription.mLookupTransform); const SkGlyph& skiaGlyph = GET_METRICS(autoCache.getCache(), textUnit); updateGlyphCache(paint, skiaGlyph, autoCache.getCache(), cachedGlyph, precaching); } @@ -298,13 +298,13 @@ CachedGlyphInfo* Font::getCachedGlyph(const SkPaint* paint, glyph_t textUnit, bo void Font::render(const SkPaint* paint, const char *text, uint32_t start, uint32_t len, int numGlyphs, int x, int y, const float* positions) { - render(paint, text, start, len, numGlyphs, x, y, FRAMEBUFFER, NULL, - 0, 0, NULL, positions); + render(paint, text, start, len, numGlyphs, x, y, FRAMEBUFFER, nullptr, + 0, 0, nullptr, positions); } void Font::render(const SkPaint* paint, const char *text, uint32_t start, uint32_t len, int numGlyphs, const SkPath* path, float hOffset, float vOffset) { - if (numGlyphs == 0 || text == NULL || len == 0) { + if (numGlyphs == 0 || text == nullptr || len == 0) { return; } @@ -354,18 +354,18 @@ void Font::render(const SkPaint* paint, const char *text, uint32_t start, uint32 void Font::measure(const SkPaint* paint, const char* text, uint32_t start, uint32_t len, int numGlyphs, Rect *bounds, const float* positions) { - if (bounds == NULL) { + if (bounds == nullptr) { ALOGE("No return rectangle provided to measure text"); return; } bounds->set(1e6, -1e6, -1e6, 1e6); - render(paint, text, start, len, numGlyphs, 0, 0, MEASURE, NULL, 0, 0, bounds, positions); + render(paint, text, start, len, numGlyphs, 0, 0, MEASURE, nullptr, 0, 0, bounds, positions); } void Font::precache(const SkPaint* paint, const char* text, int numGlyphs) { ATRACE_NAME("Precache Glyphs"); - if (numGlyphs == 0 || text == NULL) { + if (numGlyphs == 0 || text == nullptr) { return; } @@ -378,7 +378,7 @@ void Font::precache(const SkPaint* paint, const char* text, int numGlyphs) { break; } - CachedGlyphInfo* cachedGlyph = getCachedGlyph(paint, glyph, true); + getCachedGlyph(paint, glyph, true); glyphsCount++; } } @@ -386,7 +386,7 @@ void Font::precache(const SkPaint* paint, const char* text, int numGlyphs) { void Font::render(const SkPaint* paint, const char* text, uint32_t start, uint32_t len, int numGlyphs, int x, int y, RenderMode mode, uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH, Rect* bounds, const float* positions) { - if (numGlyphs == 0 || text == NULL || len == 0) { + if (numGlyphs == 0 || text == nullptr || len == 0) { return; } @@ -403,8 +403,6 @@ void Font::render(const SkPaint* paint, const char* text, uint32_t start, uint32 text += start; int glyphsCount = 0; - const SkPaint::Align align = paint->getTextAlign(); - while (glyphsCount < numGlyphs) { glyph_t glyph = GET_GLYPH(text); @@ -477,7 +475,8 @@ CachedGlyphInfo* Font::cacheGlyph(const SkPaint* paint, glyph_t glyph, bool prec CachedGlyphInfo* newGlyph = new CachedGlyphInfo(); mCachedGlyphs.add(glyph, newGlyph); - SkAutoGlyphCache autoCache(*paint, &mDeviceProperties, &mDescription.mLookupTransform); + SkDeviceProperties deviceProperties(kUnknown_SkPixelGeometry, 1.0f); + SkAutoGlyphCache autoCache(*paint, &deviceProperties, &mDescription.mLookupTransform); const SkGlyph& skiaGlyph = GET_METRICS(autoCache.getCache(), glyph); newGlyph->mIsValid = false; newGlyph->mGlyphIndex = skiaGlyph.fID; diff --git a/libs/hwui/font/Font.h b/libs/hwui/font/Font.h index 0f10464..3119d73 100644 --- a/libs/hwui/font/Font.h +++ b/libs/hwui/font/Font.h @@ -22,13 +22,12 @@ #include <utils/KeyedVector.h> #include <SkScalar.h> -#include <SkDeviceProperties.h> #include <SkGlyphCache.h> #include <SkScalerContext.h> #include <SkPaint.h> #include <SkPathMeasure.h> -#include "CachedGlyphInfo.h" +#include "FontUtil.h" #include "../Rect.h" #include "../Matrix.h" @@ -39,6 +38,8 @@ namespace uirenderer { // Font /////////////////////////////////////////////////////////////////////////////// +struct CachedGlyphInfo; +class CacheTexture; class FontRenderer; /** @@ -119,7 +120,7 @@ private: void measure(const SkPaint* paint, const char* text, uint32_t start, uint32_t len, int numGlyphs, Rect *bounds, const float* positions); - void invalidateTextureCache(CacheTexture* cacheTexture = NULL); + void invalidateTextureCache(CacheTexture* cacheTexture = nullptr); CachedGlyphInfo* cacheGlyph(const SkPaint* paint, glyph_t glyph, bool precaching); void updateGlyphCache(const SkPaint* paint, const SkGlyph& skiaGlyph, @@ -150,7 +151,6 @@ private: DefaultKeyedVector<glyph_t, CachedGlyphInfo*> mCachedGlyphs; bool mIdentityTransform; - SkDeviceProperties mDeviceProperties; }; inline int strictly_order_type(const Font::FontDescription& lhs, diff --git a/libs/hwui/font/FontUtil.h b/libs/hwui/font/FontUtil.h index c2fd5f5..4e5debe 100644 --- a/libs/hwui/font/FontUtil.h +++ b/libs/hwui/font/FontUtil.h @@ -30,9 +30,12 @@ #define DEFAULT_TEXT_LARGE_CACHE_WIDTH 2048 #define DEFAULT_TEXT_LARGE_CACHE_HEIGHT 512 -#define TEXTURE_BORDER_SIZE 1 -#if TEXTURE_BORDER_SIZE != 1 -# error TEXTURE_BORDER_SIZE other than 1 is not currently supported +#ifdef TEXTURE_BORDER_SIZE + #if TEXTURE_BORDER_SIZE != 1 + #error TEXTURE_BORDER_SIZE other than 1 is not currently supported + #endif +#else + #define TEXTURE_BORDER_SIZE 1 #endif #define CACHE_BLOCK_ROUNDING_SIZE 4 @@ -44,7 +47,7 @@ #define GET_GLYPH(text) nextGlyph((const uint16_t**) &text) #define IS_END_OF_STRING(glyph) false - static glyph_t nextGlyph(const uint16_t** srcPtr) { + static inline glyph_t nextGlyph(const uint16_t** srcPtr) { const uint16_t* src = *srcPtr; glyph_t g = *src++; *srcPtr = src; |
