| 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/GrGLEffect.h" | 9 #include "gl/GrGLEffect.h" |
| 10 #include "gl/GrGLShaderBuilder.h" | 10 #include "gl/GrGLShaderBuilder.h" |
| 11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
| 12 #include "gl/GrGLTexture.h" | 12 #include "gl/GrGLTexture.h" |
| 13 #include "GrTBackendEffectFactory.h" | 13 #include "GrTBackendEffectFactory.h" |
| 14 | 14 |
| 15 // For brevity | 15 // For brevity |
| 16 typedef GrGLUniformManager::UniformHandle UniformHandle; | 16 typedef GrGLUniformManager::UniformHandle UniformHandle; |
| 17 | 17 |
| 18 class GrGLConvolutionEffect : public GrGLEffect { | 18 class GrGLConvolutionEffect : public GrGLEffect { |
| 19 public: | 19 public: |
| 20 GrGLConvolutionEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 20 GrGLConvolutionEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 21 | 21 |
| 22 virtual void emitCode(GrGLShaderBuilder*, | 22 virtual void emitCode(GrGLShaderBuilder*, |
| 23 const GrDrawEffect&, | 23 const GrDrawEffect&, |
| 24 EffectKey, | 24 const GrEffectKey&, |
| 25 const char* outputColor, | 25 const char* outputColor, |
| 26 const char* inputColor, | 26 const char* inputColor, |
| 27 const TransformedCoordsArray&, | 27 const TransformedCoordsArray&, |
| 28 const TextureSamplerArray&) SK_OVERRIDE; | 28 const TextureSamplerArray&) SK_OVERRIDE; |
| 29 | 29 |
| 30 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect&) SK
_OVERRIDE; | 30 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect&) SK
_OVERRIDE; |
| 31 | 31 |
| 32 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 32 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); } | 35 int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); } |
| 36 bool useBounds() const { return fUseBounds; } | 36 bool useBounds() const { return fUseBounds; } |
| 37 Gr1DKernelEffect::Direction direction() const { return fDirection; } | 37 Gr1DKernelEffect::Direction direction() const { return fDirection; } |
| 38 | 38 |
| 39 int fRadius; | 39 int fRadius; |
| 40 bool fUseBounds; | 40 bool fUseBounds; |
| 41 Gr1DKernelEffect::Direction fDirection; | 41 Gr1DKernelEffect::Direction fDirection; |
| 42 UniformHandle fKernelUni; | 42 UniformHandle fKernelUni; |
| 43 UniformHandle fImageIncrementUni; | 43 UniformHandle fImageIncrementUni; |
| 44 UniformHandle fBoundsUni; | 44 UniformHandle fBoundsUni; |
| 45 | 45 |
| 46 typedef GrGLEffect INHERITED; | 46 typedef GrGLEffect INHERITED; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendEffectFactory& facto
ry, | 49 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendEffectFactory& facto
ry, |
| 50 const GrDrawEffect& drawEffect) | 50 const GrDrawEffect& drawEffect) |
| 51 : INHERITED(factory) { | 51 : INHERITED(factory) { |
| 52 const GrConvolutionEffect& c = drawEffect.castEffect<GrConvolutionEffect>(); | 52 const GrConvolutionEffect& c = drawEffect.castEffect<GrConvolutionEffect>(); |
| 53 fRadius = c.radius(); | 53 fRadius = c.radius(); |
| 54 fUseBounds = c.useBounds(); | 54 fUseBounds = c.useBounds(); |
| 55 fDirection = c.direction(); | 55 fDirection = c.direction(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder, | 58 void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder, |
| 59 const GrDrawEffect&, | 59 const GrDrawEffect&, |
| 60 EffectKey key, | 60 const GrEffectKey& key, |
| 61 const char* outputColor, | 61 const char* outputColor, |
| 62 const char* inputColor, | 62 const char* inputColor, |
| 63 const TransformedCoordsArray& coords, | 63 const TransformedCoordsArray& coords, |
| 64 const TextureSamplerArray& samplers) { | 64 const TextureSamplerArray& samplers) { |
| 65 SkString coords2D = builder->ensureFSCoords2D(coords, 0); | 65 SkString coords2D = builder->ensureFSCoords2D(coords, 0); |
| 66 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi
lity, | 66 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi
lity, |
| 67 kVec2f_GrSLType, "ImageIncrement"); | 67 kVec2f_GrSLType, "ImageIncrement"); |
| 68 if (this->useBounds()) { | 68 if (this->useBounds()) { |
| 69 fBoundsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility
, | 69 fBoundsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility
, |
| 70 kVec2f_GrSLType, "Bounds"); | 70 kVec2f_GrSLType, "Bounds"); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 if (Gr1DKernelEffect::kY_Direction == conv.direction() && | 127 if (Gr1DKernelEffect::kY_Direction == conv.direction() && |
| 128 texture.origin() != kTopLeft_GrSurfaceOrigin) { | 128 texture.origin() != kTopLeft_GrSurfaceOrigin) { |
| 129 uman.set2f(fBoundsUni, 1.0f - bounds[1], 1.0f - bounds[0]); | 129 uman.set2f(fBoundsUni, 1.0f - bounds[1], 1.0f - bounds[0]); |
| 130 } else { | 130 } else { |
| 131 uman.set2f(fBoundsUni, bounds[0], bounds[1]); | 131 uman.set2f(fBoundsUni, bounds[0], bounds[1]); |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 uman.set1fv(fKernelUni, this->width(), conv.kernel()); | 134 uman.set1fv(fKernelUni, this->width(), conv.kernel()); |
| 135 } | 135 } |
| 136 | 136 |
| 137 GrGLEffect::EffectKey GrGLConvolutionEffect::GenKey(const GrDrawEffect& drawEffe
ct, | 137 void GrGLConvolutionEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&, |
| 138 const GrGLCaps&) { | 138 GrEffectKeyBuilder* b) { |
| 139 const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect>
(); | 139 const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect>
(); |
| 140 EffectKey key = conv.radius(); | 140 uint32_t key = conv.radius(); |
| 141 key <<= 2; | 141 key <<= 2; |
| 142 if (conv.useBounds()) { | 142 if (conv.useBounds()) { |
| 143 key |= 0x2; | 143 key |= 0x2; |
| 144 key |= GrConvolutionEffect::kY_Direction == conv.direction() ? 0x1 : 0x0
; | 144 key |= GrConvolutionEffect::kY_Direction == conv.direction() ? 0x1 : 0x0
; |
| 145 } | 145 } |
| 146 return key; | 146 b->add32(key); |
| 147 } | 147 } |
| 148 | 148 |
| 149 /////////////////////////////////////////////////////////////////////////////// | 149 /////////////////////////////////////////////////////////////////////////////// |
| 150 | 150 |
| 151 GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, | 151 GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, |
| 152 Direction direction, | 152 Direction direction, |
| 153 int radius, | 153 int radius, |
| 154 const float* kernel, | 154 const float* kernel, |
| 155 bool useBounds, | 155 bool useBounds, |
| 156 float bounds[2]) | 156 float bounds[2]) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 } | 230 } |
| 231 | 231 |
| 232 bool useBounds = random->nextBool(); | 232 bool useBounds = random->nextBool(); |
| 233 return GrConvolutionEffect::Create(textures[texIdx], | 233 return GrConvolutionEffect::Create(textures[texIdx], |
| 234 dir, | 234 dir, |
| 235 radius, | 235 radius, |
| 236 kernel, | 236 kernel, |
| 237 useBounds, | 237 useBounds, |
| 238 bounds); | 238 bounds); |
| 239 } | 239 } |
| OLD | NEW |