OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 #ifndef SkCanvas_DEFINED | 8 #ifndef SkCanvas_DEFINED |
9 #define SkCanvas_DEFINED | 9 #define SkCanvas_DEFINED |
10 | 10 |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 /** Return true if the horizontal band specified by top and bottom is | 559 /** Return true if the horizontal band specified by top and bottom is |
560 completely clipped out. This is a conservative calculation, meaning | 560 completely clipped out. This is a conservative calculation, meaning |
561 that it is possible that if the method returns false, the band may still | 561 that it is possible that if the method returns false, the band may still |
562 in fact be clipped out, but the converse is not true. If this method | 562 in fact be clipped out, but the converse is not true. If this method |
563 returns true, then the band is guaranteed to be clipped out. | 563 returns true, then the band is guaranteed to be clipped out. |
564 @param top The top of the horizontal band to compare with the clip | 564 @param top The top of the horizontal band to compare with the clip |
565 @param bottom The bottom of the horizontal and to compare with the clip | 565 @param bottom The bottom of the horizontal and to compare with the clip |
566 @return true if the horizontal band is completely clipped out (i.e. does | 566 @return true if the horizontal band is completely clipped out (i.e. does |
567 not intersect the current clip) | 567 not intersect the current clip) |
568 */ | 568 */ |
569 bool quickRejectY(SkScalar top, SkScalar bottom) const { | 569 bool quickRejectY(SkScalar top, SkScalar bottom) const; |
570 SkASSERT(top <= bottom); | |
571 | |
572 #ifndef SK_WILL_NEVER_DRAW_PERSPECTIVE_TEXT | |
573 // TODO: add a hasPerspective method similar to getLocalClipBounds. This | |
574 // would cache the SkMatrix::hasPerspective result. Alternatively, have | |
575 // the MC stack just set a hasPerspective boolean as it is updated. | |
576 if (this->getTotalMatrix().hasPerspective()) { | |
577 // TODO: consider implementing some half-plane test between the | |
578 // two Y planes and the device-bounds (i.e., project the top and | |
579 // bottom Y planes and then determine if the clip bounds is complete
ly | |
580 // outside either one). | |
581 return false; | |
582 } | |
583 #endif | |
584 | |
585 const SkRect& clipR = this->getLocalClipBounds(); | |
586 // In the case where the clip is empty and we are provided with a | |
587 // negative top and positive bottom parameter then this test will return | |
588 // false even though it will be clipped. We have chosen to exclude that | |
589 // check as it is rare and would result double the comparisons. | |
590 return top >= clipR.fBottom || bottom <= clipR.fTop; | |
591 } | |
592 | 570 |
593 /** Return the bounds of the current clip (in local coordinates) in the | 571 /** Return the bounds of the current clip (in local coordinates) in the |
594 bounds parameter, and return true if it is non-empty. This can be useful | 572 bounds parameter, and return true if it is non-empty. This can be useful |
595 in a way similar to quickReject, in that it tells you that drawing | 573 in a way similar to quickReject, in that it tells you that drawing |
596 outside of these bounds will be clipped out. | 574 outside of these bounds will be clipped out. |
597 */ | 575 */ |
598 virtual bool getClipBounds(SkRect* bounds) const; | 576 virtual bool getClipBounds(SkRect* bounds) const; |
599 | 577 |
600 /** Return the bounds of the current clip, in device coordinates; returns | 578 /** Return the bounds of the current clip, in device coordinates; returns |
601 true if non-empty. Maybe faster than getting the clip explicitly and | 579 true if non-empty. Maybe faster than getting the clip explicitly and |
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 * paint (or default if null) would overwrite the entire root device of the
canvas | 1610 * paint (or default if null) would overwrite the entire root device of the
canvas |
1633 * (i.e. the canvas' surface if it had one). | 1611 * (i.e. the canvas' surface if it had one). |
1634 */ | 1612 */ |
1635 bool wouldOverwriteEntireSurface(const SkRect*, const SkPaint*, ShaderOverri
deOpacity) const; | 1613 bool wouldOverwriteEntireSurface(const SkRect*, const SkPaint*, ShaderOverri
deOpacity) const; |
1636 | 1614 |
1637 /** | 1615 /** |
1638 * Returns true if the paint's imagefilter can be invoked directly, without
needed a layer. | 1616 * Returns true if the paint's imagefilter can be invoked directly, without
needed a layer. |
1639 */ | 1617 */ |
1640 bool canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPai
nt&); | 1618 bool canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPai
nt&); |
1641 | 1619 |
1642 /* These maintain a cache of the clip bounds in local coordinates, | 1620 |
1643 (converted to 2s-compliment if floats are slow). | 1621 /** |
| 1622 * Keep track of the device clip bounds and if the matrix is scale-translat
e. This allows |
| 1623 * us to do a fast quick reject in the common case. |
1644 */ | 1624 */ |
1645 mutable SkRect fCachedLocalClipBounds; | 1625 bool fIsScaleTranslate; |
1646 mutable bool fCachedLocalClipBoundsDirty; | 1626 SkRect fDeviceClipBounds; |
| 1627 |
1647 bool fAllowSoftClip; | 1628 bool fAllowSoftClip; |
1648 bool fAllowSimplifyClip; | 1629 bool fAllowSimplifyClip; |
1649 const bool fConservativeRasterClip; | 1630 const bool fConservativeRasterClip; |
1650 | 1631 |
1651 const SkRect& getLocalClipBounds() const { | |
1652 if (fCachedLocalClipBoundsDirty) { | |
1653 if (!this->getClipBounds(&fCachedLocalClipBounds)) { | |
1654 fCachedLocalClipBounds.setEmpty(); | |
1655 } | |
1656 fCachedLocalClipBoundsDirty = false; | |
1657 } | |
1658 return fCachedLocalClipBounds; | |
1659 } | |
1660 | |
1661 class AutoValidateClip : ::SkNoncopyable { | 1632 class AutoValidateClip : ::SkNoncopyable { |
1662 public: | 1633 public: |
1663 explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) { | 1634 explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) { |
1664 fCanvas->validateClip(); | 1635 fCanvas->validateClip(); |
1665 } | 1636 } |
1666 ~AutoValidateClip() { fCanvas->validateClip(); } | 1637 ~AutoValidateClip() { fCanvas->validateClip(); } |
1667 | 1638 |
1668 private: | 1639 private: |
1669 const SkCanvas* fCanvas; | 1640 const SkCanvas* fCanvas; |
1670 }; | 1641 }; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1717 | 1688 |
1718 class SkCanvasClipVisitor { | 1689 class SkCanvasClipVisitor { |
1719 public: | 1690 public: |
1720 virtual ~SkCanvasClipVisitor(); | 1691 virtual ~SkCanvasClipVisitor(); |
1721 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; | 1692 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; |
1722 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; | 1693 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; |
1723 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; | 1694 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; |
1724 }; | 1695 }; |
1725 | 1696 |
1726 #endif | 1697 #endif |
OLD | NEW |