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 GrGLProgramDataManager::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 const GrEffectKey&, | 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 GrGLProgramDataManager& pdman, const GrDrawEffect
&) SK_OVERRIDE; |
31 | 31 |
32 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); | 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; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 builder->fsCodeAppendf(" * %s;\n", kernelIndex.c_str()); | 97 builder->fsCodeAppendf(" * %s;\n", kernelIndex.c_str()); |
98 builder->fsCodeAppendf("\t\tcoord += %s;\n", imgInc); | 98 builder->fsCodeAppendf("\t\tcoord += %s;\n", imgInc); |
99 } | 99 } |
100 | 100 |
101 SkString modulate; | 101 SkString modulate; |
102 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); | 102 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
103 builder->fsCodeAppend(modulate.c_str()); | 103 builder->fsCodeAppend(modulate.c_str()); |
104 } | 104 } |
105 | 105 |
106 void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman, | 106 void GrGLConvolutionEffect::setData(const GrGLProgramDataManager& pdman, |
107 const GrDrawEffect& drawEffect) { | 107 const GrDrawEffect& drawEffect) { |
108 const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect>
(); | 108 const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect>
(); |
109 GrTexture& texture = *conv.texture(0); | 109 GrTexture& texture = *conv.texture(0); |
110 // the code we generated was for a specific kernel radius | 110 // the code we generated was for a specific kernel radius |
111 SkASSERT(conv.radius() == fRadius); | 111 SkASSERT(conv.radius() == fRadius); |
112 float imageIncrement[2] = { 0 }; | 112 float imageIncrement[2] = { 0 }; |
113 float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; | 113 float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; |
114 switch (conv.direction()) { | 114 switch (conv.direction()) { |
115 case Gr1DKernelEffect::kX_Direction: | 115 case Gr1DKernelEffect::kX_Direction: |
116 imageIncrement[0] = 1.0f / texture.width(); | 116 imageIncrement[0] = 1.0f / texture.width(); |
117 break; | 117 break; |
118 case Gr1DKernelEffect::kY_Direction: | 118 case Gr1DKernelEffect::kY_Direction: |
119 imageIncrement[1] = ySign / texture.height(); | 119 imageIncrement[1] = ySign / texture.height(); |
120 break; | 120 break; |
121 default: | 121 default: |
122 SkFAIL("Unknown filter direction."); | 122 SkFAIL("Unknown filter direction."); |
123 } | 123 } |
124 uman.set2fv(fImageIncrementUni, 1, imageIncrement); | 124 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); |
125 if (conv.useBounds()) { | 125 if (conv.useBounds()) { |
126 const float* bounds = conv.bounds(); | 126 const float* bounds = conv.bounds(); |
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 pdman.set2f(fBoundsUni, 1.0f - bounds[1], 1.0f - bounds[0]); |
130 } else { | 130 } else { |
131 uman.set2f(fBoundsUni, bounds[0], bounds[1]); | 131 pdman.set2f(fBoundsUni, bounds[0], bounds[1]); |
132 } | 132 } |
133 } | 133 } |
134 uman.set1fv(fKernelUni, this->width(), conv.kernel()); | 134 pdman.set1fv(fKernelUni, this->width(), conv.kernel()); |
135 } | 135 } |
136 | 136 |
137 void GrGLConvolutionEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&, | 137 void GrGLConvolutionEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&, |
138 GrEffectKeyBuilder* b) { | 138 GrEffectKeyBuilder* b) { |
139 const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect>
(); | 139 const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect>
(); |
140 uint32_t 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
; |
(...skipping 85 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 |