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