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.getDstCopyTexture()) { |
| 17 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 18 const char* dstColor = fsBuilder->dstColor(); |
| 19 |
| 20 const char* dstCopyTopLeftName; |
| 21 const char* dstCopyCoordScaleName; |
| 22 |
| 23 fDstCopyTopLeftUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, |
| 24 kVec2f_GrSLType, |
| 25 kDefault_GrSLPrecision, |
| 26 "DstCopyUpperLeft", |
| 27 &dstCopyTopLeftName); |
| 28 fDstCopyScaleUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, |
| 29 kVec2f_GrSLType, |
| 30 kDefault_GrSLPrecision, |
| 31 "DstCopyCoordScale", |
| 32 &dstCopyCoordScaleName); |
| 33 const char* fragPos = fsBuilder->fragmentPosition(); |
| 34 |
| 35 fsBuilder->codeAppend("// Read color from copy of the destination.\n"); |
| 36 fsBuilder->codeAppendf("vec2 _dstTexCoord = (%s.xy - %s) * %s;", |
| 37 fragPos, dstCopyTopLeftName, dstCopyCoordScaleNam
e); |
| 38 fsBuilder->codeAppendf("vec4 %s = ", dstColor); |
| 39 fsBuilder->appendTextureLookup(args.fSamplers[0], "_dstTexCoord", kVec2f
_GrSLType); |
| 40 fsBuilder->codeAppend(";"); |
| 41 } |
| 42 |
| 43 this->onEmitCode(args); |
| 44 } |
| 45 |
| 46 void GrGLXferProcessor::setData(const GrGLProgramDataManager& pdm, const GrXferP
rocessor& xp) { |
| 47 if (xp.getDstCopyTexture()) { |
| 48 if (fDstCopyTopLeftUni.isValid()) { |
| 49 pdm.set2f(fDstCopyTopLeftUni, static_cast<GrGLfloat>(xp.dstCopyTextu
reOffset().fX), |
| 50 static_cast<GrGLfloat>(xp.dstCopyTextureOffset().fY)); |
| 51 pdm.set2f(fDstCopyScaleUni, 1.f / xp.getDstCopyTexture()->width(), |
| 52 1.f / xp.getDstCopyTexture()->height()); |
| 53 } else { |
| 54 SkASSERT(!fDstCopyScaleUni.isValid()); |
| 55 } |
| 56 } else { |
| 57 SkASSERT(!fDstCopyTopLeftUni.isValid()); |
| 58 SkASSERT(!fDstCopyScaleUni.isValid()); |
| 59 } |
| 60 this->onSetData(pdm, xp); |
| 61 } |
| 62 |
OLD | NEW |