summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Craik <ccraik@android.com>2014-05-19 19:23:07 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-05-19 19:23:07 +0000
commitb1708e9b764268a06d91219a5c39ee9efd32ab00 (patch)
treece508cc21b13540cd79de0da5efa82ba7db0bab9
parenta84d24c37a3e27cdd4f50807e9dc5fb6f14ea009 (diff)
parentc62c1cc17ded117433d23ba5dd6c364b05fbcdbd (diff)
downloadbase-b1708e9b764268a06d91219a5c39ee9efd32ab00.tar.gz
Merge "Use alpha channel instead of red in drawCachedGlyphBitmap"
-rw-r--r--libs/hwui/PixelBuffer.h19
-rw-r--r--libs/hwui/font/Font.cpp3
2 files changed, 21 insertions, 1 deletions
diff --git a/libs/hwui/PixelBuffer.h b/libs/hwui/PixelBuffer.h
index 9725a6162a2c..04225a20cfc2 100644
--- a/libs/hwui/PixelBuffer.h
+++ b/libs/hwui/PixelBuffer.h
@@ -175,6 +175,25 @@ public:
return 0;
}
+ /**
+ * Returns the alpha channel offset in the specified format.
+ *
+ * Supported formats:
+ * GL_ALPHA
+ * GL_RGBA
+ */
+ static uint32_t formatAlphaOffset(GLenum format) {
+ switch (format) {
+ case GL_ALPHA:
+ return 0;
+ case GL_RGBA:
+ return 3;
+ }
+
+ ALOGE("unsupported format: %d",format);
+ return 0;
+ }
+
protected:
/**
* Creates a new render buffer in the specified format and dimensions.
diff --git a/libs/hwui/font/Font.cpp b/libs/hwui/font/Font.cpp
index b49329834760..eb33cf1f3fdc 100644
--- a/libs/hwui/font/Font.cpp
+++ b/libs/hwui/font/Font.cpp
@@ -215,6 +215,7 @@ void Font::drawCachedGlyphBitmap(CachedGlyphInfo* glyph, int x, int y, uint8_t*
PixelBuffer* pixelBuffer = cacheTexture->getPixelBuffer();
uint32_t formatSize = PixelBuffer::formatSize(pixelBuffer->getFormat());
+ uint32_t alpha_channel_offset = PixelBuffer::formatAlphaOffset(pixelBuffer->getFormat());
uint32_t cacheWidth = cacheTexture->getWidth();
uint32_t srcStride = formatSize * cacheWidth;
uint32_t startY = glyph->mStartY * srcStride;
@@ -229,7 +230,7 @@ void Font::drawCachedGlyphBitmap(CachedGlyphInfo* glyph, int x, int y, uint8_t*
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];
+ bitmap[bitmapY + dstX + i] = cacheBuffer[cacheY + (glyph->mStartX + i)*formatSize + alpha_channel_offset];
}
}
}