| 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 "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
| 10 #include "GrSimpleTextureEffect.h" | 10 #include "GrSimpleTextureEffect.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 fDomain.fRight = SkScalarPin(domain.fRight, kFullRect.fLeft, kFullRect.f
Right); | 35 fDomain.fRight = SkScalarPin(domain.fRight, kFullRect.fLeft, kFullRect.f
Right); |
| 36 fDomain.fTop = SkScalarPin(domain.fTop, kFullRect.fTop, kFullRect.fBotto
m); | 36 fDomain.fTop = SkScalarPin(domain.fTop, kFullRect.fTop, kFullRect.fBotto
m); |
| 37 fDomain.fBottom = SkScalarPin(domain.fBottom, kFullRect.fTop, kFullRect.
fBottom); | 37 fDomain.fBottom = SkScalarPin(domain.fBottom, kFullRect.fTop, kFullRect.
fBottom); |
| 38 SkASSERT(fDomain.fLeft <= fDomain.fRight); | 38 SkASSERT(fDomain.fLeft <= fDomain.fRight); |
| 39 SkASSERT(fDomain.fTop <= fDomain.fBottom); | 39 SkASSERT(fDomain.fTop <= fDomain.fBottom); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 ////////////////////////////////////////////////////////////////////////////// | 43 ////////////////////////////////////////////////////////////////////////////// |
| 44 | 44 |
| 45 void GrTextureDomain::GLDomain::sampleTexture(GrGLShaderBuilder* builder, | 45 void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder, |
| 46 const GrTextureDomain& textureDoma
in, | 46 const GrTextureDomain& textureDoma
in, |
| 47 const char* outColor, | 47 const char* outColor, |
| 48 const SkString& inCoords, | 48 const SkString& inCoords, |
| 49 const GrGLSLTextureSampler& sample
r, | 49 const GrGLSLTextureSampler& sample
r, |
| 50 const char* inModulateColor) { | 50 const char* inModulateColor) { |
| 51 SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode); | 51 SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode); |
| 52 SkDEBUGCODE(fMode = textureDomain.mode();) | 52 SkDEBUGCODE(fMode = textureDomain.mode();) |
| 53 | 53 |
| 54 GrGLSLProgramBuilder* program = builder->getProgramBuilder(); | 54 GrGLSLProgramBuilder* program = builder->getProgramBuilder(); |
| 55 | 55 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 79 inCoords.c_str(), fDomainName.c_str(), fDomain
Name.c_str()); | 79 inCoords.c_str(), fDomainName.c_str(), fDomain
Name.c_str()); |
| 80 | 80 |
| 81 builder->codeAppendf("%s = ", outColor); | 81 builder->codeAppendf("%s = ", outColor); |
| 82 builder->appendTextureLookupAndModulate(inModulateColor, sampler, | 82 builder->appendTextureLookupAndModulate(inModulateColor, sampler, |
| 83 clampedCoords.c_str()); | 83 clampedCoords.c_str()); |
| 84 builder->codeAppend(";"); | 84 builder->codeAppend(";"); |
| 85 break; | 85 break; |
| 86 } | 86 } |
| 87 case kDecal_Mode: { | 87 case kDecal_Mode: { |
| 88 // Add a block since we're going to declare variables. | 88 // Add a block since we're going to declare variables. |
| 89 GrGLShaderBuilder::ShaderBlock block(builder); | 89 GrGLSLShaderBuilder::ShaderBlock block(builder); |
| 90 | 90 |
| 91 const char* domain = fDomainName.c_str(); | 91 const char* domain = fDomainName.c_str(); |
| 92 if (!program->glslCaps()->canUseAnyFunctionInShader()) { | 92 if (!program->glslCaps()->canUseAnyFunctionInShader()) { |
| 93 // On the NexusS and GalaxyNexus, the other path (with the 'any' | 93 // On the NexusS and GalaxyNexus, the other path (with the 'any' |
| 94 // call) causes the compilation error "Calls to any function tha
t | 94 // call) causes the compilation error "Calls to any function tha
t |
| 95 // may require a gradient calculation inside a conditional block | 95 // may require a gradient calculation inside a conditional block |
| 96 // may return undefined results". This appears to be an issue wi
th | 96 // may return undefined results". This appears to be an issue wi
th |
| 97 // the 'any' call since even the simple "result=black; if (any()
) | 97 // the 'any' call since even the simple "result=black; if (any()
) |
| 98 // result=white;" code fails to compile. | 98 // result=white;" code fails to compile. |
| 99 builder->codeAppend("vec4 outside = vec4(0.0, 0.0, 0.0, 0.0);"); | 99 builder->codeAppend("vec4 outside = vec4(0.0, 0.0, 0.0, 0.0);"); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 typedef GrGLFragmentProcessor INHERITED; | 189 typedef GrGLFragmentProcessor INHERITED; |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProcessor&) { | 192 GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProcessor&) { |
| 193 } | 193 } |
| 194 | 194 |
| 195 void GrGLTextureDomainEffect::emitCode(EmitArgs& args) { | 195 void GrGLTextureDomainEffect::emitCode(EmitArgs& args) { |
| 196 const GrTextureDomainEffect& textureDomainEffect = args.fFp.cast<GrTextureDo
mainEffect>(); | 196 const GrTextureDomainEffect& textureDomainEffect = args.fFp.cast<GrTextureDo
mainEffect>(); |
| 197 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); | 197 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); |
| 198 | 198 |
| 199 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 199 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
| 200 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 200 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 201 fGLDomain.sampleTexture(fsBuilder, domain, args.fOutputColor, coords2D, args
.fSamplers[0], | 201 fGLDomain.sampleTexture(fsBuilder, domain, args.fOutputColor, coords2D, args
.fSamplers[0], |
| 202 args.fInputColor); | 202 args.fInputColor); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void GrGLTextureDomainEffect::onSetData(const GrGLSLProgramDataManager& pdman, | 205 void GrGLTextureDomainEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
| 206 const GrProcessor& processor) { | 206 const GrProcessor& processor) { |
| 207 const GrTextureDomainEffect& textureDomainEffect = processor.cast<GrTextureD
omainEffect>(); | 207 const GrTextureDomainEffect& textureDomainEffect = processor.cast<GrTextureD
omainEffect>(); |
| 208 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); | 208 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); |
| 209 fGLDomain.setData(pdman, domain, processor.texture(0)->origin()); | 209 fGLDomain.setData(pdman, domain, processor.texture(0)->origin()); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? d->fRandom->nextBool()
: false; | 292 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? d->fRandom->nextBool()
: false; |
| 293 GrCoordSet coords = d->fRandom->nextBool() ? kLocal_GrCoordSet : kDevice_GrC
oordSet; | 293 GrCoordSet coords = d->fRandom->nextBool() ? kLocal_GrCoordSet : kDevice_GrC
oordSet; |
| 294 return GrTextureDomainEffect::Create( | 294 return GrTextureDomainEffect::Create( |
| 295 d->fTextures[texIdx], | 295 d->fTextures[texIdx], |
| 296 matrix, | 296 matrix, |
| 297 domain, | 297 domain, |
| 298 mode, | 298 mode, |
| 299 bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_Fi
lterMode, | 299 bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_Fi
lterMode, |
| 300 coords); | 300 coords); |
| 301 } | 301 } |
| OLD | NEW |