Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 744 | 744 |
| 745 GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRe ct& newClip) { | 745 GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRe ct& newClip) { |
| 746 fTarget = target; | 746 fTarget = target; |
| 747 fClip = fTarget->getClip(); | 747 fClip = fTarget->getClip(); |
| 748 fStack.init(); | 748 fStack.init(); |
| 749 fStack.get()->clipDevRect(newClip, SkRegion::kReplace_Op); | 749 fStack.get()->clipDevRect(newClip, SkRegion::kReplace_Op); |
| 750 fReplacementClip.fClipStack = fStack.get(); | 750 fReplacementClip.fClipStack = fStack.get(); |
| 751 target->setClip(&fReplacementClip); | 751 target->setClip(&fReplacementClip); |
| 752 } | 752 } |
| 753 | 753 |
| 754 namespace { | |
| 755 // returns true if the read/written rect intersects the src/dst and false if not . | |
|
robertphillips
2013/04/03 21:18:43
surely dst & src can be const here?
bsalomon
2013/04/09 15:47:42
Done.
| |
| 756 bool clip_srcrect_and_dstpoint(GrSurface* dst, | |
| 757 GrSurface* src, | |
| 758 const SkIRect& srcRect, | |
| 759 const SkIPoint& dstPoint, | |
| 760 SkIRect* clippedSrcRect, | |
| 761 SkIPoint* clippedDstPoint) { | |
| 762 *clippedSrcRect = srcRect; | |
| 763 *clippedDstPoint = dstPoint; | |
| 764 | |
| 765 // clip the left edge to src and dst bounds, adjusting dstPoint if necessary | |
| 766 if (clippedSrcRect->fLeft < 0) { | |
| 767 clippedDstPoint->fX -= clippedSrcRect->fLeft; | |
| 768 clippedSrcRect->fLeft = 0; | |
| 769 } | |
| 770 if (clippedDstPoint->fX < 0) { | |
| 771 clippedSrcRect->fLeft -= clippedDstPoint->fX; | |
| 772 clippedDstPoint->fX = 0; | |
| 773 } | |
| 774 | |
| 775 // clip the top edge to src and dst bounds, adjusting dstPoint if necessary | |
| 776 if (clippedSrcRect->fTop < 0) { | |
| 777 clippedDstPoint->fY -= clippedSrcRect->fTop; | |
| 778 clippedSrcRect->fTop = 0; | |
| 779 } | |
| 780 if (clippedDstPoint->fY < 0) { | |
| 781 clippedSrcRect->fTop -= clippedDstPoint->fY; | |
| 782 clippedDstPoint->fY = 0; | |
| 783 } | |
| 784 | |
| 785 // clip the right edge to the src and dst bounds. | |
| 786 if (clippedSrcRect->fRight > src->width()) { | |
| 787 clippedSrcRect->fRight = src->width(); | |
| 788 } | |
| 789 if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) { | |
| 790 clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedD stPoint->fX; | |
| 791 } | |
| 792 | |
| 793 // clip the bottom edge to the src and dst bounds. | |
| 794 if (clippedSrcRect->fBottom > src->height()) { | |
| 795 clippedSrcRect->fBottom = src->height(); | |
| 796 } | |
| 797 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) { | |
| 798 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clipped DstPoint->fY; | |
| 799 } | |
| 800 | |
| 801 // The above clipping steps may have inverted the rect if it didn't intersec t either the src or | |
| 802 // dst bounds. | |
| 803 return !clippedSrcRect->isEmpty(); | |
| 804 } | |
| 805 } | |
| 806 | |
| 754 bool GrDrawTarget::copySurface(GrSurface* dst, | 807 bool GrDrawTarget::copySurface(GrSurface* dst, |
| 755 GrSurface* src, | 808 GrSurface* src, |
| 756 const SkIRect& srcRect, | 809 const SkIRect& srcRect, |
| 757 const SkIPoint& dstPoint) { | 810 const SkIPoint& dstPoint) { |
| 758 SkIRect clippedSrcRect(srcRect); | 811 GrAssert(NULL != dst); |
| 759 SkIPoint clippedDstPoint(dstPoint); | 812 GrAssert(NULL != src); |
| 760 | |
| 761 // clip the left edge to src and dst bounds, adjusting dstPoint if neceessar y | |
| 762 if (clippedSrcRect.fLeft < 0) { | |
| 763 clippedDstPoint.fX -= clippedSrcRect.fLeft; | |
| 764 clippedSrcRect.fLeft = 0; | |
| 765 } | |
| 766 if (clippedDstPoint.fX < 0) { | |
| 767 clippedSrcRect.fLeft -= clippedDstPoint.fX; | |
| 768 clippedDstPoint.fX = 0; | |
| 769 } | |
| 770 | 813 |
| 771 // clip the top edge to src and dst bounds, adjusting dstPoint if neceessary | 814 SkIRect clippedSrcRect; |
| 772 if (clippedSrcRect.fTop < 0) { | 815 SkIPoint clippedDstPoint; |
| 773 clippedDstPoint.fY -= clippedSrcRect.fTop; | 816 // If the rect is outside the src or dst then we've already succeeded. |
| 774 clippedSrcRect.fTop = 0; | 817 if (!clip_srcrect_and_dstpoint(dst, |
| 775 } | 818 src, |
| 776 if (clippedDstPoint.fY < 0) { | 819 srcRect, |
| 777 clippedSrcRect.fTop -= clippedDstPoint.fY; | 820 dstPoint, |
| 778 clippedDstPoint.fY = 0; | 821 &clippedSrcRect, |
| 779 } | 822 &clippedDstPoint)) { |
| 780 | 823 GrAssert(this->canCopySurface(dst, src, srcRect, dstPoint)); |
| 781 // clip the right edge to the src and dst bounds. | |
| 782 if (clippedSrcRect.fRight > src->width()) { | |
| 783 clippedSrcRect.fRight = src->width(); | |
| 784 } | |
| 785 if (clippedDstPoint.fX + clippedSrcRect.width() > dst->width()) { | |
| 786 clippedSrcRect.fRight = clippedSrcRect.fLeft + dst->width() - clippedDst Point.fX; | |
| 787 } | |
| 788 | |
| 789 // clip the bottom edge to the src and dst bounds. | |
| 790 if (clippedSrcRect.fBottom > src->height()) { | |
| 791 clippedSrcRect.fBottom = src->height(); | |
| 792 } | |
| 793 if (clippedDstPoint.fY + clippedSrcRect.height() > dst->height()) { | |
| 794 clippedSrcRect.fBottom = clippedSrcRect.fTop + dst->height() - clippedDs tPoint.fY; | |
| 795 } | |
| 796 | |
| 797 // The above clipping steps may have inverted the rect if it didn't intersec t either the src or | |
| 798 // dst bounds. | |
| 799 if (clippedSrcRect.isEmpty()) { | |
| 800 return true; | 824 return true; |
| 801 } | 825 } |
| 802 | 826 |
| 803 bool result = this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint) ; | 827 bool result = this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint) ; |
| 804 GrAssert(result == this->canCopySurface(dst, src, clippedSrcRect, clippedDst Point)); | 828 GrAssert(result == this->canCopySurface(dst, src, clippedSrcRect, clippedDst Point)); |
| 805 return result; | 829 return result; |
| 806 } | 830 } |
| 807 | 831 |
| 808 bool GrDrawTarget::canCopySurface(GrSurface* dst, | 832 bool GrDrawTarget::canCopySurface(GrSurface* dst, |
| 809 GrSurface* src, | 833 GrSurface* src, |
| 810 const SkIRect& srcRect, | 834 const SkIRect& srcRect, |
| 811 const SkIPoint& dstPoint) { | 835 const SkIPoint& dstPoint) { |
| 836 GrAssert(NULL != dst); | |
| 837 GrAssert(NULL != src); | |
| 838 | |
| 839 SkIRect clippedSrcRect; | |
| 840 SkIPoint clippedDstPoint; | |
| 841 // If the rect is outside the src or dst then we're guaranteed success | |
| 842 if (!clip_srcrect_and_dstpoint(dst, | |
| 843 src, | |
| 844 srcRect, | |
| 845 dstPoint, | |
| 846 &clippedSrcRect, | |
| 847 &clippedDstPoint)) { | |
| 848 return true; | |
| 849 } | |
| 850 return this->onCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint); | |
| 851 } | |
| 852 | |
| 853 bool GrDrawTarget::onCanCopySurface(GrSurface* dst, | |
| 854 GrSurface* src, | |
| 855 const SkIRect& srcRect, | |
| 856 const SkIPoint& dstPoint) { | |
| 812 // Check that the read/write rects are contained within the src/dst bounds. | 857 // Check that the read/write rects are contained within the src/dst bounds. |
| 813 GrAssert(!srcRect.isEmpty()); | 858 GrAssert(!srcRect.isEmpty()); |
| 814 GrAssert(SkIRect::MakeWH(src->width(), src->height()).contains(srcRect)); | 859 GrAssert(SkIRect::MakeWH(src->width(), src->height()).contains(srcRect)); |
| 815 GrAssert(dstPoint.fX >= 0 && dstPoint.fY >= 0); | 860 GrAssert(dstPoint.fX >= 0 && dstPoint.fY >= 0); |
| 816 GrAssert(dstPoint.fX + srcRect.width() <= dst->width() && | 861 GrAssert(dstPoint.fX + srcRect.width() <= dst->width() && |
| 817 dstPoint.fY + srcRect.height() <= dst->height()); | 862 dstPoint.fY + srcRect.height() <= dst->height()); |
| 818 | 863 |
| 819 return NULL != dst->asRenderTarget() && NULL != src->asTexture(); | 864 return !dst->isSameAs(src) && NULL != dst->asRenderTarget() && NULL != src-> asTexture(); |
| 820 } | 865 } |
| 821 | 866 |
| 822 bool GrDrawTarget::onCopySurface(GrSurface* dst, | 867 bool GrDrawTarget::onCopySurface(GrSurface* dst, |
| 823 GrSurface* src, | 868 GrSurface* src, |
| 824 const SkIRect& srcRect, | 869 const SkIRect& srcRect, |
| 825 const SkIPoint& dstPoint) { | 870 const SkIPoint& dstPoint) { |
| 826 if (!GrDrawTarget::canCopySurface(dst, src, srcRect, dstPoint)) { | 871 if (!GrDrawTarget::onCanCopySurface(dst, src, srcRect, dstPoint)) { |
| 827 return false; | 872 return false; |
| 828 } | 873 } |
| 829 | 874 |
| 830 GrRenderTarget* rt = dst->asRenderTarget(); | 875 GrRenderTarget* rt = dst->asRenderTarget(); |
| 831 GrTexture* tex = src->asTexture(); | 876 GrTexture* tex = src->asTexture(); |
| 832 | 877 |
| 833 GrDrawTarget::AutoStateRestore asr(this, kReset_ASRInit); | 878 GrDrawTarget::AutoStateRestore asr(this, kReset_ASRInit); |
| 834 this->drawState()->setRenderTarget(rt); | 879 this->drawState()->setRenderTarget(rt); |
| 835 SkMatrix matrix; | 880 SkMatrix matrix; |
| 836 matrix.setTranslate(SkIntToScalar(srcRect.fLeft - dstPoint.fX), | 881 matrix.setTranslate(SkIntToScalar(srcRect.fLeft - dstPoint.fX), |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 GrPrintf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]); | 939 GrPrintf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]); |
| 895 GrPrintf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport] ); | 940 GrPrintf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport] ); |
| 896 GrPrintf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); | 941 GrPrintf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); |
| 897 GrPrintf("Dual Source Blending Support: %s\n", gNY[fDualSourceBlendingSuppor t]); | 942 GrPrintf("Dual Source Blending Support: %s\n", gNY[fDualSourceBlendingSuppor t]); |
| 898 GrPrintf("Buffer Lock Support : %s\n", gNY[fBufferLockSupport]); | 943 GrPrintf("Buffer Lock Support : %s\n", gNY[fBufferLockSupport]); |
| 899 GrPrintf("Path Stenciling Support : %s\n", gNY[fPathStencilingSupport]); | 944 GrPrintf("Path Stenciling Support : %s\n", gNY[fPathStencilingSupport]); |
| 900 GrPrintf("Max Texture Size : %d\n", fMaxTextureSize); | 945 GrPrintf("Max Texture Size : %d\n", fMaxTextureSize); |
| 901 GrPrintf("Max Render Target Size : %d\n", fMaxRenderTargetSize); | 946 GrPrintf("Max Render Target Size : %d\n", fMaxRenderTargetSize); |
| 902 GrPrintf("Max Sample Count : %d\n", fMaxSampleCount); | 947 GrPrintf("Max Sample Count : %d\n", fMaxSampleCount); |
| 903 } | 948 } |
| OLD | NEW |