OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 #include "GrContext.h" | 10 #include "GrContext.h" |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 } | 775 } |
776 } | 776 } |
777 | 777 |
778 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po
int) { | 778 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po
int) { |
779 return point.fX >= rect.fLeft && point.fX <= rect.fRight && | 779 return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
780 point.fY >= rect.fTop && point.fY <= rect.fBottom; | 780 point.fY >= rect.fTop && point.fY <= rect.fBottom; |
781 } | 781 } |
782 | 782 |
783 void GrContext::drawRect(const GrPaint& paint, | 783 void GrContext::drawRect(const GrPaint& paint, |
784 const SkRect& rect, | 784 const SkRect& rect, |
785 const GrStrokeInfo* strokeInfo, | 785 const GrStrokeInfo* strokeInfo) { |
786 const SkMatrix* matrix) { | |
787 if (NULL != strokeInfo && strokeInfo->isDashed()) { | 786 if (NULL != strokeInfo && strokeInfo->isDashed()) { |
788 SkPath path; | 787 SkPath path; |
789 path.addRect(rect); | 788 path.addRect(rect); |
790 this->drawPath(paint, path, *strokeInfo); | 789 this->drawPath(paint, path, *strokeInfo); |
791 return; | 790 return; |
792 } | 791 } |
793 | 792 |
794 AutoRestoreEffects are; | 793 AutoRestoreEffects are; |
795 AutoCheckFlush acf(this); | 794 AutoCheckFlush acf(this); |
796 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); | 795 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
797 | 796 |
798 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); | 797 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); |
799 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid
th(); | 798 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid
th(); |
800 SkMatrix combinedMatrix = target->drawState()->getViewMatrix(); | 799 SkMatrix matrix = target->drawState()->getViewMatrix(); |
801 if (NULL != matrix) { | |
802 combinedMatrix.preConcat(*matrix); | |
803 } | |
804 | 800 |
805 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking | 801 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking |
806 // cases where the RT is fully inside a stroke. | 802 // cases where the RT is fully inside a stroke. |
807 if (width < 0) { | 803 if (width < 0) { |
808 SkRect rtRect; | 804 SkRect rtRect; |
809 target->getDrawState().getRenderTarget()->getBoundsRect(&rtRect); | 805 target->getDrawState().getRenderTarget()->getBoundsRect(&rtRect); |
810 SkRect clipSpaceRTRect = rtRect; | 806 SkRect clipSpaceRTRect = rtRect; |
811 bool checkClip = false; | 807 bool checkClip = false; |
812 if (NULL != this->getClip()) { | 808 if (NULL != this->getClip()) { |
813 checkClip = true; | 809 checkClip = true; |
814 clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->fOrigin.fX), | 810 clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->fOrigin.fX), |
815 SkIntToScalar(this->getClip()->fOrigin.fY)); | 811 SkIntToScalar(this->getClip()->fOrigin.fY)); |
816 } | 812 } |
817 // Does the clip contain the entire RT? | 813 // Does the clip contain the entire RT? |
818 if (!checkClip || target->getClip()->fClipStack->quickContains(clipSpace
RTRect)) { | 814 if (!checkClip || target->getClip()->fClipStack->quickContains(clipSpace
RTRect)) { |
819 SkMatrix invM; | 815 SkMatrix invM; |
820 if (!combinedMatrix.invert(&invM)) { | 816 if (!matrix.invert(&invM)) { |
821 return; | 817 return; |
822 } | 818 } |
823 // Does the rect bound the RT? | 819 // Does the rect bound the RT? |
824 SkPoint srcSpaceRTQuad[4]; | 820 SkPoint srcSpaceRTQuad[4]; |
825 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); | 821 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
826 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && | 822 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
827 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && | 823 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
828 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && | 824 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
829 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { | 825 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { |
830 // Will it blend? | 826 // Will it blend? |
831 GrColor clearColor; | 827 GrColor clearColor; |
832 if (paint.isOpaqueAndConstantColor(&clearColor)) { | 828 if (paint.isOpaqueAndConstantColor(&clearColor)) { |
833 target->clear(NULL, clearColor, true); | 829 target->clear(NULL, clearColor, true); |
834 return; | 830 return; |
835 } | 831 } |
836 } | 832 } |
837 } | 833 } |
838 } | 834 } |
839 | 835 |
840 SkRect devBoundRect; | 836 SkRect devBoundRect; |
841 bool useVertexCoverage; | 837 bool useVertexCoverage; |
842 bool needAA = paint.isAntiAlias() && | 838 bool needAA = paint.isAntiAlias() && |
843 !target->getDrawState().getRenderTarget()->isMultisampled(); | 839 !target->getDrawState().getRenderTarget()->isMultisampled(); |
844 bool doAA = needAA && apply_aa_to_rect(target, rect, width, combinedMatrix,
&devBoundRect, | 840 bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, &devBoun
dRect, |
845 &useVertexCoverage); | 841 &useVertexCoverage); |
846 | 842 |
847 const SkStrokeRec& strokeRec = strokeInfo->getStrokeRec(); | 843 const SkStrokeRec& strokeRec = strokeInfo->getStrokeRec(); |
848 | 844 |
849 if (doAA) { | 845 if (doAA) { |
850 GrDrawState::AutoViewMatrixRestore avmr; | 846 GrDrawState::AutoViewMatrixRestore avmr; |
851 if (!avmr.setIdentity(target->drawState())) { | 847 if (!avmr.setIdentity(target->drawState())) { |
852 return; | 848 return; |
853 } | 849 } |
854 if (width >= 0) { | 850 if (width >= 0) { |
855 fAARectRenderer->strokeAARect(this->getGpu(), target, rect, | 851 fAARectRenderer->strokeAARect(this->getGpu(), target, rect, |
856 combinedMatrix, devBoundRect, | 852 matrix, devBoundRect, |
857 strokeRec, useVertexCoverage); | 853 strokeRec, useVertexCoverage); |
858 } else { | 854 } else { |
859 // filled AA rect | 855 // filled AA rect |
860 fAARectRenderer->fillAARect(this->getGpu(), target, | 856 fAARectRenderer->fillAARect(this->getGpu(), target, |
861 rect, combinedMatrix, devBoundRect, | 857 rect, matrix, devBoundRect, |
862 useVertexCoverage); | 858 useVertexCoverage); |
863 } | 859 } |
864 return; | 860 return; |
865 } | 861 } |
866 | 862 |
867 if (width >= 0) { | 863 if (width >= 0) { |
868 // TODO: consider making static vertex buffers for these cases. | 864 // TODO: consider making static vertex buffers for these cases. |
869 // Hairline could be done by just adding closing vertex to | 865 // Hairline could be done by just adding closing vertex to |
870 // unitSquareVertexBuffer() | 866 // unitSquareVertexBuffer() |
871 | 867 |
(...skipping 18 matching lines...) Expand all Loading... |
890 // hairline | 886 // hairline |
891 vertCount = 5; | 887 vertCount = 5; |
892 primType = kLineStrip_GrPrimitiveType; | 888 primType = kLineStrip_GrPrimitiveType; |
893 vertex[0].set(rect.fLeft, rect.fTop); | 889 vertex[0].set(rect.fLeft, rect.fTop); |
894 vertex[1].set(rect.fRight, rect.fTop); | 890 vertex[1].set(rect.fRight, rect.fTop); |
895 vertex[2].set(rect.fRight, rect.fBottom); | 891 vertex[2].set(rect.fRight, rect.fBottom); |
896 vertex[3].set(rect.fLeft, rect.fBottom); | 892 vertex[3].set(rect.fLeft, rect.fBottom); |
897 vertex[4].set(rect.fLeft, rect.fTop); | 893 vertex[4].set(rect.fLeft, rect.fTop); |
898 } | 894 } |
899 | 895 |
900 GrDrawState::AutoViewMatrixRestore avmr; | |
901 if (NULL != matrix) { | |
902 GrDrawState* drawState = target->drawState(); | |
903 avmr.set(drawState, *matrix); | |
904 } | |
905 | |
906 target->drawNonIndexed(primType, 0, vertCount); | 896 target->drawNonIndexed(primType, 0, vertCount); |
907 } else { | 897 } else { |
908 // filled BW rect | 898 // filled BW rect |
909 target->drawSimpleRect(rect, matrix); | 899 target->drawSimpleRect(rect); |
910 } | 900 } |
911 } | 901 } |
912 | 902 |
913 void GrContext::drawRectToRect(const GrPaint& paint, | 903 void GrContext::drawRectToRect(const GrPaint& paint, |
914 const SkRect& dstRect, | 904 const SkRect& dstRect, |
915 const SkRect& localRect, | 905 const SkRect& localRect, |
916 const SkMatrix* dstMatrix, | |
917 const SkMatrix* localMatrix) { | 906 const SkMatrix* localMatrix) { |
918 AutoRestoreEffects are; | 907 AutoRestoreEffects are; |
919 AutoCheckFlush acf(this); | 908 AutoCheckFlush acf(this); |
920 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); | 909 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
921 | 910 |
922 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); | 911 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
923 | 912 |
924 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); | 913 target->drawRect(dstRect, &localRect, localMatrix); |
925 } | 914 } |
926 | 915 |
927 namespace { | 916 namespace { |
928 | 917 |
929 extern const GrVertexAttrib gPosUVColorAttribs[] = { | 918 extern const GrVertexAttrib gPosUVColorAttribs[] = { |
930 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, | 919 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, |
931 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBind
ing }, | 920 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBind
ing }, |
932 {kVec4ub_GrVertexAttribType, 2*sizeof(SkPoint), kColor_GrVertexAttribBinding
} | 921 {kVec4ub_GrVertexAttribType, 2*sizeof(SkPoint), kColor_GrVertexAttribBinding
} |
933 }; | 922 }; |
934 | 923 |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 // We protect the existing geometry here since it may not be | 1480 // We protect the existing geometry here since it may not be |
1492 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) | 1481 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) |
1493 // can be invoked in this method | 1482 // can be invoked in this method |
1494 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget:
:kReset_ASRInit); | 1483 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget:
:kReset_ASRInit); |
1495 GrDrawState* drawState = fGpu->drawState(); | 1484 GrDrawState* drawState = fGpu->drawState(); |
1496 SkASSERT(effect); | 1485 SkASSERT(effect); |
1497 drawState->addColorEffect(effect); | 1486 drawState->addColorEffect(effect); |
1498 | 1487 |
1499 drawState->setRenderTarget(texture->asRenderTarget()); | 1488 drawState->setRenderTarget(texture->asRenderTarget()); |
1500 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); | 1489 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); |
1501 fGpu->drawSimpleRect(rect, NULL); | 1490 fGpu->drawSimpleRect(rect); |
1502 // we want to read back from the scratch's origin | 1491 // we want to read back from the scratch's origin |
1503 left = 0; | 1492 left = 0; |
1504 top = 0; | 1493 top = 0; |
1505 target = texture->asRenderTarget(); | 1494 target = texture->asRenderTarget(); |
1506 } | 1495 } |
1507 } | 1496 } |
1508 } | 1497 } |
1509 if (!fGpu->readPixels(target, | 1498 if (!fGpu->readPixels(target, |
1510 left, top, width, height, | 1499 left, top, width, height, |
1511 readConfig, buffer, rowBytes)) { | 1500 readConfig, buffer, rowBytes)) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1571 if (NULL != topLeft) { | 1560 if (NULL != topLeft) { |
1572 srcRect.offset(*topLeft); | 1561 srcRect.offset(*topLeft); |
1573 } | 1562 } |
1574 SkIRect srcBounds = SkIRect::MakeWH(src->width(), src->height()); | 1563 SkIRect srcBounds = SkIRect::MakeWH(src->width(), src->height()); |
1575 if (!srcRect.intersect(srcBounds)) { | 1564 if (!srcRect.intersect(srcBounds)) { |
1576 return; | 1565 return; |
1577 } | 1566 } |
1578 sampleM.preTranslate(SkIntToScalar(srcRect.fLeft), SkIntToScalar(srcRect.fTo
p)); | 1567 sampleM.preTranslate(SkIntToScalar(srcRect.fLeft), SkIntToScalar(srcRect.fTo
p)); |
1579 drawState->addColorTextureEffect(src, sampleM); | 1568 drawState->addColorTextureEffect(src, sampleM); |
1580 SkRect dstR = SkRect::MakeWH(SkIntToScalar(srcRect.width()), SkIntToScalar(s
rcRect.height())); | 1569 SkRect dstR = SkRect::MakeWH(SkIntToScalar(srcRect.width()), SkIntToScalar(s
rcRect.height())); |
1581 fGpu->drawSimpleRect(dstR, NULL); | 1570 fGpu->drawSimpleRect(dstR); |
1582 } | 1571 } |
1583 | 1572 |
1584 bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, | 1573 bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, |
1585 int left, int top, int width, int height
, | 1574 int left, int top, int width, int height
, |
1586 GrPixelConfig srcConfig, | 1575 GrPixelConfig srcConfig, |
1587 const void* buffer, | 1576 const void* buffer, |
1588 size_t rowBytes, | 1577 size_t rowBytes, |
1589 uint32_t flags) { | 1578 uint32_t flags) { |
1590 ASSERT_OWNED_RESOURCE(target); | 1579 ASSERT_OWNED_RESOURCE(target); |
1591 | 1580 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1698 // drawing a rect) so preserve the current geometry. | 1687 // drawing a rect) so preserve the current geometry. |
1699 SkMatrix matrix; | 1688 SkMatrix matrix; |
1700 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 1689 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
1701 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRI
nit, &matrix); | 1690 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRI
nit, &matrix); |
1702 GrDrawState* drawState = fGpu->drawState(); | 1691 GrDrawState* drawState = fGpu->drawState(); |
1703 SkASSERT(effect); | 1692 SkASSERT(effect); |
1704 drawState->addColorEffect(effect); | 1693 drawState->addColorEffect(effect); |
1705 | 1694 |
1706 drawState->setRenderTarget(target); | 1695 drawState->setRenderTarget(target); |
1707 | 1696 |
1708 fGpu->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heig
ht)), NULL); | 1697 fGpu->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heig
ht))); |
1709 return true; | 1698 return true; |
1710 } | 1699 } |
1711 //////////////////////////////////////////////////////////////////////////////// | 1700 //////////////////////////////////////////////////////////////////////////////// |
1712 | 1701 |
1713 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, | 1702 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, |
1714 BufferedDraw buffered, | 1703 BufferedDraw buffered, |
1715 AutoRestoreEffects* are, | 1704 AutoRestoreEffects* are, |
1716 AutoCheckFlush* acf) { | 1705 AutoCheckFlush* acf) { |
1717 // All users of this draw state should be freeing up all effects when they'r
e done. | 1706 // All users of this draw state should be freeing up all effects when they'r
e done. |
1718 // Otherwise effects that own resources may keep those resources alive indef
initely. | 1707 // Otherwise effects that own resources may keep those resources alive indef
initely. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1920 fDrawBuffer->removeGpuTraceMarker(marker); | 1909 fDrawBuffer->removeGpuTraceMarker(marker); |
1921 } | 1910 } |
1922 } | 1911 } |
1923 | 1912 |
1924 /////////////////////////////////////////////////////////////////////////////// | 1913 /////////////////////////////////////////////////////////////////////////////// |
1925 #if GR_CACHE_STATS | 1914 #if GR_CACHE_STATS |
1926 void GrContext::printCacheStats() const { | 1915 void GrContext::printCacheStats() const { |
1927 fResourceCache->printStats(); | 1916 fResourceCache->printStats(); |
1928 } | 1917 } |
1929 #endif | 1918 #endif |
OLD | NEW |