| 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 "gl/builders/GrGLProgramBuilder.h" | |
| 9 #include "GrConvolutionEffect.h" | 8 #include "GrConvolutionEffect.h" |
| 10 #include "gl/GrGLProcessor.h" | 9 #include "gl/GrGLProcessor.h" |
| 11 #include "gl/GrGLSL.h" | 10 #include "gl/GrGLSL.h" |
| 12 #include "gl/GrGLTexture.h" | 11 #include "gl/GrGLTexture.h" |
| 13 #include "GrTBackendProcessorFactory.h" | 12 #include "gl/builders/GrGLProgramBuilder.h" |
| 14 | 13 |
| 15 // For brevity | 14 // For brevity |
| 16 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 15 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 17 | 16 |
| 18 class GrGLConvolutionEffect : public GrGLFragmentProcessor { | 17 class GrGLConvolutionEffect : public GrGLFragmentProcessor { |
| 19 public: | 18 public: |
| 20 GrGLConvolutionEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 19 GrGLConvolutionEffect(const GrProcessor&); |
| 21 | 20 |
| 22 virtual void emitCode(GrGLFPBuilder*, | 21 virtual void emitCode(GrGLFPBuilder*, |
| 23 const GrFragmentProcessor&, | 22 const GrFragmentProcessor&, |
| 24 const char* outputColor, | 23 const char* outputColor, |
| 25 const char* inputColor, | 24 const char* inputColor, |
| 26 const TransformedCoordsArray&, | 25 const TransformedCoordsArray&, |
| 27 const TextureSamplerArray&) SK_OVERRIDE; | 26 const TextureSamplerArray&) SK_OVERRIDE; |
| 28 | 27 |
| 29 virtual void setData(const GrGLProgramDataManager& pdman, const GrProcessor&
) SK_OVERRIDE; | 28 virtual void setData(const GrGLProgramDataManager& pdman, const GrProcessor&
) SK_OVERRIDE; |
| 30 | 29 |
| 31 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 30 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
| 32 | 31 |
| 33 private: | 32 private: |
| 34 int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); } | 33 int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); } |
| 35 bool useBounds() const { return fUseBounds; } | 34 bool useBounds() const { return fUseBounds; } |
| 36 Gr1DKernelEffect::Direction direction() const { return fDirection; } | 35 Gr1DKernelEffect::Direction direction() const { return fDirection; } |
| 37 | 36 |
| 38 int fRadius; | 37 int fRadius; |
| 39 bool fUseBounds; | 38 bool fUseBounds; |
| 40 Gr1DKernelEffect::Direction fDirection; | 39 Gr1DKernelEffect::Direction fDirection; |
| 41 UniformHandle fKernelUni; | 40 UniformHandle fKernelUni; |
| 42 UniformHandle fImageIncrementUni; | 41 UniformHandle fImageIncrementUni; |
| 43 UniformHandle fBoundsUni; | 42 UniformHandle fBoundsUni; |
| 44 | 43 |
| 45 typedef GrGLFragmentProcessor INHERITED; | 44 typedef GrGLFragmentProcessor INHERITED; |
| 46 }; | 45 }; |
| 47 | 46 |
| 48 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendProcessorFactory& fa
ctory, | 47 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrProcessor& processor) { |
| 49 const GrProcessor& processor) | |
| 50 : INHERITED(factory) { | |
| 51 const GrConvolutionEffect& c = processor.cast<GrConvolutionEffect>(); | 48 const GrConvolutionEffect& c = processor.cast<GrConvolutionEffect>(); |
| 52 fRadius = c.radius(); | 49 fRadius = c.radius(); |
| 53 fUseBounds = c.useBounds(); | 50 fUseBounds = c.useBounds(); |
| 54 fDirection = c.direction(); | 51 fDirection = c.direction(); |
| 55 } | 52 } |
| 56 | 53 |
| 57 void GrGLConvolutionEffect::emitCode(GrGLFPBuilder* builder, | 54 void GrGLConvolutionEffect::emitCode(GrGLFPBuilder* builder, |
| 58 const GrFragmentProcessor&, | 55 const GrFragmentProcessor&, |
| 59 const char* outputColor, | 56 const char* outputColor, |
| 60 const char* inputColor, | 57 const char* inputColor, |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 float scale = 1.0f / sum; | 184 float scale = 1.0f / sum; |
| 188 for (int i = 0; i < width; ++i) { | 185 for (int i = 0; i < width; ++i) { |
| 189 fKernel[i] *= scale; | 186 fKernel[i] *= scale; |
| 190 } | 187 } |
| 191 memcpy(fBounds, bounds, sizeof(fBounds)); | 188 memcpy(fBounds, bounds, sizeof(fBounds)); |
| 192 } | 189 } |
| 193 | 190 |
| 194 GrConvolutionEffect::~GrConvolutionEffect() { | 191 GrConvolutionEffect::~GrConvolutionEffect() { |
| 195 } | 192 } |
| 196 | 193 |
| 197 const GrBackendFragmentProcessorFactory& GrConvolutionEffect::getFactory() const
{ | 194 void GrConvolutionEffect::getGLProcessorKey(const GrGLCaps& caps, |
| 198 return GrTBackendFragmentProcessorFactory<GrConvolutionEffect>::getInstance(
); | 195 GrProcessorKeyBuilder* b) const { |
| 196 GrGLConvolutionEffect::GenKey(*this, caps, b); |
| 197 } |
| 198 |
| 199 GrGLFragmentProcessor* GrConvolutionEffect::createGLInstance() const { |
| 200 return SkNEW_ARGS(GrGLConvolutionEffect, (*this)); |
| 199 } | 201 } |
| 200 | 202 |
| 201 bool GrConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 203 bool GrConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
| 202 const GrConvolutionEffect& s = sBase.cast<GrConvolutionEffect>(); | 204 const GrConvolutionEffect& s = sBase.cast<GrConvolutionEffect>(); |
| 203 return (this->radius() == s.radius() && | 205 return (this->radius() == s.radius() && |
| 204 this->direction() == s.direction() && | 206 this->direction() == s.direction() && |
| 205 this->useBounds() == s.useBounds() && | 207 this->useBounds() == s.useBounds() && |
| 206 0 == memcmp(fBounds, s.fBounds, sizeof(fBounds)) && | 208 0 == memcmp(fBounds, s.fBounds, sizeof(fBounds)) && |
| 207 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float))); | 209 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float))); |
| 208 } | 210 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 229 } | 231 } |
| 230 | 232 |
| 231 bool useBounds = random->nextBool(); | 233 bool useBounds = random->nextBool(); |
| 232 return GrConvolutionEffect::Create(textures[texIdx], | 234 return GrConvolutionEffect::Create(textures[texIdx], |
| 233 dir, | 235 dir, |
| 234 radius, | 236 radius, |
| 235 kernel, | 237 kernel, |
| 236 useBounds, | 238 useBounds, |
| 237 bounds); | 239 bounds); |
| 238 } | 240 } |
| OLD | NEW |