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

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

Issue 2023693002: Handle stroked single line special case in Ganesh (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix bugs Created 4 years, 6 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 | « src/gpu/SkGpuDevice.h ('k') | src/gpu/batches/GrAAFillRectBatch.cpp » ('j') | 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 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
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 // Adding support for round capping would require a GrDrawContext::fillRRect WithLocalMatrix
703 // entry point
704 SkASSERT(SkPaint::kRound_Cap != origPaint.getStrokeCap());
705 SkASSERT(SkPaint::kStroke_Style == origPaint.getStyle());
706 SkASSERT(!origPaint.getPathEffect());
707 SkASSERT(!origPaint.getMaskFilter());
708
709 const SkScalar halfWidth = 0.5f * origPaint.getStrokeWidth();
710 SkASSERT(halfWidth > 0);
711
712 SkVector v = points[1] - points[0];
713
714 SkScalar length = SkPoint::Normalize(&v);
715 if (!length) {
716 v.fX = 1.0f;
717 v.fY = 0.0f;
718 }
719
720 SkPaint newPaint(origPaint);
721 newPaint.setStyle(SkPaint::kFill_Style);
722
723 SkScalar xtraLength = 0.0f;
724 if (SkPaint::kButt_Cap != origPaint.getStrokeCap()) {
725 xtraLength = halfWidth;
726 }
727
728 SkPoint mid = points[0] + points[1];
729 mid.scale(0.5f);
730
731 SkRect rect = SkRect::MakeLTRB(mid.fX-halfWidth, mid.fY - 0.5f*length - xtra Length,
732 mid.fX+halfWidth, mid.fY + 0.5f*length + xtra Length);
733 SkMatrix m;
734 m.setSinCos(v.fX, -v.fY, mid.fX, mid.fY);
735
736 SkMatrix local = m;
737
738 m.postConcat(*draw.fMatrix);
739
740 GrPaint grPaint;
741 if (!SkPaintToGrPaint(this->context(), newPaint, m,
742 this->surfaceProps().isGammaCorrect(), &grPaint)) {
743 return;
744 }
745
746 fDrawContext->fillRectWithLocalMatrix(fClip, grPaint, m, rect, local);
747 }
695 748
696 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, 749 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
697 const SkPaint& paint, const SkMatrix* prePathMatrix, 750 const SkPaint& paint, const SkMatrix* prePathMatrix,
698 bool pathIsMutable) { 751 bool pathIsMutable) {
699 ASSERT_SINGLE_OWNER 752 ASSERT_SINGLE_OWNER
700 if (!origSrcPath.isInverseFillType() && !paint.getPathEffect() && !prePathMa trix) { 753 if (!origSrcPath.isInverseFillType() && !paint.getPathEffect() && !prePathMa trix) {
754 SkPoint points[2];
755 if (SkPaint::kStroke_Style == paint.getStyle() && paint.getStrokeWidth() > 0 &&
756 !paint.getMaskFilter() && SkPaint::kRound_Cap != paint.getStrokeCap( ) &&
757 draw.fMatrix->preservesRightAngles() && origSrcPath.isLine(points)) {
758 // Path-based stroking looks better for thin rects
759 SkScalar strokeWidth = draw.fMatrix->getMaxScale() * paint.getStroke Width();
760 if (strokeWidth > 0.9f) {
761 // Round capping support is currently disabled b.c. it would req uire
762 // a RRect batch that takes a localMatrix.
763 this->drawStrokedLine(points, draw, paint);
764 return;
765 }
766 }
701 bool isClosed; 767 bool isClosed;
702 SkRect rect; 768 SkRect rect;
703 if (origSrcPath.isRect(&rect, &isClosed) && isClosed) { 769 if (origSrcPath.isRect(&rect, &isClosed) && isClosed) {
704 this->drawRect(draw, rect, paint); 770 this->drawRect(draw, rect, paint);
705 return; 771 return;
706 } 772 }
707 if (origSrcPath.isOval(&rect)) { 773 if (origSrcPath.isOval(&rect)) {
708 this->drawOval(draw, rect, paint); 774 this->drawOval(draw, rect, paint);
709 return; 775 return;
710 } 776 }
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 } 1923 }
1858 1924
1859 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { 1925 SkImageFilterCache* SkGpuDevice::getImageFilterCache() {
1860 ASSERT_SINGLE_OWNER 1926 ASSERT_SINGLE_OWNER
1861 // We always return a transient cache, so it is freed after each 1927 // We always return a transient cache, so it is freed after each
1862 // filter traversal. 1928 // filter traversal.
1863 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); 1929 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize);
1864 } 1930 }
1865 1931
1866 #endif 1932 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | src/gpu/batches/GrAAFillRectBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698