diff options
author | Chris Craik <ccraik@google.com> | 2015-06-30 13:12:24 -0700 |
---|---|---|
committer | Chris Craik <ccraik@google.com> | 2015-06-30 13:24:18 -0700 |
commit | de25a672b18171a3d14315b34dc7c8fcf46ae91e (patch) | |
tree | 3b1d9ec041624c9f2bec3f8e1d319d311baf867c /libs | |
parent | 82b3f67711246ad5beaf7702ce16e9d433406d1e (diff) | |
download | frameworks_base-de25a672b18171a3d14315b34dc7c8fcf46ae91e.zip frameworks_base-de25a672b18171a3d14315b34dc7c8fcf46ae91e.tar.gz frameworks_base-de25a672b18171a3d14315b34dc7c8fcf46ae91e.tar.bz2 |
Saturate alpha values when overlaying glyphs
bug:19062769
Glyphs were stored to the output buffer with the assumption of
non-overlap, which is incorrect for certain fonts/strings. Instead,
blend src into dst, so new glyphs don't clobber existing content.
Change-Id: I6e22037500e67d5348ee2a43d939416c23c4d1ea
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/font/Font.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/libs/hwui/font/Font.cpp b/libs/hwui/font/Font.cpp index b07a3c8..5de64a4 100644 --- a/libs/hwui/font/Font.cpp +++ b/libs/hwui/font/Font.cpp @@ -228,15 +228,15 @@ void Font::drawCachedGlyphBitmap(CachedGlyphInfo* glyph, int x, int y, uint8_t* for (uint32_t cacheY = startY, bitmapY = dstY * bitmapWidth; cacheY < endY; cacheY += srcStride, bitmapY += bitmapWidth) { - if (formatSize == 1) { - memcpy(&bitmap[bitmapY + dstX], &cacheBuffer[cacheY + glyph->mStartX], glyph->mBitmapWidth); - } else { - for (uint32_t i = 0; i < glyph->mBitmapWidth; ++i) { - bitmap[bitmapY + dstX + i] = cacheBuffer[cacheY + (glyph->mStartX + i)*formatSize + alpha_channel_offset]; - } + for (uint32_t i = 0; i < glyph->mBitmapWidth; ++i) { + uint8_t* dst = &(bitmap[bitmapY + dstX + i]); + const uint8_t& src = cacheBuffer[ + cacheY + (glyph->mStartX + i)*formatSize + alpha_channel_offset]; + // Add alpha values to a max of 255, full opacity. This is done to handle + // fonts/strings where glyphs overlap. + *dst = std::min(*dst + src, 255); } } - } void Font::drawCachedGlyph(CachedGlyphInfo* glyph, float x, float hOffset, float vOffset, |