OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrTextureDomain.h" | 8 #include "GrTextureDomain.h" |
9 #include "GrSimpleTextureEffect.h" | 9 #include "GrSimpleTextureEffect.h" |
10 #include "GrTBackendEffectFactory.h" | 10 #include "GrTBackendEffectFactory.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 if (!fDomainUni.isValid()) { | 60 if (!fDomainUni.isValid()) { |
61 const char* name; | 61 const char* name; |
62 SkString uniName("TexDom"); | 62 SkString uniName("TexDom"); |
63 if (textureDomain.fIndex >= 0) { | 63 if (textureDomain.fIndex >= 0) { |
64 uniName.appendS32(textureDomain.fIndex); | 64 uniName.appendS32(textureDomain.fIndex); |
65 } | 65 } |
66 fDomainUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility , | 66 fDomainUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility , |
67 kVec4f_GrSLType, uniName.c_str(), &n ame); | 67 kVec4f_GrSLType, uniName.c_str(), &n ame); |
68 fDomainName = name; | 68 fDomainName = name; |
69 } | 69 } |
70 if (kClamp_Mode == textureDomain.mode()) { | |
71 SkString clampedCoords; | |
72 clampedCoords.appendf("\tclamp(%s, %s.xy, %s.zw)", | |
73 inCoords.c_str(), fDomainName.c_str(), fDomainNa me.c_str()); | |
74 | 70 |
75 builder->fsCodeAppendf("\t%s = ", outColor); | 71 switch (textureDomain.mode()) { |
76 builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, clam pedCoords.c_str()); | 72 case kClamp_Mode: { |
77 builder->fsCodeAppend(";\n"); | 73 SkString clampedCoords; |
78 } else { | 74 clampedCoords.appendf("\tclamp(%s, %s.xy, %s.zw)", |
79 SkASSERT(GrTextureDomain::kDecal_Mode == textureDomain.mode()); | 75 inCoords.c_str(), fDomainName.c_str(), fDoma inName.c_str()); |
80 // Add a block since we're going to declare variables. | |
81 GrGLShaderBuilder::FSBlock block(builder); | |
82 | 76 |
83 const char* domain = fDomainName.c_str(); | 77 builder->fsCodeAppendf("\t%s = ", outColor); |
84 if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) { | 78 builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, |
85 // On the NexusS and GalaxyNexus, the other path (with the 'any' | 79 clampedCoords.c_str()); |
86 // call) causes the compilation error "Calls to any function that | |
87 // may require a gradient calculation inside a conditional block | |
88 // may return undefined results". This appears to be an issue with | |
89 // the 'any' call since even the simple "result=black; if (any()) | |
90 // result=white;" code fails to compile. | |
91 builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n" ); | |
92 builder->fsCodeAppend("\tvec4 inside = "); | |
93 builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, inCoords.c_str()); | |
94 builder->fsCodeAppend(";\n"); | 80 builder->fsCodeAppend(";\n"); |
81 break; | |
82 } | |
83 case kDecal_Mode: { | |
84 // Add a block since we're going to declare variables. | |
85 GrGLShaderBuilder::FSBlock block(builder); | |
95 | 86 |
96 builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s .x) - 1.0);\n", | 87 const char* domain = fDomainName.c_str(); |
97 inCoords.c_str(), domain, domain, domain); | 88 if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) { |
98 builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s .y) - 1.0);\n", | 89 // On the NexusS and GalaxyNexus, the other path (with the 'any' |
99 inCoords.c_str(), domain, domain, domain); | 90 // call) causes the compilation error "Calls to any function tha t |
100 builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n"); | 91 // may require a gradient calculation inside a conditional block |
101 builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outC olor); | 92 // may return undefined results". This appears to be an issue wi th |
102 } else { | 93 // the 'any' call since even the simple "result=black; if (any() ) |
103 builder->fsCodeAppend("\tbvec4 outside;\n"); | 94 // result=white;" code fails to compile. |
104 builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", inCo ords.c_str(), | 95 builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0) ;\n"); |
105 domain); | 96 builder->fsCodeAppend("\tvec4 inside = "); |
106 builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", i nCoords.c_str(), | 97 builder->fsAppendTextureLookupAndModulate(inModulateColor, sampl er, |
107 domain); | 98 inCoords.c_str()); |
108 builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0. 0) : ", outColor); | 99 builder->fsCodeAppend(";\n"); |
109 builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, inCoords.c_str()); | 100 |
101 builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s.x) - 1.0);\n", | |
102 inCoords.c_str(), domain, domain, domain ); | |
103 builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s.y) - 1.0);\n", | |
104 inCoords.c_str(), domain, domain, domain ); | |
105 builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n") ; | |
106 builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outColor); | |
107 } else { | |
108 builder->fsCodeAppend("\tbvec4 outside;\n"); | |
109 builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", inCoords.c_str(), | |
110 domain); | |
111 builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n ", inCoords.c_str(), | |
112 domain); | |
113 builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0 , 0.0) : ", | |
114 outColor); | |
115 builder->fsAppendTextureLookupAndModulate(inModulateColor, sampl er, | |
116 inCoords.c_str()); | |
117 builder->fsCodeAppend(";\n"); | |
118 } | |
119 break; | |
120 } | |
121 case kRepeat_Mode: { | |
122 SkString clampedCoords; | |
123 clampedCoords.printf("\tmod(%s - %s.xy, %s.zw - %s.xy) + %s.xy", | |
124 inCoords.c_str(), fDomainName.c_str(), fDomainN ame.c_str(), | |
125 fDomainName.c_str(), fDomainName.c_str()); | |
126 | |
127 builder->fsCodeAppendf("\t%s = ", outColor); | |
128 builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, | |
129 clampedCoords.c_str()); | |
110 builder->fsCodeAppend(";\n"); | 130 builder->fsCodeAppend(";\n"); |
131 break; | |
111 } | 132 } |
133 default: | |
bsalomon
2014/07/28 21:27:44
I think we've moved to not having a default if all
| |
134 SkASSERT(false); | |
112 } | 135 } |
113 } | 136 } |
114 | 137 |
115 void GrTextureDomain::GLDomain::setData(const GrGLUniformManager& uman, | 138 void GrTextureDomain::GLDomain::setData(const GrGLUniformManager& uman, |
116 const GrTextureDomain& textureDomain, | 139 const GrTextureDomain& textureDomain, |
117 GrSurfaceOrigin textureOrigin) { | 140 GrSurfaceOrigin textureOrigin) { |
118 SkASSERT(textureDomain.mode() == fMode); | 141 SkASSERT(textureDomain.mode() == fMode); |
119 if (kIgnore_Mode != textureDomain.mode()) { | 142 if (kIgnore_Mode != textureDomain.mode()) { |
120 GrGLfloat values[4] = { | 143 GrGLfloat values[4] = { |
121 SkScalarToFloat(textureDomain.domain().left()), | 144 SkScalarToFloat(textureDomain.domain().left()), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 | 219 |
197 | 220 |
198 /////////////////////////////////////////////////////////////////////////////// | 221 /////////////////////////////////////////////////////////////////////////////// |
199 | 222 |
200 GrEffect* GrTextureDomainEffect::Create(GrTexture* texture, | 223 GrEffect* GrTextureDomainEffect::Create(GrTexture* texture, |
201 const SkMatrix& matrix, | 224 const SkMatrix& matrix, |
202 const SkRect& domain, | 225 const SkRect& domain, |
203 GrTextureDomain::Mode mode, | 226 GrTextureDomain::Mode mode, |
204 GrTextureParams::FilterMode filterMod e, | 227 GrTextureParams::FilterMode filterMod e, |
205 GrCoordSet coordSet) { | 228 GrCoordSet coordSet) { |
229 SkASSERT(mode != GrTextureDomain::kRepeat_Mode || filterMode == false); | |
206 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; | 230 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; |
207 if (GrTextureDomain::kIgnore_Mode == mode || | 231 if (GrTextureDomain::kIgnore_Mode == mode || |
208 (GrTextureDomain::kClamp_Mode == mode && domain.contains(kFullRect))) { | 232 (GrTextureDomain::kClamp_Mode == mode && domain.contains(kFullRect))) { |
209 return GrSimpleTextureEffect::Create(texture, matrix, filterMode); | 233 return GrSimpleTextureEffect::Create(texture, matrix, filterMode); |
210 } else { | 234 } else { |
211 | 235 |
212 return SkNEW_ARGS(GrTextureDomainEffect, (texture, | 236 return SkNEW_ARGS(GrTextureDomainEffect, (texture, |
213 matrix, | 237 matrix, |
214 domain, | 238 domain, |
215 mode, | 239 mode, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : | 285 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : |
262 GrEffectUnitTest::kAlphaTextureIdx; | 286 GrEffectUnitTest::kAlphaTextureIdx; |
263 SkRect domain; | 287 SkRect domain; |
264 domain.fLeft = random->nextUScalar1(); | 288 domain.fLeft = random->nextUScalar1(); |
265 domain.fRight = random->nextRangeScalar(domain.fLeft, SK_Scalar1); | 289 domain.fRight = random->nextRangeScalar(domain.fLeft, SK_Scalar1); |
266 domain.fTop = random->nextUScalar1(); | 290 domain.fTop = random->nextUScalar1(); |
267 domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1); | 291 domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1); |
268 GrTextureDomain::Mode mode = | 292 GrTextureDomain::Mode mode = |
269 (GrTextureDomain::Mode) random->nextULessThan(GrTextureDomain::kModeCoun t); | 293 (GrTextureDomain::Mode) random->nextULessThan(GrTextureDomain::kModeCoun t); |
270 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); | 294 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); |
271 bool bilerp = random->nextBool(); | 295 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? random->nextBool() : f alse; |
272 GrCoordSet coords = random->nextBool() ? kLocal_GrCoordSet : kPosition_GrCoo rdSet; | 296 GrCoordSet coords = random->nextBool() ? kLocal_GrCoordSet : kPosition_GrCoo rdSet; |
273 return GrTextureDomainEffect::Create(textures[texIdx], | 297 return GrTextureDomainEffect::Create(textures[texIdx], |
274 matrix, | 298 matrix, |
275 domain, | 299 domain, |
276 mode, | 300 mode, |
277 bilerp ? GrTextureParams::kBilerp_Filte rMode : GrTextureParams::kNone_FilterMode, | 301 bilerp ? GrTextureParams::kBilerp_Filte rMode : GrTextureParams::kNone_FilterMode, |
278 coords); | 302 coords); |
279 } | 303 } |
OLD | NEW |