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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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; }; | 86 bool implementsDistanceVector() const override { return true; }; |
87 | 87 |
88 const Attribute* inPosition() const { return fInPosition; } | |
89 const Attribute* inColor() const { return fInColor; } | |
90 const Attribute* inCircleEdge() const { return fInCircleEdge; } | |
91 const SkMatrix& localMatrix() const { return fLocalMatrix; } | 88 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
bsalomon
2016/08/17 15:02:39
This localMatrix getter is still needed by a templ
| |
92 | 89 |
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 |
94 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override { | |
95 GLSLProcessor::GenKey(*this, caps, b); | |
96 } | |
97 | |
98 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const overri de { | |
99 return new GLSLProcessor(); | |
100 } | |
101 | |
102 private: | |
97 class GLSLProcessor : public GrGLSLGeometryProcessor { | 103 class GLSLProcessor : public GrGLSLGeometryProcessor { |
98 public: | 104 public: |
99 GLSLProcessor() {} | 105 GLSLProcessor() {} |
100 | 106 |
101 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 107 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
102 const CircleGeometryProcessor& cgp = args.fGP.cast<CircleGeometryPro cessor>(); | 108 const CircleGeometryProcessor& cgp = args.fGP.cast<CircleGeometryPro cessor>(); |
103 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; | 109 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
104 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; | 110 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
105 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 111 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
106 | 112 |
107 // emit attributes | 113 // emit attributes |
108 varyingHandler->emitAttributes(cgp); | 114 varyingHandler->emitAttributes(cgp); |
109 | 115 |
110 GrGLSLVertToFrag v(kVec4f_GrSLType); | 116 GrGLSLVertToFrag v(kVec4f_GrSLType); |
111 varyingHandler->addVarying("CircleEdge", &v); | 117 varyingHandler->addVarying("CircleEdge", &v); |
112 vertBuilder->codeAppendf("%s = %s;", v.vsOut(), cgp.inCircleEdge()-> fName); | 118 vertBuilder->codeAppendf("%s = %s;", v.vsOut(), cgp.fInCircleEdge->f Name); |
113 | 119 |
114 GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; | 120 GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; |
115 // setup pass through color | 121 // setup pass through color |
116 varyingHandler->addPassThroughAttribute(cgp.inColor(), args.fOutputC olor); | 122 varyingHandler->addPassThroughAttribute(cgp.fInColor, args.fOutputCo lor); |
117 | 123 |
118 // Setup position | 124 // Setup position |
119 this->setupPosition(vertBuilder, gpArgs, cgp.inPosition()->fName); | 125 this->setupPosition(vertBuilder, gpArgs, cgp.fInPosition->fName); |
120 | 126 |
121 // emit transforms | 127 // emit transforms |
122 this->emitTransforms(vertBuilder, | 128 this->emitTransforms(vertBuilder, |
123 varyingHandler, | 129 varyingHandler, |
124 uniformHandler, | 130 uniformHandler, |
125 gpArgs->fPositionVar, | 131 gpArgs->fPositionVar, |
126 cgp.inPosition()->fName, | 132 cgp.fInPosition->fName, |
127 cgp.localMatrix(), | 133 cgp.fLocalMatrix, |
128 args.fTransformsIn, | 134 args.fTransformsIn, |
129 args.fTransformsOut); | 135 args.fTransformsOut); |
130 | 136 |
131 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); | 137 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); |
132 fragBuilder->codeAppendf("float distanceToEdge = %s.z * (1.0 - d);", v.fsIn()); | 138 fragBuilder->codeAppendf("float distanceToEdge = %s.z * (1.0 - d);", v.fsIn()); |
133 fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToEdge, 0. 0, 1.0);"); | 139 fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToEdge, 0. 0, 1.0);"); |
134 if (cgp.fStroke) { | 140 if (cgp.fStroke) { |
135 fragBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - % s.w), 0.0, 1.0);", | 141 fragBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - % s.w), 0.0, 1.0);", |
136 v.fsIn(), v.fsIn()); | 142 v.fsIn(), v.fsIn()); |
137 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); | 143 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); |
(...skipping 10 matching lines...) Expand all Loading... | |
148 } | 154 } |
149 | 155 |
150 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera ge); | 156 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera ge); |
151 } | 157 } |
152 | 158 |
153 static void GenKey(const GrGeometryProcessor& gp, | 159 static void GenKey(const GrGeometryProcessor& gp, |
154 const GrGLSLCaps&, | 160 const GrGLSLCaps&, |
155 GrProcessorKeyBuilder* b) { | 161 GrProcessorKeyBuilder* b) { |
156 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor >(); | 162 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor >(); |
157 uint16_t key = cgp.fStroke ? 0x1 : 0x0; | 163 uint16_t key = cgp.fStroke ? 0x1 : 0x0; |
158 key |= cgp.localMatrix().hasPerspective() ? 0x2 : 0x0; | 164 key |= cgp.fLocalMatrix.hasPerspective() ? 0x2 : 0x0; |
159 b->add32(key); | 165 b->add32(key); |
160 } | 166 } |
161 | 167 |
162 void setData(const GrGLSLProgramDataManager& pdman, | 168 void setData(const GrGLSLProgramDataManager& pdman, |
163 const GrPrimitiveProcessor& gp) override { | 169 const GrPrimitiveProcessor& gp) override { |
164 } | 170 } |
165 | 171 |
166 void setTransformData(const GrPrimitiveProcessor& primProc, | 172 void setTransformData(const GrPrimitiveProcessor& primProc, |
167 const GrGLSLProgramDataManager& pdman, | 173 const GrGLSLProgramDataManager& pdman, |
168 int index, | 174 int index, |
169 const SkTArray<const GrCoordTransform*, true>& tra nsforms) override { | 175 const SkTArray<const GrCoordTransform*, true>& tra nsforms) override { |
170 this->setTransformDataHelper<CircleGeometryProcessor>(primProc, pdma n, index, | 176 this->setTransformDataHelper<CircleGeometryProcessor>(primProc, pdma n, index, |
171 transforms); | 177 transforms); |
172 } | 178 } |
173 | 179 |
174 private: | 180 private: |
175 typedef GrGLSLGeometryProcessor INHERITED; | 181 typedef GrGLSLGeometryProcessor INHERITED; |
176 }; | 182 }; |
177 | 183 |
178 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override { | |
179 GLSLProcessor::GenKey(*this, caps, b); | |
180 } | |
181 | |
182 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const overri de { | |
183 return new GLSLProcessor(); | |
184 } | |
185 | |
186 private: | |
187 SkMatrix fLocalMatrix; | 184 SkMatrix fLocalMatrix; |
188 const Attribute* fInPosition; | 185 const Attribute* fInPosition; |
189 const Attribute* fInColor; | 186 const Attribute* fInColor; |
190 const Attribute* fInCircleEdge; | 187 const Attribute* fInCircleEdge; |
191 bool fStroke; | 188 bool fStroke; |
192 | 189 |
193 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 190 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
194 | 191 |
195 typedef GrGeometryProcessor INHERITED; | 192 typedef GrGeometryProcessor INHERITED; |
196 }; | 193 }; |
(...skipping 26 matching lines...) Expand all Loading... | |
223 kVec2f_GrVertexAttri bType)); | 220 kVec2f_GrVertexAttri bType)); |
224 fInEllipseRadii = &this->addVertexAttrib(Attribute("inEllipseRadii", | 221 fInEllipseRadii = &this->addVertexAttrib(Attribute("inEllipseRadii", |
225 kVec4f_GrVertexAttrib Type)); | 222 kVec4f_GrVertexAttrib Type)); |
226 fStroke = stroke; | 223 fStroke = stroke; |
227 } | 224 } |
228 | 225 |
229 virtual ~EllipseGeometryProcessor() {} | 226 virtual ~EllipseGeometryProcessor() {} |
230 | 227 |
231 const char* name() const override { return "EllipseEdge"; } | 228 const char* name() const override { return "EllipseEdge"; } |
232 | 229 |
233 const Attribute* inPosition() const { return fInPosition; } | |
234 const Attribute* inColor() const { return fInColor; } | |
235 const Attribute* inEllipseOffset() const { return fInEllipseOffset; } | |
236 const Attribute* inEllipseRadii() const { return fInEllipseRadii; } | |
237 const SkMatrix& localMatrix() const { return fLocalMatrix; } | 230 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
238 | 231 |
232 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override { | |
233 GLSLProcessor::GenKey(*this, caps, b); | |
234 } | |
235 | |
236 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const overri de { | |
237 return new GLSLProcessor(); | |
238 } | |
239 | |
240 private: | |
239 class GLSLProcessor : public GrGLSLGeometryProcessor { | 241 class GLSLProcessor : public GrGLSLGeometryProcessor { |
240 public: | 242 public: |
241 GLSLProcessor() {} | 243 GLSLProcessor() {} |
242 | 244 |
243 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 245 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
244 const EllipseGeometryProcessor& egp = args.fGP.cast<EllipseGeometryP rocessor>(); | 246 const EllipseGeometryProcessor& egp = args.fGP.cast<EllipseGeometryP rocessor>(); |
245 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; | 247 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
246 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; | 248 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
247 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 249 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
248 | 250 |
249 // emit attributes | 251 // emit attributes |
250 varyingHandler->emitAttributes(egp); | 252 varyingHandler->emitAttributes(egp); |
251 | 253 |
252 GrGLSLVertToFrag ellipseOffsets(kVec2f_GrSLType); | 254 GrGLSLVertToFrag ellipseOffsets(kVec2f_GrSLType); |
253 varyingHandler->addVarying("EllipseOffsets", &ellipseOffsets); | 255 varyingHandler->addVarying("EllipseOffsets", &ellipseOffsets); |
254 vertBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(), | 256 vertBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(), |
255 egp.inEllipseOffset()->fName); | 257 egp.fInEllipseOffset->fName); |
256 | 258 |
257 GrGLSLVertToFrag ellipseRadii(kVec4f_GrSLType); | 259 GrGLSLVertToFrag ellipseRadii(kVec4f_GrSLType); |
258 varyingHandler->addVarying("EllipseRadii", &ellipseRadii); | 260 varyingHandler->addVarying("EllipseRadii", &ellipseRadii); |
259 vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), | 261 vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), |
260 egp.inEllipseRadii()->fName); | 262 egp.fInEllipseRadii->fName); |
261 | 263 |
262 GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; | 264 GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; |
263 // setup pass through color | 265 // setup pass through color |
264 varyingHandler->addPassThroughAttribute(egp.inColor(), args.fOutputC olor); | 266 varyingHandler->addPassThroughAttribute(egp.fInColor, args.fOutputCo lor); |
265 | 267 |
266 // Setup position | 268 // Setup position |
267 this->setupPosition(vertBuilder, gpArgs, egp.inPosition()->fName); | 269 this->setupPosition(vertBuilder, gpArgs, egp.fInPosition->fName); |
268 | 270 |
269 // emit transforms | 271 // emit transforms |
270 this->emitTransforms(vertBuilder, | 272 this->emitTransforms(vertBuilder, |
271 varyingHandler, | 273 varyingHandler, |
272 uniformHandler, | 274 uniformHandler, |
273 gpArgs->fPositionVar, | 275 gpArgs->fPositionVar, |
274 egp.inPosition()->fName, | 276 egp.fInPosition->fName, |
275 egp.localMatrix(), | 277 egp.fLocalMatrix, |
276 args.fTransformsIn, | 278 args.fTransformsIn, |
277 args.fTransformsOut); | 279 args.fTransformsOut); |
278 | 280 |
279 // for outer curve | 281 // for outer curve |
280 fragBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOff sets.fsIn(), | 282 fragBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOff sets.fsIn(), |
281 ellipseRadii.fsIn()); | 283 ellipseRadii.fsIn()); |
282 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;"); | 284 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;"); |
283 fragBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", elli pseRadii.fsIn()); | 285 fragBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", elli pseRadii.fsIn()); |
284 fragBuilder->codeAppend("float grad_dot = dot(grad, grad);"); | 286 fragBuilder->codeAppend("float grad_dot = dot(grad, grad);"); |
285 | 287 |
(...skipping 14 matching lines...) Expand all Loading... | |
300 } | 302 } |
301 | 303 |
302 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera ge); | 304 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera ge); |
303 } | 305 } |
304 | 306 |
305 static void GenKey(const GrGeometryProcessor& gp, | 307 static void GenKey(const GrGeometryProcessor& gp, |
306 const GrGLSLCaps&, | 308 const GrGLSLCaps&, |
307 GrProcessorKeyBuilder* b) { | 309 GrProcessorKeyBuilder* b) { |
308 const EllipseGeometryProcessor& egp = gp.cast<EllipseGeometryProcess or>(); | 310 const EllipseGeometryProcessor& egp = gp.cast<EllipseGeometryProcess or>(); |
309 uint16_t key = egp.fStroke ? 0x1 : 0x0; | 311 uint16_t key = egp.fStroke ? 0x1 : 0x0; |
310 key |= egp.localMatrix().hasPerspective() ? 0x2 : 0x0; | 312 key |= egp.fLocalMatrix.hasPerspective() ? 0x2 : 0x0; |
311 b->add32(key); | 313 b->add32(key); |
312 } | 314 } |
313 | 315 |
314 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitivePro cessor& gp) override { | 316 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitivePro cessor& gp) override { |
315 } | 317 } |
316 | 318 |
317 void setTransformData(const GrPrimitiveProcessor& primProc, | 319 void setTransformData(const GrPrimitiveProcessor& primProc, |
318 const GrGLSLProgramDataManager& pdman, | 320 const GrGLSLProgramDataManager& pdman, |
319 int index, | 321 int index, |
320 const SkTArray<const GrCoordTransform*, true>& tra nsforms) override { | 322 const SkTArray<const GrCoordTransform*, true>& tra nsforms) override { |
321 this->setTransformDataHelper<EllipseGeometryProcessor>(primProc, pdm an, index, | 323 this->setTransformDataHelper<EllipseGeometryProcessor>(primProc, pdm an, index, |
322 transforms); | 324 transforms); |
323 } | 325 } |
324 | 326 |
325 private: | 327 private: |
326 typedef GrGLSLGeometryProcessor INHERITED; | 328 typedef GrGLSLGeometryProcessor INHERITED; |
327 }; | 329 }; |
328 | 330 |
329 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override { | |
330 GLSLProcessor::GenKey(*this, caps, b); | |
331 } | |
332 | |
333 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const overri de { | |
334 return new GLSLProcessor(); | |
335 } | |
336 | |
337 private: | |
338 const Attribute* fInPosition; | 331 const Attribute* fInPosition; |
339 const Attribute* fInColor; | 332 const Attribute* fInColor; |
340 const Attribute* fInEllipseOffset; | 333 const Attribute* fInEllipseOffset; |
341 const Attribute* fInEllipseRadii; | 334 const Attribute* fInEllipseRadii; |
342 SkMatrix fLocalMatrix; | 335 SkMatrix fLocalMatrix; |
343 bool fStroke; | 336 bool fStroke; |
344 | 337 |
345 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 338 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
346 | 339 |
347 typedef GrGeometryProcessor INHERITED; | 340 typedef GrGeometryProcessor INHERITED; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 fInEllipseOffsets1 = &this->addVertexAttrib(Attribute("inEllipseOffsets1 ", | 373 fInEllipseOffsets1 = &this->addVertexAttrib(Attribute("inEllipseOffsets1 ", |
381 kVec2f_GrVertexAtt ribType)); | 374 kVec2f_GrVertexAtt ribType)); |
382 fStyle = style; | 375 fStyle = style; |
383 } | 376 } |
384 | 377 |
385 | 378 |
386 virtual ~DIEllipseGeometryProcessor() {} | 379 virtual ~DIEllipseGeometryProcessor() {} |
387 | 380 |
388 const char* name() const override { return "DIEllipseEdge"; } | 381 const char* name() const override { return "DIEllipseEdge"; } |
389 | 382 |
390 const Attribute* inPosition() const { return fInPosition; } | 383 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override { |
391 const Attribute* inColor() const { return fInColor; } | 384 GLSLProcessor::GenKey(*this, caps, b); |
392 const Attribute* inEllipseOffsets0() const { return fInEllipseOffsets0; } | 385 } |
393 const Attribute* inEllipseOffsets1() const { return fInEllipseOffsets1; } | |
394 const SkMatrix& viewMatrix() const { return fViewMatrix; } | |
395 | 386 |
387 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const overri de { | |
388 return new GLSLProcessor(); | |
389 } | |
390 | |
391 private: | |
396 class GLSLProcessor : public GrGLSLGeometryProcessor { | 392 class GLSLProcessor : public GrGLSLGeometryProcessor { |
397 public: | 393 public: |
398 GLSLProcessor() | 394 GLSLProcessor() |
399 : fViewMatrix(SkMatrix::InvalidMatrix()) {} | 395 : fViewMatrix(SkMatrix::InvalidMatrix()) {} |
400 | 396 |
401 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { | 397 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
402 const DIEllipseGeometryProcessor& diegp = args.fGP.cast<DIEllipseGeo metryProcessor>(); | 398 const DIEllipseGeometryProcessor& diegp = args.fGP.cast<DIEllipseGeo metryProcessor>(); |
403 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; | 399 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
404 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; | 400 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
405 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 401 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
406 | 402 |
407 // emit attributes | 403 // emit attributes |
408 varyingHandler->emitAttributes(diegp); | 404 varyingHandler->emitAttributes(diegp); |
409 | 405 |
410 GrGLSLVertToFrag offsets0(kVec2f_GrSLType); | 406 GrGLSLVertToFrag offsets0(kVec2f_GrSLType); |
411 varyingHandler->addVarying("EllipseOffsets0", &offsets0); | 407 varyingHandler->addVarying("EllipseOffsets0", &offsets0); |
412 vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), | 408 vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), |
413 diegp.inEllipseOffsets0()->fName); | 409 diegp.fInEllipseOffsets0->fName); |
414 | 410 |
415 GrGLSLVertToFrag offsets1(kVec2f_GrSLType); | 411 GrGLSLVertToFrag offsets1(kVec2f_GrSLType); |
416 varyingHandler->addVarying("EllipseOffsets1", &offsets1); | 412 varyingHandler->addVarying("EllipseOffsets1", &offsets1); |
417 vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), | 413 vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), |
418 diegp.inEllipseOffsets1()->fName); | 414 diegp.fInEllipseOffsets1->fName); |
419 | 415 |
420 GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; | 416 GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; |
421 varyingHandler->addPassThroughAttribute(diegp.inColor(), args.fOutpu tColor); | 417 varyingHandler->addPassThroughAttribute(diegp.fInColor, args.fOutput Color); |
422 | 418 |
423 // Setup position | 419 // Setup position |
424 this->setupPosition(vertBuilder, | 420 this->setupPosition(vertBuilder, |
425 uniformHandler, | 421 uniformHandler, |
426 gpArgs, | 422 gpArgs, |
427 diegp.inPosition()->fName, | 423 diegp.fInPosition->fName, |
428 diegp.viewMatrix(), | 424 diegp.fViewMatrix, |
429 &fViewMatrixUniform); | 425 &fViewMatrixUniform); |
430 | 426 |
431 // emit transforms | 427 // emit transforms |
432 this->emitTransforms(vertBuilder, | 428 this->emitTransforms(vertBuilder, |
433 varyingHandler, | 429 varyingHandler, |
434 uniformHandler, | 430 uniformHandler, |
435 gpArgs->fPositionVar, | 431 gpArgs->fPositionVar, |
436 diegp.inPosition()->fName, | 432 diegp.fInPosition->fName, |
437 args.fTransformsIn, | 433 args.fTransformsIn, |
438 args.fTransformsOut); | 434 args.fTransformsOut); |
439 | 435 |
440 SkAssertResult(fragBuilder->enableFeature( | 436 SkAssertResult(fragBuilder->enableFeature( |
441 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur e)); | 437 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur e)); |
442 // for outer curve | 438 // for outer curve |
443 fragBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn ()); | 439 fragBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn ()); |
444 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;"); | 440 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;"); |
445 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s);", offsets0.fsIn()); | 441 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s);", offsets0.fsIn()); |
446 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s);", offsets0.fsIn()); | 442 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s);", offsets0.fsIn()); |
(...skipping 29 matching lines...) Expand all Loading... | |
476 } | 472 } |
477 | 473 |
478 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera ge); | 474 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera ge); |
479 } | 475 } |
480 | 476 |
481 static void GenKey(const GrGeometryProcessor& gp, | 477 static void GenKey(const GrGeometryProcessor& gp, |
482 const GrGLSLCaps&, | 478 const GrGLSLCaps&, |
483 GrProcessorKeyBuilder* b) { | 479 GrProcessorKeyBuilder* b) { |
484 const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryP rocessor>(); | 480 const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryP rocessor>(); |
485 uint16_t key = static_cast<uint16_t>(diegp.fStyle); | 481 uint16_t key = static_cast<uint16_t>(diegp.fStyle); |
486 key |= ComputePosKey(diegp.viewMatrix()) << 10; | 482 key |= ComputePosKey(diegp.fViewMatrix) << 10; |
487 b->add32(key); | 483 b->add32(key); |
488 } | 484 } |
489 | 485 |
490 void setData(const GrGLSLProgramDataManager& pdman, | 486 void setData(const GrGLSLProgramDataManager& pdman, |
491 const GrPrimitiveProcessor& gp) override { | 487 const GrPrimitiveProcessor& gp) override { |
492 const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryP rocessor>(); | 488 const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryP rocessor>(); |
493 | 489 |
494 if (!diegp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(di egp.viewMatrix())) { | 490 if (!diegp.fViewMatrix.isIdentity() && !fViewMatrix.cheapEqualTo(die gp.fViewMatrix)) { |
495 fViewMatrix = diegp.viewMatrix(); | 491 fViewMatrix = diegp.fViewMatrix; |
496 float viewMatrix[3 * 3]; | 492 float viewMatrix[3 * 3]; |
497 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 493 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
498 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 494 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
499 } | 495 } |
500 } | 496 } |
501 | 497 |
502 private: | 498 private: |
503 SkMatrix fViewMatrix; | 499 SkMatrix fViewMatrix; |
504 UniformHandle fViewMatrixUniform; | 500 UniformHandle fViewMatrixUniform; |
505 | 501 |
506 typedef GrGLSLGeometryProcessor INHERITED; | 502 typedef GrGLSLGeometryProcessor INHERITED; |
507 }; | 503 }; |
508 | 504 |
509 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override { | |
510 GLSLProcessor::GenKey(*this, caps, b); | |
511 } | |
512 | |
513 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const overri de { | |
514 return new GLSLProcessor(); | |
515 } | |
516 | |
517 private: | |
518 const Attribute* fInPosition; | 505 const Attribute* fInPosition; |
519 const Attribute* fInColor; | 506 const Attribute* fInColor; |
520 const Attribute* fInEllipseOffsets0; | 507 const Attribute* fInEllipseOffsets0; |
521 const Attribute* fInEllipseOffsets1; | 508 const Attribute* fInEllipseOffsets1; |
522 SkMatrix fViewMatrix; | 509 SkMatrix fViewMatrix; |
523 DIEllipseStyle fStyle; | 510 DIEllipseStyle fStyle; |
524 | 511 |
525 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 512 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
526 | 513 |
527 typedef GrGeometryProcessor INHERITED; | 514 typedef GrGeometryProcessor INHERITED; |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
OLD | NEW |