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

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

Issue 2196053002: Revert of Added distance vector support for CircleGeometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia@dvonbeck-bevel-impl-0
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | 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 "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
88 const Attribute* inPosition() const { return fInPosition; } 86 const Attribute* inPosition() const { return fInPosition; }
89 const Attribute* inColor() const { return fInColor; } 87 const Attribute* inColor() const { return fInColor; }
90 const Attribute* inCircleEdge() const { return fInCircleEdge; } 88 const Attribute* inCircleEdge() const { return fInCircleEdge; }
91 const SkMatrix& localMatrix() const { return fLocalMatrix; } 89 const SkMatrix& localMatrix() const { return fLocalMatrix; }
92
93 virtual ~CircleGeometryProcessor() {} 90 virtual ~CircleGeometryProcessor() {}
94 91
95 const char* name() const override { return "CircleEdge"; } 92 const char* name() const override { return "CircleEdge"; }
96 93
97 class GLSLProcessor : public GrGLSLGeometryProcessor { 94 class GLSLProcessor : public GrGLSLGeometryProcessor {
98 public: 95 public:
99 GLSLProcessor() {} 96 GLSLProcessor() {}
100 97
101 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ 98 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
102 const CircleGeometryProcessor& cgp = args.fGP.cast<CircleGeometryPro cessor>(); 99 const CircleGeometryProcessor& cgp = args.fGP.cast<CircleGeometryPro cessor>();
(...skipping 19 matching lines...) Expand all
122 this->emitTransforms(vertBuilder, 119 this->emitTransforms(vertBuilder,
123 varyingHandler, 120 varyingHandler,
124 uniformHandler, 121 uniformHandler,
125 gpArgs->fPositionVar, 122 gpArgs->fPositionVar,
126 cgp.inPosition()->fName, 123 cgp.inPosition()->fName,
127 cgp.localMatrix(), 124 cgp.localMatrix(),
128 args.fTransformsIn, 125 args.fTransformsIn,
129 args.fTransformsOut); 126 args.fTransformsOut);
130 127
131 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); 128 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn());
132 fragBuilder->codeAppendf("float distanceToEdge = %s.z * (1.0 - d);", v.fsIn()); 129 fragBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d), 0.0, 1.0);",
133 fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToEdge, 0. 0, 1.0);"); 130 v.fsIn());
134 if (cgp.fStroke) { 131 if (cgp.fStroke) {
135 fragBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - % s.w), 0.0, 1.0);", 132 fragBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - % s.w), 0.0, 1.0);",
136 v.fsIn(), v.fsIn()); 133 v.fsIn(), v.fsIn());
137 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); 134 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;");
138 } 135 }
139 136
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
150 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera ge); 137 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera ge);
151 } 138 }
152 139
153 static void GenKey(const GrGeometryProcessor& gp, 140 static void GenKey(const GrGeometryProcessor& gp,
154 const GrGLSLCaps&, 141 const GrGLSLCaps&,
155 GrProcessorKeyBuilder* b) { 142 GrProcessorKeyBuilder* b) {
156 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor >(); 143 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor >();
157 uint16_t key = cgp.fStroke ? 0x1 : 0x0; 144 uint16_t key = cgp.fStroke ? 0x1 : 0x0;
158 key |= cgp.localMatrix().hasPerspective() ? 0x2 : 0x0; 145 key |= cgp.localMatrix().hasPerspective() ? 0x2 : 0x0;
159 b->add32(key); 146 b->add32(key);
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 } 1693 }
1707 1694
1708 DRAW_BATCH_TEST_DEFINE(RRectBatch) { 1695 DRAW_BATCH_TEST_DEFINE(RRectBatch) {
1709 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); 1696 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random);
1710 GrColor color = GrRandomColor(random); 1697 GrColor color = GrRandomColor(random);
1711 const SkRRect& rrect = GrTest::TestRRectSimple(random); 1698 const SkRRect& rrect = GrTest::TestRRectSimple(random);
1712 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom)); 1699 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom));
1713 } 1700 }
1714 1701
1715 #endif 1702 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698