diff options
Diffstat (limited to 'libs/hwui/font')
-rw-r--r-- | libs/hwui/font/CacheTexture.cpp | 37 | ||||
-rw-r--r-- | libs/hwui/font/CacheTexture.h | 13 | ||||
-rw-r--r-- | libs/hwui/font/FontUtil.h | 3 |
3 files changed, 44 insertions, 9 deletions
diff --git a/libs/hwui/font/CacheTexture.cpp b/libs/hwui/font/CacheTexture.cpp index 5f15724..55503ce 100644 --- a/libs/hwui/font/CacheTexture.cpp +++ b/libs/hwui/font/CacheTexture.cpp @@ -108,8 +108,8 @@ CacheBlock* CacheBlock::removeBlock(CacheBlock* head, CacheBlock* blockToRemove) // CacheTexture /////////////////////////////////////////////////////////////////////////////// -CacheTexture::CacheTexture(uint16_t width, uint16_t height, uint32_t maxQuadCount) : - mTexture(NULL), mTextureId(0), mWidth(width), mHeight(height), +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()) { @@ -182,7 +182,7 @@ void CacheTexture::allocateMesh() { void CacheTexture::allocateTexture() { if (!mTexture) { - mTexture = PixelBuffer::create(GL_ALPHA, mWidth, mHeight); + mTexture = PixelBuffer::create(mFormat, mWidth, mHeight); } if (!mTextureId) { @@ -191,8 +191,8 @@ void CacheTexture::allocateTexture() { mCaches.bindTexture(mTextureId); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Initialize texture dimensions - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, mWidth, mHeight, 0, - GL_ALPHA, GL_UNSIGNED_BYTE, 0); + glTexImage2D(GL_TEXTURE_2D, 0, mFormat, mWidth, mHeight, 0, + mFormat, GL_UNSIGNED_BYTE, 0); const GLenum filtering = getLinearFiltering() ? GL_LINEAR : GL_NEAREST; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); @@ -217,8 +217,7 @@ bool CacheTexture::upload() { glPixelStorei(GL_UNPACK_ROW_LENGTH, mWidth); } - mTexture->upload(x, y, width, height, y * mWidth + x); - + mTexture->upload(x, y, width, height); setDirty(false); return mHasES3; @@ -232,6 +231,30 @@ void CacheTexture::setDirty(bool dirty) { } bool CacheTexture::fitBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_t* retOriginY) { + switch (glyph.fMaskFormat) { + case SkMask::kA8_Format: + if (mFormat != GL_ALPHA) { +#if DEBUG_FONT_RENDERER + ALOGD("fitBitmap: kA8_Format glyph cannot fit into texture format %x", mFormat); +#endif + return false; + } + break; + case SkMask::kARGB32_Format: + if (mFormat != GL_RGBA) { +#if DEBUG_FONT_RENDERER + ALOGD("fitBitmap: kARGB32_Format glyph cannot fit into texture format %x", mFormat); +#endif + return false; + } + break; + default: +#if DEBUG_FONT_RENDERER + ALOGD("fitBitmap: unknown glyph format %x encountered", glyph.fMaskFormat); +#endif + return false; + } + if (glyph.fHeight + TEXTURE_BORDER_SIZE * 2 > mHeight) { return false; } diff --git a/libs/hwui/font/CacheTexture.h b/libs/hwui/font/CacheTexture.h index 208b1ff..028b611 100644 --- a/libs/hwui/font/CacheTexture.h +++ b/libs/hwui/font/CacheTexture.h @@ -24,6 +24,7 @@ #include <utils/Log.h> #include "FontUtil.h" +#include "../PixelBuffer.h" #include "../Rect.h" #include "../Vertex.h" @@ -31,7 +32,6 @@ namespace android { namespace uirenderer { class Caches; -class PixelBuffer; /** * CacheBlock is a node in a linked list of current free space areas in a CacheTexture. @@ -74,7 +74,7 @@ struct CacheBlock { class CacheTexture { public: - CacheTexture(uint16_t width, uint16_t height, uint32_t maxQuadCount); + CacheTexture(uint16_t width, uint16_t height, GLenum format, uint32_t maxQuadCount); ~CacheTexture(); void reset(); @@ -100,6 +100,14 @@ public: return mHeight; } + inline GLenum getFormat() const { + return mFormat; + } + + inline uint32_t getOffset(uint16_t x, uint16_t y) const { + return (y * mWidth + x) * PixelBuffer::formatSize(mFormat); + } + inline const Rect* getDirtyRect() const { return &mDirtyRect; } @@ -173,6 +181,7 @@ private: GLuint mTextureId; uint16_t mWidth; uint16_t mHeight; + GLenum mFormat; bool mLinearFiltering; bool mDirty; uint16_t mNumGlyphs; diff --git a/libs/hwui/font/FontUtil.h b/libs/hwui/font/FontUtil.h index f758666..cdcb23c 100644 --- a/libs/hwui/font/FontUtil.h +++ b/libs/hwui/font/FontUtil.h @@ -31,6 +31,9 @@ #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 +#endif #define CACHE_BLOCK_ROUNDING_SIZE 4 |