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