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 27 matching lines...) Expand all Loading... | |
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 edgeAlpha = clamp(%s.z * (1.0 - d), 0.0, 1.0);", |
130 v.fsIn()); | 133 v.fsIn()); |
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->codeAppendf("%s = %s.z * (normalize(%s.xy) - %s.xy) ;", | |
egdaniel
2016/07/28 17:30:53
I feel like this would read easier as something li
dvonbeck
2016/07/28 17:55:14
That wouldn't work because d is a number from 0-1,
egdaniel
2016/07/28 18:01:52
Ahh yes duh.
Since we do in.z * (1-d) above, lets
dvonbeck
2016/07/29 15:08:55
Done.
| |
142 args.fDistanceVectorName, v.vsOut(), v. vsOut(), v.vsOut()); | |
egdaniel
2016/07/28 17:30:53
why not us fsIn() like the coverage code above?
dvonbeck
2016/07/29 15:08:55
Done.
| |
143 } | |
144 | |
137 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera ge); | 145 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera ge); |
138 } | 146 } |
139 | 147 |
140 static void GenKey(const GrGeometryProcessor& gp, | 148 static void GenKey(const GrGeometryProcessor& gp, |
141 const GrGLSLCaps&, | 149 const GrGLSLCaps&, |
142 GrProcessorKeyBuilder* b) { | 150 GrProcessorKeyBuilder* b) { |
143 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor >(); | 151 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor >(); |
144 uint16_t key = cgp.fStroke ? 0x1 : 0x0; | 152 uint16_t key = cgp.fStroke ? 0x1 : 0x0; |
145 key |= cgp.localMatrix().hasPerspective() ? 0x2 : 0x0; | 153 key |= cgp.localMatrix().hasPerspective() ? 0x2 : 0x0; |
146 b->add32(key); | 154 b->add32(key); |
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1693 } | 1701 } |
1694 | 1702 |
1695 DRAW_BATCH_TEST_DEFINE(RRectBatch) { | 1703 DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
1696 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 1704 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
1697 GrColor color = GrRandomColor(random); | 1705 GrColor color = GrRandomColor(random); |
1698 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 1706 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
1699 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom)); | 1707 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom)); |
1700 } | 1708 } |
1701 | 1709 |
1702 #endif | 1710 #endif |
OLD | NEW |