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 #include "GrMatrixConvolutionEffect.h" | 7 #include "GrMatrixConvolutionEffect.h" |
8 #include "gl/GrGLShaderBuilder.h" | 8 #include "gl/GrGLShaderBuilder.h" |
9 #include "gl/GrGLEffect.h" | 9 #include "gl/GrGLEffect.h" |
10 #include "gl/GrGLSL.h" | 10 #include "gl/GrGLSL.h" |
11 #include "gl/GrGLTexture.h" | 11 #include "gl/GrGLTexture.h" |
12 #include "GrTBackendEffectFactory.h" | 12 #include "GrTBackendEffectFactory.h" |
13 | 13 |
14 class GrGLMatrixConvolutionEffect : public GrGLEffect { | 14 class GrGLMatrixConvolutionEffect : public GrGLEffect { |
15 public: | 15 public: |
16 GrGLMatrixConvolutionEffect(const GrBackendEffectFactory& factory, | 16 GrGLMatrixConvolutionEffect(const GrBackendEffectFactory& factory, |
17 const GrDrawEffect& effect); | 17 const GrDrawEffect& effect); |
18 virtual void emitCode(GrGLShaderBuilder*, | 18 virtual void emitCode(GrGLShaderBuilder*, |
19 const GrDrawEffect&, | 19 const GrDrawEffect&, |
20 const GrEffectKey&, | 20 const GrEffectKey&, |
21 const char* outputColor, | 21 const char* outputColor, |
22 const char* inputColor, | 22 const char* inputColor, |
23 const TransformedCoordsArray&, | 23 const TransformedCoordsArray&, |
24 const TextureSamplerArray&) SK_OVERRIDE; | 24 const TextureSamplerArray&) SK_OVERRIDE; |
25 | 25 |
26 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); | 26 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
27 | 27 |
28 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 28 virtual void setData(const GrGLProgramResourceManager&, const GrDrawEffect&)
SK_OVERRIDE; |
29 | 29 |
30 private: | 30 private: |
31 typedef GrGLUniformManager::UniformHandle UniformHandle; | 31 typedef GrGLProgramResourceManager::UniformHandle UniformHandle; |
32 typedef GrMatrixConvolutionEffect::TileMode TileMode; | 32 typedef GrMatrixConvolutionEffect::TileMode TileMode; |
33 SkISize fKernelSize; | 33 SkISize fKernelSize; |
34 TileMode fTileMode; | 34 TileMode fTileMode; |
35 bool fConvolveAlpha; | 35 bool fConvolveAlpha; |
36 | 36 |
37 UniformHandle fBoundsUni; | 37 UniformHandle fBoundsUni; |
38 UniformHandle fKernelUni; | 38 UniformHandle fKernelUni; |
39 UniformHandle fImageIncrementUni; | 39 UniformHandle fImageIncrementUni; |
40 UniformHandle fKernelOffsetUni; | 40 UniformHandle fKernelOffsetUni; |
41 UniformHandle fGainUni; | 41 UniformHandle fGainUni; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 151 |
152 void GrGLMatrixConvolutionEffect::GenKey(const GrDrawEffect& drawEffect, | 152 void GrGLMatrixConvolutionEffect::GenKey(const GrDrawEffect& drawEffect, |
153 const GrGLCaps&, GrEffectKeyBuilder* b)
{ | 153 const GrGLCaps&, GrEffectKeyBuilder* b)
{ |
154 const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvoluti
onEffect>(); | 154 const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvoluti
onEffect>(); |
155 uint32_t key = encodeXY(m.kernelSize().width(), m.kernelSize().height()); | 155 uint32_t key = encodeXY(m.kernelSize().width(), m.kernelSize().height()); |
156 key |= m.tileMode() << 7; | 156 key |= m.tileMode() << 7; |
157 key |= m.convolveAlpha() ? 1 << 9 : 0; | 157 key |= m.convolveAlpha() ? 1 << 9 : 0; |
158 b->add32(key); | 158 b->add32(key); |
159 } | 159 } |
160 | 160 |
161 void GrGLMatrixConvolutionEffect::setData(const GrGLUniformManager& uman, | 161 void GrGLMatrixConvolutionEffect::setData(const GrGLProgramResourceManager& prma
n, |
162 const GrDrawEffect& drawEffect) { | 162 const GrDrawEffect& drawEffect) { |
163 const GrMatrixConvolutionEffect& conv = drawEffect.castEffect<GrMatrixConvol
utionEffect>(); | 163 const GrMatrixConvolutionEffect& conv = drawEffect.castEffect<GrMatrixConvol
utionEffect>(); |
164 GrTexture& texture = *conv.texture(0); | 164 GrTexture& texture = *conv.texture(0); |
165 // the code we generated was for a specific kernel size | 165 // the code we generated was for a specific kernel size |
166 SkASSERT(conv.kernelSize() == fKernelSize); | 166 SkASSERT(conv.kernelSize() == fKernelSize); |
167 SkASSERT(conv.tileMode() == fTileMode); | 167 SkASSERT(conv.tileMode() == fTileMode); |
168 float imageIncrement[2]; | 168 float imageIncrement[2]; |
169 float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; | 169 float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; |
170 imageIncrement[0] = 1.0f / texture.width(); | 170 imageIncrement[0] = 1.0f / texture.width(); |
171 imageIncrement[1] = ySign / texture.height(); | 171 imageIncrement[1] = ySign / texture.height(); |
172 uman.set2fv(fImageIncrementUni, 1, imageIncrement); | 172 prman.set2fv(fImageIncrementUni, 1, imageIncrement); |
173 uman.set2fv(fKernelOffsetUni, 1, conv.kernelOffset()); | 173 prman.set2fv(fKernelOffsetUni, 1, conv.kernelOffset()); |
174 uman.set1fv(fKernelUni, fKernelSize.width() * fKernelSize.height(), conv.ker
nel()); | 174 prman.set1fv(fKernelUni, fKernelSize.width() * fKernelSize.height(), conv.ke
rnel()); |
175 uman.set1f(fGainUni, conv.gain()); | 175 prman.set1f(fGainUni, conv.gain()); |
176 uman.set1f(fBiasUni, conv.bias()); | 176 prman.set1f(fBiasUni, conv.bias()); |
177 const SkIRect& bounds = conv.bounds(); | 177 const SkIRect& bounds = conv.bounds(); |
178 float left = (float) bounds.left() / texture.width(); | 178 float left = (float) bounds.left() / texture.width(); |
179 float top = (float) bounds.top() / texture.height(); | 179 float top = (float) bounds.top() / texture.height(); |
180 float right = (float) bounds.right() / texture.width(); | 180 float right = (float) bounds.right() / texture.width(); |
181 float bottom = (float) bounds.bottom() / texture.height(); | 181 float bottom = (float) bounds.bottom() / texture.height(); |
182 if (texture.origin() == kBottomLeft_GrSurfaceOrigin) { | 182 if (texture.origin() == kBottomLeft_GrSurfaceOrigin) { |
183 uman.set4f(fBoundsUni, left, 1.0f - bottom, right, 1.0f - top); | 183 prman.set4f(fBoundsUni, left, 1.0f - bottom, right, 1.0f - top); |
184 } else { | 184 } else { |
185 uman.set4f(fBoundsUni, left, top, right, bottom); | 185 prman.set4f(fBoundsUni, left, top, right, bottom); |
186 } | 186 } |
187 } | 187 } |
188 | 188 |
189 GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture, | 189 GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture, |
190 const SkIRect& bounds, | 190 const SkIRect& bounds, |
191 const SkISize& kernelSize, | 191 const SkISize& kernelSize, |
192 const SkScalar* kernel, | 192 const SkScalar* kernel, |
193 SkScalar gain, | 193 SkScalar gain, |
194 SkScalar bias, | 194 SkScalar bias, |
195 const SkIPoint& kernelOffse
t, | 195 const SkIPoint& kernelOffse
t, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 return GrMatrixConvolutionEffect::Create(textures[texIdx], | 260 return GrMatrixConvolutionEffect::Create(textures[texIdx], |
261 bounds, | 261 bounds, |
262 kernelSize, | 262 kernelSize, |
263 kernel.get(), | 263 kernel.get(), |
264 gain, | 264 gain, |
265 bias, | 265 bias, |
266 kernelOffset, | 266 kernelOffset, |
267 tileMode, | 267 tileMode, |
268 convolveAlpha); | 268 convolveAlpha); |
269 } | 269 } |
OLD | NEW |