Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: src/gpu/effects/GrConvolutionEffect.cpp

Issue 582963002: Solo gp (Closed) Base URL: https://skia.googlesource.com/skia.git@no_peb
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrConvolutionEffect.h ('k') | src/gpu/effects/GrCustomCoordsTextureEffect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 8 #include "gl/builders/GrGLProgramBuilder.h"
9 #include "GrConvolutionEffect.h" 9 #include "GrConvolutionEffect.h"
10 #include "gl/GrGLEffect.h" 10 #include "gl/GrGLProcessor.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 "GrTBackendProcessorFactory.h"
14 14
15 // For brevity 15 // For brevity
16 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 16 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
17 17
18 class GrGLConvolutionEffect : public GrGLEffect { 18 class GrGLConvolutionEffect : public GrGLFragmentProcessor {
19 public: 19 public:
20 GrGLConvolutionEffect(const GrBackendEffectFactory&, const GrEffect&); 20 GrGLConvolutionEffect(const GrBackendProcessorFactory&, const GrProcessor&);
21 21
22 virtual void emitCode(GrGLProgramBuilder*, 22 virtual void emitCode(GrGLProgramBuilder*,
23 const GrEffect&, 23 const GrFragmentProcessor&,
24 const GrEffectKey&, 24 const GrProcessorKey&,
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 GrGLProgramDataManager& pdman, const GrEffect&) S K_OVERRIDE; 30 virtual void setData(const GrGLProgramDataManager& pdman, const GrProcessor& ) SK_OVERRIDE;
31 31
32 static inline void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuild er*); 32 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*);
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 GrGLFragmentProcessor INHERITED;
47 }; 47 };
48 48
49 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendEffectFactory& facto ry, 49 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendProcessorFactory& fa ctory,
50 const GrEffect& effect) 50 const GrProcessor& processor)
51 : INHERITED(factory) { 51 : INHERITED(factory) {
52 const GrConvolutionEffect& c = effect.cast<GrConvolutionEffect>(); 52 const GrConvolutionEffect& c = processor.cast<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(GrGLProgramBuilder* builder, 58 void GrGLConvolutionEffect::emitCode(GrGLProgramBuilder* builder,
59 const GrEffect&, 59 const GrFragmentProcessor&,
60 const GrEffectKey& key, 60 const GrProcessorKey& 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 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib ility, 65 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib ility,
66 kVec2f_GrSLType, "ImageIncrement"); 66 kVec2f_GrSLType, "ImageIncrement");
67 if (this->useBounds()) { 67 if (this->useBounds()) {
68 fBoundsUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibilit y, 68 fBoundsUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibilit y,
69 kVec2f_GrSLType, "Bounds"); 69 kVec2f_GrSLType, "Bounds");
70 } 70 }
(...skipping 28 matching lines...) Expand all
99 fsBuilder->codeAppendf(" * %s;\n", kernelIndex.c_str()); 99 fsBuilder->codeAppendf(" * %s;\n", kernelIndex.c_str());
100 fsBuilder->codeAppendf("\t\tcoord += %s;\n", imgInc); 100 fsBuilder->codeAppendf("\t\tcoord += %s;\n", imgInc);
101 } 101 }
102 102
103 SkString modulate; 103 SkString modulate;
104 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); 104 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor);
105 fsBuilder->codeAppend(modulate.c_str()); 105 fsBuilder->codeAppend(modulate.c_str());
106 } 106 }
107 107
108 void GrGLConvolutionEffect::setData(const GrGLProgramDataManager& pdman, 108 void GrGLConvolutionEffect::setData(const GrGLProgramDataManager& pdman,
109 const GrEffect& effect) { 109 const GrProcessor& processor) {
110 const GrConvolutionEffect& conv = effect.cast<GrConvolutionEffect>(); 110 const GrConvolutionEffect& conv = processor.cast<GrConvolutionEffect>();
111 GrTexture& texture = *conv.texture(0); 111 GrTexture& texture = *conv.texture(0);
112 // the code we generated was for a specific kernel radius 112 // the code we generated was for a specific kernel radius
113 SkASSERT(conv.radius() == fRadius); 113 SkASSERT(conv.radius() == fRadius);
114 float imageIncrement[2] = { 0 }; 114 float imageIncrement[2] = { 0 };
115 float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; 115 float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
116 switch (conv.direction()) { 116 switch (conv.direction()) {
117 case Gr1DKernelEffect::kX_Direction: 117 case Gr1DKernelEffect::kX_Direction:
118 imageIncrement[0] = 1.0f / texture.width(); 118 imageIncrement[0] = 1.0f / texture.width();
119 break; 119 break;
120 case Gr1DKernelEffect::kY_Direction: 120 case Gr1DKernelEffect::kY_Direction:
121 imageIncrement[1] = ySign / texture.height(); 121 imageIncrement[1] = ySign / texture.height();
122 break; 122 break;
123 default: 123 default:
124 SkFAIL("Unknown filter direction."); 124 SkFAIL("Unknown filter direction.");
125 } 125 }
126 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); 126 pdman.set2fv(fImageIncrementUni, 1, imageIncrement);
127 if (conv.useBounds()) { 127 if (conv.useBounds()) {
128 const float* bounds = conv.bounds(); 128 const float* bounds = conv.bounds();
129 if (Gr1DKernelEffect::kY_Direction == conv.direction() && 129 if (Gr1DKernelEffect::kY_Direction == conv.direction() &&
130 texture.origin() != kTopLeft_GrSurfaceOrigin) { 130 texture.origin() != kTopLeft_GrSurfaceOrigin) {
131 pdman.set2f(fBoundsUni, 1.0f - bounds[1], 1.0f - bounds[0]); 131 pdman.set2f(fBoundsUni, 1.0f - bounds[1], 1.0f - bounds[0]);
132 } else { 132 } else {
133 pdman.set2f(fBoundsUni, bounds[0], bounds[1]); 133 pdman.set2f(fBoundsUni, bounds[0], bounds[1]);
134 } 134 }
135 } 135 }
136 pdman.set1fv(fKernelUni, this->width(), conv.kernel()); 136 pdman.set1fv(fKernelUni, this->width(), conv.kernel());
137 } 137 }
138 138
139 void GrGLConvolutionEffect::GenKey(const GrEffect& effect, const GrGLCaps&, 139 void GrGLConvolutionEffect::GenKey(const GrProcessor& processor, const GrGLCaps& ,
140 GrEffectKeyBuilder* b) { 140 GrProcessorKeyBuilder* b) {
141 const GrConvolutionEffect& conv = effect.cast<GrConvolutionEffect>(); 141 const GrConvolutionEffect& conv = processor.cast<GrConvolutionEffect>();
142 uint32_t key = conv.radius(); 142 uint32_t key = conv.radius();
143 key <<= 2; 143 key <<= 2;
144 if (conv.useBounds()) { 144 if (conv.useBounds()) {
145 key |= 0x2; 145 key |= 0x2;
146 key |= GrConvolutionEffect::kY_Direction == conv.direction() ? 0x1 : 0x0 ; 146 key |= GrConvolutionEffect::kY_Direction == conv.direction() ? 0x1 : 0x0 ;
147 } 147 }
148 b->add32(key); 148 b->add32(key);
149 } 149 }
150 150
151 /////////////////////////////////////////////////////////////////////////////// 151 ///////////////////////////////////////////////////////////////////////////////
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 float scale = 1.0f / sum; 189 float scale = 1.0f / sum;
190 for (int i = 0; i < width; ++i) { 190 for (int i = 0; i < width; ++i) {
191 fKernel[i] *= scale; 191 fKernel[i] *= scale;
192 } 192 }
193 memcpy(fBounds, bounds, sizeof(fBounds)); 193 memcpy(fBounds, bounds, sizeof(fBounds));
194 } 194 }
195 195
196 GrConvolutionEffect::~GrConvolutionEffect() { 196 GrConvolutionEffect::~GrConvolutionEffect() {
197 } 197 }
198 198
199 const GrBackendEffectFactory& GrConvolutionEffect::getFactory() const { 199 const GrBackendFragmentProcessorFactory& GrConvolutionEffect::getFactory() const {
200 return GrTBackendEffectFactory<GrConvolutionEffect>::getInstance(); 200 return GrTBackendFragmentProcessorFactory<GrConvolutionEffect>::getInstance( );
201 } 201 }
202 202
203 bool GrConvolutionEffect::onIsEqual(const GrEffect& sBase) const { 203 bool GrConvolutionEffect::onIsEqual(const GrProcessor& sBase) const {
204 const GrConvolutionEffect& s = sBase.cast<GrConvolutionEffect>(); 204 const GrConvolutionEffect& s = sBase.cast<GrConvolutionEffect>();
205 return (this->texture(0) == s.texture(0) && 205 return (this->texture(0) == s.texture(0) &&
206 this->radius() == s.radius() && 206 this->radius() == s.radius() &&
207 this->direction() == s.direction() && 207 this->direction() == s.direction() &&
208 this->useBounds() == s.useBounds() && 208 this->useBounds() == s.useBounds() &&
209 0 == memcmp(fBounds, s.fBounds, sizeof(fBounds)) && 209 0 == memcmp(fBounds, s.fBounds, sizeof(fBounds)) &&
210 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float))); 210 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float)));
211 } 211 }
212 212
213 /////////////////////////////////////////////////////////////////////////////// 213 ///////////////////////////////////////////////////////////////////////////////
214 214
215 GR_DEFINE_EFFECT_TEST(GrConvolutionEffect); 215 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConvolutionEffect);
216 216
217 GrEffect* GrConvolutionEffect::TestCreate(SkRandom* random, 217 GrFragmentProcessor* GrConvolutionEffect::TestCreate(SkRandom* random,
218 GrContext*, 218 GrContext*,
219 const GrDrawTargetCaps&, 219 const GrDrawTargetCaps&,
220 GrTexture* textures[]) { 220 GrTexture* textures[]) {
221 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : 221 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
222 GrEffectUnitTest::kAlphaTextureIdx; 222 GrProcessorUnitTest::kAlphaTextureIdx;
223 Direction dir = random->nextBool() ? kX_Direction : kY_Direction; 223 Direction dir = random->nextBool() ? kX_Direction : kY_Direction;
224 int radius = random->nextRangeU(1, kMaxKernelRadius); 224 int radius = random->nextRangeU(1, kMaxKernelRadius);
225 float kernel[kMaxKernelWidth]; 225 float kernel[kMaxKernelWidth];
226 for (size_t i = 0; i < SK_ARRAY_COUNT(kernel); ++i) { 226 for (size_t i = 0; i < SK_ARRAY_COUNT(kernel); ++i) {
227 kernel[i] = random->nextSScalar1(); 227 kernel[i] = random->nextSScalar1();
228 } 228 }
229 float bounds[2]; 229 float bounds[2];
230 for (size_t i = 0; i < SK_ARRAY_COUNT(bounds); ++i) { 230 for (size_t i = 0; i < SK_ARRAY_COUNT(bounds); ++i) {
231 bounds[i] = random->nextF(); 231 bounds[i] = random->nextF();
232 } 232 }
233 233
234 bool useBounds = random->nextBool(); 234 bool useBounds = random->nextBool();
235 return GrConvolutionEffect::Create(textures[texIdx], 235 return GrConvolutionEffect::Create(textures[texIdx],
236 dir, 236 dir,
237 radius, 237 radius,
238 kernel, 238 kernel,
239 useBounds, 239 useBounds,
240 bounds); 240 bounds);
241 } 241 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrConvolutionEffect.h ('k') | src/gpu/effects/GrCustomCoordsTextureEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698