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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // Setup position | 154 // Setup position |
155 this->setupPosition(vertBuilder, gpArgs, cgp.fInPosition->fName); | 155 this->setupPosition(vertBuilder, gpArgs, cgp.fInPosition->fName); |
156 | 156 |
157 // emit transforms | 157 // emit transforms |
158 this->emitTransforms(vertBuilder, | 158 this->emitTransforms(vertBuilder, |
159 varyingHandler, | 159 varyingHandler, |
160 uniformHandler, | 160 uniformHandler, |
161 gpArgs->fPositionVar, | 161 gpArgs->fPositionVar, |
162 cgp.fInPosition->fName, | 162 cgp.fInPosition->fName, |
163 cgp.fLocalMatrix, | 163 cgp.fLocalMatrix, |
164 args.fFPCoordTransformHandler); | 164 args.fTransformsIn, |
| 165 args.fTransformsOut); |
165 | 166 |
166 fragBuilder->codeAppend("float d = length(circleEdge.xy);"); | 167 fragBuilder->codeAppend("float d = length(circleEdge.xy);"); |
167 fragBuilder->codeAppend("float distanceToOuterEdge = circleEdge.z *
(1.0 - d);"); | 168 fragBuilder->codeAppend("float distanceToOuterEdge = circleEdge.z *
(1.0 - d);"); |
168 fragBuilder->codeAppend("float edgeAlpha = clamp(distanceToOuterEdge
, 0.0, 1.0);"); | 169 fragBuilder->codeAppend("float edgeAlpha = clamp(distanceToOuterEdge
, 0.0, 1.0);"); |
169 if (cgp.fStroke) { | 170 if (cgp.fStroke) { |
170 fragBuilder->codeAppend("float distanceToInnerEdge = circleEdge.
z * (d - circleEdge.w);"); | 171 fragBuilder->codeAppend("float distanceToInnerEdge = circleEdge.
z * (d - circleEdge.w);"); |
171 fragBuilder->codeAppend("float innerAlpha = clamp(distanceToInne
rEdge, 0.0, 1.0);"); | 172 fragBuilder->codeAppend("float innerAlpha = clamp(distanceToInne
rEdge, 0.0, 1.0);"); |
172 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); | 173 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); |
173 } | 174 } |
174 | 175 |
(...skipping 27 matching lines...) Expand all Loading... |
202 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor
>(); | 203 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor
>(); |
203 uint16_t key; | 204 uint16_t key; |
204 key = cgp.fStroke ? 0x01 : 0x0; | 205 key = cgp.fStroke ? 0x01 : 0x0; |
205 key |= cgp.fLocalMatrix.hasPerspective() ? 0x02 : 0x0; | 206 key |= cgp.fLocalMatrix.hasPerspective() ? 0x02 : 0x0; |
206 key |= cgp.fInClipPlane ? 0x04 : 0x0; | 207 key |= cgp.fInClipPlane ? 0x04 : 0x0; |
207 key |= cgp.fInIsectPlane ? 0x08 : 0x0; | 208 key |= cgp.fInIsectPlane ? 0x08 : 0x0; |
208 key |= cgp.fInUnionPlane ? 0x10 : 0x0; | 209 key |= cgp.fInUnionPlane ? 0x10 : 0x0; |
209 b->add32(key); | 210 b->add32(key); |
210 } | 211 } |
211 | 212 |
212 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitivePro
cessor& primProc, | 213 void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor
&) override {} |
213 FPCoordTransformIter&& transformIter) override { | 214 |
| 215 void setTransformData(const GrPrimitiveProcessor& primProc, |
| 216 const GrGLSLProgramDataManager& pdman, |
| 217 int index, |
| 218 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { |
214 this->setTransformDataHelper(primProc.cast<CircleGeometryProcessor>(
).fLocalMatrix, | 219 this->setTransformDataHelper(primProc.cast<CircleGeometryProcessor>(
).fLocalMatrix, |
215 pdman, &transformIter); | 220 pdman, index, transforms); |
216 } | 221 } |
217 | 222 |
218 private: | 223 private: |
219 typedef GrGLSLGeometryProcessor INHERITED; | 224 typedef GrGLSLGeometryProcessor INHERITED; |
220 }; | 225 }; |
221 | 226 |
222 SkMatrix fLocalMatrix; | 227 SkMatrix fLocalMatrix; |
223 const Attribute* fInPosition; | 228 const Attribute* fInPosition; |
224 const Attribute* fInColor; | 229 const Attribute* fInColor; |
225 const Attribute* fInCircleEdge; | 230 const Attribute* fInCircleEdge; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // Setup position | 312 // Setup position |
308 this->setupPosition(vertBuilder, gpArgs, egp.fInPosition->fName); | 313 this->setupPosition(vertBuilder, gpArgs, egp.fInPosition->fName); |
309 | 314 |
310 // emit transforms | 315 // emit transforms |
311 this->emitTransforms(vertBuilder, | 316 this->emitTransforms(vertBuilder, |
312 varyingHandler, | 317 varyingHandler, |
313 uniformHandler, | 318 uniformHandler, |
314 gpArgs->fPositionVar, | 319 gpArgs->fPositionVar, |
315 egp.fInPosition->fName, | 320 egp.fInPosition->fName, |
316 egp.fLocalMatrix, | 321 egp.fLocalMatrix, |
317 args.fFPCoordTransformHandler); | 322 args.fTransformsIn, |
| 323 args.fTransformsOut); |
318 | 324 |
319 // for outer curve | 325 // for outer curve |
320 fragBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOff
sets.fsIn(), | 326 fragBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOff
sets.fsIn(), |
321 ellipseRadii.fsIn()); | 327 ellipseRadii.fsIn()); |
322 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset
) - 1.0;"); | 328 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset
) - 1.0;"); |
323 fragBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", elli
pseRadii.fsIn()); | 329 fragBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", elli
pseRadii.fsIn()); |
324 fragBuilder->codeAppend("float grad_dot = dot(grad, grad);"); | 330 fragBuilder->codeAppend("float grad_dot = dot(grad, grad);"); |
325 | 331 |
326 // avoid calling inversesqrt on zero. | 332 // avoid calling inversesqrt on zero. |
327 fragBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);"); | 333 fragBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);"); |
(...skipping 16 matching lines...) Expand all Loading... |
344 | 350 |
345 static void GenKey(const GrGeometryProcessor& gp, | 351 static void GenKey(const GrGeometryProcessor& gp, |
346 const GrGLSLCaps&, | 352 const GrGLSLCaps&, |
347 GrProcessorKeyBuilder* b) { | 353 GrProcessorKeyBuilder* b) { |
348 const EllipseGeometryProcessor& egp = gp.cast<EllipseGeometryProcess
or>(); | 354 const EllipseGeometryProcessor& egp = gp.cast<EllipseGeometryProcess
or>(); |
349 uint16_t key = egp.fStroke ? 0x1 : 0x0; | 355 uint16_t key = egp.fStroke ? 0x1 : 0x0; |
350 key |= egp.fLocalMatrix.hasPerspective() ? 0x2 : 0x0; | 356 key |= egp.fLocalMatrix.hasPerspective() ? 0x2 : 0x0; |
351 b->add32(key); | 357 b->add32(key); |
352 } | 358 } |
353 | 359 |
354 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitivePro
cessor& primProc, | 360 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitivePro
cessor& gp) override { |
355 FPCoordTransformIter&& transformIter) override { | 361 } |
356 const EllipseGeometryProcessor& egp = primProc.cast<EllipseGeometryP
rocessor>(); | 362 |
357 this->setTransformDataHelper(egp.fLocalMatrix, pdman, &transformIter
); | 363 void setTransformData(const GrPrimitiveProcessor& primProc, |
| 364 const GrGLSLProgramDataManager& pdman, |
| 365 int index, |
| 366 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { |
| 367 this->setTransformDataHelper(primProc.cast<EllipseGeometryProcessor>
().fLocalMatrix, |
| 368 pdman, index, transforms); |
358 } | 369 } |
359 | 370 |
360 private: | 371 private: |
361 typedef GrGLSLGeometryProcessor INHERITED; | 372 typedef GrGLSLGeometryProcessor INHERITED; |
362 }; | 373 }; |
363 | 374 |
364 const Attribute* fInPosition; | 375 const Attribute* fInPosition; |
365 const Attribute* fInColor; | 376 const Attribute* fInColor; |
366 const Attribute* fInEllipseOffset; | 377 const Attribute* fInEllipseOffset; |
367 const Attribute* fInEllipseRadii; | 378 const Attribute* fInEllipseRadii; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 diegp.fInPosition->fName, | 465 diegp.fInPosition->fName, |
455 diegp.fViewMatrix, | 466 diegp.fViewMatrix, |
456 &fViewMatrixUniform); | 467 &fViewMatrixUniform); |
457 | 468 |
458 // emit transforms | 469 // emit transforms |
459 this->emitTransforms(vertBuilder, | 470 this->emitTransforms(vertBuilder, |
460 varyingHandler, | 471 varyingHandler, |
461 uniformHandler, | 472 uniformHandler, |
462 gpArgs->fPositionVar, | 473 gpArgs->fPositionVar, |
463 diegp.fInPosition->fName, | 474 diegp.fInPosition->fName, |
464 args.fFPCoordTransformHandler); | 475 args.fTransformsIn, |
| 476 args.fTransformsOut); |
465 | 477 |
466 SkAssertResult(fragBuilder->enableFeature( | 478 SkAssertResult(fragBuilder->enableFeature( |
467 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); | 479 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); |
468 // for outer curve | 480 // for outer curve |
469 fragBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn
()); | 481 fragBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn
()); |
470 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset
) - 1.0;"); | 482 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset
) - 1.0;"); |
471 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s);", offsets0.fsIn()); | 483 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s);", offsets0.fsIn()); |
472 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s);", offsets0.fsIn()); | 484 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s);", offsets0.fsIn()); |
473 fragBuilder->codeAppendf("vec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s
.y*duvdx.y," | 485 fragBuilder->codeAppendf("vec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s
.y*duvdx.y," |
474 " 2.0*%s.x*duvdy.x + 2.0*%s
.y*duvdy.y);", | 486 " 2.0*%s.x*duvdy.x + 2.0*%s
.y*duvdy.y);", |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 | 518 |
507 static void GenKey(const GrGeometryProcessor& gp, | 519 static void GenKey(const GrGeometryProcessor& gp, |
508 const GrGLSLCaps&, | 520 const GrGLSLCaps&, |
509 GrProcessorKeyBuilder* b) { | 521 GrProcessorKeyBuilder* b) { |
510 const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryP
rocessor>(); | 522 const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryP
rocessor>(); |
511 uint16_t key = static_cast<uint16_t>(diegp.fStyle); | 523 uint16_t key = static_cast<uint16_t>(diegp.fStyle); |
512 key |= ComputePosKey(diegp.fViewMatrix) << 10; | 524 key |= ComputePosKey(diegp.fViewMatrix) << 10; |
513 b->add32(key); | 525 b->add32(key); |
514 } | 526 } |
515 | 527 |
516 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitivePro
cessor& gp, | 528 void setData(const GrGLSLProgramDataManager& pdman, |
517 FPCoordTransformIter&& transformIter) override { | 529 const GrPrimitiveProcessor& gp) override { |
518 const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryP
rocessor>(); | 530 const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryP
rocessor>(); |
519 | 531 |
520 if (!diegp.fViewMatrix.isIdentity() && !fViewMatrix.cheapEqualTo(die
gp.fViewMatrix)) { | 532 if (!diegp.fViewMatrix.isIdentity() && !fViewMatrix.cheapEqualTo(die
gp.fViewMatrix)) { |
521 fViewMatrix = diegp.fViewMatrix; | 533 fViewMatrix = diegp.fViewMatrix; |
522 float viewMatrix[3 * 3]; | 534 float viewMatrix[3 * 3]; |
523 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 535 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
524 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 536 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
525 } | 537 } |
526 this->setTransformDataHelper(SkMatrix::I(), pdman, &transformIter); | |
527 } | 538 } |
528 | 539 |
529 private: | 540 private: |
530 SkMatrix fViewMatrix; | 541 SkMatrix fViewMatrix; |
531 UniformHandle fViewMatrixUniform; | 542 UniformHandle fViewMatrixUniform; |
532 | 543 |
533 typedef GrGLSLGeometryProcessor INHERITED; | 544 typedef GrGLSLGeometryProcessor INHERITED; |
534 }; | 545 }; |
535 | 546 |
536 const Attribute* fInPosition; | 547 const Attribute* fInPosition; |
(...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2162 } | 2173 } |
2163 | 2174 |
2164 DRAW_BATCH_TEST_DEFINE(RRectBatch) { | 2175 DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
2165 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 2176 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
2166 GrColor color = GrRandomColor(random); | 2177 GrColor color = GrRandomColor(random); |
2167 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 2178 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
2168 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 2179 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
2169 } | 2180 } |
2170 | 2181 |
2171 #endif | 2182 #endif |
OLD | NEW |