| 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 "GrBicubicEffect.h" | 8 #include "GrBicubicEffect.h" |
| 9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
| 10 #include "gl/builders/GrGLProgramBuilder.h" | 10 #include "gl/builders/GrGLProgramBuilder.h" |
| 11 | 11 |
| 12 #define DS(x) SkDoubleToScalar(x) | 12 #define DS(x) SkDoubleToScalar(x) |
| 13 | 13 |
| 14 const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = { | 14 const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = { |
| 15 DS( 1.0 / 18.0), DS(-9.0 / 18.0), DS( 15.0 / 18.0), DS( -7.0 / 18.0), | 15 DS( 1.0 / 18.0), DS(-9.0 / 18.0), DS( 15.0 / 18.0), DS( -7.0 / 18.0), |
| 16 DS(16.0 / 18.0), DS( 0.0 / 18.0), DS(-36.0 / 18.0), DS( 21.0 / 18.0), | 16 DS(16.0 / 18.0), DS( 0.0 / 18.0), DS(-36.0 / 18.0), DS( 21.0 / 18.0), |
| 17 DS( 1.0 / 18.0), DS( 9.0 / 18.0), DS( 27.0 / 18.0), DS(-21.0 / 18.0), | 17 DS( 1.0 / 18.0), DS( 9.0 / 18.0), DS( 27.0 / 18.0), DS(-21.0 / 18.0), |
| 18 DS( 0.0 / 18.0), DS( 0.0 / 18.0), DS( -6.0 / 18.0), DS( 7.0 / 18.0), | 18 DS( 0.0 / 18.0), DS( 0.0 / 18.0), DS( -6.0 / 18.0), DS( 7.0 / 18.0), |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 | 21 |
| 22 class GrGLBicubicEffect : public GrGLFragmentProcessor { | 22 class GrGLBicubicEffect : public GrGLFragmentProcessor { |
| 23 public: | 23 public: |
| 24 GrGLBicubicEffect(const GrProcessor&); | 24 GrGLBicubicEffect(const GrProcessor&); |
| 25 | 25 |
| 26 virtual void emitCode(EmitArgs&) override; | 26 virtual void emitCode(EmitArgs&) override; |
| 27 | 27 |
| 28 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | |
| 29 | |
| 30 static inline void GenKey(const GrProcessor& effect, const GrGLSLCaps&, | 28 static inline void GenKey(const GrProcessor& effect, const GrGLSLCaps&, |
| 31 GrProcessorKeyBuilder* b) { | 29 GrProcessorKeyBuilder* b) { |
| 32 const GrTextureDomain& domain = effect.cast<GrBicubicEffect>().domain(); | 30 const GrTextureDomain& domain = effect.cast<GrBicubicEffect>().domain(); |
| 33 b->add32(GrTextureDomain::GLDomain::DomainKey(domain)); | 31 b->add32(GrTextureDomain::GLDomain::DomainKey(domain)); |
| 34 } | 32 } |
| 35 | 33 |
| 34 protected: |
| 35 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; |
| 36 |
| 36 private: | 37 private: |
| 37 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 38 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 38 | 39 |
| 39 UniformHandle fCoefficientsUni; | 40 UniformHandle fCoefficientsUni; |
| 40 UniformHandle fImageIncrementUni; | 41 UniformHandle fImageIncrementUni; |
| 41 GrTextureDomain::GLDomain fDomain; | 42 GrTextureDomain::GLDomain fDomain; |
| 42 | 43 |
| 43 typedef GrGLFragmentProcessor INHERITED; | 44 typedef GrGLFragmentProcessor INHERITED; |
| 44 }; | 45 }; |
| 45 | 46 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 fDomain.sampleTexture(fsBuilder, domain, sampleVar.c_str(), coord, a
rgs.fSamplers[0]); | 98 fDomain.sampleTexture(fsBuilder, domain, sampleVar.c_str(), coord, a
rgs.fSamplers[0]); |
| 98 } | 99 } |
| 99 fsBuilder->codeAppendf("\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors
[1], rowColors[2], rowColors[3]);\n", y, cubicBlendName.c_str(), coeff); | 100 fsBuilder->codeAppendf("\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors
[1], rowColors[2], rowColors[3]);\n", y, cubicBlendName.c_str(), coeff); |
| 100 } | 101 } |
| 101 SkString bicubicColor; | 102 SkString bicubicColor; |
| 102 bicubicColor.printf("%s(%s, f.y, s0, s1, s2, s3)", cubicBlendName.c_str(), c
oeff); | 103 bicubicColor.printf("%s(%s, f.y, s0, s1, s2, s3)", cubicBlendName.c_str(), c
oeff); |
| 103 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor,(GrGLSLExpr4(bicubi
cColor.c_str()) * | 104 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor,(GrGLSLExpr4(bicubi
cColor.c_str()) * |
| 104 GrGLSLExpr4(args.fInputColor)).c_str()); | 105 GrGLSLExpr4(args.fInputColor)).c_str()); |
| 105 } | 106 } |
| 106 | 107 |
| 107 void GrGLBicubicEffect::setData(const GrGLProgramDataManager& pdman, | 108 void GrGLBicubicEffect::onSetData(const GrGLProgramDataManager& pdman, |
| 108 const GrProcessor& processor) { | 109 const GrProcessor& processor) { |
| 109 const GrBicubicEffect& bicubicEffect = processor.cast<GrBicubicEffect>(); | 110 const GrBicubicEffect& bicubicEffect = processor.cast<GrBicubicEffect>(); |
| 110 const GrTexture& texture = *processor.texture(0); | 111 const GrTexture& texture = *processor.texture(0); |
| 111 float imageIncrement[2]; | 112 float imageIncrement[2]; |
| 112 imageIncrement[0] = 1.0f / texture.width(); | 113 imageIncrement[0] = 1.0f / texture.width(); |
| 113 imageIncrement[1] = 1.0f / texture.height(); | 114 imageIncrement[1] = 1.0f / texture.height(); |
| 114 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); | 115 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); |
| 115 pdman.setMatrix4f(fCoefficientsUni, bicubicEffect.coefficients()); | 116 pdman.setMatrix4f(fCoefficientsUni, bicubicEffect.coefficients()); |
| 116 fDomain.setData(pdman, bicubicEffect.domain(), texture.origin()); | 117 fDomain.setData(pdman, bicubicEffect.domain(), texture.origin()); |
| 117 } | 118 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 151 } |
| 151 | 152 |
| 152 GrBicubicEffect::~GrBicubicEffect() { | 153 GrBicubicEffect::~GrBicubicEffect() { |
| 153 } | 154 } |
| 154 | 155 |
| 155 void GrBicubicEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 156 void GrBicubicEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 156 GrProcessorKeyBuilder* b) const { | 157 GrProcessorKeyBuilder* b) const { |
| 157 GrGLBicubicEffect::GenKey(*this, caps, b); | 158 GrGLBicubicEffect::GenKey(*this, caps, b); |
| 158 } | 159 } |
| 159 | 160 |
| 160 GrGLFragmentProcessor* GrBicubicEffect::createGLInstance() const { | 161 GrGLFragmentProcessor* GrBicubicEffect::onCreateGLInstance() const { |
| 161 return SkNEW_ARGS(GrGLBicubicEffect, (*this)); | 162 return SkNEW_ARGS(GrGLBicubicEffect, (*this)); |
| 162 } | 163 } |
| 163 | 164 |
| 164 bool GrBicubicEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 165 bool GrBicubicEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
| 165 const GrBicubicEffect& s = sBase.cast<GrBicubicEffect>(); | 166 const GrBicubicEffect& s = sBase.cast<GrBicubicEffect>(); |
| 166 return !memcmp(fCoefficients, s.coefficients(), 16) && | 167 return !memcmp(fCoefficients, s.coefficients(), 16) && |
| 167 fDomain == s.fDomain; | 168 fDomain == s.fDomain; |
| 168 } | 169 } |
| 169 | 170 |
| 170 void GrBicubicEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { | 171 void GrBicubicEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // Use bilerp to handle rotation or fractional translation. | 210 // Use bilerp to handle rotation or fractional translation. |
| 210 *filterMode = GrTextureParams::kBilerp_FilterMode; | 211 *filterMode = GrTextureParams::kBilerp_FilterMode; |
| 211 } | 212 } |
| 212 return false; | 213 return false; |
| 213 } | 214 } |
| 214 // When we use the bicubic filtering effect each sample is read from the tex
ture using | 215 // When we use the bicubic filtering effect each sample is read from the tex
ture using |
| 215 // nearest neighbor sampling. | 216 // nearest neighbor sampling. |
| 216 *filterMode = GrTextureParams::kNone_FilterMode; | 217 *filterMode = GrTextureParams::kNone_FilterMode; |
| 217 return true; | 218 return true; |
| 218 } | 219 } |
| OLD | NEW |