From d3bac753aa885a5dd91c4e608cc6c770d3d80daf Mon Sep 17 00:00:00 2001 From: John Reck Date: Tue, 29 May 2012 20:41:06 -0700 Subject: Don't use setupPaintFill for drawBitmap Bug: 6505013 When drawing a bitmap, don't use setupPaintFill(). The reason is that setupPaintFill will use the fillColor to influence the alpha set on the SkPaint. However, that fillColor does not apply to the bitmap, and can have the result of applying the wrong alpha (as the alpha set is fillColor alpha * graphicsContext's alpha). Instead, set the alpha on the paint directly and use setupPaintCommon Change-Id: Ib8d7ef494593a2896e6e3ed03c00d8d4d4b7232a --- .../graphics/android/context/PlatformGraphicsContext.cpp | 10 ++++++++++ .../graphics/android/context/PlatformGraphicsContext.h | 1 + .../graphics/android/context/PlatformGraphicsContextSkia.cpp | 6 ++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.cpp b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.cpp index bb5d990..ce9ce5a 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.cpp +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.cpp @@ -229,6 +229,16 @@ void PlatformGraphicsContext::setAlpha(float alpha) m_state->alpha = alpha; } +int PlatformGraphicsContext::getNormalizedAlpha() const +{ + int alpha = roundf(m_state->alpha * 256); + if (alpha > 255) + alpha = 255; + else if (alpha < 0) + alpha = 0; + return alpha; +} + void PlatformGraphicsContext::setCompositeOperation(CompositeOperator op) { m_state->mode = WebCoreCompositeToSkiaComposite(op); diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.h b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.h index 601de0f..1916014 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.h +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.h @@ -59,6 +59,7 @@ public: // State values virtual void setAlpha(float alpha); + int getNormalizedAlpha() const; virtual void setCompositeOperation(CompositeOperator op); virtual void setFillColor(const Color& c); virtual void setFillShader(SkShader* fillShader); diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.cpp b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.cpp index 9b32726..f00bb02 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.cpp +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextSkia.cpp @@ -234,7 +234,8 @@ void PlatformGraphicsContextSkia::drawBitmapPattern( SkShader::kRepeat_TileMode); shader->setLocalMatrix(matrix); SkPaint paint; - setupPaintFill(&paint); + setupPaintCommon(&paint); + paint.setAlpha(getNormalizedAlpha()); paint.setShader(shader); paint.setXfermodeMode(WebCoreCompositeToSkiaComposite(compositeOp)); fixPaintForBitmapsThatMaySeam(&paint); @@ -246,7 +247,8 @@ void PlatformGraphicsContextSkia::drawBitmapRect(const SkBitmap& bitmap, CompositeOperator op) { SkPaint paint; - setupPaintFill(&paint); + setupPaintCommon(&paint); + paint.setAlpha(getNormalizedAlpha()); paint.setXfermodeMode(WebCoreCompositeToSkiaComposite(op)); fixPaintForBitmapsThatMaySeam(&paint); -- cgit v1.1