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 GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; |
29 | 29 |
30 private: | 30 private: |
31 typedef GrGLUniformManager::UniformHandle UniformHandle; | 31 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
32 SkISize fKernelSize; | 32 SkISize fKernelSize; |
33 bool fConvolveAlpha; | 33 bool fConvolveAlpha; |
34 | 34 |
35 UniformHandle fBoundsUni; | 35 UniformHandle fBoundsUni; |
36 UniformHandle fKernelUni; | 36 UniformHandle fKernelUni; |
37 UniformHandle fImageIncrementUni; | 37 UniformHandle fImageIncrementUni; |
38 UniformHandle fKernelOffsetUni; | 38 UniformHandle fKernelOffsetUni; |
39 UniformHandle fGainUni; | 39 UniformHandle fGainUni; |
40 UniformHandle fBiasUni; | 40 UniformHandle fBiasUni; |
41 GrTextureDomain::GLDomain fDomain; | 41 GrTextureDomain::GLDomain fDomain; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 void GrGLMatrixConvolutionEffect::GenKey(const GrDrawEffect& drawEffect, | 117 void GrGLMatrixConvolutionEffect::GenKey(const GrDrawEffect& drawEffect, |
118 const GrGLCaps&, GrEffectKeyBuilder* b)
{ | 118 const GrGLCaps&, GrEffectKeyBuilder* b)
{ |
119 const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvoluti
onEffect>(); | 119 const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvoluti
onEffect>(); |
120 SkASSERT(m.kernelSize().width() <= 0x7FFF && m.kernelSize().height() <= 0xFF
FF); | 120 SkASSERT(m.kernelSize().width() <= 0x7FFF && m.kernelSize().height() <= 0xFF
FF); |
121 uint32_t key = m.kernelSize().width() << 16 | m.kernelSize().height(); | 121 uint32_t key = m.kernelSize().width() << 16 | m.kernelSize().height(); |
122 key |= m.convolveAlpha() ? 1 << 31 : 0; | 122 key |= m.convolveAlpha() ? 1 << 31 : 0; |
123 b->add32(key); | 123 b->add32(key); |
124 b->add32(GrTextureDomain::GLDomain::DomainKey(m.domain())); | 124 b->add32(GrTextureDomain::GLDomain::DomainKey(m.domain())); |
125 } | 125 } |
126 | 126 |
127 void GrGLMatrixConvolutionEffect::setData(const GrGLUniformManager& uman, | 127 void GrGLMatrixConvolutionEffect::setData(const GrGLProgramDataManager& pdman, |
128 const GrDrawEffect& drawEffect) { | 128 const GrDrawEffect& drawEffect) { |
129 const GrMatrixConvolutionEffect& conv = drawEffect.castEffect<GrMatrixConvol
utionEffect>(); | 129 const GrMatrixConvolutionEffect& conv = drawEffect.castEffect<GrMatrixConvol
utionEffect>(); |
130 GrTexture& texture = *conv.texture(0); | 130 GrTexture& texture = *conv.texture(0); |
131 // the code we generated was for a specific kernel size | 131 // the code we generated was for a specific kernel size |
132 SkASSERT(conv.kernelSize() == fKernelSize); | 132 SkASSERT(conv.kernelSize() == fKernelSize); |
133 float imageIncrement[2]; | 133 float imageIncrement[2]; |
134 float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; | 134 float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; |
135 imageIncrement[0] = 1.0f / texture.width(); | 135 imageIncrement[0] = 1.0f / texture.width(); |
136 imageIncrement[1] = ySign / texture.height(); | 136 imageIncrement[1] = ySign / texture.height(); |
137 uman.set2fv(fImageIncrementUni, 1, imageIncrement); | 137 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); |
138 uman.set2fv(fKernelOffsetUni, 1, conv.kernelOffset()); | 138 pdman.set2fv(fKernelOffsetUni, 1, conv.kernelOffset()); |
139 uman.set1fv(fKernelUni, fKernelSize.width() * fKernelSize.height(), conv.ker
nel()); | 139 pdman.set1fv(fKernelUni, fKernelSize.width() * fKernelSize.height(), conv.ke
rnel()); |
140 uman.set1f(fGainUni, conv.gain()); | 140 pdman.set1f(fGainUni, conv.gain()); |
141 uman.set1f(fBiasUni, conv.bias()); | 141 pdman.set1f(fBiasUni, conv.bias()); |
142 fDomain.setData(uman, conv.domain(), texture.origin()); | 142 fDomain.setData(pdman, conv.domain(), texture.origin()); |
143 } | 143 } |
144 | 144 |
145 GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture, | 145 GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture, |
146 const SkIRect& bounds, | 146 const SkIRect& bounds, |
147 const SkISize& kernelSize, | 147 const SkISize& kernelSize, |
148 const SkScalar* kernel, | 148 const SkScalar* kernel, |
149 SkScalar gain, | 149 SkScalar gain, |
150 SkScalar bias, | 150 SkScalar bias, |
151 const SkIPoint& kernelOffse
t, | 151 const SkIPoint& kernelOffse
t, |
152 GrTextureDomain::Mode tileM
ode, | 152 GrTextureDomain::Mode tileM
ode, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 return GrMatrixConvolutionEffect::Create(textures[texIdx], | 215 return GrMatrixConvolutionEffect::Create(textures[texIdx], |
216 bounds, | 216 bounds, |
217 kernelSize, | 217 kernelSize, |
218 kernel.get(), | 218 kernel.get(), |
219 gain, | 219 gain, |
220 bias, | 220 bias, |
221 kernelOffset, | 221 kernelOffset, |
222 tileMode, | 222 tileMode, |
223 convolveAlpha); | 223 convolveAlpha); |
224 } | 224 } |
OLD | NEW |