summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-05 16:45:01 +0000
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-05 16:45:01 +0000
commitcb3f436b7cf9abedc24f6cc02a081fed7cbc81ee (patch)
tree1f65cef3519830b4fc740b72752d1446b8f45d84
parentd8fd8c7718508a11547505b00b1dbb324d461767 (diff)
downloadsrc-cb3f436b7cf9abedc24f6cc02a081fed7cbc81ee.tar.gz
fix composeshader to respect the paint's alpha
BUG=skia: R=scroggo@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/265163008 git-svn-id: http://skia.googlecode.com/svn/trunk/src@14569 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--core/SkComposeShader.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/core/SkComposeShader.cpp b/core/SkComposeShader.cpp
index df8215c1..28511e3e 100644
--- a/core/SkComposeShader.cpp
+++ b/core/SkComposeShader.cpp
@@ -100,20 +100,23 @@ SkShader::Context* SkComposeShader::createContext(const ContextRec& rec, void* s
return NULL;
}
- // TODO : must fix this to not "cheat" and modify fPaint
- SkAutoAlphaRestore restore(const_cast<SkPaint*>(rec.fPaint), 0xFF);
-
char* aStorage = (char*) storage + sizeof(ComposeShaderContext);
char* bStorage = aStorage + fShaderA->contextSize();
// we preconcat our localMatrix (if any) with the device matrix
// before calling our sub-shaders
-
SkMatrix tmpM;
tmpM.setConcat(*rec.fMatrix, this->getLocalMatrix());
+ // Our sub-shaders need to see opaque, so by combining them we don't double-alphatize the
+ // result. ComposeShader itself will respect the alpha, and post-apply it after calling the
+ // sub-shaders.
+ SkPaint opaquePaint(*rec.fPaint);
+ opaquePaint.setAlpha(0xFF);
+
ContextRec newRec(rec);
newRec.fMatrix = &tmpM;
+ newRec.fPaint = &opaquePaint;
SkShader::Context* contextA = fShaderA->createContext(newRec, aStorage);
SkShader::Context* contextB = fShaderB->createContext(newRec, bStorage);
@@ -148,6 +151,10 @@ void SkComposeShader::ComposeShaderContext::shadeSpan(int x, int y, SkPMColor re
SkXfermode* mode = static_cast<const SkComposeShader&>(fShader).fMode;
unsigned scale = SkAlpha255To256(this->getPaintAlpha());
+#ifdef SK_BUILD_FOR_ANDROID
+ scale = 256; // ugh -- maintain old bug/behavior for now
+#endif
+
SkPMColor tmp[TMP_COLOR_COUNT];
if (NULL == mode) { // implied SRC_OVER
@@ -188,7 +195,7 @@ void SkComposeShader::ComposeShaderContext::shadeSpan(int x, int y, SkPMColor re
shaderContextB->shadeSpan(x, y, tmp, n);
mode->xfer32(result, tmp, n, NULL);
- if (256 == scale) {
+ if (256 != scale) {
for (int i = 0; i < n; i++) {
result[i] = SkAlphaMulQ(result[i], scale);
}