summaryrefslogtreecommitdiffstats
path: root/libs/hwui/font/CacheTexture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/font/CacheTexture.cpp')
-rw-r--r--libs/hwui/font/CacheTexture.cpp80
1 files changed, 39 insertions, 41 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,