Skip to content

Commit 16c8808

Browse files
author
Romain Guy
committed
Textured text calls could be invisible
Bug #6597730 Text would sometimes not appear when rendered with textured content (BitmapShader, LinearGradientShader, etc.) This was due to a misuse of OpenGL texture unit in FontRenderer. Textured text normally uses two texture units: - texture unit 0 for the font cache - texture unit 1 for the textured content (gradient, etc.) Recent changes to the font renderer allow it to bind new textures while processing the text's geometry (this happens when caches get full or when switching font size for instance.) The bindings were done without ensuring the texture unit was the correct one (unit 0), thus replacing the content of another texture unit (unit 1). This lead to text being drawn using the font cache itself as the content texture, making the text invisible. Change-Id: I392b4c884f09223305f6cbc6253e2ef9a98944c9
1 parent 527ee91 commit 16c8808

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

libs/hwui/FontRenderer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ void FontRenderer::allocateTextureMemory(CacheTexture* cacheTexture) {
598598
glGenTextures(1, &cacheTexture->mTextureId);
599599
}
600600

601+
Caches::getInstance().activeTexture(0);
601602
glBindTexture(GL_TEXTURE_2D, cacheTexture->mTextureId);
602603
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
603604
// Initialize texture dimensions
@@ -826,6 +827,7 @@ void FontRenderer::checkTextureUpdate() {
826827
}
827828
}
828829

830+
caches.activeTexture(0);
829831
glBindTexture(GL_TEXTURE_2D, mCurrentCacheTexture->mTextureId);
830832
if (mLinearFiltering != mCurrentCacheTexture->mLinearFiltering) {
831833
const GLenum filtering = mLinearFiltering ? GL_LINEAR : GL_NEAREST;

libs/hwui/OpenGLRenderer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,6 +2422,7 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
24222422
linearFilter = fabs(y - (int) y) > 0.0f || fabs(x - (int) x) > 0.0f;
24232423
}
24242424

2425+
// The font renderer will always use texture unit 0
24252426
mCaches.activeTexture(0);
24262427
setupDraw();
24272428
setupDrawDirtyRegionsDisabled();
@@ -2432,6 +2433,8 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
24322433
setupDrawBlending(true, mode);
24332434
setupDrawProgram();
24342435
setupDrawModelView(x, y, x, y, pureTranslate, true);
2436+
// See comment above; the font renderer must use texture unit 0
2437+
// assert(mTextureUnit == 0)
24352438
setupDrawTexture(fontRenderer.getTexture(linearFilter));
24362439
setupDrawPureColorUniforms();
24372440
setupDrawColorFilterUniforms();

0 commit comments

Comments
 (0)