| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "effects/GrXfermodeFragmentProcessor.h" | 8 #include "effects/GrXfermodeFragmentProcessor.h" |
| 9 | 9 |
| 10 #include "GrFragmentProcessor.h" | 10 #include "GrFragmentProcessor.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 return new GLComposeTwoFragmentProcessor(*this); | 83 return new GLComposeTwoFragmentProcessor(*this); |
| 84 } | 84 } |
| 85 | 85 |
| 86 ///////////////////////////////////////////////////////////////////// | 86 ///////////////////////////////////////////////////////////////////// |
| 87 | 87 |
| 88 void GLComposeTwoFragmentProcessor::emitCode(EmitArgs& args) { | 88 void GLComposeTwoFragmentProcessor::emitCode(EmitArgs& args) { |
| 89 | 89 |
| 90 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 90 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); |
| 91 const ComposeTwoFragmentProcessor& cs = args.fFp.cast<ComposeTwoFragmentProc
essor>(); | 91 const ComposeTwoFragmentProcessor& cs = args.fFp.cast<ComposeTwoFragmentProc
essor>(); |
| 92 | 92 |
| 93 // Store alpha of input color and un-premultiply the input color by its alph
a. We will | 93 const char* inputColor = nullptr; |
| 94 // re-multiply by this alpha after blending the output colors of the two chi
ld procs. | |
| 95 // This is because we don't want the paint's alpha to affect either child pr
oc's output | |
| 96 // before the blend; we want to apply the paint's alpha AFTER the blend. Thi
s mirrors the | |
| 97 // software implementation of SkComposeShader. | |
| 98 const char* opaqueInput = nullptr; | |
| 99 const char* inputAlpha = nullptr; | |
| 100 if (args.fInputColor) { | 94 if (args.fInputColor) { |
| 101 inputAlpha = "inputAlpha"; | 95 inputColor = "inputColor"; |
| 102 opaqueInput = "opaqueInput"; | 96 fsBuilder->codeAppendf("vec4 inputColor = vec4(%s.rgb, 1.0);", args.fInp
utColor); |
| 103 fsBuilder->codeAppendf("float inputAlpha = %s.a;", args.fInputColor); | |
| 104 fsBuilder->codeAppendf("vec4 opaqueInput = vec4(%s.rgb / inputAlpha, 1);
", | |
| 105 args.fInputColor); | |
| 106 } | 97 } |
| 107 | 98 |
| 108 // declare outputColor and emit the code for each of the two children | 99 // declare outputColor and emit the code for each of the two children |
| 109 SkString srcColor("src"); | 100 SkString srcColor("src"); |
| 110 this->emitChild(0, opaqueInput, &srcColor, args); | 101 this->emitChild(0, inputColor, &srcColor, args); |
| 111 | 102 |
| 112 SkString dstColor("dst"); | 103 SkString dstColor("dst"); |
| 113 this->emitChild(1, opaqueInput, &dstColor, args); | 104 this->emitChild(1, inputColor, &dstColor, args); |
| 114 | 105 |
| 115 // emit blend code | 106 // emit blend code |
| 116 SkXfermode::Mode mode = cs.getMode(); | 107 SkXfermode::Mode mode = cs.getMode(); |
| 117 fsBuilder->codeAppendf("// Compose Xfer Mode: %s\n", SkXfermode::ModeName(mo
de)); | 108 fsBuilder->codeAppendf("// Compose Xfer Mode: %s\n", SkXfermode::ModeName(mo
de)); |
| 118 GrGLSLBlend::AppendMode(fsBuilder, srcColor.c_str(), dstColor.c_str(), args.
fOutputColor, mode); | 109 GrGLSLBlend::AppendMode(fsBuilder, srcColor.c_str(), dstColor.c_str(), args.
fOutputColor, mode); |
| 119 | 110 |
| 120 // re-multiply the output color by the input color's alpha | 111 // re-multiply the output color by the input color's alpha |
| 121 if (inputAlpha) { | 112 if (args.fInputColor) { |
| 122 fsBuilder->codeAppendf("%s *= %s;", args.fOutputColor, inputAlpha); | 113 fsBuilder->codeAppendf("%s *= %s.a;", args.fOutputColor, args.fInputColo
r); |
| 123 } | 114 } |
| 124 } | 115 } |
| 125 | 116 |
| 126 const GrFragmentProcessor* GrXfermodeFragmentProcessor::CreateFromTwoProcessors( | 117 const GrFragmentProcessor* GrXfermodeFragmentProcessor::CreateFromTwoProcessors( |
| 127 const GrFragmentProcessor* src, const GrFragmentProcessor* dst, SkXferm
ode::Mode mode) { | 118 const GrFragmentProcessor* src, const GrFragmentProcessor* dst, SkXferm
ode::Mode mode) { |
| 128 switch (mode) { | 119 switch (mode) { |
| 129 case SkXfermode::kClear_Mode: | 120 case SkXfermode::kClear_Mode: |
| 130 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, | 121 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, |
| 131 GrConstColorProcessor::kIgnore_
InputMode); | 122 GrConstColorProcessor::kIgnore_
InputMode); |
| 132 case SkXfermode::kSrc_Mode: | 123 case SkXfermode::kSrc_Mode: |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 case SkXfermode::kClear_Mode: | 288 case SkXfermode::kClear_Mode: |
| 298 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, | 289 return GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK, |
| 299 GrConstColorProcessor::kIgnore_
InputMode); | 290 GrConstColorProcessor::kIgnore_
InputMode); |
| 300 case SkXfermode::kDst_Mode: | 291 case SkXfermode::kDst_Mode: |
| 301 return nullptr; | 292 return nullptr; |
| 302 default: | 293 default: |
| 303 return new ComposeOneFragmentProcessor(src, mode, | 294 return new ComposeOneFragmentProcessor(src, mode, |
| 304 ComposeOneFragmentProcessor::
kSrc_Child); | 295 ComposeOneFragmentProcessor::
kSrc_Child); |
| 305 } | 296 } |
| 306 } | 297 } |
| OLD | NEW |