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 "gl/GrGLFragmentProcessor.h" |
10 #include "gl/GrGLTexture.h" | 10 #include "gl/GrGLTexture.h" |
11 #include "gl/builders/GrGLProgramBuilder.h" | 11 #include "gl/builders/GrGLProgramBuilder.h" |
12 | 12 |
13 // For brevity | 13 // For brevity |
14 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 14 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
15 | 15 |
16 class GrGLConvolutionEffect : public GrGLFragmentProcessor { | 16 class GrGLConvolutionEffect : public GrGLFragmentProcessor { |
17 public: | 17 public: |
18 GrGLConvolutionEffect(const GrProcessor&); | 18 GrGLConvolutionEffect(const GrProcessor&); |
19 | 19 |
20 virtual void emitCode(EmitArgs&) override; | 20 virtual void emitCode(EmitArgs&) override; |
21 | 21 |
22 void setData(const GrGLProgramDataManager& pdman, const GrProcessor&) overri
de; | 22 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
23 | 23 |
24 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 24 protected: |
| 25 void onSetData(const GrGLProgramDataManager& pdman, const GrProcessor&) over
ride; |
25 | 26 |
26 private: | 27 private: |
27 int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); } | 28 int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); } |
28 bool useBounds() const { return fUseBounds; } | 29 bool useBounds() const { return fUseBounds; } |
29 Gr1DKernelEffect::Direction direction() const { return fDirection; } | 30 Gr1DKernelEffect::Direction direction() const { return fDirection; } |
30 | 31 |
31 int fRadius; | 32 int fRadius; |
32 bool fUseBounds; | 33 bool fUseBounds; |
33 Gr1DKernelEffect::Direction fDirection; | 34 Gr1DKernelEffect::Direction fDirection; |
34 UniformHandle fKernelUni; | 35 UniformHandle fKernelUni; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 fsBuilder->codeAppend("}"); | 93 fsBuilder->codeAppend("}"); |
93 } | 94 } |
94 fsBuilder->codeAppendf("\t\tcoord += %s;\n", imgInc); | 95 fsBuilder->codeAppendf("\t\tcoord += %s;\n", imgInc); |
95 } | 96 } |
96 | 97 |
97 SkString modulate; | 98 SkString modulate; |
98 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); | 99 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); |
99 fsBuilder->codeAppend(modulate.c_str()); | 100 fsBuilder->codeAppend(modulate.c_str()); |
100 } | 101 } |
101 | 102 |
102 void GrGLConvolutionEffect::setData(const GrGLProgramDataManager& pdman, | 103 void GrGLConvolutionEffect::onSetData(const GrGLProgramDataManager& pdman, |
103 const GrProcessor& processor) { | 104 const GrProcessor& processor) { |
104 const GrConvolutionEffect& conv = processor.cast<GrConvolutionEffect>(); | 105 const GrConvolutionEffect& conv = processor.cast<GrConvolutionEffect>(); |
105 GrTexture& texture = *conv.texture(0); | 106 GrTexture& texture = *conv.texture(0); |
106 // the code we generated was for a specific kernel radius | 107 // the code we generated was for a specific kernel radius |
107 SkASSERT(conv.radius() == fRadius); | 108 SkASSERT(conv.radius() == fRadius); |
108 float imageIncrement[2] = { 0 }; | 109 float imageIncrement[2] = { 0 }; |
109 float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; | 110 float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; |
110 switch (conv.direction()) { | 111 switch (conv.direction()) { |
111 case Gr1DKernelEffect::kX_Direction: | 112 case Gr1DKernelEffect::kX_Direction: |
112 imageIncrement[0] = 1.0f / texture.width(); | 113 imageIncrement[0] = 1.0f / texture.width(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 193 } |
193 | 194 |
194 GrConvolutionEffect::~GrConvolutionEffect() { | 195 GrConvolutionEffect::~GrConvolutionEffect() { |
195 } | 196 } |
196 | 197 |
197 void GrConvolutionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 198 void GrConvolutionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
198 GrProcessorKeyBuilder* b) const { | 199 GrProcessorKeyBuilder* b) const { |
199 GrGLConvolutionEffect::GenKey(*this, caps, b); | 200 GrGLConvolutionEffect::GenKey(*this, caps, b); |
200 } | 201 } |
201 | 202 |
202 GrGLFragmentProcessor* GrConvolutionEffect::createGLInstance() const { | 203 GrGLFragmentProcessor* GrConvolutionEffect::onCreateGLInstance() const { |
203 return SkNEW_ARGS(GrGLConvolutionEffect, (*this)); | 204 return SkNEW_ARGS(GrGLConvolutionEffect, (*this)); |
204 } | 205 } |
205 | 206 |
206 bool GrConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 207 bool GrConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
207 const GrConvolutionEffect& s = sBase.cast<GrConvolutionEffect>(); | 208 const GrConvolutionEffect& s = sBase.cast<GrConvolutionEffect>(); |
208 return (this->radius() == s.radius() && | 209 return (this->radius() == s.radius() && |
209 this->direction() == s.direction() && | 210 this->direction() == s.direction() && |
210 this->useBounds() == s.useBounds() && | 211 this->useBounds() == s.useBounds() && |
211 0 == memcmp(fBounds, s.fBounds, sizeof(fBounds)) && | 212 0 == memcmp(fBounds, s.fBounds, sizeof(fBounds)) && |
212 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float))); | 213 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float))); |
(...skipping 19 matching lines...) Expand all Loading... |
232 | 233 |
233 bool useBounds = d->fRandom->nextBool(); | 234 bool useBounds = d->fRandom->nextBool(); |
234 return GrConvolutionEffect::Create(d->fProcDataManager, | 235 return GrConvolutionEffect::Create(d->fProcDataManager, |
235 d->fTextures[texIdx], | 236 d->fTextures[texIdx], |
236 dir, | 237 dir, |
237 radius, | 238 radius, |
238 kernel, | 239 kernel, |
239 useBounds, | 240 useBounds, |
240 bounds); | 241 bounds); |
241 } | 242 } |
OLD | NEW |