OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrConvolutionEffect.h" | 8 #include "GrConvolutionEffect.h" |
9 #include "gl/GrGLFragmentProcessor.h" | 9 #include "glsl/GrGLSLFragmentProcessor.h" |
10 #include "gl/GrGLTexture.h" | |
11 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 10 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
12 #include "glsl/GrGLSLProgramBuilder.h" | 11 #include "glsl/GrGLSLProgramBuilder.h" |
13 #include "glsl/GrGLSLProgramDataManager.h" | 12 #include "glsl/GrGLSLProgramDataManager.h" |
14 | 13 |
15 // For brevity | 14 // For brevity |
16 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 15 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
17 | 16 |
18 class GrGLConvolutionEffect : public GrGLFragmentProcessor { | 17 class GrGLConvolutionEffect : public GrGLSLFragmentProcessor { |
19 public: | 18 public: |
20 GrGLConvolutionEffect(const GrProcessor&); | 19 GrGLConvolutionEffect(const GrProcessor&); |
21 | 20 |
22 virtual void emitCode(EmitArgs&) override; | 21 virtual void emitCode(EmitArgs&) override; |
23 | 22 |
24 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 23 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
25 | 24 |
26 protected: | 25 protected: |
27 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&) ov
erride; | 26 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&) ov
erride; |
28 | 27 |
29 private: | 28 private: |
30 int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); } | 29 int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); } |
31 bool useBounds() const { return fUseBounds; } | 30 bool useBounds() const { return fUseBounds; } |
32 Gr1DKernelEffect::Direction direction() const { return fDirection; } | 31 Gr1DKernelEffect::Direction direction() const { return fDirection; } |
33 | 32 |
34 int fRadius; | 33 int fRadius; |
35 bool fUseBounds; | 34 bool fUseBounds; |
36 Gr1DKernelEffect::Direction fDirection; | 35 Gr1DKernelEffect::Direction fDirection; |
37 UniformHandle fKernelUni; | 36 UniformHandle fKernelUni; |
38 UniformHandle fImageIncrementUni; | 37 UniformHandle fImageIncrementUni; |
39 UniformHandle fBoundsUni; | 38 UniformHandle fBoundsUni; |
40 | 39 |
41 typedef GrGLFragmentProcessor INHERITED; | 40 typedef GrGLSLFragmentProcessor INHERITED; |
42 }; | 41 }; |
43 | 42 |
44 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrProcessor& processor) { | 43 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrProcessor& processor) { |
45 const GrConvolutionEffect& c = processor.cast<GrConvolutionEffect>(); | 44 const GrConvolutionEffect& c = processor.cast<GrConvolutionEffect>(); |
46 fRadius = c.radius(); | 45 fRadius = c.radius(); |
47 fUseBounds = c.useBounds(); | 46 fUseBounds = c.useBounds(); |
48 fDirection = c.direction(); | 47 fDirection = c.direction(); |
49 } | 48 } |
50 | 49 |
51 void GrGLConvolutionEffect::emitCode(EmitArgs& args) { | 50 void GrGLConvolutionEffect::emitCode(EmitArgs& args) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 192 } |
194 | 193 |
195 GrConvolutionEffect::~GrConvolutionEffect() { | 194 GrConvolutionEffect::~GrConvolutionEffect() { |
196 } | 195 } |
197 | 196 |
198 void GrConvolutionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 197 void GrConvolutionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
199 GrProcessorKeyBuilder* b) const { | 198 GrProcessorKeyBuilder* b) const { |
200 GrGLConvolutionEffect::GenKey(*this, caps, b); | 199 GrGLConvolutionEffect::GenKey(*this, caps, b); |
201 } | 200 } |
202 | 201 |
203 GrGLFragmentProcessor* GrConvolutionEffect::onCreateGLInstance() const { | 202 GrGLSLFragmentProcessor* GrConvolutionEffect::onCreateGLInstance() const { |
204 return new GrGLConvolutionEffect(*this); | 203 return new GrGLConvolutionEffect(*this); |
205 } | 204 } |
206 | 205 |
207 bool GrConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 206 bool GrConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
208 const GrConvolutionEffect& s = sBase.cast<GrConvolutionEffect>(); | 207 const GrConvolutionEffect& s = sBase.cast<GrConvolutionEffect>(); |
209 return (this->radius() == s.radius() && | 208 return (this->radius() == s.radius() && |
210 this->direction() == s.direction() && | 209 this->direction() == s.direction() && |
211 this->useBounds() == s.useBounds() && | 210 this->useBounds() == s.useBounds() && |
212 0 == memcmp(fBounds, s.fBounds, sizeof(fBounds)) && | 211 0 == memcmp(fBounds, s.fBounds, sizeof(fBounds)) && |
213 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float))); | 212 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float))); |
(...skipping 18 matching lines...) Expand all Loading... |
232 } | 231 } |
233 | 232 |
234 bool useBounds = d->fRandom->nextBool(); | 233 bool useBounds = d->fRandom->nextBool(); |
235 return GrConvolutionEffect::Create(d->fTextures[texIdx], | 234 return GrConvolutionEffect::Create(d->fTextures[texIdx], |
236 dir, | 235 dir, |
237 radius, | 236 radius, |
238 kernel, | 237 kernel, |
239 useBounds, | 238 useBounds, |
240 bounds); | 239 bounds); |
241 } | 240 } |
OLD | NEW |