diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/effects/GrAlphaThresholdFragmentProcessor.cpp | 9 | ||||
-rw-r--r-- | src/effects/SkDisplacementMapEffect.cpp | 10 | ||||
-rw-r--r-- | src/effects/SkMagnifierImageFilter.cpp | 9 | ||||
-rw-r--r-- | src/effects/gradients/SkGradientShader.cpp | 7 | ||||
-rw-r--r-- | src/effects/gradients/SkGradientShaderPriv.h | 3 | ||||
-rw-r--r-- | src/gpu/effects/GrBicubicEffect.cpp | 11 | ||||
-rw-r--r-- | src/gpu/effects/GrSimpleTextureEffect.cpp | 10 | ||||
-rw-r--r-- | src/gpu/effects/GrTextureDomain.cpp | 10 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLColorSpaceXformHelper.h | 32 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLShaderBuilder.cpp | 7 |
10 files changed, 52 insertions, 56 deletions
diff --git a/src/effects/GrAlphaThresholdFragmentProcessor.cpp b/src/effects/GrAlphaThresholdFragmentProcessor.cpp index 897d44768f..12933ee3c2 100644 --- a/src/effects/GrAlphaThresholdFragmentProcessor.cpp +++ b/src/effects/GrAlphaThresholdFragmentProcessor.cpp @@ -79,7 +79,7 @@ protected: private: GrGLSLProgramDataManager::UniformHandle fInnerThresholdVar; GrGLSLProgramDataManager::UniformHandle fOuterThresholdVar; - GrGLSLProgramDataManager::UniformHandle fColorSpaceXformVar; + GrGLSLColorSpaceXformHelper fColorSpaceHelper; typedef GrGLSLFragmentProcessor INHERITED; }; @@ -94,8 +94,7 @@ void GrGLAlphaThresholdFragmentProcessor::emitCode(EmitArgs& args) { const GrAlphaThresholdFragmentProcessor& atfp = args.fFp.cast<GrAlphaThresholdFragmentProcessor>(); - GrGLSLColorSpaceXformHelper colorSpaceHelper(uniformHandler, atfp.colorSpaceXform(), - &fColorSpaceXformVar); + fColorSpaceHelper.emitCode(uniformHandler, atfp.colorSpaceXform()); GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); @@ -105,7 +104,7 @@ void GrGLAlphaThresholdFragmentProcessor::emitCode(EmitArgs& args) { fragBuilder->codeAppendf("vec2 mask_coord = %s;", maskCoords2D.c_str()); fragBuilder->codeAppend("vec4 input_color = "); fragBuilder->appendTextureLookup(args.fTexSamplers[0], "coord", kVec2f_GrSLType, - &colorSpaceHelper); + &fColorSpaceHelper); fragBuilder->codeAppend(";"); fragBuilder->codeAppend("vec4 mask_color = "); fragBuilder->appendTextureLookup(args.fTexSamplers[1], "mask_coord"); @@ -140,7 +139,7 @@ void GrGLAlphaThresholdFragmentProcessor::onSetData(const GrGLSLProgramDataManag pdman.set1f(fInnerThresholdVar, atfp.innerThreshold()); pdman.set1f(fOuterThresholdVar, atfp.outerThreshold()); if (SkToBool(atfp.colorSpaceXform())) { - pdman.setSkMatrix44(fColorSpaceXformVar, atfp.colorSpaceXform()->srcToDst()); + fColorSpaceHelper.setData(pdman, atfp.colorSpaceXform()); } } diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index 00059817dd..8384058370 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -467,7 +467,7 @@ private: typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; UniformHandle fScaleUni; - UniformHandle fColorSpaceXformUni; + GrGLSLColorSpaceXformHelper fColorSpaceHelper; GrTextureDomain::GLDomain fGLDomain; typedef GrGLSLFragmentProcessor INHERITED; @@ -571,9 +571,7 @@ void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) { // a number smaller than that to approximate 0, but // leave room for 32-bit float GPU rounding errors. - GrGLSLColorSpaceXformHelper colorSpaceHelper(args.fUniformHandler, - displacementMap.colorSpaceXform(), - &fColorSpaceXformUni); + fColorSpaceHelper.emitCode(args.fUniformHandler, displacementMap.colorSpaceXform()); GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor); @@ -634,7 +632,7 @@ void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) { SkString(cCoords), args.fTexSamplers[1], nullptr, - &colorSpaceHelper); + &fColorSpaceHelper); fragBuilder->codeAppend(";\n"); } @@ -649,7 +647,7 @@ void GrGLDisplacementMapEffect::onSetData(const GrGLSLProgramDataManager& pdman, SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); fGLDomain.setData(pdman, displacementMap.domain(), colorTex); if (SkToBool(displacementMap.colorSpaceXform())) { - pdman.setSkMatrix44(fColorSpaceXformUni, displacementMap.colorSpaceXform()->srcToDst()); + fColorSpaceHelper.setData(pdman, displacementMap.colorSpaceXform()); } } diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index a78f2235ab..4312fb714e 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -143,7 +143,7 @@ private: UniformHandle fInvZoomVar; UniformHandle fInvInsetVar; UniformHandle fBoundsVar; - UniformHandle fColorSpaceXformVar; + GrGLSLColorSpaceXformHelper fColorSpaceHelper; typedef GrGLSLFragmentProcessor INHERITED; }; @@ -164,8 +164,7 @@ void GrGLMagnifierEffect::emitCode(EmitArgs& args) { "Bounds"); const GrMagnifierEffect& zoom = args.fFp.cast<GrMagnifierEffect>(); - GrGLSLColorSpaceXformHelper colorSpaceHelper(uniformHandler, zoom.colorSpaceXform(), - &fColorSpaceXformVar); + fColorSpaceHelper.emitCode(uniformHandler, zoom.colorSpaceXform()); GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); @@ -194,7 +193,7 @@ void GrGLMagnifierEffect::emitCode(EmitArgs& args) { fragBuilder->codeAppend("\t\tvec2 mix_coord = mix(coord, zoom_coord, weight);\n"); fragBuilder->codeAppend("\t\tvec4 output_color = "); fragBuilder->appendTextureLookup(args.fTexSamplers[0], "mix_coord", kVec2f_GrSLType, - &colorSpaceHelper); + &fColorSpaceHelper); fragBuilder->codeAppend(";\n"); fragBuilder->codeAppendf("\t\t%s = output_color;", args.fOutputColor); @@ -239,7 +238,7 @@ void GrGLMagnifierEffect::onSetData(const GrGLSLProgramDataManager& pdman, } if (SkToBool(zoom.colorSpaceXform())) { - pdman.setSkMatrix44(fColorSpaceXformVar, zoom.colorSpaceXform()->srcToDst()); + fColorSpaceHelper.setData(pdman, zoom.colorSpaceXform()); } } diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index bba9f857cd..8538ddd7fe 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -1345,7 +1345,7 @@ void GrGradientEffect::GLSLProcessor::onSetData(const GrGLSLProgramDataManager& fCachedYCoord = yCoord; } if (SkToBool(e.fColorSpaceXform)) { - pdman.setSkMatrix44(fColorSpaceXformUni, e.fColorSpaceXform->srcToDst()); + fColorSpaceHelper.setData(pdman, e.fColorSpaceXform.get()); } break; } @@ -1583,15 +1583,14 @@ void GrGradientEffect::GLSLProcessor::emitColor(GrGLSLFPFragmentBuilder* fragBui } case kTexture_ColorType: { - GrGLSLColorSpaceXformHelper colorSpaceHelper(uniformHandler, ge.fColorSpaceXform.get(), - &fColorSpaceXformUni); + fColorSpaceHelper.emitCode(uniformHandler, ge.fColorSpaceXform.get()); const char* fsyuni = uniformHandler->getUniformCStr(fFSYUni); fragBuilder->codeAppendf("vec2 coord = vec2(%s, %s);", gradientTValue, fsyuni); fragBuilder->codeAppendf("%s = ", outputColor); fragBuilder->appendTextureLookupAndModulate(inputColor, texSamplers[0], "coord", - kVec2f_GrSLType, &colorSpaceHelper); + kVec2f_GrSLType, &fColorSpaceHelper); fragBuilder->codeAppend(";"); break; diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h index 1e3415371e..7f1f5f8c88 100644 --- a/src/effects/gradients/SkGradientShaderPriv.h +++ b/src/effects/gradients/SkGradientShaderPriv.h @@ -295,6 +295,7 @@ static inline int next_dither_toggle(int toggle) { #include "GrColorSpaceXform.h" #include "GrCoordTransform.h" #include "GrFragmentProcessor.h" +#include "glsl/GrGLSLColorSpaceXformHelper.h" #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLProgramDataManager.h" @@ -520,7 +521,7 @@ private: GrGLSLProgramDataManager::UniformHandle fColorsUni; GrGLSLProgramDataManager::UniformHandle fHardStopT; GrGLSLProgramDataManager::UniformHandle fFSYUni; - GrGLSLProgramDataManager::UniformHandle fColorSpaceXformUni; + GrGLSLColorSpaceXformHelper fColorSpaceHelper; typedef GrGLSLFragmentProcessor INHERITED; }; diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp index 5f06fc166a..ec7ad79475 100644 --- a/src/gpu/effects/GrBicubicEffect.cpp +++ b/src/gpu/effects/GrBicubicEffect.cpp @@ -32,7 +32,7 @@ private: typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; UniformHandle fImageIncrementUni; - UniformHandle fColorSpaceXformUni; + GrGLSLColorSpaceXformHelper fColorSpaceHelper; GrTextureDomain::GLDomain fDomain; typedef GrGLSLFragmentProcessor INHERITED; @@ -48,8 +48,7 @@ void GrGLBicubicEffect::emitCode(EmitArgs& args) { const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni); - GrGLSLColorSpaceXformHelper colorSpaceHelper(uniformHandler, bicubicEffect.colorSpaceXform(), - &fColorSpaceXformUni); + fColorSpaceHelper.emitCode(uniformHandler, bicubicEffect.colorSpaceXform()); GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); @@ -107,9 +106,9 @@ void GrGLBicubicEffect::emitCode(EmitArgs& args) { y); } SkString bicubicColor("(wy.x * s0 + wy.y * s1 + wy.z * s2 + wy.w * s3)"); - if (colorSpaceHelper.getXformMatrix()) { + if (fColorSpaceHelper.isValid()) { SkString xformedColor; - fragBuilder->appendColorGamutXform(&xformedColor, bicubicColor.c_str(), &colorSpaceHelper); + fragBuilder->appendColorGamutXform(&xformedColor, bicubicColor.c_str(), &fColorSpaceHelper); bicubicColor.swap(xformedColor); } fragBuilder->codeAppendf("%s = %s;", @@ -127,7 +126,7 @@ void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman, pdman.set2fv(fImageIncrementUni, 1, imageIncrement); fDomain.setData(pdman, bicubicEffect.domain(), texture); if (SkToBool(bicubicEffect.colorSpaceXform())) { - pdman.setSkMatrix44(fColorSpaceXformUni, bicubicEffect.colorSpaceXform()->srcToDst()); + fColorSpaceHelper.setData(pdman, bicubicEffect.colorSpaceXform()); } } diff --git a/src/gpu/effects/GrSimpleTextureEffect.cpp b/src/gpu/effects/GrSimpleTextureEffect.cpp index bd4e7206f8..8492f5b80b 100644 --- a/src/gpu/effects/GrSimpleTextureEffect.cpp +++ b/src/gpu/effects/GrSimpleTextureEffect.cpp @@ -42,9 +42,7 @@ class GrGLSimpleTextureEffect : public GrGLSLFragmentProcessor { public: void emitCode(EmitArgs& args) override { const GrSimpleTextureEffect& textureEffect = args.fFp.cast<GrSimpleTextureEffect>(); - GrGLSLColorSpaceXformHelper colorSpaceHelper(args.fUniformHandler, - textureEffect.colorSpaceXform(), - &fColorSpaceXformUni); + fColorSpaceHelper.emitCode(args.fUniformHandler, textureEffect.colorSpaceXform()); GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; fragBuilder->codeAppendf("%s = ", args.fOutputColor); @@ -52,7 +50,7 @@ public: args.fTexSamplers[0], args.fTransformedCoords[0].c_str(), args.fTransformedCoords[0].getType(), - &colorSpaceHelper); + &fColorSpaceHelper); fragBuilder->codeAppend(";"); } @@ -66,14 +64,14 @@ protected: void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& processor) override { const GrSimpleTextureEffect& textureEffect = processor.cast<GrSimpleTextureEffect>(); if (SkToBool(textureEffect.colorSpaceXform())) { - pdman.setSkMatrix44(fColorSpaceXformUni, textureEffect.colorSpaceXform()->srcToDst()); + fColorSpaceHelper.setData(pdman, textureEffect.colorSpaceXform()); } } private: typedef GrGLSLFragmentProcessor INHERITED; - UniformHandle fColorSpaceXformUni; + GrGLSLColorSpaceXformHelper fColorSpaceHelper; }; /////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp index 2ac6af8375..7a43328bc1 100644 --- a/src/gpu/effects/GrTextureDomain.cpp +++ b/src/gpu/effects/GrTextureDomain.cpp @@ -321,9 +321,7 @@ GrGLSLFragmentProcessor* GrTextureDomainEffect::onCreateGLSLInstance() const { GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); - GrGLSLColorSpaceXformHelper colorSpaceHelper(args.fUniformHandler, - tde.colorSpaceXform(), - &fColorSpaceXformUni); + fColorSpaceHelper.emitCode(args.fUniformHandler, tde.colorSpaceXform()); fGLDomain.sampleTexture(fragBuilder, args.fUniformHandler, args.fShaderCaps, @@ -332,7 +330,7 @@ GrGLSLFragmentProcessor* GrTextureDomainEffect::onCreateGLSLInstance() const { coords2D, args.fTexSamplers[0], args.fInputColor, - &colorSpaceHelper); + &fColorSpaceHelper); } protected: @@ -341,13 +339,13 @@ GrGLSLFragmentProcessor* GrTextureDomainEffect::onCreateGLSLInstance() const { const GrTextureDomain& domain = tde.fTextureDomain; fGLDomain.setData(pdman, domain, tde.textureSampler(0).texture()); if (SkToBool(tde.colorSpaceXform())) { - pdman.setSkMatrix44(fColorSpaceXformUni, tde.colorSpaceXform()->srcToDst()); + fColorSpaceHelper.setData(pdman, tde.colorSpaceXform()); } } private: GrTextureDomain::GLDomain fGLDomain; - UniformHandle fColorSpaceXformUni; + GrGLSLColorSpaceXformHelper fColorSpaceHelper; }; return new GLSLProcessor; diff --git a/src/gpu/glsl/GrGLSLColorSpaceXformHelper.h b/src/gpu/glsl/GrGLSLColorSpaceXformHelper.h index 5e112f9f91..1571b06231 100644 --- a/src/gpu/glsl/GrGLSLColorSpaceXformHelper.h +++ b/src/gpu/glsl/GrGLSLColorSpaceXformHelper.h @@ -12,29 +12,33 @@ #include "GrGLSLUniformHandler.h" /** - * Stack helper class to assist with using GrColorSpaceXform within an FP's emitCode function. - * This injects the uniform declaration, and stores the information needed to generate correct - * gamut-transformation shader code. + * Helper class to assist with using GrColorSpaceXform within an FP. This manages all of the + * uniforms needed, and can be passed to shader builder functions to automatically generate the + * correct color space transformation code. */ class GrGLSLColorSpaceXformHelper : public SkNoncopyable { public: - GrGLSLColorSpaceXformHelper(GrGLSLUniformHandler* uniformHandler, - GrColorSpaceXform* colorSpaceXform, - GrGLSLProgramDataManager::UniformHandle* handle) { - SkASSERT(uniformHandler && handle); + GrGLSLColorSpaceXformHelper() : fValid(false) {} + + void emitCode(GrGLSLUniformHandler* uniformHandler, GrColorSpaceXform* colorSpaceXform) { + SkASSERT(uniformHandler); if (colorSpaceXform) { - *handle = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat44f_GrSLType, - kDefault_GrSLPrecision, "ColorXform", - &fXformMatrix); - } else { - fXformMatrix = nullptr; + fGamutXformVar = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat44f_GrSLType, + kDefault_GrSLPrecision, "ColorXform"); + fValid = true; } } - const char* getXformMatrix() const { return fXformMatrix; } + void setData(const GrGLSLProgramDataManager& pdman, GrColorSpaceXform* colorSpaceXform) { + pdman.setSkMatrix44(fGamutXformVar, colorSpaceXform->srcToDst()); + } + + bool isValid() const { return fValid; } + GrGLSLProgramDataManager::UniformHandle const gamutXformUniform() { return fGamutXformVar; } private: - const char* fXformMatrix; + GrGLSLProgramDataManager::UniformHandle fGamutXformVar; + bool fValid; }; #endif diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp index 17f7f10287..865876611a 100644 --- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp +++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp @@ -91,7 +91,7 @@ void GrGLSLShaderBuilder::appendTextureLookup(SamplerHandle samplerHandle, const char* coordName, GrSLType varyingType, GrGLSLColorSpaceXformHelper* colorXformHelper) { - if (colorXformHelper && colorXformHelper->getXformMatrix()) { + if (colorXformHelper && colorXformHelper->isValid()) { // With a color gamut transform, we need to wrap the lookup in another function call SkString lookup; this->appendTextureLookup(&lookup, samplerHandle, coordName, varyingType); @@ -109,7 +109,7 @@ void GrGLSLShaderBuilder::appendTextureLookupAndModulate( GrGLSLColorSpaceXformHelper* colorXformHelper) { SkString lookup; this->appendTextureLookup(&lookup, samplerHandle, coordName, varyingType); - if (colorXformHelper && colorXformHelper->getXformMatrix()) { + if (colorXformHelper && colorXformHelper->isValid()) { SkString xform; this->appendColorGamutXform(&xform, lookup.c_str(), colorXformHelper); this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(xform)).c_str()); @@ -141,8 +141,9 @@ void GrGLSLShaderBuilder::appendColorGamutXform(SkString* out, functionBody.c_str(), &colorGamutXformFuncName); + GrGLSLUniformHandler* uniformHandler = fProgramBuilder->uniformHandler(); out->appendf("%s(%s, %s)", colorGamutXformFuncName.c_str(), srcColor, - colorXformHelper->getXformMatrix()); + uniformHandler->getUniformCStr(colorXformHelper->gamutXformUniform())); } void GrGLSLShaderBuilder::appendColorGamutXform(const char* srcColor, |