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/GrGLFragmentProcessor.h" | 8 #include "gl/GrGLFragmentProcessor.h" |
9 #include "gl/GrGLTexture.h" | 9 #include "gl/GrGLTexture.h" |
10 #include "gl/builders/GrGLProgramBuilder.h" | 10 #include "gl/builders/GrGLProgramBuilder.h" |
11 | 11 |
12 class GrGLMatrixConvolutionEffect : public GrGLFragmentProcessor { | 12 class GrGLMatrixConvolutionEffect : public GrGLFragmentProcessor { |
13 public: | 13 public: |
14 GrGLMatrixConvolutionEffect(const GrProcessor&); | 14 GrGLMatrixConvolutionEffect(const GrProcessor&); |
15 virtual void emitCode(EmitArgs&) override; | 15 virtual void emitCode(EmitArgs&) override; |
16 | 16 |
17 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 17 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
18 | 18 |
19 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 19 protected: |
| 20 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; |
20 | 21 |
21 private: | 22 private: |
22 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 23 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
23 SkISize fKernelSize; | 24 SkISize fKernelSize; |
24 bool fConvolveAlpha; | 25 bool fConvolveAlpha; |
25 | 26 |
26 UniformHandle fKernelUni; | 27 UniformHandle fKernelUni; |
27 UniformHandle fImageIncrementUni; | 28 UniformHandle fImageIncrementUni; |
28 UniformHandle fKernelOffsetUni; | 29 UniformHandle fKernelOffsetUni; |
29 UniformHandle fGainUni; | 30 UniformHandle fGainUni; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 void GrGLMatrixConvolutionEffect::GenKey(const GrProcessor& processor, | 104 void GrGLMatrixConvolutionEffect::GenKey(const GrProcessor& processor, |
104 const GrGLSLCaps&, GrProcessorKeyBuilde
r* b) { | 105 const GrGLSLCaps&, GrProcessorKeyBuilde
r* b) { |
105 const GrMatrixConvolutionEffect& m = processor.cast<GrMatrixConvolutionEffec
t>(); | 106 const GrMatrixConvolutionEffect& m = processor.cast<GrMatrixConvolutionEffec
t>(); |
106 SkASSERT(m.kernelSize().width() <= 0x7FFF && m.kernelSize().height() <= 0xFF
FF); | 107 SkASSERT(m.kernelSize().width() <= 0x7FFF && m.kernelSize().height() <= 0xFF
FF); |
107 uint32_t key = m.kernelSize().width() << 16 | m.kernelSize().height(); | 108 uint32_t key = m.kernelSize().width() << 16 | m.kernelSize().height(); |
108 key |= m.convolveAlpha() ? 1 << 31 : 0; | 109 key |= m.convolveAlpha() ? 1 << 31 : 0; |
109 b->add32(key); | 110 b->add32(key); |
110 b->add32(GrTextureDomain::GLDomain::DomainKey(m.domain())); | 111 b->add32(GrTextureDomain::GLDomain::DomainKey(m.domain())); |
111 } | 112 } |
112 | 113 |
113 void GrGLMatrixConvolutionEffect::setData(const GrGLProgramDataManager& pdman, | 114 void GrGLMatrixConvolutionEffect::onSetData(const GrGLProgramDataManager& pdman, |
114 const GrProcessor& processor) { | 115 const GrProcessor& processor) { |
115 const GrMatrixConvolutionEffect& conv = processor.cast<GrMatrixConvolutionEf
fect>(); | 116 const GrMatrixConvolutionEffect& conv = processor.cast<GrMatrixConvolutionEf
fect>(); |
116 GrTexture& texture = *conv.texture(0); | 117 GrTexture& texture = *conv.texture(0); |
117 // the code we generated was for a specific kernel size | 118 // the code we generated was for a specific kernel size |
118 SkASSERT(conv.kernelSize() == fKernelSize); | 119 SkASSERT(conv.kernelSize() == fKernelSize); |
119 float imageIncrement[2]; | 120 float imageIncrement[2]; |
120 float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; | 121 float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; |
121 imageIncrement[0] = 1.0f / texture.width(); | 122 imageIncrement[0] = 1.0f / texture.width(); |
122 imageIncrement[1] = ySign / texture.height(); | 123 imageIncrement[1] = ySign / texture.height(); |
123 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); | 124 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); |
(...skipping 29 matching lines...) Expand all Loading... |
153 } | 154 } |
154 | 155 |
155 GrMatrixConvolutionEffect::~GrMatrixConvolutionEffect() { | 156 GrMatrixConvolutionEffect::~GrMatrixConvolutionEffect() { |
156 } | 157 } |
157 | 158 |
158 void GrMatrixConvolutionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 159 void GrMatrixConvolutionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
159 GrProcessorKeyBuilder* b) cons
t { | 160 GrProcessorKeyBuilder* b) cons
t { |
160 GrGLMatrixConvolutionEffect::GenKey(*this, caps, b); | 161 GrGLMatrixConvolutionEffect::GenKey(*this, caps, b); |
161 } | 162 } |
162 | 163 |
163 GrGLFragmentProcessor* GrMatrixConvolutionEffect::createGLInstance() const { | 164 GrGLFragmentProcessor* GrMatrixConvolutionEffect::onCreateGLInstance() const { |
164 return SkNEW_ARGS(GrGLMatrixConvolutionEffect, (*this)); | 165 return SkNEW_ARGS(GrGLMatrixConvolutionEffect, (*this)); |
165 } | 166 } |
166 | 167 |
167 bool GrMatrixConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) cons
t { | 168 bool GrMatrixConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) cons
t { |
168 const GrMatrixConvolutionEffect& s = sBase.cast<GrMatrixConvolutionEffect>()
; | 169 const GrMatrixConvolutionEffect& s = sBase.cast<GrMatrixConvolutionEffect>()
; |
169 return fKernelSize == s.kernelSize() && | 170 return fKernelSize == s.kernelSize() && |
170 !memcmp(fKernel, s.kernel(), | 171 !memcmp(fKernel, s.kernel(), |
171 fKernelSize.width() * fKernelSize.height() * sizeof(float)) &
& | 172 fKernelSize.width() * fKernelSize.height() * sizeof(float)) &
& |
172 fGain == s.gain() && | 173 fGain == s.gain() && |
173 fBias == s.bias() && | 174 fBias == s.bias() && |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 d->fTextures[texIdx], | 255 d->fTextures[texIdx], |
255 bounds, | 256 bounds, |
256 kernelSize, | 257 kernelSize, |
257 kernel.get(), | 258 kernel.get(), |
258 gain, | 259 gain, |
259 bias, | 260 bias, |
260 kernelOffset, | 261 kernelOffset, |
261 tileMode, | 262 tileMode, |
262 convolveAlpha); | 263 convolveAlpha); |
263 } | 264 } |
OLD | NEW |