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