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 | 9 |
10 #include "gl/GrGLShaderBuilder.h" | 10 #include "gl/GrGLShaderBuilder.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 const GrDrawEffect&); | 25 const GrDrawEffect&); |
26 | 26 |
27 virtual void emitCode(GrGLShaderBuilder*, | 27 virtual void emitCode(GrGLShaderBuilder*, |
28 const GrDrawEffect&, | 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 GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 35 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; |
36 | 36 |
37 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, | 37 static inline void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
38 GrEffectKeyBuilder* b) { | 38 GrEffectKeyBuilder* b) { |
39 const GrTextureDomain& domain = drawEffect.castEffect<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 GrGLUniformManager::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 GrDrawEffect&) | 53 GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory, cons
t GrDrawEffect&) |
54 : INHERITED(factory) { | 54 : INHERITED(factory) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 sampleVar.printf("rowColors[%d]", x); | 107 sampleVar.printf("rowColors[%d]", x); |
108 fDomain.sampleTexture(builder, domain, sampleVar.c_str(), coord, sam
plers[0]); | 108 fDomain.sampleTexture(builder, domain, sampleVar.c_str(), coord, sam
plers[0]); |
109 } | 109 } |
110 builder->fsCodeAppendf("\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors
[1], rowColors[2], rowColors[3]);\n", y, cubicBlendName.c_str(), coeff); | 110 builder->fsCodeAppendf("\tvec4 s%d = %s(%s, f.x, rowColors[0], rowColors
[1], rowColors[2], rowColors[3]);\n", y, cubicBlendName.c_str(), coeff); |
111 } | 111 } |
112 SkString bicubicColor; | 112 SkString bicubicColor; |
113 bicubicColor.printf("%s(%s, f.y, s0, s1, s2, s3)", cubicBlendName.c_str(), c
oeff); | 113 bicubicColor.printf("%s(%s, f.y, s0, s1, s2, s3)", cubicBlendName.c_str(), c
oeff); |
114 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, (GrGLSLExpr4(bicubicColo
r.c_str()) * GrGLSLExpr4(inputColor)).c_str()); | 114 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, (GrGLSLExpr4(bicubicColo
r.c_str()) * GrGLSLExpr4(inputColor)).c_str()); |
115 } | 115 } |
116 | 116 |
117 void GrGLBicubicEffect::setData(const GrGLUniformManager& uman, | 117 void GrGLBicubicEffect::setData(const GrGLProgramDataManager& pdman, |
118 const GrDrawEffect& drawEffect) { | 118 const GrDrawEffect& drawEffect) { |
119 const GrBicubicEffect& effect = drawEffect.castEffect<GrBicubicEffect>(); | 119 const GrBicubicEffect& effect = drawEffect.castEffect<GrBicubicEffect>(); |
120 const GrTexture& texture = *effect.texture(0); | 120 const GrTexture& texture = *effect.texture(0); |
121 float imageIncrement[2]; | 121 float imageIncrement[2]; |
122 imageIncrement[0] = 1.0f / texture.width(); | 122 imageIncrement[0] = 1.0f / texture.width(); |
123 imageIncrement[1] = 1.0f / texture.height(); | 123 imageIncrement[1] = 1.0f / texture.height(); |
124 uman.set2fv(fImageIncrementUni, 1, imageIncrement); | 124 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); |
125 uman.setMatrix4f(fCoefficientsUni, effect.coefficients()); | 125 pdman.setMatrix4f(fCoefficientsUni, effect.coefficients()); |
126 fDomain.setData(uman, effect.domain(), texture.origin()); | 126 fDomain.setData(pdman, effect.domain(), texture.origin()); |
127 } | 127 } |
128 | 128 |
129 static inline void convert_row_major_scalar_coeffs_to_column_major_floats(float
dst[16], | 129 static inline void convert_row_major_scalar_coeffs_to_column_major_floats(float
dst[16], |
130 const
SkScalar src[16]) { | 130 const
SkScalar src[16]) { |
131 for (int y = 0; y < 4; y++) { | 131 for (int y = 0; y < 4; y++) { |
132 for (int x = 0; x < 4; x++) { | 132 for (int x = 0; x < 4; x++) { |
133 dst[x * 4 + y] = SkScalarToFloat(src[y * 4 + x]); | 133 dst[x * 4 + y] = SkScalarToFloat(src[y * 4 + x]); |
134 } | 134 } |
135 } | 135 } |
136 } | 136 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 // Use bilerp to handle rotation or fractional translation. | 213 // Use bilerp to handle rotation or fractional translation. |
214 *filterMode = GrTextureParams::kBilerp_FilterMode; | 214 *filterMode = GrTextureParams::kBilerp_FilterMode; |
215 } | 215 } |
216 return false; | 216 return false; |
217 } | 217 } |
218 // When we use the bicubic filtering effect each sample is read from the tex
ture using | 218 // When we use the bicubic filtering effect each sample is read from the tex
ture using |
219 // nearest neighbor sampling. | 219 // nearest neighbor sampling. |
220 *filterMode = GrTextureParams::kNone_FilterMode; | 220 *filterMode = GrTextureParams::kNone_FilterMode; |
221 return true; | 221 return true; |
222 } | 222 } |
OLD | NEW |