OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 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 #include "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 #include <new> | 39 #include <new> |
40 | 40 |
41 #if SK_SUPPORT_GPU | 41 #if SK_SUPPORT_GPU |
42 #include "GrContext.h" | 42 #include "GrContext.h" |
43 #include "GrRenderTarget.h" | 43 #include "GrRenderTarget.h" |
44 #include "SkGr.h" | 44 #include "SkGr.h" |
45 #endif | 45 #endif |
46 | 46 |
47 #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0) | 47 #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0) |
48 | 48 |
49 //#define SK_SUPPORT_PRECHECK_CLIPRECT | |
50 | |
49 /* | 51 /* |
50 * Return true if the drawing this rect would hit every pixels in the canvas. | 52 * Return true if the drawing this rect would hit every pixels in the canvas. |
51 * | 53 * |
52 * Returns false if | 54 * Returns false if |
53 * - rect does not contain the canvas' bounds | 55 * - rect does not contain the canvas' bounds |
54 * - paint is not fill | 56 * - paint is not fill |
55 * - paint would blur or otherwise change the coverage of the rect | 57 * - paint would blur or otherwise change the coverage of the rect |
56 */ | 58 */ |
57 bool SkCanvas::wouldOverwriteEntireSurface(const SkRect* rect, const SkPaint* pa int, | 59 bool SkCanvas::wouldOverwriteEntireSurface(const SkRect* rect, const SkPaint* pa int, |
58 ShaderOverrideOpacity overrideOpacity ) const { | 60 ShaderOverrideOpacity overrideOpacity ) const { |
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1515 this->didSetMatrix(matrix); | 1517 this->didSetMatrix(matrix); |
1516 } | 1518 } |
1517 | 1519 |
1518 void SkCanvas::resetMatrix() { | 1520 void SkCanvas::resetMatrix() { |
1519 this->setMatrix(SkMatrix::I()); | 1521 this->setMatrix(SkMatrix::I()); |
1520 } | 1522 } |
1521 | 1523 |
1522 ////////////////////////////////////////////////////////////////////////////// | 1524 ////////////////////////////////////////////////////////////////////////////// |
1523 | 1525 |
1524 void SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { | 1526 void SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
1527 if (!fAllowSoftClip) { | |
1528 doAA = false; | |
1529 } | |
1530 | |
1531 #ifdef SK_SUPPORT_PRECHECK_CLIPRECT | |
1532 const bool rectStaysRect = fMCRec->fMatrix.rectStaysRect(); | |
1533 SkRect devR; | |
1534 if (rectStaysRect) { | |
1535 fMCRec->fMatrix.mapRect(&devR, rect); | |
f(malita)
2016/06/29 20:55:52
Can we move all this under the top-level condition
reed1
2016/06/29 21:07:17
Done.
| |
1536 } | |
1537 | |
1538 // Check if we can quick-accept the clip call (and do nothing) | |
1539 // | |
1540 // TODO: investigate if a (conservative) version of this could be done in :: clipRect, | |
f(malita)
2016/06/29 20:55:52
Nit: TODO solved :)
reed1
2016/06/29 21:07:18
Done.
| |
1541 // so that subclasses (like PictureRecording) didn't see unnecessary c lips, which in turn | |
1542 // might allow lazy save/restores to eliminate entire save/restore blo cks. | |
1543 // | |
1544 if (SkRegion::kIntersect_Op == op && !doAA && rectStaysRect) { | |
1545 if (devR.round().contains(fMCRec->fRasterClip.getBounds())) { | |
f(malita)
2016/06/29 20:55:52
Maybe add a comment about round() vs. unknown reso
reed1
2016/06/29 21:07:17
Done.
| |
1546 #if 0 | |
1547 SkDebugf("ignored clipRect [%g %g %g %g]\n", | |
1548 rect.left(), rect.top(), rect.right(), rect.bottom()); | |
1549 #endif | |
1550 return; | |
1551 } | |
1552 } | |
1553 #endif | |
1554 | |
1525 this->checkForDeferredSave(); | 1555 this->checkForDeferredSave(); |
1526 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; | 1556 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
1527 this->onClipRect(rect, op, edgeStyle); | 1557 this->onClipRect(rect, op, edgeStyle); |
1528 } | 1558 } |
1529 | 1559 |
1530 void SkCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edg eStyle) { | 1560 void SkCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edg eStyle) { |
1531 #ifdef SK_ENABLE_CLIP_QUICKREJECT | 1561 #ifdef SK_ENABLE_CLIP_QUICKREJECT |
1532 if (SkRegion::kIntersect_Op == op) { | 1562 if (SkRegion::kIntersect_Op == op) { |
1533 if (fMCRec->fRasterClip.isEmpty()) { | 1563 if (fMCRec->fRasterClip.isEmpty()) { |
1534 return false; | 1564 return; |
1535 } | 1565 } |
1536 | 1566 |
1537 if (this->quickReject(rect)) { | 1567 if (this->quickReject(rect)) { |
1538 fDeviceCMDirty = true; | 1568 fDeviceCMDirty = true; |
1539 fCachedLocalClipBoundsDirty = true; | 1569 fCachedLocalClipBoundsDirty = true; |
1540 | 1570 |
1541 fClipStack->clipEmpty(); | 1571 fClipStack->clipEmpty(); |
1542 return fMCRec->fRasterClip.setEmpty(); | 1572 (void)fMCRec->fRasterClip.setEmpty(); |
1573 return; | |
1543 } | 1574 } |
1544 } | 1575 } |
1545 #endif | 1576 #endif |
1546 | 1577 |
1547 if (!fAllowSoftClip) { | |
1548 edgeStyle = kHard_ClipEdgeStyle; | |
1549 } | |
1550 | |
1551 const bool rectStaysRect = fMCRec->fMatrix.rectStaysRect(); | 1578 const bool rectStaysRect = fMCRec->fMatrix.rectStaysRect(); |
1552 SkRect devR; | 1579 SkRect devR; |
1553 if (rectStaysRect) { | 1580 if (rectStaysRect) { |
1554 fMCRec->fMatrix.mapRect(&devR, rect); | 1581 fMCRec->fMatrix.mapRect(&devR, rect); |
1555 } | 1582 } |
1556 | 1583 |
1557 // Check if we can quick-accept the clip call (and do nothing) | 1584 #ifndef SK_SUPPORT_PRECHECK_CLIPRECT |
1558 // | |
1559 // TODO: investigate if a (conservative) version of this could be done in :: clipRect, | |
1560 // so that subclasses (like PictureRecording) didn't see unnecessary c lips, which in turn | |
1561 // might allow lazy save/restores to eliminate entire save/restore blo cks. | |
1562 // | |
1563 if (SkRegion::kIntersect_Op == op && | 1585 if (SkRegion::kIntersect_Op == op && |
1564 kHard_ClipEdgeStyle == edgeStyle | 1586 kHard_ClipEdgeStyle == edgeStyle |
1565 && rectStaysRect) | 1587 && rectStaysRect) |
1566 { | 1588 { |
1567 if (devR.round().contains(fMCRec->fRasterClip.getBounds())) { | 1589 if (devR.round().contains(fMCRec->fRasterClip.getBounds())) { |
1568 #if 0 | 1590 #if 0 |
1569 SkDebugf("------- ignored clipRect [%g %g %g %g]\n", | 1591 SkDebugf("------- ignored clipRect [%g %g %g %g]\n", |
1570 rect.left(), rect.top(), rect.right(), rect.bottom()); | 1592 rect.left(), rect.top(), rect.right(), rect.bottom()); |
1571 #endif | 1593 #endif |
1572 return; | 1594 return; |
1573 } | 1595 } |
1574 } | 1596 } |
1597 #endif | |
1575 | 1598 |
1576 AutoValidateClip avc(this); | 1599 AutoValidateClip avc(this); |
1577 | 1600 |
1578 fDeviceCMDirty = true; | 1601 fDeviceCMDirty = true; |
1579 fCachedLocalClipBoundsDirty = true; | 1602 fCachedLocalClipBoundsDirty = true; |
1580 | 1603 |
1581 if (rectStaysRect) { | 1604 if (rectStaysRect) { |
1582 const bool isAA = kSoft_ClipEdgeStyle == edgeStyle; | 1605 const bool isAA = kSoft_ClipEdgeStyle == edgeStyle; |
1583 fClipStack->clipDevRect(devR, op, isAA); | 1606 fClipStack->clipDevRect(devR, op, isAA); |
1584 fMCRec->fRasterClip.op(devR, this->getTopLayerBounds(), op, isAA); | 1607 fMCRec->fRasterClip.op(devR, this->getTopLayerBounds(), op, isAA); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1650 } | 1673 } |
1651 } | 1674 } |
1652 | 1675 |
1653 this->onClipPath(path, op, edgeStyle); | 1676 this->onClipPath(path, op, edgeStyle); |
1654 } | 1677 } |
1655 | 1678 |
1656 void SkCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edg eStyle) { | 1679 void SkCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edg eStyle) { |
1657 #ifdef SK_ENABLE_CLIP_QUICKREJECT | 1680 #ifdef SK_ENABLE_CLIP_QUICKREJECT |
1658 if (SkRegion::kIntersect_Op == op && !path.isInverseFillType()) { | 1681 if (SkRegion::kIntersect_Op == op && !path.isInverseFillType()) { |
1659 if (fMCRec->fRasterClip.isEmpty()) { | 1682 if (fMCRec->fRasterClip.isEmpty()) { |
1660 return false; | 1683 return; |
1661 } | 1684 } |
1662 | 1685 |
1663 if (this->quickReject(path.getBounds())) { | 1686 if (this->quickReject(path.getBounds())) { |
1664 fDeviceCMDirty = true; | 1687 fDeviceCMDirty = true; |
1665 fCachedLocalClipBoundsDirty = true; | 1688 fCachedLocalClipBoundsDirty = true; |
1666 | 1689 |
1667 fClipStack->clipEmpty(); | 1690 fClipStack->clipEmpty(); |
1668 return fMCRec->fRasterClip.setEmpty(); | 1691 (void)fMCRec->fRasterClip.setEmpty(); |
1692 return; | |
1669 } | 1693 } |
1670 } | 1694 } |
1671 #endif | 1695 #endif |
1672 | 1696 |
1673 AutoValidateClip avc(this); | 1697 AutoValidateClip avc(this); |
1674 | 1698 |
1675 fDeviceCMDirty = true; | 1699 fDeviceCMDirty = true; |
1676 fCachedLocalClipBoundsDirty = true; | 1700 fCachedLocalClipBoundsDirty = true; |
1677 if (!fAllowSoftClip) { | 1701 if (!fAllowSoftClip) { |
1678 edgeStyle = kHard_ClipEdgeStyle; | 1702 edgeStyle = kHard_ClipEdgeStyle; |
(...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3075 | 3099 |
3076 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3100 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
3077 fCanvas->restoreToCount(fSaveCount); | 3101 fCanvas->restoreToCount(fSaveCount); |
3078 } | 3102 } |
3079 | 3103 |
3080 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API | 3104 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
3081 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { | 3105 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { |
3082 return this->makeSurface(info, props).release(); | 3106 return this->makeSurface(info, props).release(); |
3083 } | 3107 } |
3084 #endif | 3108 #endif |
OLD | NEW |