OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "gl/GrGLXferProcessor.h" |
| 9 |
| 10 #include "GrXferProcessor.h" |
| 11 #include "gl/builders/GrGLFragmentShaderBuilder.h" |
| 12 #include "gl/builders/GrGLProgramBuilder.h" |
| 13 |
| 14 void GrGLXferProcessor::emitCode(const EmitArgs& args) { |
| 15 const GrPorterDuffXferProcessor& xp = args.fXP.cast<GrPorterDuffXferProcesso
r>(); |
| 16 if (xp.hasDstCopy()) { |
| 17 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 18 const char* dstColor = fsBuilder->dstColor(); |
| 19 |
| 20 bool topDown = xp.dstCopyIsTopDown(); |
| 21 const char* dstCopyTopLeftName; |
| 22 const char* dstCopyCoordScaleName; |
| 23 |
| 24 fDstCopyTopLeftUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, |
| 25 kVec2f_GrSLType, |
| 26 kDefault_GrSLPrecision, |
| 27 "DstCopyUpperLeft", |
| 28 &dstCopyTopLeftName); |
| 29 fDstCopyScaleUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, |
| 30 kVec2f_GrSLType, |
| 31 kDefault_GrSLPrecision, |
| 32 "DstCopyCoordScale", |
| 33 &dstCopyCoordScaleName); |
| 34 const char* fragPos = fsBuilder->fragmentPosition(); |
| 35 |
| 36 fsBuilder->codeAppend("// Read color from copy of the destination.\n"); |
| 37 fsBuilder->codeAppendf("vec2 _dstTexCoord = (%s.xy - %s) * %s;", |
| 38 fragPos, dstCopyTopLeftName, dstCopyCoordScaleNam
e); |
| 39 if (!topDown) { |
| 40 fsBuilder->codeAppend("_dstTexCoord.y = 1.0 - _dstTexCoord.y;"); |
| 41 } |
| 42 fsBuilder->codeAppendf("vec4 %s = ", dstColor); |
| 43 fsBuilder->appendTextureLookup(args.fSamplers[0], |
| 44 "_dstTexCoord", |
| 45 kVec2f_GrSLType); |
| 46 fsBuilder->codeAppend(";"); |
| 47 } |
| 48 |
| 49 this->onEmitCode(args); |
| 50 } |
| 51 |
| 52 void GrGLXferProcessor::setData(const GrGLProgramDataManager& pdm, const GrXferP
rocessor& xp) { |
| 53 if (xp.hasDstCopy()) { |
| 54 if (fDstCopyTopLeftUni.isValid()) { |
| 55 pdm.set2f(fDstCopyTopLeftUni, static_cast<GrGLfloat>(xp.offset().fX)
, |
| 56 static_cast<GrGLfloat>(xp.offset().fY)); |
| 57 pdm.set2f(fDstCopyScaleUni, 1.f / xp.getDstCopyTexture()->width(), |
| 58 1.f / xp.getDstCopyTexture()->height()); |
| 59 } else { |
| 60 SkASSERT(!fDstCopyScaleUni.isValid()); |
| 61 } |
| 62 } else { |
| 63 SkASSERT(!fDstCopyTopLeftUni.isValid()); |
| 64 SkASSERT(!fDstCopyScaleUni.isValid()); |
| 65 } |
| 66 this->onSetData(pdm, xp); |
| 67 } |
| 68 |
OLD | NEW |