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

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

Issue 1457543003: Add ShaderBuilders to EmitArgs and remove gettings from ProgBuilder. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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/GrConstColorProcessor.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 "GrConvexPolyEffect.h" 8 #include "GrConvexPolyEffect.h"
9 #include "GrInvariantOutput.h" 9 #include "GrInvariantOutput.h"
10 #include "SkPathPriv.h" 10 #include "SkPathPriv.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 const AARectEffect& aare = args.fFp.cast<AARectEffect>(); 104 const AARectEffect& aare = args.fFp.cast<AARectEffect>();
105 const char *rectName; 105 const char *rectName;
106 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5), 106 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5),
107 // respectively. 107 // respectively.
108 fRectUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Vis ibility, 108 fRectUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Vis ibility,
109 kVec4f_GrSLType, 109 kVec4f_GrSLType,
110 kDefault_GrSLPrecision, 110 kDefault_GrSLPrecision,
111 "rect", 111 "rect",
112 &rectName); 112 &rectName);
113 113
114 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder() ; 114 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
115 const char* fragmentPos = fsBuilder->fragmentPosition(); 115 const char* fragmentPos = fragBuilder->fragmentPosition();
116 if (GrProcessorEdgeTypeIsAA(aare.getEdgeType())) { 116 if (GrProcessorEdgeTypeIsAA(aare.getEdgeType())) {
117 // The amount of coverage removed in x and y by the edges is computed as a pair of negative 117 // The amount of coverage removed in x and y by the edges is computed as a pair of negative
118 // numbers, xSub and ySub. 118 // numbers, xSub and ySub.
119 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); 119 fragBuilder->codeAppend("\t\tfloat xSub, ySub;\n");
120 fsBuilder->codeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragmentPo s, rectName); 120 fragBuilder->codeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragment Pos, rectName);
121 fsBuilder->codeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectName, fragmentPos); 121 fragBuilder->codeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectNam e, fragmentPos);
122 fsBuilder->codeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragmentPo s, rectName); 122 fragBuilder->codeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragment Pos, rectName);
123 fsBuilder->codeAppendf("\t\tySub += min(%s.w - %s.y, 0.0);\n", rectName, fragmentPos); 123 fragBuilder->codeAppendf("\t\tySub += min(%s.w - %s.y, 0.0);\n", rectNam e, fragmentPos);
124 // Now compute coverage in x and y and multiply them to get the fraction of the pixel 124 // Now compute coverage in x and y and multiply them to get the fraction of the pixel
125 // covered. 125 // covered.
126 fsBuilder->codeAppendf("\t\tfloat alpha = (1.0 + max(xSub, -1.0)) * (1.0 + max(ySub, -1.0));\n"); 126 fragBuilder->codeAppendf("\t\tfloat alpha = (1.0 + max(xSub, -1.0)) * (1 .0 + max(ySub, -1.0));\n");
127 } else { 127 } else {
128 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); 128 fragBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n");
129 fsBuilder->codeAppendf("\t\talpha *= (%s.x - %s.x) > -0.5 ? 1.0 : 0.0;\n ", fragmentPos, rectName); 129 fragBuilder->codeAppendf("\t\talpha *= (%s.x - %s.x) > -0.5 ? 1.0 : 0.0; \n", fragmentPos, rectName);
130 fsBuilder->codeAppendf("\t\talpha *= (%s.z - %s.x) > -0.5 ? 1.0 : 0.0;\n ", rectName, fragmentPos); 130 fragBuilder->codeAppendf("\t\talpha *= (%s.z - %s.x) > -0.5 ? 1.0 : 0.0; \n", rectName, fragmentPos);
131 fsBuilder->codeAppendf("\t\talpha *= (%s.y - %s.y) > -0.5 ? 1.0 : 0.0;\n ", fragmentPos, rectName); 131 fragBuilder->codeAppendf("\t\talpha *= (%s.y - %s.y) > -0.5 ? 1.0 : 0.0; \n", fragmentPos, rectName);
132 fsBuilder->codeAppendf("\t\talpha *= (%s.w - %s.y) > -0.5 ? 1.0 : 0.0;\n ", rectName, fragmentPos); 132 fragBuilder->codeAppendf("\t\talpha *= (%s.w - %s.y) > -0.5 ? 1.0 : 0.0; \n", rectName, fragmentPos);
133 } 133 }
134 134
135 if (GrProcessorEdgeTypeIsInverseFill(aare.getEdgeType())) { 135 if (GrProcessorEdgeTypeIsInverseFill(aare.getEdgeType())) {
136 fsBuilder->codeAppend("\t\talpha = 1.0 - alpha;\n"); 136 fragBuilder->codeAppend("\t\talpha = 1.0 - alpha;\n");
137 } 137 }
138 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor, 138 fragBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor,
139 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str()); 139 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha ")).c_str());
140 } 140 }
141 141
142 void GLAARectEffect::onSetData(const GrGLSLProgramDataManager& pdman, 142 void GLAARectEffect::onSetData(const GrGLSLProgramDataManager& pdman,
143 const GrProcessor& processor) { 143 const GrProcessor& processor) {
144 const AARectEffect& aare = processor.cast<AARectEffect>(); 144 const AARectEffect& aare = processor.cast<AARectEffect>();
145 const SkRect& rect = aare.getRect(); 145 const SkRect& rect = aare.getRect();
146 if (rect != fPrevRect) { 146 if (rect != fPrevRect) {
147 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, 147 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f,
148 rect.fRight - 0.5f, rect.fBottom - 0.5f); 148 rect.fRight - 0.5f, rect.fBottom - 0.5f);
149 fPrevRect = rect; 149 fPrevRect = rect;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 void GrGLConvexPolyEffect::emitCode(EmitArgs& args) { 190 void GrGLConvexPolyEffect::emitCode(EmitArgs& args) {
191 const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>(); 191 const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>();
192 192
193 const char *edgeArrayName; 193 const char *edgeArrayName;
194 fEdgeUniform = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragmen t_Visibility, 194 fEdgeUniform = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragmen t_Visibility,
195 kVec3f_GrSLType, 195 kVec3f_GrSLType,
196 kDefault_GrSLPrecision, 196 kDefault_GrSLPrecision,
197 "edges", 197 "edges",
198 cpe.getEdgeCount(), 198 cpe.getEdgeCount(),
199 &edgeArrayName); 199 &edgeArrayName);
200 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder() ; 200 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
201 fsBuilder->codeAppend("\t\tfloat alpha = 1.0;\n"); 201 fragBuilder->codeAppend("\t\tfloat alpha = 1.0;\n");
202 fsBuilder->codeAppend("\t\tfloat edge;\n"); 202 fragBuilder->codeAppend("\t\tfloat edge;\n");
203 const char* fragmentPos = fsBuilder->fragmentPosition(); 203 const char* fragmentPos = fragBuilder->fragmentPosition();
204 for (int i = 0; i < cpe.getEdgeCount(); ++i) { 204 for (int i = 0; i < cpe.getEdgeCount(); ++i) {
205 fsBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n", 205 fragBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n ",
206 edgeArrayName, i, fragmentPos, fragmentPos); 206 edgeArrayName, i, fragmentPos, fragmentPos);
207 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) { 207 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) {
208 fsBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); 208 fragBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n");
209 } else { 209 } else {
210 fsBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n"); 210 fragBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n");
211 } 211 }
212 fsBuilder->codeAppend("\t\talpha *= edge;\n"); 212 fragBuilder->codeAppend("\t\talpha *= edge;\n");
213 } 213 }
214 214
215 if (GrProcessorEdgeTypeIsInverseFill(cpe.getEdgeType())) { 215 if (GrProcessorEdgeTypeIsInverseFill(cpe.getEdgeType())) {
216 fsBuilder->codeAppend("\talpha = 1.0 - alpha;\n"); 216 fragBuilder->codeAppend("\talpha = 1.0 - alpha;\n");
217 } 217 }
218 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor, 218 fragBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor,
219 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str()); 219 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha ")).c_str());
220 } 220 }
221 221
222 void GrGLConvexPolyEffect::onSetData(const GrGLSLProgramDataManager& pdman, 222 void GrGLConvexPolyEffect::onSetData(const GrGLSLProgramDataManager& pdman,
223 const GrProcessor& effect) { 223 const GrProcessor& effect) {
224 const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>(); 224 const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>();
225 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); 225 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar);
226 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { 226 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) {
227 pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges()); 227 pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges());
228 memcpy(fPrevEdges, cpe.getEdges(), byteSize); 228 memcpy(fPrevEdges, cpe.getEdges(), byteSize);
229 } 229 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 346 }
347 347
348 GrFragmentProcessor* fp; 348 GrFragmentProcessor* fp;
349 do { 349 do {
350 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( 350 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(
351 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); 351 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt));
352 fp = GrConvexPolyEffect::Create(edgeType, count, edges); 352 fp = GrConvexPolyEffect::Create(edgeType, count, edges);
353 } while (nullptr == fp); 353 } while (nullptr == fp);
354 return fp; 354 return fp;
355 } 355 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrConstColorProcessor.cpp ('k') | src/gpu/effects/GrConvolutionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698