Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
| 9 | 9 |
| 10 #include "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 this->surfaceProps().isGammaCorrect(), &grPaint)) { | 685 this->surfaceProps().isGammaCorrect(), &grPaint)) { |
| 686 return; | 686 return; |
| 687 } | 687 } |
| 688 | 688 |
| 689 fDrawContext->drawOval(fClip, grPaint, *draw.fMatrix, oval, GrStyle(paint)); | 689 fDrawContext->drawOval(fClip, grPaint, *draw.fMatrix, oval, GrStyle(paint)); |
| 690 } | 690 } |
| 691 | 691 |
| 692 #include "SkMaskFilter.h" | 692 #include "SkMaskFilter.h" |
| 693 | 693 |
| 694 /////////////////////////////////////////////////////////////////////////////// | 694 /////////////////////////////////////////////////////////////////////////////// |
| 695 void SkGpuDevice::drawStrokedLine(const SkPoint points[2], | |
| 696 const SkDraw& draw, | |
| 697 const SkPaint& origPaint) { | |
| 698 ASSERT_SINGLE_OWNER | |
| 699 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawStrokedLine", fContext); | |
| 700 CHECK_SHOULD_DRAW(draw); | |
| 701 | |
| 702 SkASSERT(SkPaint::kStroke_Style == origPaint.getStyle()); | |
| 703 SkASSERT(!origPaint.getPathEffect()); | |
| 704 SkASSERT(!origPaint.getMaskFilter()); | |
| 705 | |
| 706 const SkScalar halfWidth = origPaint.getStrokeWidth()/2.0f; | |
|
reed1
2016/05/31 12:54:48
Does this version devolve into multiply-by-0.5 ?
robertphillips
2016/05/31 19:06:54
Done.
| |
| 707 SkASSERT(halfWidth > 0); | |
|
reed1
2016/05/31 12:54:48
Do you not try to trigger your hairline code for t
robertphillips
2016/05/31 19:06:54
To the best of my knowledge we only kick into hair
| |
| 708 | |
| 709 SkVector v = points[1] - points[0]; | |
| 710 | |
| 711 SkScalar length = SkPoint::Normalize(&v); | |
| 712 | |
| 713 SkPaint newPaint(origPaint); | |
| 714 newPaint.setStyle(SkPaint::kFill_Style); | |
| 715 | |
| 716 SkScalar xtraLength = 0.0f; | |
| 717 if (SkPaint::kButt_Cap != origPaint.getStrokeCap()) { | |
| 718 xtraLength = halfWidth; | |
| 719 } | |
| 720 | |
| 721 SkPoint mid = points[0] + points[1]; | |
| 722 mid.scale(0.5f); | |
| 723 | |
| 724 SkRect rect = SkRect::MakeLTRB(mid.fX-halfWidth, mid.fY - 0.5f*length - xtra Length, | |
| 725 mid.fX+halfWidth, mid.fY + 0.5f*length + xtra Length); | |
| 726 SkMatrix m; | |
| 727 m.setSinCos(v.fX, -v.fY, mid.fX, mid.fY); | |
|
reed1
2016/05/31 12:54:48
Is this really faster than just drawing a quad? I
robertphillips
2016/05/31 19:06:54
Doing it this way allows greater batching. A more
| |
| 728 | |
| 729 SkMatrix local = m; | |
| 730 | |
| 731 m.postConcat(*draw.fMatrix); | |
| 732 | |
| 733 GrPaint grPaint; | |
| 734 if (!SkPaintToGrPaint(this->context(), newPaint, m, | |
| 735 this->surfaceProps().isGammaCorrect(), &grPaint)) { | |
| 736 return; | |
| 737 } | |
| 738 | |
| 739 if (SkPaint::kRound_Cap != origPaint.getStrokeCap()) { | |
| 740 fDrawContext->fillRectWithLocalMatrix(fClip, grPaint, m, rect, local); | |
| 741 } else { | |
| 742 // TODO: add a GrDrawContext::fillRRectWithLocalMatrix entry point | |
| 743 SkASSERT(0); | |
| 744 const SkRRect rrect = SkRRect::MakeRectXY(rect, halfWidth, halfWidth); | |
| 745 | |
| 746 GrStyle style(newPaint); | |
| 747 fDrawContext->drawRRect(fClip, grPaint, m, rrect, style); | |
| 748 } | |
| 749 } | |
| 695 | 750 |
| 696 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, | 751 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
| 697 const SkPaint& paint, const SkMatrix* prePathMatrix, | 752 const SkPaint& paint, const SkMatrix* prePathMatrix, |
| 698 bool pathIsMutable) { | 753 bool pathIsMutable) { |
| 699 ASSERT_SINGLE_OWNER | 754 ASSERT_SINGLE_OWNER |
| 700 if (!origSrcPath.isInverseFillType() && !paint.getPathEffect() && !prePathMa trix) { | 755 if (!origSrcPath.isInverseFillType() && !paint.getPathEffect() && !prePathMa trix) { |
| 756 SkPoint points[2]; | |
| 757 if (SkPaint::kStroke_Style == paint.getStyle() && paint.getStrokeWidth() > 0 && | |
| 758 !paint.getMaskFilter() && SkPaint::kRound_Cap != paint.getStrokeCap( ) && | |
| 759 draw.fMatrix->preservesRightAngles() && origSrcPath.isLine(points)) { | |
|
reed1
2016/05/31 12:54:48
May not come up much, but if we just create quads,
robertphillips
2016/05/31 19:06:54
Right. The skew and perspective cases don't seem t
| |
| 760 // TODO: to support round capped stroked lines we need RRect batches | |
|
bsalomon
2016/05/31 16:47:27
Re to TODO. Unless we really have to, I strongly p
robertphillips
2016/05/31 19:06:54
Done. Switched the TODO over to an informational c
| |
| 761 // that take a localMatrix | |
| 762 this->drawStrokedLine(points, draw, paint); | |
| 763 return; | |
| 764 } | |
| 701 bool isClosed; | 765 bool isClosed; |
| 702 SkRect rect; | 766 SkRect rect; |
| 703 if (origSrcPath.isRect(&rect, &isClosed) && isClosed) { | 767 if (origSrcPath.isRect(&rect, &isClosed) && isClosed) { |
| 704 this->drawRect(draw, rect, paint); | 768 this->drawRect(draw, rect, paint); |
| 705 return; | 769 return; |
| 706 } | 770 } |
| 707 if (origSrcPath.isOval(&rect)) { | 771 if (origSrcPath.isOval(&rect)) { |
| 708 this->drawOval(draw, rect, paint); | 772 this->drawOval(draw, rect, paint); |
| 709 return; | 773 return; |
| 710 } | 774 } |
| (...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1857 } | 1921 } |
| 1858 | 1922 |
| 1859 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1923 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
| 1860 ASSERT_SINGLE_OWNER | 1924 ASSERT_SINGLE_OWNER |
| 1861 // We always return a transient cache, so it is freed after each | 1925 // We always return a transient cache, so it is freed after each |
| 1862 // filter traversal. | 1926 // filter traversal. |
| 1863 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1927 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
| 1864 } | 1928 } |
| 1865 | 1929 |
| 1866 #endif | 1930 #endif |
| OLD | NEW |