Use glops for text rendering
Change-Id: I5e155c8baf3149f0ff231ec3c89dbff6bb8eae92
diff --git a/libs/hwui/font/CacheTexture.cpp b/libs/hwui/font/CacheTexture.cpp
index 9314126..845cf30 100644
--- a/libs/hwui/font/CacheTexture.cpp
+++ b/libs/hwui/font/CacheTexture.cpp
@@ -109,13 +109,17 @@
// CacheTexture
///////////////////////////////////////////////////////////////////////////////
-CacheTexture::CacheTexture(uint16_t width, uint16_t height, GLenum format, uint32_t maxQuadCount) :
- mTexture(nullptr), mTextureId(0), mWidth(width), mHeight(height), mFormat(format),
- mLinearFiltering(false), mDirty(false), mNumGlyphs(0),
- mMesh(nullptr), 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.
@@ -125,7 +129,7 @@
CacheTexture::~CacheTexture() {
releaseMesh();
- releaseTexture();
+ releasePixelBuffer();
reset();
}
@@ -144,35 +148,28 @@
// 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 = nullptr;
+void CacheTexture::releasePixelBuffer() {
+ if (mPixelBuffer) {
+ delete mPixelBuffer;
+ mPixelBuffer = nullptr;
}
- if (mTextureId) {
- mCaches.textureState().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.textureState().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() {
@@ -181,18 +178,18 @@
}
}
-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.textureState().bindTexture(mTextureId);
+ mCaches.textureState().bindTexture(mTexture.id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// Initialize texture dimensions
- glTexImage2D(GL_TEXTURE_2D, 0, mFormat, mWidth, mHeight, 0,
+ glTexImage2D(GL_TEXTURE_2D, 0, mFormat, getWidth(), getHeight(), 0,
mFormat, GL_UNSIGNED_BYTE, nullptr);
const GLenum filtering = getLinearFiltering() ? GL_LINEAR : GL_NEAREST;
@@ -209,16 +206,16 @@
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;
@@ -258,7 +255,7 @@
return false;
}
- if (glyph.fHeight + TEXTURE_BORDER_SIZE * 2 > mHeight) {
+ if (glyph.fHeight + TEXTURE_BORDER_SIZE * 2 > getHeight()) {
return false;
}
@@ -295,10 +292,10 @@
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 5d3f959..6dabc76 100644
--- a/libs/hwui/font/CacheTexture.h
+++ b/libs/hwui/font/CacheTexture.h
@@ -17,15 +17,15 @@
#ifndef ANDROID_HWUI_CACHE_TEXTURE_H
#define ANDROID_HWUI_CACHE_TEXTURE_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 "../PixelBuffer.h"
-#include "../Rect.h"
-#include "../Vertex.h"
namespace android {
namespace uirenderer {
@@ -80,9 +80,9 @@
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
@@ -92,11 +92,11 @@
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 {
@@ -104,7 +104,7 @@
}
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 {
@@ -112,12 +112,17 @@
}
inline PixelBuffer* getPixelBuffer() const {
+ return mPixelBuffer;
+ }
+
+ Texture& getTexture() {
+ allocatePixelBuffer();
return mTexture;
}
GLuint getTextureId() {
- allocateTexture();
- return mTextureId;
+ allocatePixelBuffer();
+ return mTexture.id;
}
inline bool isDirty() const {
@@ -131,7 +136,7 @@
/**
* 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;
@@ -176,16 +181,14 @@
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;