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 #include "GrContext.h" | 9 #include "GrContext.h" |
10 | 10 |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 // if filtering is not desired then we want to ensure all | 308 // if filtering is not desired then we want to ensure all |
309 // texels in the resampled image are copies of texels from | 309 // texels in the resampled image are copies of texels from |
310 // the original. | 310 // the original. |
311 GrTextureParams params(SkShader::kClamp_TileMode, | 311 GrTextureParams params(SkShader::kClamp_TileMode, |
312 filter ? GrTextureParams::kBilerp_FilterMode : | 312 filter ? GrTextureParams::kBilerp_FilterMode : |
313 GrTextureParams::kNone_FilterMode); | 313 GrTextureParams::kNone_FilterMode); |
314 drawState.addColorTextureProcessor(clampedTexture, SkMatrix::I(), params
); | 314 drawState.addColorTextureProcessor(clampedTexture, SkMatrix::I(), params
); |
315 | 315 |
316 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | | 316 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
317 GrDefaultGeoProcFactory::kLocalCoord_GPType; | 317 GrDefaultGeoProcFactory::kLocalCoord_GPType; |
318 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(flags); | 318 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(GrColor_
WHITE, flags); |
319 drawState.setGeometryProcessor(gp)->unref(); | 319 drawState.setGeometryProcessor(gp)->unref(); |
320 | 320 |
321 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, gp->getVertexStrid
e(), 0); | 321 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, gp->getVertexStrid
e(), 0); |
322 SkASSERT(gp->getVertexStride() == 2 * sizeof(SkPoint)); | 322 SkASSERT(gp->getVertexStride() == 2 * sizeof(SkPoint)); |
323 | 323 |
324 if (arg.succeeded()) { | 324 if (arg.succeeded()) { |
325 SkPoint* verts = (SkPoint*) arg.vertices(); | 325 SkPoint* verts = (SkPoint*) arg.vertices(); |
326 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 *
sizeof(SkPoint)); | 326 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 *
sizeof(SkPoint)); |
327 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); | 327 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); |
328 fDrawBuffer->drawNonIndexed(&drawState, kTriangleFan_GrPrimitiveType
, 0, 4); | 328 fDrawBuffer->drawNonIndexed(&drawState, kTriangleFan_GrPrimitiveType
, 0, 4); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 static inline bool is_irect(const SkRect& r) { | 615 static inline bool is_irect(const SkRect& r) { |
616 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && | 616 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && |
617 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); | 617 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); |
618 } | 618 } |
619 | 619 |
620 static bool apply_aa_to_rect(GrDrawTarget* target, | 620 static bool apply_aa_to_rect(GrDrawTarget* target, |
621 GrDrawState* ds, | 621 GrDrawState* ds, |
622 SkRect* devBoundRect, | 622 SkRect* devBoundRect, |
623 const SkRect& rect, | 623 const SkRect& rect, |
624 SkScalar strokeWidth, | 624 SkScalar strokeWidth, |
625 const SkMatrix& combinedMatrix) { | 625 const SkMatrix& combinedMatrix, |
626 if (!ds->canTweakAlphaForCoverage() && !ds->couldApplyCoverage(*target->caps
())) { | 626 GrColor color) { |
| 627 if (!ds->canTweakAlphaForCoverage() && !ds->couldApplyCoverage(color, |
| 628 GrColor_WHITE
, |
| 629 *target->caps
())) { |
627 #ifdef SK_DEBUG | 630 #ifdef SK_DEBUG |
628 //SkDebugf("Turning off AA to correctly apply blend.\n"); | 631 //SkDebugf("Turning off AA to correctly apply blend.\n"); |
629 #endif | 632 #endif |
630 return false; | 633 return false; |
631 } | 634 } |
632 | 635 |
633 if (ds->getRenderTarget()->isMultisampled()) { | 636 if (ds->getRenderTarget()->isMultisampled()) { |
634 return false; | 637 return false; |
635 } | 638 } |
636 | 639 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 // Will it blend? | 718 // Will it blend? |
716 GrColor clearColor; | 719 GrColor clearColor; |
717 if (paint.isOpaqueAndConstantColor(&clearColor)) { | 720 if (paint.isOpaqueAndConstantColor(&clearColor)) { |
718 target->clear(NULL, clearColor, true, fRenderTarget); | 721 target->clear(NULL, clearColor, true, fRenderTarget); |
719 return; | 722 return; |
720 } | 723 } |
721 } | 724 } |
722 } | 725 } |
723 } | 726 } |
724 | 727 |
| 728 GrColor color = paint.getColor(); |
725 SkRect devBoundRect; | 729 SkRect devBoundRect; |
726 bool needAA = paint.isAntiAlias() && !drawState.getRenderTarget()->isMultisa
mpled(); | 730 bool needAA = paint.isAntiAlias() && !drawState.getRenderTarget()->isMultisa
mpled(); |
727 bool doAA = needAA && apply_aa_to_rect(target, &drawState, &devBoundRect, re
ct, width, matrix); | 731 bool doAA = needAA && apply_aa_to_rect(target, &drawState, &devBoundRect, re
ct, width, matrix, |
| 732 color); |
728 | 733 |
729 if (doAA) { | 734 if (doAA) { |
730 GrDrawState::AutoViewMatrixRestore avmr; | 735 GrDrawState::AutoViewMatrixRestore avmr; |
731 if (!avmr.setIdentity(&drawState)) { | 736 if (!avmr.setIdentity(&drawState)) { |
732 return; | 737 return; |
733 } | 738 } |
734 | 739 |
735 if (width >= 0) { | 740 if (width >= 0) { |
736 const SkStrokeRec& strokeRec = strokeInfo->getStrokeRec(); | 741 const SkStrokeRec& strokeRec = strokeInfo->getStrokeRec(); |
737 fAARectRenderer->strokeAARect(target, | 742 fAARectRenderer->strokeAARect(target, |
738 &drawState, | 743 &drawState, |
| 744 color, |
739 rect, | 745 rect, |
740 matrix, | 746 matrix, |
741 devBoundRect, | 747 devBoundRect, |
742 strokeRec); | 748 strokeRec); |
743 } else { | 749 } else { |
744 // filled AA rect | 750 // filled AA rect |
745 fAARectRenderer->fillAARect(target, &drawState, rect, matrix, devBou
ndRect); | 751 fAARectRenderer->fillAARect(target, &drawState, color, rect, matrix,
devBoundRect); |
746 } | 752 } |
747 return; | 753 return; |
748 } | 754 } |
749 | 755 |
750 if (width >= 0) { | 756 if (width >= 0) { |
751 // TODO: consider making static vertex buffers for these cases. | 757 // TODO: consider making static vertex buffers for these cases. |
752 // Hairline could be done by just adding closing vertex to | 758 // Hairline could be done by just adding closing vertex to |
753 // unitSquareVertexBuffer() | 759 // unitSquareVertexBuffer() |
754 | 760 |
755 static const int worstCaseVertCount = 10; | 761 static const int worstCaseVertCount = 10; |
756 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(); | 762 const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(color); |
757 drawState.setGeometryProcessor(gp)->unref(); | 763 drawState.setGeometryProcessor(gp)->unref(); |
758 GrDrawTarget::AutoReleaseGeometry geo(target, | 764 GrDrawTarget::AutoReleaseGeometry geo(target, |
759 worstCaseVertCount, | 765 worstCaseVertCount, |
760 gp->getVertexStride(), | 766 gp->getVertexStride(), |
761 0); | 767 0); |
762 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 768 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
763 | 769 |
764 if (!geo.succeeded()) { | 770 if (!geo.succeeded()) { |
765 SkDebugf("Failed to get space for vertices!\n"); | 771 SkDebugf("Failed to get space for vertices!\n"); |
766 return; | 772 return; |
(...skipping 14 matching lines...) Expand all Loading... |
781 vertex[0].set(rect.fLeft, rect.fTop); | 787 vertex[0].set(rect.fLeft, rect.fTop); |
782 vertex[1].set(rect.fRight, rect.fTop); | 788 vertex[1].set(rect.fRight, rect.fTop); |
783 vertex[2].set(rect.fRight, rect.fBottom); | 789 vertex[2].set(rect.fRight, rect.fBottom); |
784 vertex[3].set(rect.fLeft, rect.fBottom); | 790 vertex[3].set(rect.fLeft, rect.fBottom); |
785 vertex[4].set(rect.fLeft, rect.fTop); | 791 vertex[4].set(rect.fLeft, rect.fTop); |
786 } | 792 } |
787 | 793 |
788 target->drawNonIndexed(&drawState, primType, 0, vertCount); | 794 target->drawNonIndexed(&drawState, primType, 0, vertCount); |
789 } else { | 795 } else { |
790 // filled BW rect | 796 // filled BW rect |
791 target->drawSimpleRect(&drawState, rect); | 797 target->drawSimpleRect(&drawState, color, rect); |
792 } | 798 } |
793 } | 799 } |
794 | 800 |
795 void GrContext::drawRectToRect(const GrPaint& paint, | 801 void GrContext::drawRectToRect(const GrPaint& paint, |
796 const SkRect& dstRect, | 802 const SkRect& dstRect, |
797 const SkRect& localRect, | 803 const SkRect& localRect, |
798 const SkMatrix* localMatrix) { | 804 const SkMatrix* localMatrix) { |
799 AutoCheckFlush acf(this); | 805 AutoCheckFlush acf(this); |
800 GrDrawState drawState; | 806 GrDrawState drawState; |
801 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 807 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
802 if (NULL == target) { | 808 if (NULL == target) { |
803 return; | 809 return; |
804 } | 810 } |
805 | 811 |
806 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); | 812 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
807 | 813 |
808 target->drawRect(&drawState, dstRect, &localRect, localMatrix); | 814 target->drawRect(&drawState, paint.getColor(), dstRect, &localRect, localMat
rix); |
809 } | 815 } |
810 | 816 |
811 static void set_vertex_attributes(GrDrawState* drawState, | 817 static void set_vertex_attributes(GrDrawState* drawState, |
812 const SkPoint* texCoords, | 818 const SkPoint* texCoords, |
813 const GrColor* colors, | 819 const GrColor* colors, |
814 int* colorOffset, | 820 int* colorOffset, |
815 int* texOffset) { | 821 int* texOffset, |
| 822 GrColor color) { |
816 *texOffset = -1; | 823 *texOffset = -1; |
817 *colorOffset = -1; | 824 *colorOffset = -1; |
818 | 825 |
819 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; | 826 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; |
820 if (texCoords && colors) { | 827 if (texCoords && colors) { |
821 *colorOffset = sizeof(SkPoint); | 828 *colorOffset = sizeof(SkPoint); |
822 *texOffset = sizeof(SkPoint) + sizeof(GrColor); | 829 *texOffset = sizeof(SkPoint) + sizeof(GrColor); |
823 flags |= GrDefaultGeoProcFactory::kColor_GPType | | 830 flags |= GrDefaultGeoProcFactory::kColor_GPType | |
824 GrDefaultGeoProcFactory::kLocalCoord_GPType; | 831 GrDefaultGeoProcFactory::kLocalCoord_GPType; |
825 } else if (texCoords) { | 832 } else if (texCoords) { |
826 *texOffset = sizeof(SkPoint); | 833 *texOffset = sizeof(SkPoint); |
827 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; | 834 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
828 } else if (colors) { | 835 } else if (colors) { |
829 *colorOffset = sizeof(SkPoint); | 836 *colorOffset = sizeof(SkPoint); |
830 flags |= GrDefaultGeoProcFactory::kColor_GPType; | 837 flags |= GrDefaultGeoProcFactory::kColor_GPType; |
831 } | 838 } |
832 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(flags))->unr
ef(); | 839 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(color, flags
))->unref(); |
833 } | 840 } |
834 | 841 |
835 void GrContext::drawVertices(const GrPaint& paint, | 842 void GrContext::drawVertices(const GrPaint& paint, |
836 GrPrimitiveType primitiveType, | 843 GrPrimitiveType primitiveType, |
837 int vertexCount, | 844 int vertexCount, |
838 const SkPoint positions[], | 845 const SkPoint positions[], |
839 const SkPoint texCoords[], | 846 const SkPoint texCoords[], |
840 const GrColor colors[], | 847 const GrColor colors[], |
841 const uint16_t indices[], | 848 const uint16_t indices[], |
842 int indexCount) { | 849 int indexCount) { |
843 AutoCheckFlush acf(this); | 850 AutoCheckFlush acf(this); |
844 GrDrawState drawState; | 851 GrDrawState drawState; |
845 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e | 852 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e |
846 | 853 |
847 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 854 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
848 if (NULL == target) { | 855 if (NULL == target) { |
849 return; | 856 return; |
850 } | 857 } |
851 | 858 |
852 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); | 859 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
853 | 860 |
854 int colorOffset = -1, texOffset = -1; | 861 int colorOffset = -1, texOffset = -1; |
855 set_vertex_attributes(&drawState, texCoords, colors, &colorOffset, &texOffse
t); | 862 set_vertex_attributes(&drawState, texCoords, colors, &colorOffset, &texOffse
t, |
| 863 paint.getColor()); |
856 | 864 |
857 size_t vertexStride = drawState.getGeometryProcessor()->getVertexStride(); | 865 size_t vertexStride = drawState.getGeometryProcessor()->getVertexStride(); |
858 SkASSERT(vertexStride == sizeof(SkPoint) + (SkToBool(texCoords) ? sizeof(SkP
oint) : 0) | 866 SkASSERT(vertexStride == sizeof(SkPoint) + (SkToBool(texCoords) ? sizeof(SkP
oint) : 0) |
859 + (SkToBool(colors) ? sizeof(GrColo
r) : 0)); | 867 + (SkToBool(colors) ? sizeof(GrColo
r) : 0)); |
860 if (!geo.set(target, vertexCount, vertexStride, indexCount)) { | 868 if (!geo.set(target, vertexCount, vertexStride, indexCount)) { |
861 SkDebugf("Failed to get space for vertices!\n"); | 869 SkDebugf("Failed to get space for vertices!\n"); |
862 return; | 870 return; |
863 } | 871 } |
864 void* curVertex = geo.vertices(); | 872 void* curVertex = geo.vertices(); |
865 | 873 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 GrDrawState drawState; | 916 GrDrawState drawState; |
909 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 917 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
910 if (NULL == target) { | 918 if (NULL == target) { |
911 return; | 919 return; |
912 } | 920 } |
913 | 921 |
914 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); | 922 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); |
915 | 923 |
916 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 924 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
917 | 925 |
918 if (!fOvalRenderer->drawRRect(target, &drawState, this, paint.isAntiAlias(),
rrect, | 926 GrColor color = paint.getColor(); |
| 927 if (!fOvalRenderer->drawRRect(target, &drawState, color, this, paint.isAntiA
lias(), rrect, |
919 strokeRec)) { | 928 strokeRec)) { |
920 SkPath path; | 929 SkPath path; |
921 path.addRRect(rrect); | 930 path.addRRect(rrect); |
922 this->internalDrawPath(target, &drawState, paint.isAntiAlias(), path, st
rokeInfo); | 931 this->internalDrawPath(target, &drawState, color, paint.isAntiAlias(), p
ath, strokeInfo); |
923 } | 932 } |
924 } | 933 } |
925 | 934 |
926 /////////////////////////////////////////////////////////////////////////////// | 935 /////////////////////////////////////////////////////////////////////////////// |
927 | 936 |
928 void GrContext::drawDRRect(const GrPaint& paint, | 937 void GrContext::drawDRRect(const GrPaint& paint, |
929 const SkRRect& outer, | 938 const SkRRect& outer, |
930 const SkRRect& inner) { | 939 const SkRRect& inner) { |
931 if (outer.isEmpty()) { | 940 if (outer.isEmpty()) { |
932 return; | 941 return; |
933 } | 942 } |
934 | 943 |
935 AutoCheckFlush acf(this); | 944 AutoCheckFlush acf(this); |
936 GrDrawState drawState; | 945 GrDrawState drawState; |
937 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 946 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
938 | 947 |
939 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); | 948 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); |
940 | 949 |
941 if (!fOvalRenderer->drawDRRect(target, &drawState, this, paint.isAntiAlias()
, outer, inner)) { | 950 GrColor color = paint.getColor(); |
| 951 if (!fOvalRenderer->drawDRRect(target, &drawState, color, this, paint.isAnti
Alias(), outer, |
| 952 inner)) { |
942 SkPath path; | 953 SkPath path; |
943 path.addRRect(inner); | 954 path.addRRect(inner); |
944 path.addRRect(outer); | 955 path.addRRect(outer); |
945 path.setFillType(SkPath::kEvenOdd_FillType); | 956 path.setFillType(SkPath::kEvenOdd_FillType); |
946 | 957 |
947 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); | 958 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); |
948 this->internalDrawPath(target, &drawState, paint.isAntiAlias(), path, fi
llRec); | 959 this->internalDrawPath(target, &drawState, color, paint.isAntiAlias(), p
ath, fillRec); |
949 } | 960 } |
950 } | 961 } |
951 | 962 |
952 /////////////////////////////////////////////////////////////////////////////// | 963 /////////////////////////////////////////////////////////////////////////////// |
953 | 964 |
954 void GrContext::drawOval(const GrPaint& paint, | 965 void GrContext::drawOval(const GrPaint& paint, |
955 const SkRect& oval, | 966 const SkRect& oval, |
956 const GrStrokeInfo& strokeInfo) { | 967 const GrStrokeInfo& strokeInfo) { |
957 if (oval.isEmpty()) { | 968 if (oval.isEmpty()) { |
958 return; | 969 return; |
(...skipping 10 matching lines...) Expand all Loading... |
969 GrDrawState drawState; | 980 GrDrawState drawState; |
970 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 981 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
971 if (NULL == target) { | 982 if (NULL == target) { |
972 return; | 983 return; |
973 } | 984 } |
974 | 985 |
975 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); | 986 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); |
976 | 987 |
977 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 988 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
978 | 989 |
979 | 990 GrColor color = paint.getColor(); |
980 if (!fOvalRenderer->drawOval(target, &drawState, this, paint.isAntiAlias(),
oval, strokeRec)) { | 991 if (!fOvalRenderer->drawOval(target, &drawState, color, this, paint.isAntiAl
ias(), oval, |
| 992 strokeRec)) { |
981 SkPath path; | 993 SkPath path; |
982 path.addOval(oval); | 994 path.addOval(oval); |
983 this->internalDrawPath(target, &drawState, paint.isAntiAlias(), path, st
rokeInfo); | 995 this->internalDrawPath(target, &drawState, color, paint.isAntiAlias(), p
ath, strokeInfo); |
984 } | 996 } |
985 } | 997 } |
986 | 998 |
987 // Can 'path' be drawn as a pair of filled nested rectangles? | 999 // Can 'path' be drawn as a pair of filled nested rectangles? |
988 static bool is_nested_rects(GrDrawTarget* target, | 1000 static bool is_nested_rects(GrDrawTarget* target, |
989 GrDrawState* drawState, | 1001 GrDrawState* drawState, |
| 1002 GrColor color, |
990 const SkPath& path, | 1003 const SkPath& path, |
991 const SkStrokeRec& stroke, | 1004 const SkStrokeRec& stroke, |
992 SkRect rects[2]) { | 1005 SkRect rects[2]) { |
993 SkASSERT(stroke.isFillStyle()); | 1006 SkASSERT(stroke.isFillStyle()); |
994 | 1007 |
995 if (path.isInverseFillType()) { | 1008 if (path.isInverseFillType()) { |
996 return false; | 1009 return false; |
997 } | 1010 } |
998 | 1011 |
999 // TODO: this restriction could be lifted if we were willing to apply | 1012 // TODO: this restriction could be lifted if we were willing to apply |
1000 // the matrix to all the points individually rather than just to the rect | 1013 // the matrix to all the points individually rather than just to the rect |
1001 if (!drawState->getViewMatrix().preservesAxisAlignment()) { | 1014 if (!drawState->getViewMatrix().preservesAxisAlignment()) { |
1002 return false; | 1015 return false; |
1003 } | 1016 } |
1004 | 1017 |
1005 if (!drawState->canTweakAlphaForCoverage() && !drawState->couldApplyCoverage
(*target->caps())) { | 1018 if (!drawState->canTweakAlphaForCoverage() && !drawState->couldApplyCoverage
(color, |
| 1019
GrColor_WHITE, |
| 1020
*target->caps())) { |
1006 return false; | 1021 return false; |
1007 } | 1022 } |
1008 | 1023 |
1009 SkPath::Direction dirs[2]; | 1024 SkPath::Direction dirs[2]; |
1010 if (!path.isNestedRects(rects, dirs)) { | 1025 if (!path.isNestedRects(rects, dirs)) { |
1011 return false; | 1026 return false; |
1012 } | 1027 } |
1013 | 1028 |
1014 if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) { | 1029 if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) { |
1015 // The two rects need to be wound opposite to each other | 1030 // The two rects need to be wound opposite to each other |
(...skipping 25 matching lines...) Expand all Loading... |
1041 | 1056 |
1042 void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrok
eInfo& strokeInfo) { | 1057 void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrok
eInfo& strokeInfo) { |
1043 | 1058 |
1044 if (path.isEmpty()) { | 1059 if (path.isEmpty()) { |
1045 if (path.isInverseFillType()) { | 1060 if (path.isInverseFillType()) { |
1046 this->drawPaint(paint); | 1061 this->drawPaint(paint); |
1047 } | 1062 } |
1048 return; | 1063 return; |
1049 } | 1064 } |
1050 | 1065 |
| 1066 GrColor color = paint.getColor(); |
1051 if (strokeInfo.isDashed()) { | 1067 if (strokeInfo.isDashed()) { |
1052 SkPoint pts[2]; | 1068 SkPoint pts[2]; |
1053 if (path.isLine(pts)) { | 1069 if (path.isLine(pts)) { |
1054 AutoCheckFlush acf(this); | 1070 AutoCheckFlush acf(this); |
1055 GrDrawState drawState; | 1071 GrDrawState drawState; |
1056 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf)
; | 1072 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf)
; |
1057 if (NULL == target) { | 1073 if (NULL == target) { |
1058 return; | 1074 return; |
1059 }; | 1075 }; |
1060 | 1076 |
1061 SkMatrix origViewMatrix = drawState.getViewMatrix(); | 1077 SkMatrix origViewMatrix = drawState.getViewMatrix(); |
1062 GrDrawState::AutoViewMatrixRestore avmr; | 1078 GrDrawState::AutoViewMatrixRestore avmr; |
1063 if (avmr.setIdentity(&drawState)) { | 1079 if (avmr.setIdentity(&drawState)) { |
1064 if (GrDashingEffect::DrawDashLine(fGpu, target, &drawState, pts,
paint, | 1080 if (GrDashingEffect::DrawDashLine(fGpu, target, &drawState, colo
r, pts, paint, |
1065 strokeInfo, origViewMatrix)) { | 1081 strokeInfo, origViewMatrix)) { |
1066 return; | 1082 return; |
1067 } | 1083 } |
1068 } | 1084 } |
1069 } | 1085 } |
1070 | 1086 |
1071 // Filter dashed path into new path with the dashing applied | 1087 // Filter dashed path into new path with the dashing applied |
1072 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); | 1088 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); |
1073 SkTLazy<SkPath> effectPath; | 1089 SkTLazy<SkPath> effectPath; |
1074 GrStrokeInfo newStrokeInfo(strokeInfo, false); | 1090 GrStrokeInfo newStrokeInfo(strokeInfo, false); |
(...skipping 22 matching lines...) Expand all Loading... |
1097 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC
onvex()); | 1113 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC
onvex()); |
1098 | 1114 |
1099 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 1115 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
1100 | 1116 |
1101 bool useCoverageAA = paint.isAntiAlias() && !drawState.getRenderTarget()->is
Multisampled(); | 1117 bool useCoverageAA = paint.isAntiAlias() && !drawState.getRenderTarget()->is
Multisampled(); |
1102 | 1118 |
1103 if (useCoverageAA && strokeRec.getWidth() < 0 && !path.isConvex()) { | 1119 if (useCoverageAA && strokeRec.getWidth() < 0 && !path.isConvex()) { |
1104 // Concave AA paths are expensive - try to avoid them for special cases | 1120 // Concave AA paths are expensive - try to avoid them for special cases |
1105 SkRect rects[2]; | 1121 SkRect rects[2]; |
1106 | 1122 |
1107 if (is_nested_rects(target, &drawState, path, strokeRec, rects)) { | 1123 if (is_nested_rects(target, &drawState, color, path, strokeRec, rects))
{ |
1108 SkMatrix origViewMatrix = drawState.getViewMatrix(); | 1124 SkMatrix origViewMatrix = drawState.getViewMatrix(); |
1109 GrDrawState::AutoViewMatrixRestore avmr; | 1125 GrDrawState::AutoViewMatrixRestore avmr; |
1110 if (!avmr.setIdentity(&drawState)) { | 1126 if (!avmr.setIdentity(&drawState)) { |
1111 return; | 1127 return; |
1112 } | 1128 } |
1113 | 1129 |
1114 fAARectRenderer->fillAANestedRects(target, &drawState, rects, origVi
ewMatrix); | 1130 fAARectRenderer->fillAANestedRects(target, &drawState, color, rects,
origViewMatrix); |
1115 return; | 1131 return; |
1116 } | 1132 } |
1117 } | 1133 } |
1118 | 1134 |
1119 SkRect ovalRect; | 1135 SkRect ovalRect; |
1120 bool isOval = path.isOval(&ovalRect); | 1136 bool isOval = path.isOval(&ovalRect); |
1121 | 1137 |
1122 if (!isOval || path.isInverseFillType() | 1138 if (!isOval || path.isInverseFillType() |
1123 || !fOvalRenderer->drawOval(target, &drawState, this, paint.isAntiAlias(
), ovalRect, | 1139 || !fOvalRenderer->drawOval(target, &drawState, color, this, paint.isAnt
iAlias(), ovalRect, |
1124 strokeRec)) { | 1140 strokeRec)) { |
1125 this->internalDrawPath(target, &drawState, paint.isAntiAlias(), path, st
rokeInfo); | 1141 this->internalDrawPath(target, &drawState, color, paint.isAntiAlias(), p
ath, strokeInfo); |
1126 } | 1142 } |
1127 } | 1143 } |
1128 | 1144 |
1129 void GrContext::internalDrawPath(GrDrawTarget* target, | 1145 void GrContext::internalDrawPath(GrDrawTarget* target, |
1130 GrDrawState* drawState, | 1146 GrDrawState* drawState, |
| 1147 GrColor color, |
1131 bool useAA, | 1148 bool useAA, |
1132 const SkPath& path, | 1149 const SkPath& path, |
1133 const GrStrokeInfo& strokeInfo) { | 1150 const GrStrokeInfo& strokeInfo) { |
1134 SkASSERT(!path.isEmpty()); | 1151 SkASSERT(!path.isEmpty()); |
1135 | 1152 |
1136 GR_CREATE_TRACE_MARKER("GrContext::internalDrawPath", target); | 1153 GR_CREATE_TRACE_MARKER("GrContext::internalDrawPath", target); |
1137 | 1154 |
1138 | 1155 |
1139 // An Assumption here is that path renderer would use some form of tweaking | 1156 // An Assumption here is that path renderer would use some form of tweaking |
1140 // the src color (either the input alpha or in the frag shader) to implement | 1157 // the src color (either the input alpha or in the frag shader) to implement |
1141 // aa. If we have some future driver-mojo path AA that can do the right | 1158 // aa. If we have some future driver-mojo path AA that can do the right |
1142 // thing WRT to the blend then we'll need some query on the PR. | 1159 // thing WRT to the blend then we'll need some query on the PR. |
1143 bool useCoverageAA = useAA && | 1160 bool useCoverageAA = useAA && |
1144 !drawState->getRenderTarget()->isMultisampled() && | 1161 !drawState->getRenderTarget()->isMultisampled() && |
1145 drawState->couldApplyCoverage(*target->caps()); | 1162 drawState->couldApplyCoverage(color, GrColor_WHITE, *target->caps()); |
1146 | 1163 |
1147 | 1164 |
1148 GrPathRendererChain::DrawType type = | 1165 GrPathRendererChain::DrawType type = |
1149 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : | 1166 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : |
1150 GrPathRendererChain::kColor_DrawType; | 1167 GrPathRendererChain::kColor_DrawType; |
1151 | 1168 |
1152 const SkPath* pathPtr = &path; | 1169 const SkPath* pathPtr = &path; |
1153 SkTLazy<SkPath> tmpPath; | 1170 SkTLazy<SkPath> tmpPath; |
1154 SkTCopyOnFirstWrite<SkStrokeRec> stroke(strokeInfo.getStrokeRec()); | 1171 SkTCopyOnFirstWrite<SkStrokeRec> stroke(strokeInfo.getStrokeRec()); |
1155 | 1172 |
(...skipping 16 matching lines...) Expand all Loading... |
1172 pr = this->getPathRenderer(target, drawState, *pathPtr, *stroke, true, t
ype); | 1189 pr = this->getPathRenderer(target, drawState, *pathPtr, *stroke, true, t
ype); |
1173 } | 1190 } |
1174 | 1191 |
1175 if (NULL == pr) { | 1192 if (NULL == pr) { |
1176 #ifdef SK_DEBUG | 1193 #ifdef SK_DEBUG |
1177 SkDebugf("Unable to find path renderer compatible with path.\n"); | 1194 SkDebugf("Unable to find path renderer compatible with path.\n"); |
1178 #endif | 1195 #endif |
1179 return; | 1196 return; |
1180 } | 1197 } |
1181 | 1198 |
1182 pr->drawPath(target, drawState, *pathPtr, *stroke, useCoverageAA); | 1199 pr->drawPath(target, drawState, color, *pathPtr, *stroke, useCoverageAA); |
1183 } | 1200 } |
1184 | 1201 |
1185 //////////////////////////////////////////////////////////////////////////////// | 1202 //////////////////////////////////////////////////////////////////////////////// |
1186 | 1203 |
1187 void GrContext::flush(int flagsBitfield) { | 1204 void GrContext::flush(int flagsBitfield) { |
1188 if (NULL == fDrawBuffer) { | 1205 if (NULL == fDrawBuffer) { |
1189 return; | 1206 return; |
1190 } | 1207 } |
1191 | 1208 |
1192 if (kDiscard_FlushBit & flagsBitfield) { | 1209 if (kDiscard_FlushBit & flagsBitfield) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1313 // SW-rasterized clip while issuing a draw). So we push the current geometry
state before | 1330 // SW-rasterized clip while issuing a draw). So we push the current geometry
state before |
1314 // drawing a rect to the render target. | 1331 // drawing a rect to the render target. |
1315 // The bracket ensures we pop the stack if we wind up flushing below. | 1332 // The bracket ensures we pop the stack if we wind up flushing below. |
1316 { | 1333 { |
1317 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL); | 1334 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL); |
1318 GrDrawTarget::AutoGeometryPush agp(drawTarget); | 1335 GrDrawTarget::AutoGeometryPush agp(drawTarget); |
1319 | 1336 |
1320 GrDrawState drawState(matrix); | 1337 GrDrawState drawState(matrix); |
1321 drawState.addColorProcessor(fp); | 1338 drawState.addColorProcessor(fp); |
1322 drawState.setRenderTarget(renderTarget); | 1339 drawState.setRenderTarget(renderTarget); |
1323 drawTarget->drawSimpleRect(&drawState, SkRect::MakeWH(SkIntToScalar(widt
h), | 1340 drawTarget->drawSimpleRect(&drawState, GrColor_WHITE,SkRect::MakeWH(SkIn
tToScalar(width), |
1324 SkIntToScalar(heig
ht))); | 1341 SkIn
tToScalar(height))); |
1325 } | 1342 } |
1326 | 1343 |
1327 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 1344 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
1328 this->flushSurfaceWrites(surface); | 1345 this->flushSurfaceWrites(surface); |
1329 } | 1346 } |
1330 | 1347 |
1331 return true; | 1348 return true; |
1332 } | 1349 } |
1333 | 1350 |
1334 // toggles between RGBA and BGRA | 1351 // toggles between RGBA and BGRA |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) | 1452 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) |
1436 // can be invoked in this method | 1453 // can be invoked in this method |
1437 { | 1454 { |
1438 GrDrawTarget::AutoGeometryPush agp(fDrawBuffer); | 1455 GrDrawTarget::AutoGeometryPush agp(fDrawBuffer); |
1439 GrDrawState drawState; | 1456 GrDrawState drawState; |
1440 SkASSERT(fp); | 1457 SkASSERT(fp); |
1441 drawState.addColorProcessor(fp); | 1458 drawState.addColorProcessor(fp); |
1442 | 1459 |
1443 drawState.setRenderTarget(tempTexture->asRenderTarget()); | 1460 drawState.setRenderTarget(tempTexture->asRenderTarget()); |
1444 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToSc
alar(height)); | 1461 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToSc
alar(height)); |
1445 fDrawBuffer->drawSimpleRect(&drawState, rect); | 1462 fDrawBuffer->drawSimpleRect(&drawState, GrColor_WHITE, rect)
; |
1446 // we want to read back from the scratch's origin | 1463 // we want to read back from the scratch's origin |
1447 left = 0; | 1464 left = 0; |
1448 top = 0; | 1465 top = 0; |
1449 target = tempTexture->asRenderTarget(); | 1466 target = tempTexture->asRenderTarget(); |
1450 } | 1467 } |
1451 this->flushSurfaceWrites(target); | 1468 this->flushSurfaceWrites(target); |
1452 } | 1469 } |
1453 } | 1470 } |
1454 } | 1471 } |
1455 | 1472 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 fResourceCache2->printStats(); | 1729 fResourceCache2->printStats(); |
1713 } | 1730 } |
1714 #endif | 1731 #endif |
1715 | 1732 |
1716 #if GR_GPU_STATS | 1733 #if GR_GPU_STATS |
1717 const GrContext::GPUStats* GrContext::gpuStats() const { | 1734 const GrContext::GPUStats* GrContext::gpuStats() const { |
1718 return fGpu->gpuStats(); | 1735 return fGpu->gpuStats(); |
1719 } | 1736 } |
1720 #endif | 1737 #endif |
1721 | 1738 |
OLD | NEW |