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

Side by Side Diff: src/gpu/GrOvalRenderer.cpp

Issue 23754003: Isolate VertexBuilder from GrGLShaderBuilder (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrAARectRenderer.cpp ('k') | src/gpu/effects/GrBezierEffect.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 2013 Google Inc. 2 * Copyright 2013 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 "GrOvalRenderer.h" 8 #include "GrOvalRenderer.h"
9 9
10 #include "GrEffect.h" 10 #include "GrEffect.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 public: 84 public:
85 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) 85 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
86 : INHERITED (factory) {} 86 : INHERITED (factory) {}
87 87
88 virtual void emitCode(GrGLShaderBuilder* builder, 88 virtual void emitCode(GrGLShaderBuilder* builder,
89 const GrDrawEffect& drawEffect, 89 const GrDrawEffect& drawEffect,
90 EffectKey key, 90 EffectKey key,
91 const char* outputColor, 91 const char* outputColor,
92 const char* inputColor, 92 const char* inputColor,
93 const TextureSamplerArray& samplers) SK_OVERRIDE { 93 const TextureSamplerArray& samplers) SK_OVERRIDE {
94 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertex Builder();
95 SkASSERT(NULL != vertexBuilder);
96
94 const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleE dgeEffect>(); 97 const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleE dgeEffect>();
95 const char *vsName, *fsName; 98 const char *vsName, *fsName;
96 builder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName) ; 99 vertexBuilder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &f sName);
97 100
98 const SkString* attrName = 101 const SkString* attrName =
99 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[0]); 102 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttrib Indices()[0]);
100 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); 103 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str ());
101 104
102 builder->fsCodeAppendf("\tfloat d = length(%s.xy);\n", fsName); 105 builder->fsCodeAppendf("\tfloat d = length(%s.xy);\n", fsName);
103 builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0 );\n", fsName); 106 builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0 );\n", fsName);
104 if (circleEffect.isStroked()) { 107 if (circleEffect.isStroked()) {
105 builder->fsCodeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0 , 1.0);\n", fsName); 108 builder->fsCodeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0 , 1.0);\n", fsName);
106 builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n"); 109 builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n");
107 } 110 }
108 111
109 SkString modulate; 112 SkString modulate;
110 GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); 113 GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha");
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 public: 198 public:
196 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) 199 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
197 : INHERITED (factory) {} 200 : INHERITED (factory) {}
198 201
199 virtual void emitCode(GrGLShaderBuilder* builder, 202 virtual void emitCode(GrGLShaderBuilder* builder,
200 const GrDrawEffect& drawEffect, 203 const GrDrawEffect& drawEffect,
201 EffectKey key, 204 EffectKey key,
202 const char* outputColor, 205 const char* outputColor,
203 const char* inputColor, 206 const char* inputColor,
204 const TextureSamplerArray& samplers) SK_OVERRIDE { 207 const TextureSamplerArray& samplers) SK_OVERRIDE {
208 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertex Builder();
209 SkASSERT(NULL != vertexBuilder);
210
205 const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<Ellip seEdgeEffect>(); 211 const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<Ellip seEdgeEffect>();
206 212
207 const char *vsOffsetName, *fsOffsetName; 213 const char *vsOffsetName, *fsOffsetName;
208 const char *vsRadiiName, *fsRadiiName; 214 const char *vsRadiiName, *fsRadiiName;
209 215
210 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets", &vsOffsetName , &fsOffsetName); 216 vertexBuilder->addVarying(kVec2f_GrSLType, "EllipseOffsets", &vsOffs etName, &fsOffsetName);
211 const SkString* attr0Name = 217 const SkString* attr0Name =
212 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[0]); 218 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttrib Indices()[0]);
213 builder->vsCodeAppendf("\t%s = %s;\n", vsOffsetName, attr0Name->c_st r()); 219 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsOffsetName, attr0Name ->c_str());
214 220
215 builder->addVarying(kVec4f_GrSLType, "EllipseRadii", &vsRadiiName, & fsRadiiName); 221 vertexBuilder->addVarying(kVec4f_GrSLType, "EllipseRadii", &vsRadiiN ame, &fsRadiiName);
216 const SkString* attr1Name = 222 const SkString* attr1Name =
217 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[1]); 223 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttrib Indices()[1]);
218 builder->vsCodeAppendf("\t%s = %s;\n", vsRadiiName, attr1Name->c_str ()); 224 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsRadiiName, attr1Name- >c_str());
219 225
220 // for outer curve 226 // for outer curve
221 builder->fsCodeAppendf("\tvec2 scaledOffset = %s*%s.xy;\n", fsOffset Name, fsRadiiName); 227 builder->fsCodeAppendf("\tvec2 scaledOffset = %s*%s.xy;\n", fsOffset Name, fsRadiiName);
222 builder->fsCodeAppend("\tfloat test = dot(scaledOffset, scaledOffset ) - 1.0;\n"); 228 builder->fsCodeAppend("\tfloat test = dot(scaledOffset, scaledOffset ) - 1.0;\n");
223 builder->fsCodeAppendf("\tvec2 grad = 2.0*scaledOffset*%s.xy;\n", fs RadiiName); 229 builder->fsCodeAppendf("\tvec2 grad = 2.0*scaledOffset*%s.xy;\n", fs RadiiName);
224 builder->fsCodeAppend("\tfloat grad_dot = dot(grad, grad);\n"); 230 builder->fsCodeAppend("\tfloat grad_dot = dot(grad, grad);\n");
225 // we need to clamp the length^2 of the gradiant vector to a non-zer o value, because 231 // we need to clamp the length^2 of the gradiant vector to a non-zer o value, because
226 // on the Nexus 4 the undefined result of inversesqrt(0) drops out a n entire tile 232 // on the Nexus 4 the undefined result of inversesqrt(0) drops out a n entire tile
227 // TODO: restrict this to Adreno-only 233 // TODO: restrict this to Adreno-only
228 builder->fsCodeAppend("\tgrad_dot = max(grad_dot, 1.0e-4);\n"); 234 builder->fsCodeAppend("\tgrad_dot = max(grad_dot, 1.0e-4);\n");
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 } 857 }
852 858
853 // drop out the middle quad if we're stroked 859 // drop out the middle quad if we're stroked
854 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO UNT(gRRectIndices); 860 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO UNT(gRRectIndices);
855 target->setIndexSourceToBuffer(indexBuffer); 861 target->setIndexSourceToBuffer(indexBuffer);
856 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou nds); 862 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou nds);
857 } 863 }
858 864
859 return true; 865 return true;
860 } 866 }
OLDNEW
« no previous file with comments | « src/gpu/GrAARectRenderer.cpp ('k') | src/gpu/effects/GrBezierEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698