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 "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 CircleGeometryProcessor(bool stroke, const SkMatrix& localMatrix) : fLocalMa
trix(localMatrix){ | 76 CircleGeometryProcessor(bool stroke, const SkMatrix& localMatrix) : fLocalMa
trix(localMatrix){ |
77 this->initClassID<CircleGeometryProcessor>(); | 77 this->initClassID<CircleGeometryProcessor>(); |
78 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType, | 78 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType, |
79 kHigh_GrSLPrecision)); | 79 kHigh_GrSLPrecision)); |
80 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | 80 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); |
81 fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge", | 81 fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge", |
82 kVec4f_GrVertexAttribTy
pe)); | 82 kVec4f_GrVertexAttribTy
pe)); |
83 fStroke = stroke; | 83 fStroke = stroke; |
84 } | 84 } |
85 | 85 |
| 86 bool implementsDistanceVector() const override { return true; }; |
| 87 |
86 const Attribute* inPosition() const { return fInPosition; } | 88 const Attribute* inPosition() const { return fInPosition; } |
87 const Attribute* inColor() const { return fInColor; } | 89 const Attribute* inColor() const { return fInColor; } |
88 const Attribute* inCircleEdge() const { return fInCircleEdge; } | 90 const Attribute* inCircleEdge() const { return fInCircleEdge; } |
89 const SkMatrix& localMatrix() const { return fLocalMatrix; } | 91 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
| 92 |
90 virtual ~CircleGeometryProcessor() {} | 93 virtual ~CircleGeometryProcessor() {} |
91 | 94 |
92 const char* name() const override { return "CircleEdge"; } | 95 const char* name() const override { return "CircleEdge"; } |
93 | 96 |
94 class GLSLProcessor : public GrGLSLGeometryProcessor { | 97 class GLSLProcessor : public GrGLSLGeometryProcessor { |
95 public: | 98 public: |
96 GLSLProcessor() {} | 99 GLSLProcessor() {} |
97 | 100 |
98 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 101 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
99 const CircleGeometryProcessor& cgp = args.fGP.cast<CircleGeometryPro
cessor>(); | 102 const CircleGeometryProcessor& cgp = args.fGP.cast<CircleGeometryPro
cessor>(); |
(...skipping 19 matching lines...) Expand all Loading... |
119 this->emitTransforms(vertBuilder, | 122 this->emitTransforms(vertBuilder, |
120 varyingHandler, | 123 varyingHandler, |
121 uniformHandler, | 124 uniformHandler, |
122 gpArgs->fPositionVar, | 125 gpArgs->fPositionVar, |
123 cgp.inPosition()->fName, | 126 cgp.inPosition()->fName, |
124 cgp.localMatrix(), | 127 cgp.localMatrix(), |
125 args.fTransformsIn, | 128 args.fTransformsIn, |
126 args.fTransformsOut); | 129 args.fTransformsOut); |
127 | 130 |
128 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); | 131 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); |
129 fragBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d),
0.0, 1.0);", | 132 fragBuilder->codeAppendf("float distanceToEdge = %s.z * (1.0 - d);",
v.fsIn()); |
130 v.fsIn()); | 133 fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToEdge, 0.
0, 1.0);"); |
131 if (cgp.fStroke) { | 134 if (cgp.fStroke) { |
132 fragBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %
s.w), 0.0, 1.0);", | 135 fragBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %
s.w), 0.0, 1.0);", |
133 v.fsIn(), v.fsIn()); | 136 v.fsIn(), v.fsIn()); |
134 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); | 137 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); |
135 } | 138 } |
136 | 139 |
| 140 if (args.fDistanceVectorName) { |
| 141 fragBuilder->codeAppend ("if (d == 0.0) {"); // if on the center
of the circle |
| 142 fragBuilder->codeAppendf(" %s = vec2(distanceToEdge, 0.0);",
// avoid normalizing |
| 143 args.fDistanceVectorName); |
| 144 fragBuilder->codeAppend ("} else {"); |
| 145 fragBuilder->codeAppendf(" %s = normalize(%s.xy) * distanceTo
Edge;", |
| 146 args.fDistanceVectorName, v.fsIn()); |
| 147 fragBuilder->codeAppend ("}"); |
| 148 } |
| 149 |
137 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera
ge); | 150 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera
ge); |
138 } | 151 } |
139 | 152 |
140 static void GenKey(const GrGeometryProcessor& gp, | 153 static void GenKey(const GrGeometryProcessor& gp, |
141 const GrGLSLCaps&, | 154 const GrGLSLCaps&, |
142 GrProcessorKeyBuilder* b) { | 155 GrProcessorKeyBuilder* b) { |
143 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor
>(); | 156 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor
>(); |
144 uint16_t key = cgp.fStroke ? 0x1 : 0x0; | 157 uint16_t key = cgp.fStroke ? 0x1 : 0x0; |
145 key |= cgp.localMatrix().hasPerspective() ? 0x2 : 0x0; | 158 key |= cgp.localMatrix().hasPerspective() ? 0x2 : 0x0; |
146 b->add32(key); | 159 b->add32(key); |
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 } | 1706 } |
1694 | 1707 |
1695 DRAW_BATCH_TEST_DEFINE(RRectBatch) { | 1708 DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
1696 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 1709 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
1697 GrColor color = GrRandomColor(random); | 1710 GrColor color = GrRandomColor(random); |
1698 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 1711 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
1699 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 1712 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
1700 } | 1713 } |
1701 | 1714 |
1702 #endif | 1715 #endif |
OLD | NEW |