OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkComposeShader.h" | 10 #include "SkComposeShader.h" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 276 |
277 // Store alpha of input color and un-premultiply the input color by its alph
a. We will | 277 // Store alpha of input color and un-premultiply the input color by its alph
a. We will |
278 // re-multiply by this alpha after blending the output colors of the two chi
ld procs. | 278 // re-multiply by this alpha after blending the output colors of the two chi
ld procs. |
279 // This is because we don't want the paint's alpha to affect either child pr
oc's output | 279 // This is because we don't want the paint's alpha to affect either child pr
oc's output |
280 // before the blend; we want to apply the paint's alpha AFTER the blend. Thi
s mirrors the | 280 // before the blend; we want to apply the paint's alpha AFTER the blend. Thi
s mirrors the |
281 // software implementation of SkComposeShader. | 281 // software implementation of SkComposeShader. |
282 SkString inputAlpha("inputAlpha"); | 282 SkString inputAlpha("inputAlpha"); |
283 fsBuilder->codeAppendf("float %s = %s.a;", inputAlpha.c_str(), args.fInputCo
lor); | 283 fsBuilder->codeAppendf("float %s = %s.a;", inputAlpha.c_str(), args.fInputCo
lor); |
284 fsBuilder->codeAppendf("%s /= %s.a;", args.fInputColor, args.fInputColor); | 284 fsBuilder->codeAppendf("%s /= %s.a;", args.fInputColor, args.fInputColor); |
285 | 285 |
286 // emit the code of the two child shaders | 286 // declare outputColor and emit the code for each of the two children |
287 SkString mangledOutputColorA; | 287 SkString outputColorA(args.fOutputColor); |
288 this->emitChild(0, args.fInputColor, &mangledOutputColorA, args); | 288 outputColorA.append("_dst"); |
289 SkString mangledOutputColorB; | 289 fsBuilder->codeAppendf("vec4 %s;\n", outputColorA.c_str()); |
290 this->emitChild(1, args.fInputColor, &mangledOutputColorB, args); | 290 this->emitChild(0, args.fInputColor, outputColorA.c_str(), args); |
| 291 |
| 292 SkString outputColorB(args.fOutputColor); |
| 293 outputColorB.append("_src"); |
| 294 fsBuilder->codeAppendf("vec4 %s;\n", outputColorB.c_str()); |
| 295 this->emitChild(1, args.fInputColor, outputColorB.c_str(), args); |
291 | 296 |
292 // emit blend code | 297 // emit blend code |
293 SkXfermode::Mode mode = cs.getMode(); | 298 SkXfermode::Mode mode = cs.getMode(); |
294 fsBuilder->codeAppend("{"); | 299 fsBuilder->codeAppend("{"); |
295 fsBuilder->codeAppendf("// Compose Xfer Mode: %s\n", SkXfermode::ModeName(mo
de)); | 300 fsBuilder->codeAppendf("// Compose Xfer Mode: %s\n", SkXfermode::ModeName(mo
de)); |
296 GrGLBlend::AppendPorterDuffBlend(fsBuilder, mangledOutputColorB.c_str(), | 301 GrGLBlend::AppendPorterDuffBlend(fsBuilder, outputColorB.c_str(), |
297 mangledOutputColorA.c_str(), args.fOutputCo
lor, mode); | 302 outputColorA.c_str(), args.fOutputColor, mo
de); |
298 fsBuilder->codeAppend("}"); | 303 fsBuilder->codeAppend("}"); |
299 | 304 |
300 // re-multiply the output color by the input color's alpha | 305 // re-multiply the output color by the input color's alpha |
301 fsBuilder->codeAppendf("%s *= %s;", args.fOutputColor, inputAlpha.c_str()); | 306 fsBuilder->codeAppendf("%s *= %s;", args.fOutputColor, inputAlpha.c_str()); |
302 } | 307 } |
303 | 308 |
304 ///////////////////////////////////////////////////////////////////// | 309 ///////////////////////////////////////////////////////////////////// |
305 | 310 |
306 const GrFragmentProcessor* SkComposeShader::asFragmentProcessor(GrContext* conte
xt, | 311 const GrFragmentProcessor* SkComposeShader::asFragmentProcessor(GrContext* conte
xt, |
307 const SkMatrix& view
M, | 312 const SkMatrix& view
M, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 if (fMode) { | 360 if (fMode) { |
356 str->append(" Xfermode: "); | 361 str->append(" Xfermode: "); |
357 fMode->toString(str); | 362 fMode->toString(str); |
358 } | 363 } |
359 | 364 |
360 this->INHERITED::toString(str); | 365 this->INHERITED::toString(str); |
361 | 366 |
362 str->append(")"); | 367 str->append(")"); |
363 } | 368 } |
364 #endif | 369 #endif |
OLD | NEW |