| 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 "gl/builders/GrGLProgramBuilder.h" | 8 #include "gl/builders/GrGLProgramBuilder.h" |
| 9 #include "GrBicubicEffect.h" | 9 #include "GrBicubicEffect.h" |
| 10 | 10 |
| 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 GrGLEffect { | 22 class GrGLBicubicEffect : public GrGLFragmentProcessor { |
| 23 public: | 23 public: |
| 24 GrGLBicubicEffect(const GrBackendEffectFactory& factory, | 24 GrGLBicubicEffect(const GrBackendProcessorFactory& factory, |
| 25 const GrEffect&); | 25 const GrProcessor&); |
| 26 | 26 |
| 27 virtual void emitCode(GrGLProgramBuilder*, | 27 virtual void emitCode(GrGLProgramBuilder*, |
| 28 const GrEffect&, | 28 const GrFragmentProcessor&, |
| 29 const GrEffectKey&, | 29 const GrProcessorKey&, |
| 30 const char* outputColor, | 30 const char* outputColor, |
| 31 const char* inputColor, | 31 const char* inputColor, |
| 32 const TransformedCoordsArray&, | 32 const TransformedCoordsArray&, |
| 33 const TextureSamplerArray&) SK_OVERRIDE; | 33 const TextureSamplerArray&) SK_OVERRIDE; |
| 34 | 34 |
| 35 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER
RIDE; | 35 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
| 36 | 36 |
| 37 static inline void GenKey(const GrEffect& effect, const GrGLCaps&, | 37 static inline void GenKey(const GrProcessor& effect, const GrGLCaps&, |
| 38 GrEffectKeyBuilder* b) { | 38 GrProcessorKeyBuilder* b) { |
| 39 const GrTextureDomain& domain = effect.cast<GrBicubicEffect>().domain(); | 39 const GrTextureDomain& domain = effect.cast<GrBicubicEffect>().domain(); |
| 40 b->add32(GrTextureDomain::GLDomain::DomainKey(domain)); | 40 b->add32(GrTextureDomain::GLDomain::DomainKey(domain)); |
| 41 } | 41 } |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 44 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 45 | 45 |
| 46 UniformHandle fCoefficientsUni; | 46 UniformHandle fCoefficientsUni; |
| 47 UniformHandle fImageIncrementUni; | 47 UniformHandle fImageIncrementUni; |
| 48 GrTextureDomain::GLDomain fDomain; | 48 GrTextureDomain::GLDomain fDomain; |
| 49 | 49 |
| 50 typedef GrGLEffect INHERITED; | 50 typedef GrGLFragmentProcessor INHERITED; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory, cons
t GrEffect&) | 53 GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendProcessorFactory& factory, c
onst GrProcessor&) |
| 54 : INHERITED(factory) { | 54 : INHERITED(factory) { |
| 55 } | 55 } |
| 56 | 56 |
| 57 void GrGLBicubicEffect::emitCode(GrGLProgramBuilder* builder, | 57 void GrGLBicubicEffect::emitCode(GrGLProgramBuilder* builder, |
| 58 const GrEffect& effect, | 58 const GrFragmentProcessor& effect, |
| 59 const GrEffectKey& key, | 59 const GrProcessorKey& key, |
| 60 const char* outputColor, | 60 const char* outputColor, |
| 61 const char* inputColor, | 61 const char* inputColor, |
| 62 const TransformedCoordsArray& coords, | 62 const TransformedCoordsArray& coords, |
| 63 const TextureSamplerArray& samplers) { | 63 const TextureSamplerArray& samplers) { |
| 64 const GrTextureDomain& domain = effect.cast<GrBicubicEffect>().domain(); | 64 const GrTextureDomain& domain = effect.cast<GrBicubicEffect>().domain(); |
| 65 | 65 |
| 66 fCoefficientsUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, | 66 fCoefficientsUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, |
| 67 kMat44f_GrSLType, "Coefficients"); | 67 kMat44f_GrSLType, "Coefficients"); |
| 68 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, | 68 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, |
| 69 kVec2f_GrSLType, "ImageIncrement"); | 69 kVec2f_GrSLType, "ImageIncrement"); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 fDomain.sampleTexture(fsBuilder, domain, sampleVar.c_str(), coord, s
amplers[0]); | 109 fDomain.sampleTexture(fsBuilder, domain, sampleVar.c_str(), coord, s
amplers[0]); |
| 110 } | 110 } |
| 111 fsBuilder->codeAppendf("\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors
[1], rowColors[2], rowColors[3]);\n", y, cubicBlendName.c_str(), coeff); | 111 fsBuilder->codeAppendf("\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors
[1], rowColors[2], rowColors[3]);\n", y, cubicBlendName.c_str(), coeff); |
| 112 } | 112 } |
| 113 SkString bicubicColor; | 113 SkString bicubicColor; |
| 114 bicubicColor.printf("%s(%s, f.y, s0, s1, s2, s3)", cubicBlendName.c_str(), c
oeff); | 114 bicubicColor.printf("%s(%s, f.y, s0, s1, s2, s3)", cubicBlendName.c_str(), c
oeff); |
| 115 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, (GrGLSLExpr4(bicubicColo
r.c_str()) * GrGLSLExpr4(inputColor)).c_str()); | 115 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, (GrGLSLExpr4(bicubicColo
r.c_str()) * GrGLSLExpr4(inputColor)).c_str()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void GrGLBicubicEffect::setData(const GrGLProgramDataManager& pdman, | 118 void GrGLBicubicEffect::setData(const GrGLProgramDataManager& pdman, |
| 119 const GrEffect& effect) { | 119 const GrProcessor& processor) { |
| 120 const GrBicubicEffect& bicubicEffect = effect.cast<GrBicubicEffect>(); | 120 const GrBicubicEffect& bicubicEffect = processor.cast<GrBicubicEffect>(); |
| 121 const GrTexture& texture = *effect.texture(0); | 121 const GrTexture& texture = *processor.texture(0); |
| 122 float imageIncrement[2]; | 122 float imageIncrement[2]; |
| 123 imageIncrement[0] = 1.0f / texture.width(); | 123 imageIncrement[0] = 1.0f / texture.width(); |
| 124 imageIncrement[1] = 1.0f / texture.height(); | 124 imageIncrement[1] = 1.0f / texture.height(); |
| 125 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); | 125 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); |
| 126 pdman.setMatrix4f(fCoefficientsUni, bicubicEffect.coefficients()); | 126 pdman.setMatrix4f(fCoefficientsUni, bicubicEffect.coefficients()); |
| 127 fDomain.setData(pdman, bicubicEffect.domain(), texture.origin()); | 127 fDomain.setData(pdman, bicubicEffect.domain(), texture.origin()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 static inline void convert_row_major_scalar_coeffs_to_column_major_floats(float
dst[16], | 130 static inline void convert_row_major_scalar_coeffs_to_column_major_floats(float
dst[16], |
| 131 const
SkScalar src[16]) { | 131 const
SkScalar src[16]) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 151 const SkRect& domain) | 151 const SkRect& domain) |
| 152 : INHERITED(texture, matrix, GrTextureParams(SkShader::kClamp_TileMode, | 152 : INHERITED(texture, matrix, GrTextureParams(SkShader::kClamp_TileMode, |
| 153 GrTextureParams::kNone_FilterMode
)) | 153 GrTextureParams::kNone_FilterMode
)) |
| 154 , fDomain(domain, GrTextureDomain::kClamp_Mode) { | 154 , fDomain(domain, GrTextureDomain::kClamp_Mode) { |
| 155 convert_row_major_scalar_coeffs_to_column_major_floats(fCoefficients, coeffi
cients); | 155 convert_row_major_scalar_coeffs_to_column_major_floats(fCoefficients, coeffi
cients); |
| 156 } | 156 } |
| 157 | 157 |
| 158 GrBicubicEffect::~GrBicubicEffect() { | 158 GrBicubicEffect::~GrBicubicEffect() { |
| 159 } | 159 } |
| 160 | 160 |
| 161 const GrBackendEffectFactory& GrBicubicEffect::getFactory() const { | 161 const GrBackendFragmentProcessorFactory& GrBicubicEffect::getFactory() const { |
| 162 return GrTBackendEffectFactory<GrBicubicEffect>::getInstance(); | 162 return GrTBackendFragmentProcessorFactory<GrBicubicEffect>::getInstance(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 bool GrBicubicEffect::onIsEqual(const GrEffect& sBase) const { | 165 bool GrBicubicEffect::onIsEqual(const GrProcessor& sBase) const { |
| 166 const GrBicubicEffect& s = sBase.cast<GrBicubicEffect>(); | 166 const GrBicubicEffect& s = sBase.cast<GrBicubicEffect>(); |
| 167 return this->textureAccess(0) == s.textureAccess(0) && | 167 return this->textureAccess(0) == s.textureAccess(0) && |
| 168 !memcmp(fCoefficients, s.coefficients(), 16) && | 168 !memcmp(fCoefficients, s.coefficients(), 16) && |
| 169 fDomain == s.fDomain; | 169 fDomain == s.fDomain; |
| 170 } | 170 } |
| 171 | 171 |
| 172 void GrBicubicEffect::getConstantColorComponents(GrColor* color, uint32_t* valid
Flags) const { | 172 void GrBicubicEffect::getConstantColorComponents(GrColor* color, uint32_t* valid
Flags) const { |
| 173 // FIXME: Perhaps we can do better. | 173 // FIXME: Perhaps we can do better. |
| 174 *validFlags = 0; | 174 *validFlags = 0; |
| 175 return; | 175 return; |
| 176 } | 176 } |
| 177 | 177 |
| 178 GR_DEFINE_EFFECT_TEST(GrBicubicEffect); | 178 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrBicubicEffect); |
| 179 | 179 |
| 180 GrEffect* GrBicubicEffect::TestCreate(SkRandom* random, | 180 GrFragmentProcessor* GrBicubicEffect::TestCreate(SkRandom* random, |
| 181 GrContext* context, | 181 GrContext* context, |
| 182 const GrDrawTargetCaps&, | 182 const GrDrawTargetCaps&, |
| 183 GrTexture* textures[]) { | 183 GrTexture* textures[]) { |
| 184 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : | 184 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 185 GrEffectUnitTest::kAlphaTextureIdx; | 185 GrProcessorUnitTest::kAlphaTextureIdx; |
| 186 SkScalar coefficients[16]; | 186 SkScalar coefficients[16]; |
| 187 for (int i = 0; i < 16; i++) { | 187 for (int i = 0; i < 16; i++) { |
| 188 coefficients[i] = random->nextSScalar1(); | 188 coefficients[i] = random->nextSScalar1(); |
| 189 } | 189 } |
| 190 return GrBicubicEffect::Create(textures[texIdx], coefficients); | 190 return GrBicubicEffect::Create(textures[texIdx], coefficients); |
| 191 } | 191 } |
| 192 | 192 |
| 193 ////////////////////////////////////////////////////////////////////////////// | 193 ////////////////////////////////////////////////////////////////////////////// |
| 194 | 194 |
| 195 bool GrBicubicEffect::ShouldUseBicubic(const SkMatrix& matrix, | 195 bool GrBicubicEffect::ShouldUseBicubic(const SkMatrix& matrix, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 215 // Use bilerp to handle rotation or fractional translation. | 215 // Use bilerp to handle rotation or fractional translation. |
| 216 *filterMode = GrTextureParams::kBilerp_FilterMode; | 216 *filterMode = GrTextureParams::kBilerp_FilterMode; |
| 217 } | 217 } |
| 218 return false; | 218 return false; |
| 219 } | 219 } |
| 220 // When we use the bicubic filtering effect each sample is read from the tex
ture using | 220 // When we use the bicubic filtering effect each sample is read from the tex
ture using |
| 221 // nearest neighbor sampling. | 221 // nearest neighbor sampling. |
| 222 *filterMode = GrTextureParams::kNone_FilterMode; | 222 *filterMode = GrTextureParams::kNone_FilterMode; |
| 223 return true; | 223 return true; |
| 224 } | 224 } |
| OLD | NEW |