Skip to content

Commit 0a332e3

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Draw an empty border around glyphs to avoid sampling issues Bug #6942209" into jb-mr1-dev
2 parents 96f1ee9 + 33fa1f7 commit 0a332e3

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

libs/hwui/FontRenderer.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace uirenderer {
3737
#define DEFAULT_TEXT_CACHE_WIDTH 1024
3838
#define DEFAULT_TEXT_CACHE_HEIGHT 256
3939
#define MAX_TEXT_CACHE_WIDTH 2048
40-
#define TEXTURE_BORDER_SIZE 2
40+
#define TEXTURE_BORDER_SIZE 1
4141

4242
#define AUTO_KERN(prev, next) (((next) - (prev) + 32) >> 6 << 16)
4343

@@ -50,10 +50,10 @@ bool CacheTextureLine::fitBitmap(const SkGlyph& glyph, uint32_t *retOriginX, uin
5050
return false;
5151
}
5252

53-
if (mCurrentCol + glyph.fWidth + TEXTURE_BORDER_SIZE < mMaxWidth) {
54-
*retOriginX = mCurrentCol + 1;
55-
*retOriginY = mCurrentRow + 1;
56-
mCurrentCol += glyph.fWidth + TEXTURE_BORDER_SIZE;
53+
if (mCurrentCol + glyph.fWidth + TEXTURE_BORDER_SIZE * 2 < mMaxWidth) {
54+
*retOriginX = mCurrentCol + TEXTURE_BORDER_SIZE;
55+
*retOriginY = mCurrentRow + TEXTURE_BORDER_SIZE;
56+
mCurrentCol += glyph.fWidth + TEXTURE_BORDER_SIZE * 2;
5757
mDirty = true;
5858
return true;
5959
}
@@ -412,10 +412,10 @@ void Font::updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, CachedGlyp
412412
uint32_t cacheWidth = glyph->mCachedTextureLine->mCacheTexture->mWidth;
413413
uint32_t cacheHeight = glyph->mCachedTextureLine->mCacheTexture->mHeight;
414414

415-
glyph->mBitmapMinU = (float) startX / (float) cacheWidth;
416-
glyph->mBitmapMinV = (float) startY / (float) cacheHeight;
417-
glyph->mBitmapMaxU = (float) endX / (float) cacheWidth;
418-
glyph->mBitmapMaxV = (float) endY / (float) cacheHeight;
415+
glyph->mBitmapMinU = startX / (float) cacheWidth;
416+
glyph->mBitmapMinV = startY / (float) cacheHeight;
417+
glyph->mBitmapMaxU = endX / (float) cacheWidth;
418+
glyph->mBitmapMaxV = endY / (float) cacheHeight;
419419

420420
mState->mUploadTexture = true;
421421
}
@@ -590,9 +590,6 @@ void FontRenderer::allocateTextureMemory(CacheTexture* cacheTexture) {
590590
int height = cacheTexture->mHeight;
591591

592592
cacheTexture->mTexture = new uint8_t[width * height];
593-
#if DEBUG_FONT_RENDERER
594-
memset(cacheTexture->mTexture, 0, width * height * sizeof(uint8_t));
595-
#endif
596593

597594
if (!cacheTexture->mTextureId) {
598595
glGenTextures(1, &cacheTexture->mTextureId);
@@ -617,7 +614,7 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp
617614
uint32_t* retOriginX, uint32_t* retOriginY) {
618615
cachedGlyph->mIsValid = false;
619616
// If the glyph is too tall, don't cache it
620-
if (glyph.fHeight + TEXTURE_BORDER_SIZE > mCacheLines[mCacheLines.size() - 1]->mMaxHeight) {
617+
if (glyph.fHeight + TEXTURE_BORDER_SIZE * 2 > mCacheLines[mCacheLines.size() - 1]->mMaxHeight) {
621618
ALOGE("Font size to large to fit in cache. width, height = %i, %i",
622619
(int) glyph.fWidth, (int) glyph.fHeight);
623620
return;
@@ -677,6 +674,18 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp
677674
unsigned int stride = glyph.rowBytes();
678675

679676
uint32_t cacheX = 0, bX = 0, cacheY = 0, bY = 0;
677+
678+
for (cacheX = startX - TEXTURE_BORDER_SIZE; cacheX < endX + TEXTURE_BORDER_SIZE; cacheX++) {
679+
cacheBuffer[(startY - TEXTURE_BORDER_SIZE) * cacheWidth + cacheX] = 0;
680+
cacheBuffer[(endY + TEXTURE_BORDER_SIZE - 1) * cacheWidth + cacheX] = 0;
681+
}
682+
683+
for (cacheY = startY - TEXTURE_BORDER_SIZE + 1;
684+
cacheY < endY + TEXTURE_BORDER_SIZE - 1; cacheY++) {
685+
cacheBuffer[cacheY * cacheWidth + startX - TEXTURE_BORDER_SIZE] = 0;
686+
cacheBuffer[cacheY * cacheWidth + endX + TEXTURE_BORDER_SIZE - 1] = 0;
687+
}
688+
680689
if (mGammaTable) {
681690
for (cacheX = startX, bX = 0; cacheX < endX; cacheX++, bX++) {
682691
for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY++) {

libs/hwui/OpenGLRenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,7 @@ void OpenGLRenderer::chooseBlending(bool blend, SkXfermode::Mode mode,
28922892
// the blending, turn blending off here
28932893
// If the blend mode cannot be implemented using shaders, fall
28942894
// back to the default SrcOver blend mode instead
2895-
if CC_UNLIKELY((mode > SkXfermode::kScreen_Mode)) {
2895+
if (CC_UNLIKELY(mode > SkXfermode::kScreen_Mode)) {
28962896
if (CC_UNLIKELY(mCaches.extensions.hasFramebufferFetch())) {
28972897
description.framebufferMode = mode;
28982898
description.swapSrcDst = swapSrcDst;

tests/HwAccelerationTest/src/com/android/test/hwui/TextActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ protected void onDraw(Canvas canvas) {
153153
canvas.drawText("Hello OpenGL renderer!", 100, 300, mLargePaint);
154154
canvas.restore();
155155

156+
// mStrikePaint.setUnderlineText(false);
157+
// canvas.save();
158+
// canvas.scale(20.0f, 20.0f);
159+
// canvas.drawText("aeiouyw", 5.0f, 750 / 20.0f, mStrikePaint);
160+
// canvas.restore();
161+
// mStrikePaint.setUnderlineText(true);
156162
}
157163
}
158164
}

0 commit comments

Comments
 (0)