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 GrGLEffect { |
23 public: | 23 public: |
24 GrGLBicubicEffect(const GrBackendEffectFactory& factory, | 24 GrGLBicubicEffect(const GrBackendEffectFactory& factory, |
25 const GrEffect&); | 25 const GrDrawEffect&); |
26 | 26 |
27 virtual void emitCode(GrGLProgramBuilder*, | 27 virtual void emitCode(GrGLProgramBuilder*, |
28 const GrEffect&, | 28 const GrDrawEffect&, |
29 const GrEffectKey&, | 29 const GrEffectKey&, |
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 GrDrawEffect&) SK_
OVERRIDE; |
36 | 36 |
37 static inline void GenKey(const GrEffect& effect, const GrGLCaps&, | 37 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
38 GrEffectKeyBuilder* b) { | 38 GrEffectKeyBuilder* b) { |
39 const GrTextureDomain& domain = effect.cast<GrBicubicEffect>().domain(); | 39 const GrTextureDomain& domain = drawEffect.castEffect<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 GrGLEffect INHERITED; |
51 }; | 51 }; |
52 | 52 |
53 GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory, cons
t GrEffect&) | 53 GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory, cons
t GrDrawEffect&) |
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 GrDrawEffect& drawEffect, |
59 const GrEffectKey& key, | 59 const GrEffectKey& 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 = drawEffect.castEffect<GrBicubicEffect>().dom
ain(); |
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"); |
70 | 70 |
71 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); | 71 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); |
72 const char* coeff = builder->getUniformCStr(fCoefficientsUni); | 72 const char* coeff = builder->getUniformCStr(fCoefficientsUni); |
73 | 73 |
74 SkString cubicBlendName; | 74 SkString cubicBlendName; |
(...skipping 34 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 GrDrawEffect& drawEffect) { |
120 const GrBicubicEffect& bicubicEffect = effect.cast<GrBicubicEffect>(); | 120 const GrBicubicEffect& effect = drawEffect.castEffect<GrBicubicEffect>(); |
121 const GrTexture& texture = *effect.texture(0); | 121 const GrTexture& texture = *effect.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, effect.coefficients()); |
127 fDomain.setData(pdman, bicubicEffect.domain(), texture.origin()); | 127 fDomain.setData(pdman, effect.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]) { |
132 for (int y = 0; y < 4; y++) { | 132 for (int y = 0; y < 4; y++) { |
133 for (int x = 0; x < 4; x++) { | 133 for (int x = 0; x < 4; x++) { |
134 dst[x * 4 + y] = SkScalarToFloat(src[y * 4 + x]); | 134 dst[x * 4 + y] = SkScalarToFloat(src[y * 4 + x]); |
135 } | 135 } |
136 } | 136 } |
137 } | 137 } |
(...skipping 18 matching lines...) Expand all Loading... |
156 } | 156 } |
157 | 157 |
158 GrBicubicEffect::~GrBicubicEffect() { | 158 GrBicubicEffect::~GrBicubicEffect() { |
159 } | 159 } |
160 | 160 |
161 const GrBackendEffectFactory& GrBicubicEffect::getFactory() const { | 161 const GrBackendEffectFactory& GrBicubicEffect::getFactory() const { |
162 return GrTBackendEffectFactory<GrBicubicEffect>::getInstance(); | 162 return GrTBackendEffectFactory<GrBicubicEffect>::getInstance(); |
163 } | 163 } |
164 | 164 |
165 bool GrBicubicEffect::onIsEqual(const GrEffect& sBase) const { | 165 bool GrBicubicEffect::onIsEqual(const GrEffect& sBase) const { |
166 const GrBicubicEffect& s = sBase.cast<GrBicubicEffect>(); | 166 const GrBicubicEffect& s = CastEffect<GrBicubicEffect>(sBase); |
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 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |