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 "GrEffect.h" | 10 #include "GrEffect.h" |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 | 418 |
419 GrEffectRef* AltEllipseEdgeEffect::TestCreate(SkMWCRandom* random, | 419 GrEffectRef* AltEllipseEdgeEffect::TestCreate(SkMWCRandom* random, |
420 GrContext* context, | 420 GrContext* context, |
421 const GrDrawTargetCaps&, | 421 const GrDrawTargetCaps&, |
422 GrTexture* textures[]) { | 422 GrTexture* textures[]) { |
423 return AltEllipseEdgeEffect::Create(random->nextBool()); | 423 return AltEllipseEdgeEffect::Create(random->nextBool()); |
424 } | 424 } |
425 | 425 |
426 /////////////////////////////////////////////////////////////////////////////// | 426 /////////////////////////////////////////////////////////////////////////////// |
427 | 427 |
428 bool GrOvalRenderer::drawOval(GrDrawTarget* target, const GrContext* context, co
nst GrPaint& paint, | 428 bool GrOvalRenderer::drawOval(GrDrawTarget* target, const GrContext* context, bo
ol useAA, |
429 const GrRect& oval, const SkStrokeRec& stroke) | 429 const GrRect& oval, const SkStrokeRec& stroke) |
430 { | 430 { |
431 if (!paint.isAntiAlias()) { | 431 if (!useAA) { |
432 return false; | 432 return false; |
433 } | 433 } |
434 | 434 |
435 const SkMatrix& vm = context->getMatrix(); | 435 const SkMatrix& vm = context->getMatrix(); |
436 | 436 |
437 // we can draw circles | 437 // we can draw circles |
438 if (SkScalarNearlyEqual(oval.width(), oval.height()) | 438 if (SkScalarNearlyEqual(oval.width(), oval.height()) |
439 && circle_stays_circle(vm)) { | 439 && circle_stays_circle(vm)) { |
440 drawCircle(target, paint, oval, stroke); | 440 this->drawCircle(target, useAA, oval, stroke); |
441 | 441 |
442 // and axis-aligned ellipses only | 442 // and axis-aligned ellipses only |
443 } else if (vm.rectStaysRect()) { | 443 } else if (vm.rectStaysRect()) { |
444 return drawEllipse(target, paint, oval, stroke); | 444 return this->drawEllipse(target, useAA, oval, stroke); |
445 | 445 |
446 } else { | 446 } else { |
447 return false; | 447 return false; |
448 } | 448 } |
449 | 449 |
450 return true; | 450 return true; |
451 } | 451 } |
452 | 452 |
453 namespace { | 453 namespace { |
454 | 454 |
455 /////////////////////////////////////////////////////////////////////////////// | 455 /////////////////////////////////////////////////////////////////////////////// |
456 | 456 |
457 // position + edge | 457 // position + edge |
458 extern const GrVertexAttrib gCircleVertexAttribs[] = { | 458 extern const GrVertexAttrib gCircleVertexAttribs[] = { |
459 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | 459 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
460 {kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} | 460 {kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} |
461 }; | 461 }; |
462 | 462 |
463 }; | 463 }; |
464 | 464 |
465 void GrOvalRenderer::drawCircle(GrDrawTarget* target, | 465 void GrOvalRenderer::drawCircle(GrDrawTarget* target, |
466 const GrPaint& paint, | 466 bool useAA, |
467 const GrRect& circle, | 467 const GrRect& circle, |
468 const SkStrokeRec& stroke) | 468 const SkStrokeRec& stroke) |
469 { | 469 { |
470 GrDrawState* drawState = target->drawState(); | 470 GrDrawState* drawState = target->drawState(); |
471 | 471 |
472 const SkMatrix& vm = drawState->getViewMatrix(); | 472 const SkMatrix& vm = drawState->getViewMatrix(); |
473 GrPoint center = GrPoint::Make(circle.centerX(), circle.centerY()); | 473 GrPoint center = GrPoint::Make(circle.centerX(), circle.centerY()); |
474 vm.mapPoints(¢er, 1); | 474 vm.mapPoints(¢er, 1); |
475 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); | 475 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); |
476 SkScalar strokeWidth = vm.mapRadius(stroke.getWidth()); | 476 SkScalar strokeWidth = vm.mapRadius(stroke.getWidth()); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 // position + edge | 564 // position + edge |
565 extern const GrVertexAttrib gEllipseVertexAttribs[] = { | 565 extern const GrVertexAttrib gEllipseVertexAttribs[] = { |
566 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, | 566 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, |
567 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding
}, | 567 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding
}, |
568 {kVec4f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBinding
} | 568 {kVec4f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBinding
} |
569 }; | 569 }; |
570 | 570 |
571 }; | 571 }; |
572 | 572 |
573 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, | 573 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, |
574 const GrPaint& paint, | 574 bool useAA, |
575 const GrRect& ellipse, | 575 const GrRect& ellipse, |
576 const SkStrokeRec& stroke) | 576 const SkStrokeRec& stroke) |
577 { | 577 { |
578 GrDrawState* drawState = target->drawState(); | 578 GrDrawState* drawState = target->drawState(); |
579 #ifdef SK_DEBUG | 579 #ifdef SK_DEBUG |
580 { | 580 { |
581 // we should have checked for this previously | 581 // we should have checked for this previously |
582 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); | 582 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); |
583 SkASSERT(paint.isAntiAlias() && isAxisAlignedEllipse); | 583 SkASSERT(useAA && isAxisAlignedEllipse); |
584 } | 584 } |
585 #endif | 585 #endif |
586 | 586 |
587 // do any matrix crunching before we reset the draw state for device coords | 587 // do any matrix crunching before we reset the draw state for device coords |
588 const SkMatrix& vm = drawState->getViewMatrix(); | 588 const SkMatrix& vm = drawState->getViewMatrix(); |
589 GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY()); | 589 GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY()); |
590 vm.mapPoints(¢er, 1); | 590 vm.mapPoints(¢er, 1); |
591 SkScalar ellipseXRadius = SkScalarHalf(ellipse.width()); | 591 SkScalar ellipseXRadius = SkScalarHalf(ellipse.width()); |
592 SkScalar ellipseYRadius = SkScalarHalf(ellipse.height()); | 592 SkScalar ellipseYRadius = SkScalarHalf(ellipse.height()); |
593 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*ellipseXRadius + | 593 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*ellipseXRadius + |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 bool updated = | 735 bool updated = |
736 #endif | 736 #endif |
737 fRRectIndexBuffer->updateData(gRRectIndices, | 737 fRRectIndexBuffer->updateData(gRRectIndices, |
738 sizeof(gRRectIndices)); | 738 sizeof(gRRectIndices)); |
739 GR_DEBUGASSERT(updated); | 739 GR_DEBUGASSERT(updated); |
740 } | 740 } |
741 } | 741 } |
742 return fRRectIndexBuffer; | 742 return fRRectIndexBuffer; |
743 } | 743 } |
744 | 744 |
745 bool GrOvalRenderer::drawSimpleRRect(GrDrawTarget* target, GrContext* context, | 745 bool GrOvalRenderer::drawSimpleRRect(GrDrawTarget* target, GrContext* context, b
ool useAA, |
746 const GrPaint& paint, const SkRRect& rrect, | 746 const SkRRect& rrect, const SkStrokeRec& st
roke) |
747 const SkStrokeRec& stroke) | |
748 { | 747 { |
| 748 // only anti-aliased rrects for now |
| 749 if (!useAA) { |
| 750 return false; |
| 751 } |
| 752 |
749 const SkMatrix& vm = context->getMatrix(); | 753 const SkMatrix& vm = context->getMatrix(); |
750 #ifdef SK_DEBUG | 754 #ifdef SK_DEBUG |
751 { | 755 { |
752 // we should have checked for this previously | 756 // we should have checked for this previously |
753 SkASSERT(paint.isAntiAlias() && vm.rectStaysRect() && rrect.isSimple()); | 757 SkASSERT(useAA && vm.rectStaysRect() && rrect.isSimple()); |
754 } | 758 } |
755 #endif | 759 #endif |
756 | 760 |
757 // do any matrix crunching before we reset the draw state for device coords | 761 // do any matrix crunching before we reset the draw state for device coords |
758 const SkRect& rrectBounds = rrect.getBounds(); | 762 const SkRect& rrectBounds = rrect.getBounds(); |
759 SkRect bounds; | 763 SkRect bounds; |
760 vm.mapRect(&bounds, rrectBounds); | 764 vm.mapRect(&bounds, rrectBounds); |
761 | 765 |
762 SkVector radii = rrect.getSimpleRadii(); | 766 SkVector radii = rrect.getSimpleRadii(); |
763 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*radii.fX + | 767 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*radii.fX + |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 } | 986 } |
983 | 987 |
984 // drop out the middle quad if we're stroked | 988 // drop out the middle quad if we're stroked |
985 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO
UNT(gRRectIndices); | 989 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO
UNT(gRRectIndices); |
986 target->setIndexSourceToBuffer(indexBuffer); | 990 target->setIndexSourceToBuffer(indexBuffer); |
987 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 991 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); |
988 } | 992 } |
989 | 993 |
990 return true; | 994 return true; |
991 } | 995 } |
OLD | NEW |