OLD | NEW |
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 "gl/builders/GrGLProgramBuilder.h" | 10 #include "gl/builders/GrGLFullProgramBuilder.h" |
11 #include "gl/GrGLProcessor.h" | 11 #include "gl/GrGLProcessor.h" |
12 #include "gl/GrGLSL.h" | 12 #include "gl/GrGLSL.h" |
13 #include "gl/GrGLGeometryProcessor.h" | 13 #include "gl/GrGLGeometryProcessor.h" |
14 #include "GrProcessor.h" | 14 #include "GrProcessor.h" |
15 #include "GrTBackendProcessorFactory.h" | 15 #include "GrTBackendProcessorFactory.h" |
16 | 16 |
17 #include "GrDrawState.h" | 17 #include "GrDrawState.h" |
18 #include "GrDrawTarget.h" | 18 #include "GrDrawTarget.h" |
19 #include "GrGpu.h" | 19 #include "GrGpu.h" |
20 | 20 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 static const char* Name() { return "CircleEdge"; } | 86 static const char* Name() { return "CircleEdge"; } |
87 | 87 |
88 inline bool isStroked() const { return fStroke; } | 88 inline bool isStroked() const { return fStroke; } |
89 | 89 |
90 class GLProcessor : public GrGLGeometryProcessor { | 90 class GLProcessor : public GrGLGeometryProcessor { |
91 public: | 91 public: |
92 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
) | 92 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
) |
93 : INHERITED (factory) {} | 93 : INHERITED (factory) {} |
94 | 94 |
95 virtual void emitCode(GrGLGPBuilder* builder, | 95 virtual void emitCode(GrGLFullProgramBuilder* builder, |
96 const GrGeometryProcessor& geometryProcessor, | 96 const GrGeometryProcessor& geometryProcessor, |
97 const GrProcessorKey& key, | 97 const GrProcessorKey& key, |
98 const char* outputColor, | 98 const char* outputColor, |
99 const char* inputColor, | 99 const char* inputColor, |
100 const TransformedCoordsArray&, | 100 const TransformedCoordsArray&, |
101 const TextureSamplerArray& samplers) SK_OVERRIDE { | 101 const TextureSamplerArray& samplers) SK_OVERRIDE { |
102 const CircleEdgeEffect& circleEffect = geometryProcessor.cast<Circle
EdgeEffect>(); | 102 const CircleEdgeEffect& circleEffect = geometryProcessor.cast<Circle
EdgeEffect>(); |
103 const char *vsName, *fsName; | 103 const char *vsName, *fsName; |
104 builder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName)
; | 104 builder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName)
; |
105 | 105 |
106 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder();; | 106 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder
();; |
107 vsBuilder->codeAppendf("\t%s = %s;\n", vsName, circleEffect.inCircle
Edge().c_str()); | 107 vsBuilder->codeAppendf("\t%s = %s;\n", vsName, circleEffect.inCircle
Edge().c_str()); |
108 | 108 |
109 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder
(); | 109 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragment
ShaderBuilder(); |
110 fsBuilder->codeAppendf("\tfloat d = length(%s.xy);\n", fsName); | 110 fsBuilder->codeAppendf("\tfloat d = length(%s.xy);\n", fsName); |
111 fsBuilder->codeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0
);\n", fsName); | 111 fsBuilder->codeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0
);\n", fsName); |
112 if (circleEffect.isStroked()) { | 112 if (circleEffect.isStroked()) { |
113 fsBuilder->codeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0
, 1.0);\n", fsName); | 113 fsBuilder->codeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0
, 1.0);\n", fsName); |
114 fsBuilder->codeAppend("\tedgeAlpha *= innerAlpha;\n"); | 114 fsBuilder->codeAppend("\tedgeAlpha *= innerAlpha;\n"); |
115 } | 115 } |
116 | 116 |
117 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, | 117 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, |
118 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); | 118 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); |
119 } | 119 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 const GrShaderVar& inEllipseOffset() const { return fInEllipseOffset; } | 203 const GrShaderVar& inEllipseOffset() const { return fInEllipseOffset; } |
204 const GrShaderVar& inEllipseRadii() const { return fInEllipseRadii; } | 204 const GrShaderVar& inEllipseRadii() const { return fInEllipseRadii; } |
205 | 205 |
206 inline bool isStroked() const { return fStroke; } | 206 inline bool isStroked() const { return fStroke; } |
207 | 207 |
208 class GLProcessor : public GrGLGeometryProcessor { | 208 class GLProcessor : public GrGLGeometryProcessor { |
209 public: | 209 public: |
210 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
) | 210 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
) |
211 : INHERITED (factory) {} | 211 : INHERITED (factory) {} |
212 | 212 |
213 virtual void emitCode(GrGLGPBuilder* builder, | 213 virtual void emitCode(GrGLFullProgramBuilder* builder, |
214 const GrGeometryProcessor& geometryProcessor, | 214 const GrGeometryProcessor& geometryProcessor, |
215 const GrProcessorKey& key, | 215 const GrProcessorKey& key, |
216 const char* outputColor, | 216 const char* outputColor, |
217 const char* inputColor, | 217 const char* inputColor, |
218 const TransformedCoordsArray&, | 218 const TransformedCoordsArray&, |
219 const TextureSamplerArray& samplers) SK_OVERRIDE { | 219 const TextureSamplerArray& samplers) SK_OVERRIDE { |
220 const EllipseEdgeEffect& ellipseEffect = geometryProcessor.cast<Elli
pseEdgeEffect>(); | 220 const EllipseEdgeEffect& ellipseEffect = geometryProcessor.cast<Elli
pseEdgeEffect>(); |
221 | 221 |
222 const char *vsOffsetName, *fsOffsetName; | 222 const char *vsOffsetName, *fsOffsetName; |
223 const char *vsRadiiName, *fsRadiiName; | 223 const char *vsRadiiName, *fsRadiiName; |
224 | 224 |
225 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets", &vsOffsetName
, &fsOffsetName); | 225 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets", &vsOffsetName
, &fsOffsetName); |
226 | 226 |
227 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 227 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder
(); |
228 vsBuilder->codeAppendf("%s = %s;", vsOffsetName, | 228 vsBuilder->codeAppendf("%s = %s;", vsOffsetName, |
229 ellipseEffect.inEllipseOffset().c_str()); | 229 ellipseEffect.inEllipseOffset().c_str()); |
230 | 230 |
231 builder->addVarying(kVec4f_GrSLType, "EllipseRadii", &vsRadiiName, &
fsRadiiName); | 231 builder->addVarying(kVec4f_GrSLType, "EllipseRadii", &vsRadiiName, &
fsRadiiName); |
232 vsBuilder->codeAppendf("%s = %s;", vsRadiiName, ellipseEffect.inElli
pseRadii().c_str()); | 232 vsBuilder->codeAppendf("%s = %s;", vsRadiiName, ellipseEffect.inElli
pseRadii().c_str()); |
233 | 233 |
234 // for outer curve | 234 // for outer curve |
235 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder
(); | 235 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragment
ShaderBuilder(); |
236 fsBuilder->codeAppendf("\tvec2 scaledOffset = %s*%s.xy;\n", fsOffset
Name, fsRadiiName); | 236 fsBuilder->codeAppendf("\tvec2 scaledOffset = %s*%s.xy;\n", fsOffset
Name, fsRadiiName); |
237 fsBuilder->codeAppend("\tfloat test = dot(scaledOffset, scaledOffset
) - 1.0;\n"); | 237 fsBuilder->codeAppend("\tfloat test = dot(scaledOffset, scaledOffset
) - 1.0;\n"); |
238 fsBuilder->codeAppendf("\tvec2 grad = 2.0*scaledOffset*%s.xy;\n", fs
RadiiName); | 238 fsBuilder->codeAppendf("\tvec2 grad = 2.0*scaledOffset*%s.xy;\n", fs
RadiiName); |
239 fsBuilder->codeAppend("\tfloat grad_dot = dot(grad, grad);\n"); | 239 fsBuilder->codeAppend("\tfloat grad_dot = dot(grad, grad);\n"); |
240 // avoid calling inversesqrt on zero. | 240 // avoid calling inversesqrt on zero. |
241 fsBuilder->codeAppend("\tgrad_dot = max(grad_dot, 1.0e-4);\n"); | 241 fsBuilder->codeAppend("\tgrad_dot = max(grad_dot, 1.0e-4);\n"); |
242 fsBuilder->codeAppend("\tfloat invlen = inversesqrt(grad_dot);\n"); | 242 fsBuilder->codeAppend("\tfloat invlen = inversesqrt(grad_dot);\n"); |
243 fsBuilder->codeAppend("\tfloat edgeAlpha = clamp(0.5-test*invlen, 0.
0, 1.0);\n"); | 243 fsBuilder->codeAppend("\tfloat edgeAlpha = clamp(0.5-test*invlen, 0.
0, 1.0);\n"); |
244 | 244 |
245 // for inner curve | 245 // for inner curve |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 const GrShaderVar& inEllipseOffsets0() const { return fInEllipseOffsets0; } | 352 const GrShaderVar& inEllipseOffsets0() const { return fInEllipseOffsets0; } |
353 const GrShaderVar& inEllipseOffsets1() const { return fInEllipseOffsets1; } | 353 const GrShaderVar& inEllipseOffsets1() const { return fInEllipseOffsets1; } |
354 | 354 |
355 inline Mode getMode() const { return fMode; } | 355 inline Mode getMode() const { return fMode; } |
356 | 356 |
357 class GLProcessor : public GrGLGeometryProcessor { | 357 class GLProcessor : public GrGLGeometryProcessor { |
358 public: | 358 public: |
359 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
) | 359 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
) |
360 : INHERITED (factory) {} | 360 : INHERITED (factory) {} |
361 | 361 |
362 virtual void emitCode(GrGLGPBuilder* builder, | 362 virtual void emitCode(GrGLFullProgramBuilder* builder, |
363 const GrGeometryProcessor& geometryProcessor, | 363 const GrGeometryProcessor& geometryProcessor, |
364 const GrProcessorKey& key, | 364 const GrProcessorKey& key, |
365 const char* outputColor, | 365 const char* outputColor, |
366 const char* inputColor, | 366 const char* inputColor, |
367 const TransformedCoordsArray&, | 367 const TransformedCoordsArray&, |
368 const TextureSamplerArray& samplers) SK_OVERRIDE { | 368 const TextureSamplerArray& samplers) SK_OVERRIDE { |
369 const DIEllipseEdgeEffect& ellipseEffect = | 369 const DIEllipseEdgeEffect& ellipseEffect = |
370 geometryProcessor.cast<DIEllipseEdgeEffect>(); | 370 geometryProcessor.cast<DIEllipseEdgeEffect>(); |
371 | 371 |
372 const char *vsOffsetName0, *fsOffsetName0; | 372 const char *vsOffsetName0, *fsOffsetName0; |
373 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets0", | 373 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets0", |
374 &vsOffsetName0, &fsOffsetName0); | 374 &vsOffsetName0, &fsOffsetName0); |
375 | 375 |
376 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 376 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder
(); |
377 vsBuilder->codeAppendf("%s = %s;", vsOffsetName0, | 377 vsBuilder->codeAppendf("%s = %s;", vsOffsetName0, |
378 ellipseEffect.inEllipseOffsets0().c_str()); | 378 ellipseEffect.inEllipseOffsets0().c_str()); |
379 const char *vsOffsetName1, *fsOffsetName1; | 379 const char *vsOffsetName1, *fsOffsetName1; |
380 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets1", | 380 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets1", |
381 &vsOffsetName1, &fsOffsetName1); | 381 &vsOffsetName1, &fsOffsetName1); |
382 vsBuilder->codeAppendf("\t%s = %s;\n", vsOffsetName1, | 382 vsBuilder->codeAppendf("\t%s = %s;\n", vsOffsetName1, |
383 ellipseEffect.inEllipseOffsets1().c_str()); | 383 ellipseEffect.inEllipseOffsets1().c_str()); |
384 | 384 |
385 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder
(); | 385 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragment
ShaderBuilder(); |
386 SkAssertResult(fsBuilder->enableFeature( | 386 SkAssertResult(fsBuilder->enableFeature( |
387 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)
); | 387 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)
); |
388 // for outer curve | 388 // for outer curve |
389 fsBuilder->codeAppendf("\tvec2 scaledOffset = %s.xy;\n", fsOffsetNam
e0); | 389 fsBuilder->codeAppendf("\tvec2 scaledOffset = %s.xy;\n", fsOffsetNam
e0); |
390 fsBuilder->codeAppend("\tfloat test = dot(scaledOffset, scaledOffset
) - 1.0;\n"); | 390 fsBuilder->codeAppend("\tfloat test = dot(scaledOffset, scaledOffset
) - 1.0;\n"); |
391 fsBuilder->codeAppendf("\tvec2 duvdx = dFdx(%s);\n", fsOffsetName0); | 391 fsBuilder->codeAppendf("\tvec2 duvdx = dFdx(%s);\n", fsOffsetName0); |
392 fsBuilder->codeAppendf("\tvec2 duvdy = dFdy(%s);\n", fsOffsetName0); | 392 fsBuilder->codeAppendf("\tvec2 duvdy = dFdy(%s);\n", fsOffsetName0); |
393 fsBuilder->codeAppendf("\tvec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s
.y*duvdx.y,\n" | 393 fsBuilder->codeAppendf("\tvec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s
.y*duvdx.y,\n" |
394 "\t 2.0*%s.x*duvdy.x + 2.0*%s
.y*duvdy.y);\n", | 394 "\t 2.0*%s.x*duvdy.x + 2.0*%s
.y*duvdy.y);\n", |
395 fsOffsetName0, fsOffsetName0, fsOffsetName0,
fsOffsetName0); | 395 fsOffsetName0, fsOffsetName0, fsOffsetName0,
fsOffsetName0); |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 | 1237 |
1238 // drop out the middle quad if we're stroked | 1238 // drop out the middle quad if we're stroked |
1239 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : | 1239 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : |
1240 SK_ARRAY_COUNT(gRRectIndices); | 1240 SK_ARRAY_COUNT(gRRectIndices); |
1241 target->setIndexSourceToBuffer(indexBuffer); | 1241 target->setIndexSourceToBuffer(indexBuffer); |
1242 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 1242 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); |
1243 } | 1243 } |
1244 | 1244 |
1245 return true; | 1245 return true; |
1246 } | 1246 } |
OLD | NEW |