Chromium Code Reviews| Index: src/gpu/effects/GrTextureDomain.cpp |
| diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp |
| index 5af5bc86f3a95eb339a7bc824fa114234f8f5eb5..0640c9cfacbcdbe1536e616cc0dfc6e573082c0a 100644 |
| --- a/src/gpu/effects/GrTextureDomain.cpp |
| +++ b/src/gpu/effects/GrTextureDomain.cpp |
| @@ -67,48 +67,71 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLShaderBuilder* builder, |
| kVec4f_GrSLType, uniName.c_str(), &name); |
| fDomainName = name; |
| } |
| - if (kClamp_Mode == textureDomain.mode()) { |
| - SkString clampedCoords; |
| - clampedCoords.appendf("\tclamp(%s, %s.xy, %s.zw)", |
| - inCoords.c_str(), fDomainName.c_str(), fDomainName.c_str()); |
| - builder->fsCodeAppendf("\t%s = ", outColor); |
| - builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, clampedCoords.c_str()); |
| - builder->fsCodeAppend(";\n"); |
| - } else { |
| - SkASSERT(GrTextureDomain::kDecal_Mode == textureDomain.mode()); |
| - // Add a block since we're going to declare variables. |
| - GrGLShaderBuilder::FSBlock block(builder); |
| - |
| - const char* domain = fDomainName.c_str(); |
| - if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) { |
| - // On the NexusS and GalaxyNexus, the other path (with the 'any' |
| - // call) causes the compilation error "Calls to any function that |
| - // may require a gradient calculation inside a conditional block |
| - // may return undefined results". This appears to be an issue with |
| - // the 'any' call since even the simple "result=black; if (any()) |
| - // result=white;" code fails to compile. |
| - builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n"); |
| - builder->fsCodeAppend("\tvec4 inside = "); |
| - builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, inCoords.c_str()); |
| - builder->fsCodeAppend(";\n"); |
| + switch (textureDomain.mode()) { |
| + case kClamp_Mode: { |
| + SkString clampedCoords; |
| + clampedCoords.appendf("\tclamp(%s, %s.xy, %s.zw)", |
| + inCoords.c_str(), fDomainName.c_str(), fDomainName.c_str()); |
| - builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s.x) - 1.0);\n", |
| - inCoords.c_str(), domain, domain, domain); |
| - builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s.y) - 1.0);\n", |
| - inCoords.c_str(), domain, domain, domain); |
| - builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n"); |
| - builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outColor); |
| - } else { |
| - builder->fsCodeAppend("\tbvec4 outside;\n"); |
| - builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", inCoords.c_str(), |
| - domain); |
| - builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", inCoords.c_str(), |
| - domain); |
| - builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ", outColor); |
| - builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, inCoords.c_str()); |
| + builder->fsCodeAppendf("\t%s = ", outColor); |
| + builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, |
| + clampedCoords.c_str()); |
| + builder->fsCodeAppend(";\n"); |
| + break; |
| + } |
| + case kDecal_Mode: { |
| + // Add a block since we're going to declare variables. |
| + GrGLShaderBuilder::FSBlock block(builder); |
| + |
| + const char* domain = fDomainName.c_str(); |
| + if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) { |
| + // On the NexusS and GalaxyNexus, the other path (with the 'any' |
| + // call) causes the compilation error "Calls to any function that |
| + // may require a gradient calculation inside a conditional block |
| + // may return undefined results". This appears to be an issue with |
| + // the 'any' call since even the simple "result=black; if (any()) |
| + // result=white;" code fails to compile. |
| + builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n"); |
| + builder->fsCodeAppend("\tvec4 inside = "); |
| + builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, |
| + inCoords.c_str()); |
| + builder->fsCodeAppend(";\n"); |
| + |
| + builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s.x) - 1.0);\n", |
| + inCoords.c_str(), domain, domain, domain); |
| + builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s.y) - 1.0);\n", |
| + inCoords.c_str(), domain, domain, domain); |
| + builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n"); |
| + builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outColor); |
| + } else { |
| + builder->fsCodeAppend("\tbvec4 outside;\n"); |
| + builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", inCoords.c_str(), |
| + domain); |
| + builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", inCoords.c_str(), |
| + domain); |
| + builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ", |
| + outColor); |
| + builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, |
| + inCoords.c_str()); |
| + builder->fsCodeAppend(";\n"); |
| + } |
| + break; |
| + } |
| + case kRepeat_Mode: { |
| + SkString clampedCoords; |
| + clampedCoords.printf("\tmod(%s - %s.xy, %s.zw - %s.xy) + %s.xy", |
| + inCoords.c_str(), fDomainName.c_str(), fDomainName.c_str(), |
| + fDomainName.c_str(), fDomainName.c_str()); |
| + |
| + builder->fsCodeAppendf("\t%s = ", outColor); |
| + builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, |
| + clampedCoords.c_str()); |
| builder->fsCodeAppend(";\n"); |
| + break; |
| } |
| + default: |
|
bsalomon
2014/07/28 21:27:44
I think we've moved to not having a default if all
|
| + SkASSERT(false); |
| } |
| } |
| @@ -203,6 +226,7 @@ GrEffect* GrTextureDomainEffect::Create(GrTexture* texture, |
| GrTextureDomain::Mode mode, |
| GrTextureParams::FilterMode filterMode, |
| GrCoordSet coordSet) { |
| + SkASSERT(mode != GrTextureDomain::kRepeat_Mode || filterMode == false); |
| static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; |
| if (GrTextureDomain::kIgnore_Mode == mode || |
| (GrTextureDomain::kClamp_Mode == mode && domain.contains(kFullRect))) { |
| @@ -268,7 +292,7 @@ GrEffect* GrTextureDomainEffect::TestCreate(SkRandom* random, |
| GrTextureDomain::Mode mode = |
| (GrTextureDomain::Mode) random->nextULessThan(GrTextureDomain::kModeCount); |
| const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); |
| - bool bilerp = random->nextBool(); |
| + bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? random->nextBool() : false; |
| GrCoordSet coords = random->nextBool() ? kLocal_GrCoordSet : kPosition_GrCoordSet; |
| return GrTextureDomainEffect::Create(textures[texIdx], |
| matrix, |