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 "effects/GrTextureDomainEffect.h" | 10 #include "effects/GrTextureDomainEffect.h" |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 | 613 |
614 void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, | 614 void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, |
615 const SkPaint& paint) { | 615 const SkPaint& paint) { |
616 CHECK_FOR_NODRAW_ANNOTATION(paint); | 616 CHECK_FOR_NODRAW_ANNOTATION(paint); |
617 CHECK_SHOULD_DRAW(draw, false); | 617 CHECK_SHOULD_DRAW(draw, false); |
618 | 618 |
619 bool doStroke = paint.getStyle() != SkPaint::kFill_Style; | 619 bool doStroke = paint.getStyle() != SkPaint::kFill_Style; |
620 SkScalar width = paint.getStrokeWidth(); | 620 SkScalar width = paint.getStrokeWidth(); |
621 | 621 |
622 /* | 622 /* |
623 We have special code for hairline strokes, miter-strokes, and fills. | 623 We have special code for hairline strokes, miter-strokes, bevel-stroke |
624 Anything else we just call our path code. | 624 and fills. Anything else we just call our path code. |
625 */ | 625 */ |
626 bool usePath = doStroke && width > 0 && | 626 bool usePath = doStroke && width > 0 && |
627 paint.getStrokeJoin() != SkPaint::kMiter_Join; | 627 paint.getStrokeJoin() == SkPaint::kRound_Join; |
628 // another two reasons we might need to call drawPath... | 628 // another two reasons we might need to call drawPath... |
629 if (paint.getMaskFilter() || paint.getPathEffect()) { | 629 if (paint.getMaskFilter() || paint.getPathEffect()) { |
630 usePath = true; | 630 usePath = true; |
631 } | 631 } |
632 if (!usePath && paint.isAntiAlias() && !fContext->getMatrix().rectStaysRect( )) { | 632 if (!usePath && paint.isAntiAlias() && !fContext->getMatrix().rectStaysRect( )) { |
633 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) | 633 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) |
634 if (doStroke) { | 634 if (doStroke) { |
635 #endif | 635 #endif |
636 usePath = true; | 636 usePath = true; |
637 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) | 637 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) |
638 } else { | 638 } else { |
639 usePath = !fContext->getMatrix().preservesRightAngles(); | 639 usePath = !fContext->getMatrix().preservesRightAngles(); |
640 } | 640 } |
641 #endif | 641 #endif |
642 } | 642 } |
643 // small miter limit means right angles show bevel... | |
644 if (SkPaint::kMiter_Join == paint.getStrokeJoin() && | |
645 paint.getStrokeMiter() < SK_ScalarSqrt2) | |
646 { | |
647 usePath = true; | |
648 } | |
649 // until we can both stroke and fill rectangles | 643 // until we can both stroke and fill rectangles |
650 if (paint.getStyle() == SkPaint::kStrokeAndFill_Style) { | 644 if (paint.getStyle() == SkPaint::kStrokeAndFill_Style) { |
651 usePath = true; | 645 usePath = true; |
652 } | 646 } |
653 | 647 |
654 if (usePath) { | 648 if (usePath) { |
655 SkPath path; | 649 SkPath path; |
656 path.addRect(rect); | 650 path.addRect(rect); |
657 this->drawPath(draw, path, paint, NULL, true); | 651 this->drawPath(draw, path, paint, NULL, true); |
658 return; | 652 return; |
659 } | 653 } |
660 | 654 |
661 GrPaint grPaint; | 655 GrPaint grPaint; |
662 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 656 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
663 return; | 657 return; |
664 } | 658 } |
665 fContext->drawRect(grPaint, rect, doStroke ? width : -1); | 659 |
robertphillips
2013/10/30 14:36:08
How expensive is it to create the SkStrokeRect all
yunchao
2013/10/31 07:47:23
Agree. create the SkStrokeRec when it is needed to
| |
660 SkStrokeRec stroke(paint); | |
661 fContext->drawRect(grPaint, rect, doStroke ? &stroke : NULL, NULL); | |
666 } | 662 } |
667 | 663 |
668 /////////////////////////////////////////////////////////////////////////////// | 664 /////////////////////////////////////////////////////////////////////////////// |
669 | 665 |
670 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, | 666 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, |
671 const SkPaint& paint) { | 667 const SkPaint& paint) { |
672 CHECK_FOR_NODRAW_ANNOTATION(paint); | 668 CHECK_FOR_NODRAW_ANNOTATION(paint); |
673 CHECK_SHOULD_DRAW(draw, false); | 669 CHECK_SHOULD_DRAW(draw, false); |
674 | 670 |
675 bool usePath = !rect.isSimple(); | 671 bool usePath = !rect.isSimple(); |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1854 GrTexture* texture, | 1850 GrTexture* texture, |
1855 bool needClear) | 1851 bool needClear) |
1856 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1852 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
1857 | 1853 |
1858 SkASSERT(texture && texture->asRenderTarget()); | 1854 SkASSERT(texture && texture->asRenderTarget()); |
1859 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture | 1855 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture |
1860 // cache. We pass true for the third argument so that it will get unlocked. | 1856 // cache. We pass true for the third argument so that it will get unlocked. |
1861 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1857 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1862 fNeedClear = needClear; | 1858 fNeedClear = needClear; |
1863 } | 1859 } |
OLD | NEW |