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

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

Issue 648463003: FPs now use the correct builder types(just a rename) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 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/GrConfigConversionEffect.cpp ('k') | src/gpu/effects/GrConvolutionEffect.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 2014 Google Inc. 2 * Copyright 2014 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 "GrConvexPolyEffect.h" 9 #include "GrConvexPolyEffect.h"
10 10
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } while (NULL == fp); 82 } while (NULL == fp);
83 return fp; 83 return fp;
84 } 84 }
85 85
86 ////////////////////////////////////////////////////////////////////////////// 86 //////////////////////////////////////////////////////////////////////////////
87 87
88 class GLAARectEffect : public GrGLFragmentProcessor { 88 class GLAARectEffect : public GrGLFragmentProcessor {
89 public: 89 public:
90 GLAARectEffect(const GrBackendProcessorFactory&, const GrProcessor&); 90 GLAARectEffect(const GrBackendProcessorFactory&, const GrProcessor&);
91 91
92 virtual void emitCode(GrGLProgramBuilder* builder, 92 virtual void emitCode(GrGLFPBuilder* builder,
93 const GrFragmentProcessor& fp, 93 const GrFragmentProcessor& fp,
94 const GrProcessorKey& key, 94 const GrProcessorKey& key,
95 const char* outputColor, 95 const char* outputColor,
96 const char* inputColor, 96 const char* inputColor,
97 const TransformedCoordsArray&, 97 const TransformedCoordsArray&,
98 const TextureSamplerArray&) SK_OVERRIDE; 98 const TextureSamplerArray&) SK_OVERRIDE;
99 99
100 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*); 100 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*);
101 101
102 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE; 102 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE;
103 103
104 private: 104 private:
105 GrGLProgramDataManager::UniformHandle fRectUniform; 105 GrGLProgramDataManager::UniformHandle fRectUniform;
106 SkRect fPrevRect; 106 SkRect fPrevRect;
107 typedef GrGLFragmentProcessor INHERITED; 107 typedef GrGLFragmentProcessor INHERITED;
108 }; 108 };
109 109
110 GLAARectEffect::GLAARectEffect(const GrBackendProcessorFactory& factory, 110 GLAARectEffect::GLAARectEffect(const GrBackendProcessorFactory& factory,
111 const GrProcessor& effect) 111 const GrProcessor& effect)
112 : INHERITED (factory) { 112 : INHERITED (factory) {
113 fPrevRect.fLeft = SK_ScalarNaN; 113 fPrevRect.fLeft = SK_ScalarNaN;
114 } 114 }
115 115
116 void GLAARectEffect::emitCode(GrGLProgramBuilder* builder, 116 void GLAARectEffect::emitCode(GrGLFPBuilder* builder,
117 const GrFragmentProcessor& fp, 117 const GrFragmentProcessor& fp,
118 const GrProcessorKey& key, 118 const GrProcessorKey& key,
119 const char* outputColor, 119 const char* outputColor,
120 const char* inputColor, 120 const char* inputColor,
121 const TransformedCoordsArray&, 121 const TransformedCoordsArray&,
122 const TextureSamplerArray& samplers) { 122 const TextureSamplerArray& samplers) {
123 const AARectEffect& aare = fp.cast<AARectEffect>(); 123 const AARectEffect& aare = fp.cast<AARectEffect>();
124 const char *rectName; 124 const char *rectName;
125 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5), 125 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5),
126 // respectively. 126 // respectively.
127 fRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, 127 fRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
128 kVec4f_GrSLType, 128 kVec4f_GrSLType,
129 "rect", 129 "rect",
130 &rectName); 130 &rectName);
131 131
132 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 132 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
133 const char* fragmentPos = fsBuilder->fragmentPosition(); 133 const char* fragmentPos = fsBuilder->fragmentPosition();
134 if (GrProcessorEdgeTypeIsAA(aare.getEdgeType())) { 134 if (GrProcessorEdgeTypeIsAA(aare.getEdgeType())) {
135 // The amount of coverage removed in x and y by the edges is computed as a pair of negative 135 // The amount of coverage removed in x and y by the edges is computed as a pair of negative
136 // numbers, xSub and ySub. 136 // numbers, xSub and ySub.
137 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); 137 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n");
138 fsBuilder->codeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragmentPo s, rectName); 138 fsBuilder->codeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragmentPo s, rectName);
139 fsBuilder->codeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectName, fragmentPos); 139 fsBuilder->codeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectName, fragmentPos);
140 fsBuilder->codeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragmentPo s, rectName); 140 fsBuilder->codeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragmentPo s, rectName);
141 fsBuilder->codeAppendf("\t\tySub += min(%s.w - %s.y, 0.0);\n", rectName, fragmentPos); 141 fsBuilder->codeAppendf("\t\tySub += min(%s.w - %s.y, 0.0);\n", rectName, fragmentPos);
142 // Now compute coverage in x and y and multiply them to get the fraction of the pixel 142 // Now compute coverage in x and y and multiply them to get the fraction of the pixel
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 const GrBackendFragmentProcessorFactory& AARectEffect::getFactory() const { 176 const GrBackendFragmentProcessorFactory& AARectEffect::getFactory() const {
177 return GrTBackendFragmentProcessorFactory<AARectEffect>::getInstance(); 177 return GrTBackendFragmentProcessorFactory<AARectEffect>::getInstance();
178 } 178 }
179 179
180 ////////////////////////////////////////////////////////////////////////////// 180 //////////////////////////////////////////////////////////////////////////////
181 181
182 class GrGLConvexPolyEffect : public GrGLFragmentProcessor { 182 class GrGLConvexPolyEffect : public GrGLFragmentProcessor {
183 public: 183 public:
184 GrGLConvexPolyEffect(const GrBackendProcessorFactory&, const GrProcessor&); 184 GrGLConvexPolyEffect(const GrBackendProcessorFactory&, const GrProcessor&);
185 185
186 virtual void emitCode(GrGLProgramBuilder* builder, 186 virtual void emitCode(GrGLFPBuilder* builder,
187 const GrFragmentProcessor& fp, 187 const GrFragmentProcessor& fp,
188 const GrProcessorKey& key, 188 const GrProcessorKey& key,
189 const char* outputColor, 189 const char* outputColor,
190 const char* inputColor, 190 const char* inputColor,
191 const TransformedCoordsArray&, 191 const TransformedCoordsArray&,
192 const TextureSamplerArray&) SK_OVERRIDE; 192 const TextureSamplerArray&) SK_OVERRIDE;
193 193
194 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*); 194 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*);
195 195
196 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE; 196 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE;
197 197
198 private: 198 private:
199 GrGLProgramDataManager::UniformHandle fEdgeUniform; 199 GrGLProgramDataManager::UniformHandle fEdgeUniform;
200 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa xEdges]; 200 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa xEdges];
201 typedef GrGLFragmentProcessor INHERITED; 201 typedef GrGLFragmentProcessor INHERITED;
202 }; 202 };
203 203
204 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrBackendProcessorFactory& fact ory, 204 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrBackendProcessorFactory& fact ory,
205 const GrProcessor&) 205 const GrProcessor&)
206 : INHERITED (factory) { 206 : INHERITED (factory) {
207 fPrevEdges[0] = SK_ScalarNaN; 207 fPrevEdges[0] = SK_ScalarNaN;
208 } 208 }
209 209
210 void GrGLConvexPolyEffect::emitCode(GrGLProgramBuilder* builder, 210 void GrGLConvexPolyEffect::emitCode(GrGLFPBuilder* builder,
211 const GrFragmentProcessor& fp, 211 const GrFragmentProcessor& fp,
212 const GrProcessorKey& key, 212 const GrProcessorKey& key,
213 const char* outputColor, 213 const char* outputColor,
214 const char* inputColor, 214 const char* inputColor,
215 const TransformedCoordsArray&, 215 const TransformedCoordsArray&,
216 const TextureSamplerArray& samplers) { 216 const TextureSamplerArray& samplers) {
217 const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>(); 217 const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>();
218 218
219 const char *edgeArrayName; 219 const char *edgeArrayName;
220 fEdgeUniform = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibi lity, 220 fEdgeUniform = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibi lity,
221 kVec3f_GrSLType, 221 kVec3f_GrSLType,
222 "edges", 222 "edges",
223 cpe.getEdgeCount(), 223 cpe.getEdgeCount(),
224 &edgeArrayName); 224 &edgeArrayName);
225 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 225 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
226 fsBuilder->codeAppend("\t\tfloat alpha = 1.0;\n"); 226 fsBuilder->codeAppend("\t\tfloat alpha = 1.0;\n");
227 fsBuilder->codeAppend("\t\tfloat edge;\n"); 227 fsBuilder->codeAppend("\t\tfloat edge;\n");
228 const char* fragmentPos = fsBuilder->fragmentPosition(); 228 const char* fragmentPos = fsBuilder->fragmentPosition();
229 for (int i = 0; i < cpe.getEdgeCount(); ++i) { 229 for (int i = 0; i < cpe.getEdgeCount(); ++i) {
230 fsBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n", 230 fsBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n",
231 edgeArrayName, i, fragmentPos, fragmentPos); 231 edgeArrayName, i, fragmentPos, fragmentPos);
232 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) { 232 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) {
233 fsBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); 233 fsBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n");
234 } else { 234 } else {
235 fsBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n"); 235 fsBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n");
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 } 373 }
374 374
375 GrFragmentProcessor* fp; 375 GrFragmentProcessor* fp;
376 do { 376 do {
377 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( 377 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(
378 random->nextULessThan(kGrProcessorEdgeTy peCnt)); 378 random->nextULessThan(kGrProcessorEdgeTy peCnt));
379 fp = GrConvexPolyEffect::Create(edgeType, count, edges); 379 fp = GrConvexPolyEffect::Create(edgeType, count, edges);
380 } while (NULL == fp); 380 } while (NULL == fp);
381 return fp; 381 return fp;
382 } 382 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrConfigConversionEffect.cpp ('k') | src/gpu/effects/GrConvolutionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698