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

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

Issue 491673002: Initial refactor of shaderbuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 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/GrConvexPolyEffect.cpp ('k') | src/gpu/effects/GrCustomCoordsTextureEffect.cpp » ('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 "GrConvolutionEffect.h" 9 #include "GrConvolutionEffect.h"
9 #include "gl/GrGLEffect.h" 10 #include "gl/GrGLEffect.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 GrGLProgramDataManager::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(GrGLProgramBuilder*,
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 GrGLProgramDataManager& pdman, 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*);
(...skipping 15 matching lines...) Expand all
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(GrGLProgramBuilder* builder,
59 const GrDrawEffect&, 59 const GrDrawEffect&,
60 const GrEffectKey& 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 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib ility,
66 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi lity,
67 kVec2f_GrSLType, "ImageIncrement"); 66 kVec2f_GrSLType, "ImageIncrement");
68 if (this->useBounds()) { 67 if (this->useBounds()) {
69 fBoundsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility , 68 fBoundsUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibilit y,
70 kVec2f_GrSLType, "Bounds"); 69 kVec2f_GrSLType, "Bounds");
71 } 70 }
72 fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibilit y, 71 fKernelUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibili ty,
73 kFloat_GrSLType, "Kernel", this->width ()); 72 kFloat_GrSLType, "Kernel", this->width ());
74 73
75 builder->fsCodeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor); 74 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
75 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0);
76
77 fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor);
76 78
77 int width = this->width(); 79 int width = this->width();
78 const GrGLShaderVar& kernel = builder->getUniformVariable(fKernelUni); 80 const GrGLShaderVar& kernel = builder->getUniformVariable(fKernelUni);
79 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); 81 const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
80 82
81 builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str( ), fRadius, imgInc); 83 fsBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str( ), fRadius, imgInc);
82 84
83 // Manually unroll loop because some drivers don't; yields 20-30% speedup. 85 // Manually unroll loop because some drivers don't; yields 20-30% speedup.
84 for (int i = 0; i < width; i++) { 86 for (int i = 0; i < width; i++) {
85 SkString index; 87 SkString index;
86 SkString kernelIndex; 88 SkString kernelIndex;
87 index.appendS32(i); 89 index.appendS32(i);
88 kernel.appendArrayAccess(index.c_str(), &kernelIndex); 90 kernel.appendArrayAccess(index.c_str(), &kernelIndex);
89 builder->fsCodeAppendf("\t\t%s += ", outputColor); 91 fsBuilder->codeAppendf("\t\t%s += ", outputColor);
90 builder->fsAppendTextureLookup(samplers[0], "coord"); 92 fsBuilder->appendTextureLookup(samplers[0], "coord");
91 if (this->useBounds()) { 93 if (this->useBounds()) {
92 const char* bounds = builder->getUniformCStr(fBoundsUni); 94 const char* bounds = builder->getUniformCStr(fBoundsUni);
93 const char* component = this->direction() == Gr1DKernelEffect::kY_Di rection ? "y" : "x"; 95 const char* component = this->direction() == Gr1DKernelEffect::kY_Di rection ? "y" : "x";
94 builder->fsCodeAppendf(" * float(coord.%s >= %s.x && coord.%s <= %s. y)", 96 fsBuilder->codeAppendf(" * float(coord.%s >= %s.x && coord.%s <= %s. y)",
95 component, bounds, component, bounds); 97 component, bounds, component, bounds);
96 } 98 }
97 builder->fsCodeAppendf(" * %s;\n", kernelIndex.c_str()); 99 fsBuilder->codeAppendf(" * %s;\n", kernelIndex.c_str());
98 builder->fsCodeAppendf("\t\tcoord += %s;\n", imgInc); 100 fsBuilder->codeAppendf("\t\tcoord += %s;\n", imgInc);
99 } 101 }
100 102
101 SkString modulate; 103 SkString modulate;
102 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); 104 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor);
103 builder->fsCodeAppend(modulate.c_str()); 105 fsBuilder->codeAppend(modulate.c_str());
104 } 106 }
105 107
106 void GrGLConvolutionEffect::setData(const GrGLProgramDataManager& pdman, 108 void GrGLConvolutionEffect::setData(const GrGLProgramDataManager& pdman,
107 const GrDrawEffect& drawEffect) { 109 const GrDrawEffect& drawEffect) {
108 const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect> (); 110 const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect> ();
109 GrTexture& texture = *conv.texture(0); 111 GrTexture& texture = *conv.texture(0);
110 // the code we generated was for a specific kernel radius 112 // the code we generated was for a specific kernel radius
111 SkASSERT(conv.radius() == fRadius); 113 SkASSERT(conv.radius() == fRadius);
112 float imageIncrement[2] = { 0 }; 114 float imageIncrement[2] = { 0 };
113 float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; 115 float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 232 }
231 233
232 bool useBounds = random->nextBool(); 234 bool useBounds = random->nextBool();
233 return GrConvolutionEffect::Create(textures[texIdx], 235 return GrConvolutionEffect::Create(textures[texIdx],
234 dir, 236 dir,
235 radius, 237 radius,
236 kernel, 238 kernel,
237 useBounds, 239 useBounds,
238 bounds); 240 bounds);
239 } 241 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrConvexPolyEffect.cpp ('k') | src/gpu/effects/GrCustomCoordsTextureEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698