OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "glsl/GrGLSLXferProcessor.h" | 8 #include "glsl/GrGLSLXferProcessor.h" |
9 | 9 |
10 #include "GrXferProcessor.h" | 10 #include "GrXferProcessor.h" |
11 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 11 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
12 #include "glsl/GrGLSLProgramBuilder.h" | |
13 #include "glsl/GrGLSLProgramDataManager.h" | 12 #include "glsl/GrGLSLProgramDataManager.h" |
| 13 #include "glsl/GrGLSLUniformHandler.h" |
14 | 14 |
15 void GrGLSLXferProcessor::emitCode(const EmitArgs& args) { | 15 void GrGLSLXferProcessor::emitCode(const EmitArgs& args) { |
16 if (!args.fXP.willReadDstColor()) { | 16 if (!args.fXP.willReadDstColor()) { |
17 this->emitOutputsForBlendState(args); | 17 this->emitOutputsForBlendState(args); |
18 return; | 18 return; |
19 } | 19 } |
20 | 20 |
21 GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder; | 21 GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder; |
| 22 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
22 const char* dstColor = fragBuilder->dstColor(); | 23 const char* dstColor = fragBuilder->dstColor(); |
23 | 24 |
24 if (args.fXP.getDstTexture()) { | 25 if (args.fXP.getDstTexture()) { |
25 bool topDown = kTopLeft_GrSurfaceOrigin == args.fXP.getDstTexture()->ori
gin(); | 26 bool topDown = kTopLeft_GrSurfaceOrigin == args.fXP.getDstTexture()->ori
gin(); |
26 | 27 |
27 if (args.fInputCoverage) { | 28 if (args.fInputCoverage) { |
28 // We don't think any shaders actually output negative coverage, but
just as a safety | 29 // We don't think any shaders actually output negative coverage, but
just as a safety |
29 // check for floating point precision errors we compare with <= here | 30 // check for floating point precision errors we compare with <= here |
30 fragBuilder->codeAppendf("if (all(lessThanEqual(%s, vec4(0)))) {" | 31 fragBuilder->codeAppendf("if (all(lessThanEqual(%s, vec4(0)))) {" |
31 " discard;" | 32 " discard;" |
32 "}", args.fInputCoverage); | 33 "}", args.fInputCoverage); |
33 } | 34 } |
34 | 35 |
35 const char* dstTopLeftName; | 36 const char* dstTopLeftName; |
36 const char* dstCoordScaleName; | 37 const char* dstCoordScaleName; |
37 | 38 |
38 fDstTopLeftUni = args.fPB->addUniform(GrGLSLProgramBuilder::kFragment_Vi
sibility, | 39 fDstTopLeftUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragm
ent_Visibility, |
39 kVec2f_GrSLType, | 40 kVec2f_GrSLType, |
40 kDefault_GrSLPrecision, | 41 kDefault_GrSLPrecision, |
41 "DstTextureUpperLeft", | 42 "DstTextureUpperLeft", |
42 &dstTopLeftName); | 43 &dstTopLeftName); |
43 fDstScaleUni = args.fPB->addUniform(GrGLSLProgramBuilder::kFragment_Visi
bility, | 44 fDstScaleUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragmen
t_Visibility, |
44 kVec2f_GrSLType, | 45 kVec2f_GrSLType, |
45 kDefault_GrSLPrecision, | 46 kDefault_GrSLPrecision, |
46 "DstTextureCoordScale", | 47 "DstTextureCoordScale", |
47 &dstCoordScaleName); | 48 &dstCoordScaleName); |
48 const char* fragPos = fragBuilder->fragmentPosition(); | 49 const char* fragPos = fragBuilder->fragmentPosition(); |
49 | 50 |
50 fragBuilder->codeAppend("// Read color from copy of the destination.\n")
; | 51 fragBuilder->codeAppend("// Read color from copy of the destination.\n")
; |
51 fragBuilder->codeAppendf("vec2 _dstTexCoord = (%s.xy - %s) * %s;", | 52 fragBuilder->codeAppendf("vec2 _dstTexCoord = (%s.xy - %s) * %s;", |
52 fragPos, dstTopLeftName, dstCoordScaleName); | 53 fragPos, dstTopLeftName, dstCoordScaleName); |
53 | 54 |
54 if (!topDown) { | 55 if (!topDown) { |
55 fragBuilder->codeAppend("_dstTexCoord.y = 1.0 - _dstTexCoord.y;"); | 56 fragBuilder->codeAppend("_dstTexCoord.y = 1.0 - _dstTexCoord.y;"); |
56 } | 57 } |
57 | 58 |
58 fragBuilder->codeAppendf("vec4 %s = ", dstColor); | 59 fragBuilder->codeAppendf("vec4 %s = ", dstColor); |
59 fragBuilder->appendTextureLookup(args.fSamplers[0], "_dstTexCoord", kVec
2f_GrSLType); | 60 fragBuilder->appendTextureLookup(args.fSamplers[0], "_dstTexCoord", kVec
2f_GrSLType); |
60 fragBuilder->codeAppend(";"); | 61 fragBuilder->codeAppend(";"); |
61 } | 62 } |
62 | 63 |
63 this->emitBlendCodeForDstRead(args.fPB, | 64 this->emitBlendCodeForDstRead(fragBuilder, |
64 fragBuilder, | 65 uniformHandler, |
65 args.fInputColor, | 66 args.fInputColor, |
66 args.fInputCoverage, | 67 args.fInputCoverage, |
67 dstColor, | 68 dstColor, |
68 args.fOutputPrimary, | 69 args.fOutputPrimary, |
69 args.fOutputSecondary, | 70 args.fOutputSecondary, |
70 args.fXP); | 71 args.fXP); |
71 } | 72 } |
72 | 73 |
73 void GrGLSLXferProcessor::setData(const GrGLSLProgramDataManager& pdm, const GrX
ferProcessor& xp) { | 74 void GrGLSLXferProcessor::setData(const GrGLSLProgramDataManager& pdm, const GrX
ferProcessor& xp) { |
74 if (xp.getDstTexture()) { | 75 if (xp.getDstTexture()) { |
75 if (fDstTopLeftUni.isValid()) { | 76 if (fDstTopLeftUni.isValid()) { |
76 pdm.set2f(fDstTopLeftUni, static_cast<float>(xp.dstTextureOffset().f
X), | 77 pdm.set2f(fDstTopLeftUni, static_cast<float>(xp.dstTextureOffset().f
X), |
77 static_cast<float>(xp.dstTextureOffset().fY)); | 78 static_cast<float>(xp.dstTextureOffset().fY)); |
78 pdm.set2f(fDstScaleUni, 1.f / xp.getDstTexture()->width(), | 79 pdm.set2f(fDstScaleUni, 1.f / xp.getDstTexture()->width(), |
79 1.f / xp.getDstTexture()->height()); | 80 1.f / xp.getDstTexture()->height()); |
80 } else { | 81 } else { |
81 SkASSERT(!fDstScaleUni.isValid()); | 82 SkASSERT(!fDstScaleUni.isValid()); |
82 } | 83 } |
83 } else { | 84 } else { |
84 SkASSERT(!fDstTopLeftUni.isValid()); | 85 SkASSERT(!fDstTopLeftUni.isValid()); |
85 SkASSERT(!fDstScaleUni.isValid()); | 86 SkASSERT(!fDstScaleUni.isValid()); |
86 } | 87 } |
87 this->onSetData(pdm, xp); | 88 this->onSetData(pdm, xp); |
88 } | 89 } |
89 | 90 |
OLD | NEW |