diff options
| author | 2013-02-05 14:38:40 -0800 | |
|---|---|---|
| committer | 2013-02-05 14:44:43 -0800 | |
| commit | b969a0de65730b071d846f8302e751e2637e6dbe (patch) | |
| tree | d49fd8cc93d96c54e991359e375c093882734909 /libs/hwui/FontRenderer.cpp | |
| parent | 15a4620b18412d81c1f9102cfc85777dece41a8b (diff) | |
Add support for non-antialiased text
Change-Id: I17c073955ab94abc9b409e5fcfbc675faa07c5ba
Diffstat (limited to 'libs/hwui/FontRenderer.cpp')
| -rw-r--r-- | libs/hwui/FontRenderer.cpp | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp index 5c1eb38786a2..97988f78454b 100644 --- a/libs/hwui/FontRenderer.cpp +++ b/libs/hwui/FontRenderer.cpp @@ -218,12 +218,14 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp cacheTexture->allocateTexture(); } - uint8_t* cacheBuffer = cacheTexture->getTexture(); - uint8_t* bitmapBuffer = (uint8_t*) glyph.fImage; - unsigned int stride = glyph.rowBytes(); + // Tells us whether the glyphs is B&W (1 bit per pixel) + // or anti-aliased (8 bits per pixel) + SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat); + uint8_t* cacheBuffer = cacheTexture->getTexture(); uint32_t cacheX = 0, bX = 0, cacheY = 0, bY = 0; + // Zero out the borders for (cacheX = startX - TEXTURE_BORDER_SIZE; cacheX < endX + TEXTURE_BORDER_SIZE; cacheX++) { cacheBuffer[(startY - TEXTURE_BORDER_SIZE) * cacheWidth + cacheX] = 0; cacheBuffer[(endY + TEXTURE_BORDER_SIZE - 1) * cacheWidth + cacheX] = 0; @@ -235,20 +237,49 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp cacheBuffer[cacheY * cacheWidth + endX + TEXTURE_BORDER_SIZE - 1] = 0; } - if (mGammaTable) { - for (cacheX = startX, bX = 0; cacheX < endX; cacheX++, bX++) { - for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY++) { - uint8_t tempCol = bitmapBuffer[bY * stride + bX]; - cacheBuffer[cacheY * cacheWidth + cacheX] = mGammaTable[tempCol]; + // Copy the glyph image, taking the mask format into account + uint8_t* bitmapBuffer = (uint8_t*) glyph.fImage; + int stride = glyph.rowBytes(); + + switch (format) { + case SkMask::kA8_Format: { + if (mGammaTable) { + for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY += stride) { + for (cacheX = startX, bX = 0; cacheX < endX; cacheX++, bX++) { + uint8_t tempCol = bitmapBuffer[bY + bX]; + cacheBuffer[cacheY * cacheWidth + cacheX] = mGammaTable[tempCol]; + } + } + } else { + for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY += stride) { + memcpy(&cacheBuffer[cacheY * cacheWidth + startX], &bitmapBuffer[bY], + glyph.fWidth); + } } + break; } - } else { - for (cacheX = startX, bX = 0; cacheX < endX; cacheX++, bX++) { - for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY++) { - uint8_t tempCol = bitmapBuffer[bY * stride + bX]; - cacheBuffer[cacheY * cacheWidth + cacheX] = tempCol; + case SkMask::kBW_Format: { + static const uint8_t COLORS[2] = { 0, 255 }; + + for (cacheY = startY; cacheY < endY; cacheY++) { + cacheX = startX; + int rowBytes = stride; + uint8_t* buffer = bitmapBuffer; + + while (--rowBytes >= 0) { + uint8_t b = *buffer++; + for (int8_t mask = 7; mask >= 0 && cacheX < endX; mask--) { + cacheBuffer[cacheY * cacheWidth + cacheX++] = COLORS[(b >> mask) & 0x1]; + } + } + + bitmapBuffer += stride; } + break; } + default: + ALOGW("Unkown glyph format: 0x%x", format); + break; } cachedGlyph->mIsValid = true; |