summaryrefslogtreecommitdiffstats
path: root/libs/hwui/OpenGLRenderer.cpp
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2012-07-19 22:48:17 -0700
committerRaph Levien <raph@google.com>2012-07-20 12:55:30 -0700
commit416a847633680d94efb926837efdc18726d54918 (patch)
tree0a5d914259e9ae5fa040e179ba5630d7102a49ad /libs/hwui/OpenGLRenderer.cpp
parent592b29f4ad3d46b483b2d6ed2c5cfac8d139afe8 (diff)
downloadframeworks_base-416a847633680d94efb926837efdc18726d54918.zip
frameworks_base-416a847633680d94efb926837efdc18726d54918.tar.gz
frameworks_base-416a847633680d94efb926837efdc18726d54918.tar.bz2
Add drop shadow for drawPosText in hwui renderer.
This patch adds support for drop shadows (setShadowLayer) for drawPosText in the hwui renderer. In and of itself, it's not very important, but it's on the critical path for correct mark positioning, tracked as bug 5443796. The change itself is fairly straightforward - it basically just adds an extra "positions" argument to all draw and measure methods on the code path for drawing drop shadowed text, as well as to the cache key for cached shadow textures. Change-Id: Ic1cb63299ba61ccbef31779459ecb82aa4a5e672
Diffstat (limited to 'libs/hwui/OpenGLRenderer.cpp')
-rw-r--r--libs/hwui/OpenGLRenderer.cpp77
1 files changed, 44 insertions, 33 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index a47d732..fe056b0 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -2294,6 +2294,44 @@ status_t OpenGLRenderer::drawRect(float left, float top, float right, float bott
return DrawGlInfo::kStatusDrew;
}
+void OpenGLRenderer::drawTextShadow(SkPaint* paint, const char* text, int bytesCount, int count,
+ const float* positions, FontRenderer& fontRenderer, int alpha, SkXfermode::Mode mode,
+ float x, float y) {
+ mCaches.activeTexture(0);
+
+ // NOTE: The drop shadow will not perform gamma correction
+ // if shader-based correction is enabled
+ mCaches.dropShadowCache.setFontRenderer(fontRenderer);
+ const ShadowTexture* shadow = mCaches.dropShadowCache.get(
+ paint, text, bytesCount, count, mShadowRadius, positions);
+ const AutoTexture autoCleanup(shadow);
+
+ const float sx = x - shadow->left + mShadowDx;
+ const float sy = y - shadow->top + mShadowDy;
+
+ const int shadowAlpha = ((mShadowColor >> 24) & 0xFF) * mSnapshot->alpha;
+ int shadowColor = mShadowColor;
+ if (mShader) {
+ shadowColor = 0xffffffff;
+ }
+
+ setupDraw();
+ setupDrawWithTexture(true);
+ setupDrawAlpha8Color(shadowColor, shadowAlpha < 255 ? shadowAlpha : alpha);
+ setupDrawColorFilter();
+ setupDrawShader();
+ setupDrawBlending(true, mode);
+ setupDrawProgram();
+ setupDrawModelView(sx, sy, sx + shadow->width, sy + shadow->height);
+ setupDrawTexture(shadow->id);
+ setupDrawPureColorUniforms();
+ setupDrawColorFilterUniforms();
+ setupDrawShaderUniforms();
+ setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset);
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
+}
+
status_t OpenGLRenderer::drawPosText(const char* text, int bytesCount, int count,
const float* positions, SkPaint* paint) {
if (text == NULL || count == 0 || mSnapshot->isIgnored() ||
@@ -2322,6 +2360,11 @@ status_t OpenGLRenderer::drawPosText(const char* text, int bytesCount, int count
SkXfermode::Mode mode;
getAlphaAndMode(paint, &alpha, &mode);
+ if (CC_UNLIKELY(mHasShadow)) {
+ drawTextShadow(paint, text, bytesCount, count, positions, fontRenderer, alpha, mode,
+ 0.0f, 0.0f);
+ }
+
// Pick the appropriate texture filtering
bool linearFilter = mSnapshot->transform->changesBounds();
if (pureTranslate && !linearFilter) {
@@ -2415,39 +2458,7 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
getAlphaAndMode(paint, &alpha, &mode);
if (CC_UNLIKELY(mHasShadow)) {
- mCaches.activeTexture(0);
-
- // NOTE: The drop shadow will not perform gamma correction
- // if shader-based correction is enabled
- mCaches.dropShadowCache.setFontRenderer(fontRenderer);
- const ShadowTexture* shadow = mCaches.dropShadowCache.get(
- paint, text, bytesCount, count, mShadowRadius);
- const AutoTexture autoCleanup(shadow);
-
- const float sx = oldX - shadow->left + mShadowDx;
- const float sy = oldY - shadow->top + mShadowDy;
-
- const int shadowAlpha = ((mShadowColor >> 24) & 0xFF) * mSnapshot->alpha;
- int shadowColor = mShadowColor;
- if (mShader) {
- shadowColor = 0xffffffff;
- }
-
- setupDraw();
- setupDrawWithTexture(true);
- setupDrawAlpha8Color(shadowColor, shadowAlpha < 255 ? shadowAlpha : alpha);
- setupDrawColorFilter();
- setupDrawShader();
- setupDrawBlending(true, mode);
- setupDrawProgram();
- setupDrawModelView(sx, sy, sx + shadow->width, sy + shadow->height);
- setupDrawTexture(shadow->id);
- setupDrawPureColorUniforms();
- setupDrawColorFilterUniforms();
- setupDrawShaderUniforms();
- setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
+ drawTextShadow(paint, text, bytesCount, count, NULL, fontRenderer, alpha, mode, oldX, oldY);
}
// Pick the appropriate texture filtering