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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 fPathRendererChain = NULL; | 96 fPathRendererChain = NULL; |
97 fSoftwarePathRenderer = NULL; | 97 fSoftwarePathRenderer = NULL; |
98 fResourceCache2 = NULL; | 98 fResourceCache2 = NULL; |
99 fFontCache = NULL; | 99 fFontCache = NULL; |
100 fDrawBuffer = NULL; | 100 fDrawBuffer = NULL; |
101 fDrawBufferVBAllocPool = NULL; | 101 fDrawBufferVBAllocPool = NULL; |
102 fDrawBufferIBAllocPool = NULL; | 102 fDrawBufferIBAllocPool = NULL; |
103 fFlushToReduceCacheSize = false; | 103 fFlushToReduceCacheSize = false; |
104 fAARectRenderer = NULL; | 104 fAARectRenderer = NULL; |
105 fOvalRenderer = NULL; | 105 fOvalRenderer = NULL; |
106 fViewMatrix.reset(); | |
107 fMaxTextureSizeOverride = 1 << 20; | 106 fMaxTextureSizeOverride = 1 << 20; |
108 } | 107 } |
109 | 108 |
110 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { | 109 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { |
111 SkASSERT(NULL == fGpu); | 110 SkASSERT(NULL == fGpu); |
112 | 111 |
113 fGpu = GrGpu::Create(backend, backendContext, this); | 112 fGpu = GrGpu::Create(backend, backendContext, this); |
114 if (NULL == fGpu) { | 113 if (NULL == fGpu) { |
115 return false; | 114 return false; |
116 } | 115 } |
117 this->initCommon(); | 116 this->initCommon(); |
118 return true; | 117 return true; |
119 } | 118 } |
120 | 119 |
121 void GrContext::initCommon() { | 120 void GrContext::initCommon() { |
122 fResourceCache2 = SkNEW(GrResourceCache2); | 121 fResourceCache2 = SkNEW(GrResourceCache2); |
123 fResourceCache2->setOverBudgetCallback(OverBudgetCB, this); | 122 fResourceCache2->setOverBudgetCallback(OverBudgetCB, this); |
124 | 123 |
125 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); | 124 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); |
126 | 125 |
127 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); | 126 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); |
128 | 127 |
129 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); | 128 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); |
130 fOvalRenderer = SkNEW(GrOvalRenderer); | 129 fOvalRenderer = SkNEW_ARGS(GrOvalRenderer, (fGpu)); |
131 | 130 |
132 fDidTestPMConversions = false; | 131 fDidTestPMConversions = false; |
133 | 132 |
134 this->setupDrawBuffer(); | 133 this->setupDrawBuffer(); |
135 } | 134 } |
136 | 135 |
137 GrContext::~GrContext() { | 136 GrContext::~GrContext() { |
138 if (NULL == fGpu) { | 137 if (NULL == fGpu) { |
139 return; | 138 return; |
140 } | 139 } |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 | 533 |
535 void GrContext::clear(const SkIRect* rect, | 534 void GrContext::clear(const SkIRect* rect, |
536 const GrColor color, | 535 const GrColor color, |
537 bool canIgnoreRect, | 536 bool canIgnoreRect, |
538 GrRenderTarget* renderTarget) { | 537 GrRenderTarget* renderTarget) { |
539 ASSERT_OWNED_RESOURCE(renderTarget); | 538 ASSERT_OWNED_RESOURCE(renderTarget); |
540 SkASSERT(renderTarget); | 539 SkASSERT(renderTarget); |
541 | 540 |
542 AutoCheckFlush acf(this); | 541 AutoCheckFlush acf(this); |
543 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); | 542 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); |
544 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, &acf); | 543 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, &acf); |
545 if (NULL == target) { | 544 if (NULL == target) { |
546 return; | 545 return; |
547 } | 546 } |
548 target->clear(rect, color, canIgnoreRect, renderTarget); | 547 target->clear(rect, color, canIgnoreRect, renderTarget); |
549 } | 548 } |
550 | 549 |
551 void GrContext::drawPaint(const GrPaint& origPaint) { | 550 void GrContext::drawPaint(const GrPaint& origPaint, const SkMatrix& viewMatrix) { |
552 // set rect to be big enough to fill the space, but not super-huge, so we | 551 // set rect to be big enough to fill the space, but not super-huge, so we |
553 // don't overflow fixed-point implementations | 552 // don't overflow fixed-point implementations |
554 SkRect r; | 553 SkRect r; |
555 r.setLTRB(0, 0, | 554 r.setLTRB(0, 0, |
556 SkIntToScalar(getRenderTarget()->width()), | 555 SkIntToScalar(getRenderTarget()->width()), |
557 SkIntToScalar(getRenderTarget()->height())); | 556 SkIntToScalar(getRenderTarget()->height())); |
558 SkMatrix inverse; | |
559 SkTCopyOnFirstWrite<GrPaint> paint(origPaint); | 557 SkTCopyOnFirstWrite<GrPaint> paint(origPaint); |
560 AutoMatrix am; | |
561 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::drawPaint", this); | 558 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::drawPaint", this); |
562 | 559 |
563 // We attempt to map r by the inverse matrix and draw that. mapRect will | 560 // We attempt to map r by the inverse matrix and draw that. mapRect will |
564 // map the four corners and bound them with a new rect. This will not | 561 // map the four corners and bound them with a new rect. This will not |
565 // produce a correct result for some perspective matrices. | 562 // produce a correct result for some perspective matrices. |
566 if (!this->getMatrix().hasPerspective()) { | 563 if (!viewMatrix.hasPerspective()) { |
bsalomon
2014/12/17 17:12:33
gotta figure out how to not go to identity for per
| |
567 if (!fViewMatrix.invert(&inverse)) { | 564 SkMatrix inverse; |
565 if (!viewMatrix.invert(&inverse)) { | |
568 SkDebugf("Could not invert matrix\n"); | 566 SkDebugf("Could not invert matrix\n"); |
569 return; | 567 return; |
570 } | 568 } |
571 inverse.mapRect(&r); | 569 inverse.mapRect(&r); |
572 } else { | 570 } else { |
573 if (!am.setIdentity(this, paint.writable())) { | 571 if (!paint.writable()->localCoordChangeInverse(viewMatrix)) { |
574 SkDebugf("Could not invert matrix\n"); | 572 SkDebugf("Could not invert matrix\n"); |
575 return; | 573 return; |
576 } | 574 } |
577 } | 575 } |
578 // by definition this fills the entire clip, no need for AA | 576 // by definition this fills the entire clip, no need for AA |
579 if (paint->isAntiAlias()) { | 577 if (paint->isAntiAlias()) { |
580 paint.writable()->setAntiAlias(false); | 578 paint.writable()->setAntiAlias(false); |
581 } | 579 } |
582 this->drawRect(*paint, r); | 580 this->drawRect(*paint, viewMatrix.hasPerspective() ? SkMatrix::I() : viewMat rix, r); |
583 } | 581 } |
584 | 582 |
585 #ifdef SK_DEVELOPER | 583 #ifdef SK_DEVELOPER |
586 void GrContext::dumpFontCache() const { | 584 void GrContext::dumpFontCache() const { |
587 fFontCache->dump(); | 585 fFontCache->dump(); |
588 } | 586 } |
589 #endif | 587 #endif |
590 | 588 |
591 //////////////////////////////////////////////////////////////////////////////// | 589 //////////////////////////////////////////////////////////////////////////////// |
592 | 590 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
662 | 660 |
663 return true; | 661 return true; |
664 } | 662 } |
665 | 663 |
666 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) { | 664 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) { |
667 return point.fX >= rect.fLeft && point.fX <= rect.fRight && | 665 return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
668 point.fY >= rect.fTop && point.fY <= rect.fBottom; | 666 point.fY >= rect.fTop && point.fY <= rect.fBottom; |
669 } | 667 } |
670 | 668 |
671 void GrContext::drawRect(const GrPaint& paint, | 669 void GrContext::drawRect(const GrPaint& paint, |
670 const SkMatrix& viewMatrix, | |
672 const SkRect& rect, | 671 const SkRect& rect, |
673 const GrStrokeInfo* strokeInfo) { | 672 const GrStrokeInfo* strokeInfo) { |
674 if (strokeInfo && strokeInfo->isDashed()) { | 673 if (strokeInfo && strokeInfo->isDashed()) { |
675 SkPath path; | 674 SkPath path; |
676 path.addRect(rect); | 675 path.addRect(rect); |
677 this->drawPath(paint, path, *strokeInfo); | 676 this->drawPath(paint, viewMatrix, path, *strokeInfo); |
678 return; | 677 return; |
679 } | 678 } |
680 | 679 |
681 AutoCheckFlush acf(this); | 680 AutoCheckFlush acf(this); |
682 GrDrawState drawState; | 681 GrDrawState drawState; |
683 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 682 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); |
684 if (NULL == target) { | 683 if (NULL == target) { |
685 return; | 684 return; |
686 } | 685 } |
687 | 686 |
688 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); | 687 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); |
689 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid th(); | 688 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid th(); |
690 SkMatrix matrix = drawState.getViewMatrix(); | 689 SkMatrix matrix = drawState.getViewMatrix(); |
691 | 690 |
692 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking | 691 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking |
693 // cases where the RT is fully inside a stroke. | 692 // cases where the RT is fully inside a stroke. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 } | 789 } |
791 | 790 |
792 target->drawNonIndexed(&drawState, gp, primType, 0, vertCount); | 791 target->drawNonIndexed(&drawState, gp, primType, 0, vertCount); |
793 } else { | 792 } else { |
794 // filled BW rect | 793 // filled BW rect |
795 target->drawSimpleRect(&drawState, color, rect); | 794 target->drawSimpleRect(&drawState, color, rect); |
796 } | 795 } |
797 } | 796 } |
798 | 797 |
799 void GrContext::drawRectToRect(const GrPaint& paint, | 798 void GrContext::drawRectToRect(const GrPaint& paint, |
799 const SkMatrix& viewMatrix, | |
800 const SkRect& dstRect, | 800 const SkRect& dstRect, |
801 const SkRect& localRect, | 801 const SkRect& localRect, |
802 const SkMatrix* localMatrix) { | 802 const SkMatrix* localMatrix) { |
803 AutoCheckFlush acf(this); | 803 AutoCheckFlush acf(this); |
804 GrDrawState drawState; | 804 GrDrawState drawState; |
805 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 805 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); |
806 if (NULL == target) { | 806 if (NULL == target) { |
807 return; | 807 return; |
808 } | 808 } |
809 | 809 |
810 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); | 810 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
811 | 811 |
812 target->drawRect(&drawState, paint.getColor(), dstRect, &localRect, localMat rix); | 812 target->drawRect(&drawState, paint.getColor(), dstRect, &localRect, localMat rix); |
813 } | 813 } |
814 | 814 |
815 static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords , | 815 static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords , |
(...skipping 13 matching lines...) Expand all Loading... | |
829 *texOffset = sizeof(SkPoint); | 829 *texOffset = sizeof(SkPoint); |
830 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; | 830 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
831 } else if (colors) { | 831 } else if (colors) { |
832 *colorOffset = sizeof(SkPoint); | 832 *colorOffset = sizeof(SkPoint); |
833 flags |= GrDefaultGeoProcFactory::kColor_GPType; | 833 flags |= GrDefaultGeoProcFactory::kColor_GPType; |
834 } | 834 } |
835 return GrDefaultGeoProcFactory::Create(color, flags); | 835 return GrDefaultGeoProcFactory::Create(color, flags); |
836 } | 836 } |
837 | 837 |
838 void GrContext::drawVertices(const GrPaint& paint, | 838 void GrContext::drawVertices(const GrPaint& paint, |
839 const SkMatrix& viewMatrix, | |
839 GrPrimitiveType primitiveType, | 840 GrPrimitiveType primitiveType, |
840 int vertexCount, | 841 int vertexCount, |
841 const SkPoint positions[], | 842 const SkPoint positions[], |
842 const SkPoint texCoords[], | 843 const SkPoint texCoords[], |
843 const GrColor colors[], | 844 const GrColor colors[], |
844 const uint16_t indices[], | 845 const uint16_t indices[], |
845 int indexCount) { | 846 int indexCount) { |
846 AutoCheckFlush acf(this); | 847 AutoCheckFlush acf(this); |
847 GrDrawState drawState; | 848 GrDrawState drawState; |
848 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e | 849 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e |
849 | 850 |
850 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 851 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); |
851 if (NULL == target) { | 852 if (NULL == target) { |
852 return; | 853 return; |
853 } | 854 } |
854 | 855 |
855 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); | 856 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
856 | 857 |
857 int colorOffset = -1, texOffset = -1; | 858 int colorOffset = -1, texOffset = -1; |
858 SkAutoTUnref<const GrGeometryProcessor> gp( | 859 SkAutoTUnref<const GrGeometryProcessor> gp( |
859 set_vertex_attributes(texCoords, colors, &colorOffset, &texOffset, p aint.getColor())); | 860 set_vertex_attributes(texCoords, colors, &colorOffset, &texOffset, p aint.getColor())); |
860 | 861 |
(...skipping 27 matching lines...) Expand all Loading... | |
888 } | 889 } |
889 target->drawIndexed(&drawState, gp, primitiveType, 0, 0, vertexCount, in dexCount); | 890 target->drawIndexed(&drawState, gp, primitiveType, 0, 0, vertexCount, in dexCount); |
890 } else { | 891 } else { |
891 target->drawNonIndexed(&drawState, gp, primitiveType, 0, vertexCount); | 892 target->drawNonIndexed(&drawState, gp, primitiveType, 0, vertexCount); |
892 } | 893 } |
893 } | 894 } |
894 | 895 |
895 /////////////////////////////////////////////////////////////////////////////// | 896 /////////////////////////////////////////////////////////////////////////////// |
896 | 897 |
897 void GrContext::drawRRect(const GrPaint& paint, | 898 void GrContext::drawRRect(const GrPaint& paint, |
899 const SkMatrix& viewMatrix, | |
898 const SkRRect& rrect, | 900 const SkRRect& rrect, |
899 const GrStrokeInfo& strokeInfo) { | 901 const GrStrokeInfo& strokeInfo) { |
900 if (rrect.isEmpty()) { | 902 if (rrect.isEmpty()) { |
901 return; | 903 return; |
902 } | 904 } |
903 | 905 |
904 if (strokeInfo.isDashed()) { | 906 if (strokeInfo.isDashed()) { |
905 SkPath path; | 907 SkPath path; |
906 path.addRRect(rrect); | 908 path.addRRect(rrect); |
907 this->drawPath(paint, path, strokeInfo); | 909 this->drawPath(paint, viewMatrix, path, strokeInfo); |
908 return; | 910 return; |
909 } | 911 } |
910 | 912 |
911 AutoCheckFlush acf(this); | 913 AutoCheckFlush acf(this); |
912 GrDrawState drawState; | 914 GrDrawState drawState; |
913 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 915 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); |
914 if (NULL == target) { | 916 if (NULL == target) { |
915 return; | 917 return; |
916 } | 918 } |
917 | 919 |
918 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); | 920 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); |
919 | 921 |
920 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 922 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
921 | 923 |
922 GrColor color = paint.getColor(); | 924 GrColor color = paint.getColor(); |
923 if (!fOvalRenderer->drawRRect(target, &drawState, color, this, paint.isAntiA lias(), rrect, | 925 if (!fOvalRenderer->drawRRect(target, &drawState, color, paint.isAntiAlias() , rrect, |
924 strokeRec)) { | 926 strokeRec)) { |
925 SkPath path; | 927 SkPath path; |
926 path.addRRect(rrect); | 928 path.addRRect(rrect); |
927 this->internalDrawPath(target, &drawState, color, paint.isAntiAlias(), p ath, strokeInfo); | 929 this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAn tiAlias(), path, |
930 strokeInfo); | |
928 } | 931 } |
929 } | 932 } |
930 | 933 |
931 /////////////////////////////////////////////////////////////////////////////// | 934 /////////////////////////////////////////////////////////////////////////////// |
932 | 935 |
933 void GrContext::drawDRRect(const GrPaint& paint, | 936 void GrContext::drawDRRect(const GrPaint& paint, |
937 const SkMatrix& viewMatrix, | |
934 const SkRRect& outer, | 938 const SkRRect& outer, |
935 const SkRRect& inner) { | 939 const SkRRect& inner) { |
936 if (outer.isEmpty()) { | 940 if (outer.isEmpty()) { |
937 return; | 941 return; |
938 } | 942 } |
939 | 943 |
940 AutoCheckFlush acf(this); | 944 AutoCheckFlush acf(this); |
941 GrDrawState drawState; | 945 GrDrawState drawState; |
942 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 946 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); |
943 | 947 |
944 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); | 948 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); |
945 | 949 |
946 GrColor color = paint.getColor(); | 950 GrColor color = paint.getColor(); |
947 if (!fOvalRenderer->drawDRRect(target, &drawState, color, this, paint.isAnti Alias(), outer, | 951 if (!fOvalRenderer->drawDRRect(target, &drawState, color, paint.isAntiAlias( ), outer, inner)) { |
948 inner)) { | |
949 SkPath path; | 952 SkPath path; |
950 path.addRRect(inner); | 953 path.addRRect(inner); |
951 path.addRRect(outer); | 954 path.addRRect(outer); |
952 path.setFillType(SkPath::kEvenOdd_FillType); | 955 path.setFillType(SkPath::kEvenOdd_FillType); |
953 | 956 |
954 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); | 957 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); |
955 this->internalDrawPath(target, &drawState, color, paint.isAntiAlias(), p ath, fillRec); | 958 this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAn tiAlias(), path, |
959 fillRec); | |
956 } | 960 } |
957 } | 961 } |
958 | 962 |
959 /////////////////////////////////////////////////////////////////////////////// | 963 /////////////////////////////////////////////////////////////////////////////// |
960 | 964 |
961 void GrContext::drawOval(const GrPaint& paint, | 965 void GrContext::drawOval(const GrPaint& paint, |
966 const SkMatrix& viewMatrix, | |
962 const SkRect& oval, | 967 const SkRect& oval, |
963 const GrStrokeInfo& strokeInfo) { | 968 const GrStrokeInfo& strokeInfo) { |
964 if (oval.isEmpty()) { | 969 if (oval.isEmpty()) { |
965 return; | 970 return; |
966 } | 971 } |
967 | 972 |
968 if (strokeInfo.isDashed()) { | 973 if (strokeInfo.isDashed()) { |
969 SkPath path; | 974 SkPath path; |
970 path.addOval(oval); | 975 path.addOval(oval); |
971 this->drawPath(paint, path, strokeInfo); | 976 this->drawPath(paint, viewMatrix, path, strokeInfo); |
972 return; | 977 return; |
973 } | 978 } |
974 | 979 |
975 AutoCheckFlush acf(this); | 980 AutoCheckFlush acf(this); |
976 GrDrawState drawState; | 981 GrDrawState drawState; |
977 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 982 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); |
978 if (NULL == target) { | 983 if (NULL == target) { |
979 return; | 984 return; |
980 } | 985 } |
981 | 986 |
982 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); | 987 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); |
983 | 988 |
984 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 989 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
985 | 990 |
986 GrColor color = paint.getColor(); | 991 GrColor color = paint.getColor(); |
987 if (!fOvalRenderer->drawOval(target, &drawState, color, this, paint.isAntiAl ias(), oval, | 992 if (!fOvalRenderer->drawOval(target, &drawState, color, paint.isAntiAlias(), oval, strokeRec)) { |
988 strokeRec)) { | |
989 SkPath path; | 993 SkPath path; |
990 path.addOval(oval); | 994 path.addOval(oval); |
991 this->internalDrawPath(target, &drawState, color, paint.isAntiAlias(), p ath, strokeInfo); | 995 this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAn tiAlias(), path, |
996 strokeInfo); | |
992 } | 997 } |
993 } | 998 } |
994 | 999 |
995 // Can 'path' be drawn as a pair of filled nested rectangles? | 1000 // Can 'path' be drawn as a pair of filled nested rectangles? |
996 static bool is_nested_rects(GrDrawTarget* target, | 1001 static bool is_nested_rects(GrDrawTarget* target, |
997 GrDrawState* drawState, | 1002 GrDrawState* drawState, |
998 GrColor color, | 1003 GrColor color, |
999 const SkPath& path, | 1004 const SkPath& path, |
1000 const SkStrokeRec& stroke, | 1005 const SkStrokeRec& stroke, |
1001 SkRect rects[2]) { | 1006 SkRect rects[2]) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1042 allGoE1 = false; | 1047 allGoE1 = false; |
1043 } | 1048 } |
1044 if (!SkScalarNearlyEqual(margin, temp)) { | 1049 if (!SkScalarNearlyEqual(margin, temp)) { |
1045 allEq = false; | 1050 allEq = false; |
1046 } | 1051 } |
1047 } | 1052 } |
1048 | 1053 |
1049 return allEq || allGoE1; | 1054 return allEq || allGoE1; |
1050 } | 1055 } |
1051 | 1056 |
1052 void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrok eInfo& strokeInfo) { | 1057 void GrContext::drawPath(const GrPaint& paint, |
1058 const SkMatrix& viewMatrix, | |
1059 const SkPath& path, | |
1060 const GrStrokeInfo& strokeInfo) { | |
1053 | 1061 |
1054 if (path.isEmpty()) { | 1062 if (path.isEmpty()) { |
1055 if (path.isInverseFillType()) { | 1063 if (path.isInverseFillType()) { |
1056 this->drawPaint(paint); | 1064 this->drawPaint(paint, viewMatrix); |
1057 } | 1065 } |
1058 return; | 1066 return; |
1059 } | 1067 } |
1060 | 1068 |
1061 GrColor color = paint.getColor(); | 1069 GrColor color = paint.getColor(); |
1062 if (strokeInfo.isDashed()) { | 1070 if (strokeInfo.isDashed()) { |
1063 SkPoint pts[2]; | 1071 SkPoint pts[2]; |
1064 if (path.isLine(pts)) { | 1072 if (path.isLine(pts)) { |
1065 AutoCheckFlush acf(this); | 1073 AutoCheckFlush acf(this); |
1066 GrDrawState drawState; | 1074 GrDrawState drawState; |
1067 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf) ; | 1075 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &view Matrix, &acf); |
1068 if (NULL == target) { | 1076 if (NULL == target) { |
1069 return; | 1077 return; |
1070 }; | 1078 }; |
1071 | 1079 |
1072 SkMatrix origViewMatrix = drawState.getViewMatrix(); | 1080 SkMatrix origViewMatrix = drawState.getViewMatrix(); |
1073 GrDrawState::AutoViewMatrixRestore avmr; | 1081 GrDrawState::AutoViewMatrixRestore avmr; |
1074 if (avmr.setIdentity(&drawState)) { | 1082 if (avmr.setIdentity(&drawState)) { |
1075 if (GrDashingEffect::DrawDashLine(fGpu, target, &drawState, colo r, pts, paint, | 1083 if (GrDashingEffect::DrawDashLine(fGpu, target, &drawState, colo r, pts, paint, |
1076 strokeInfo, origViewMatrix)) { | 1084 strokeInfo, origViewMatrix)) { |
1077 return; | 1085 return; |
1078 } | 1086 } |
1079 } | 1087 } |
1080 } | 1088 } |
1081 | 1089 |
1082 // Filter dashed path into new path with the dashing applied | 1090 // Filter dashed path into new path with the dashing applied |
1083 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); | 1091 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); |
1084 SkTLazy<SkPath> effectPath; | 1092 SkTLazy<SkPath> effectPath; |
1085 GrStrokeInfo newStrokeInfo(strokeInfo, false); | 1093 GrStrokeInfo newStrokeInfo(strokeInfo, false); |
1086 SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr(); | 1094 SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr(); |
1087 if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, in fo)) { | 1095 if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, in fo)) { |
1088 this->drawPath(paint, *effectPath.get(), newStrokeInfo); | 1096 this->drawPath(paint, viewMatrix, *effectPath.get(), newStrokeInfo); |
1089 return; | 1097 return; |
1090 } | 1098 } |
1091 | 1099 |
1092 this->drawPath(paint, path, newStrokeInfo); | 1100 this->drawPath(paint, viewMatrix, path, newStrokeInfo); |
1093 return; | 1101 return; |
1094 } | 1102 } |
1095 | 1103 |
1096 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. | 1104 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. |
1097 // Scratch textures can be recycled after they are returned to the texture | 1105 // Scratch textures can be recycled after they are returned to the texture |
1098 // cache. This presents a potential hazard for buffered drawing. However, | 1106 // cache. This presents a potential hazard for buffered drawing. However, |
1099 // the writePixels that uploads to the scratch will perform a flush so we're | 1107 // the writePixels that uploads to the scratch will perform a flush so we're |
1100 // OK. | 1108 // OK. |
1101 AutoCheckFlush acf(this); | 1109 AutoCheckFlush acf(this); |
1102 GrDrawState drawState; | 1110 GrDrawState drawState; |
1103 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); | 1111 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); |
1104 if (NULL == target) { | 1112 if (NULL == target) { |
1105 return; | 1113 return; |
1106 } | 1114 } |
1107 | 1115 |
1108 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC onvex()); | 1116 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC onvex()); |
1109 | 1117 |
1110 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 1118 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
1111 | 1119 |
1112 bool useCoverageAA = paint.isAntiAlias() && !drawState.getRenderTarget()->is Multisampled(); | 1120 bool useCoverageAA = paint.isAntiAlias() && !drawState.getRenderTarget()->is Multisampled(); |
1113 | 1121 |
(...skipping 10 matching lines...) Expand all Loading... | |
1124 | 1132 |
1125 fAARectRenderer->fillAANestedRects(target, &drawState, color, rects, origViewMatrix); | 1133 fAARectRenderer->fillAANestedRects(target, &drawState, color, rects, origViewMatrix); |
1126 return; | 1134 return; |
1127 } | 1135 } |
1128 } | 1136 } |
1129 | 1137 |
1130 SkRect ovalRect; | 1138 SkRect ovalRect; |
1131 bool isOval = path.isOval(&ovalRect); | 1139 bool isOval = path.isOval(&ovalRect); |
1132 | 1140 |
1133 if (!isOval || path.isInverseFillType() | 1141 if (!isOval || path.isInverseFillType() |
1134 || !fOvalRenderer->drawOval(target, &drawState, color, this, paint.isAnt iAlias(), ovalRect, | 1142 || !fOvalRenderer->drawOval(target, &drawState, color, paint.isAntiAlias (), ovalRect, |
1135 strokeRec)) { | 1143 strokeRec)) { |
1136 this->internalDrawPath(target, &drawState, color, paint.isAntiAlias(), p ath, strokeInfo); | 1144 this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAn tiAlias(), path, |
1145 strokeInfo); | |
1137 } | 1146 } |
1138 } | 1147 } |
1139 | 1148 |
1140 void GrContext::internalDrawPath(GrDrawTarget* target, | 1149 void GrContext::internalDrawPath(GrDrawTarget* target, |
1141 GrDrawState* drawState, | 1150 GrDrawState* drawState, |
1151 const SkMatrix& viewMatrix, | |
1142 GrColor color, | 1152 GrColor color, |
1143 bool useAA, | 1153 bool useAA, |
1144 const SkPath& path, | 1154 const SkPath& path, |
1145 const GrStrokeInfo& strokeInfo) { | 1155 const GrStrokeInfo& strokeInfo) { |
1146 SkASSERT(!path.isEmpty()); | 1156 SkASSERT(!path.isEmpty()); |
1147 | 1157 |
1148 GR_CREATE_TRACE_MARKER("GrContext::internalDrawPath", target); | 1158 GR_CREATE_TRACE_MARKER("GrContext::internalDrawPath", target); |
1149 | 1159 |
1150 | 1160 |
1151 // An Assumption here is that path renderer would use some form of tweaking | 1161 // An Assumption here is that path renderer would use some form of tweaking |
(...skipping 10 matching lines...) Expand all Loading... | |
1162 GrPathRendererChain::kColor_DrawType; | 1172 GrPathRendererChain::kColor_DrawType; |
1163 | 1173 |
1164 const SkPath* pathPtr = &path; | 1174 const SkPath* pathPtr = &path; |
1165 SkTLazy<SkPath> tmpPath; | 1175 SkTLazy<SkPath> tmpPath; |
1166 SkTCopyOnFirstWrite<SkStrokeRec> stroke(strokeInfo.getStrokeRec()); | 1176 SkTCopyOnFirstWrite<SkStrokeRec> stroke(strokeInfo.getStrokeRec()); |
1167 | 1177 |
1168 // Try a 1st time without stroking the path and without allowing the SW rend erer | 1178 // Try a 1st time without stroking the path and without allowing the SW rend erer |
1169 GrPathRenderer* pr = this->getPathRenderer(target, drawState, *pathPtr, *str oke, false, type); | 1179 GrPathRenderer* pr = this->getPathRenderer(target, drawState, *pathPtr, *str oke, false, type); |
1170 | 1180 |
1171 if (NULL == pr) { | 1181 if (NULL == pr) { |
1172 if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*stroke, this->getMatr ix(), NULL)) { | 1182 if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*stroke, viewMatrix, N ULL)) { |
1173 // It didn't work the 1st time, so try again with the stroked path | 1183 // It didn't work the 1st time, so try again with the stroked path |
1174 if (stroke->applyToPath(tmpPath.init(), *pathPtr)) { | 1184 if (stroke->applyToPath(tmpPath.init(), *pathPtr)) { |
1175 pathPtr = tmpPath.get(); | 1185 pathPtr = tmpPath.get(); |
1176 stroke.writable()->setFillStyle(); | 1186 stroke.writable()->setFillStyle(); |
1177 if (pathPtr->isEmpty()) { | 1187 if (pathPtr->isEmpty()) { |
1178 return; | 1188 return; |
1179 } | 1189 } |
1180 } | 1190 } |
1181 } | 1191 } |
1182 | 1192 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1319 } | 1329 } |
1320 | 1330 |
1321 SkMatrix matrix; | 1331 SkMatrix matrix; |
1322 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 1332 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
1323 | 1333 |
1324 // This function can be called in the midst of drawing another object (e.g., when uploading a | 1334 // This function can be called in the midst of drawing another object (e.g., when uploading a |
1325 // SW-rasterized clip while issuing a draw). So we push the current geometry state before | 1335 // SW-rasterized clip while issuing a draw). So we push the current geometry state before |
1326 // drawing a rect to the render target. | 1336 // drawing a rect to the render target. |
1327 // The bracket ensures we pop the stack if we wind up flushing below. | 1337 // The bracket ensures we pop the stack if we wind up flushing below. |
1328 { | 1338 { |
1329 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL); | 1339 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL, NULL); |
1330 GrDrawTarget::AutoGeometryPush agp(drawTarget); | 1340 GrDrawTarget::AutoGeometryPush agp(drawTarget); |
1331 | 1341 |
1332 GrDrawState drawState(matrix); | 1342 GrDrawState drawState(matrix); |
1333 drawState.addColorProcessor(fp); | 1343 drawState.addColorProcessor(fp); |
1334 drawState.setRenderTarget(renderTarget); | 1344 drawState.setRenderTarget(renderTarget); |
1335 drawTarget->drawSimpleRect(&drawState, GrColor_WHITE,SkRect::MakeWH(SkIn tToScalar(width), | 1345 drawTarget->drawSimpleRect(&drawState, GrColor_WHITE,SkRect::MakeWH(SkIn tToScalar(width), |
1336 SkIn tToScalar(height))); | 1346 SkIn tToScalar(height))); |
1337 } | 1347 } |
1338 | 1348 |
1339 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 1349 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1500 GrRenderTarget* rt = surface->asRenderTarget(); | 1510 GrRenderTarget* rt = surface->asRenderTarget(); |
1501 if (fGpu && rt) { | 1511 if (fGpu && rt) { |
1502 fGpu->resolveRenderTarget(rt); | 1512 fGpu->resolveRenderTarget(rt); |
1503 } | 1513 } |
1504 } | 1514 } |
1505 | 1515 |
1506 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { | 1516 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { |
1507 SkASSERT(renderTarget); | 1517 SkASSERT(renderTarget); |
1508 ASSERT_OWNED_RESOURCE(renderTarget); | 1518 ASSERT_OWNED_RESOURCE(renderTarget); |
1509 AutoCheckFlush acf(this); | 1519 AutoCheckFlush acf(this); |
1510 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, &acf); | 1520 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, &acf); |
1511 if (NULL == target) { | 1521 if (NULL == target) { |
1512 return; | 1522 return; |
1513 } | 1523 } |
1514 target->discard(renderTarget); | 1524 target->discard(renderTarget); |
1515 } | 1525 } |
1516 | 1526 |
1517 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe ct, | 1527 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe ct, |
1518 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { | 1528 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { |
1519 if (NULL == src || NULL == dst) { | 1529 if (NULL == src || NULL == dst) { |
1520 return; | 1530 return; |
1521 } | 1531 } |
1522 ASSERT_OWNED_RESOURCE(src); | 1532 ASSERT_OWNED_RESOURCE(src); |
1523 ASSERT_OWNED_RESOURCE(dst); | 1533 ASSERT_OWNED_RESOURCE(dst); |
1524 | 1534 |
1525 // Since we're going to the draw target and not GPU, no need to check kNoFlu sh | 1535 // Since we're going to the draw target and not GPU, no need to check kNoFlu sh |
1526 // here. | 1536 // here. |
1527 | 1537 |
1528 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL); | 1538 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, NULL); |
1529 if (NULL == target) { | 1539 if (NULL == target) { |
1530 return; | 1540 return; |
1531 } | 1541 } |
1532 target->copySurface(dst, src, srcRect, dstPoint); | 1542 target->copySurface(dst, src, srcRect, dstPoint); |
1533 | 1543 |
1534 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 1544 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
1535 this->flush(); | 1545 this->flush(); |
1536 } | 1546 } |
1537 } | 1547 } |
1538 | 1548 |
1539 void GrContext::flushSurfaceWrites(GrSurface* surface) { | 1549 void GrContext::flushSurfaceWrites(GrSurface* surface) { |
1540 if (surface->surfacePriv().hasPendingWrite()) { | 1550 if (surface->surfacePriv().hasPendingWrite()) { |
1541 this->flush(); | 1551 this->flush(); |
1542 } | 1552 } |
1543 } | 1553 } |
1544 | 1554 |
1545 GrDrawTarget* GrContext::prepareToDraw(GrDrawState* ds, | 1555 GrDrawTarget* GrContext::prepareToDraw(GrDrawState* ds, |
1546 const GrPaint* paint, | 1556 const GrPaint* paint, |
1557 const SkMatrix* viewMatrix, | |
1547 const AutoCheckFlush* acf) { | 1558 const AutoCheckFlush* acf) { |
1548 if (NULL == fGpu) { | 1559 if (NULL == fGpu) { |
1549 return NULL; | 1560 return NULL; |
1550 } | 1561 } |
1551 | 1562 |
1552 ASSERT_OWNED_RESOURCE(fRenderTarget.get()); | 1563 ASSERT_OWNED_RESOURCE(fRenderTarget.get()); |
1553 if (ds) { | 1564 if (ds) { |
1565 SkASSERT(viewMatrix); | |
1554 if (paint) { | 1566 if (paint) { |
1555 SkASSERT(acf); | 1567 SkASSERT(acf); |
1556 ds->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); | 1568 ds->setFromPaint(*paint, *viewMatrix, fRenderTarget.get()); |
1557 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK | 1569 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK |
1558 if ((paint->hasMask()) && | 1570 if ((paint->hasMask()) && |
1559 !fDrawState->canUseFracCoveragePrimProc(paint.getColor(), fGpu-> caps())) { | 1571 !fDrawState->canUseFracCoveragePrimProc(paint.getColor(), fGpu-> caps())) { |
1560 SkDebugf("Partial pixel coverage will be incorrectly blended.\n" ); | 1572 SkDebugf("Partial pixel coverage will be incorrectly blended.\n" ); |
1561 } | 1573 } |
1562 #endif | 1574 #endif |
1563 } else { | 1575 } else { |
1564 ds->reset(fViewMatrix); | 1576 ds->reset(*viewMatrix); |
1565 ds->setRenderTarget(fRenderTarget.get()); | 1577 ds->setRenderTarget(fRenderTarget.get()); |
1566 } | 1578 } |
1567 ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->i sWideOpen()); | 1579 ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->i sWideOpen()); |
1568 } | 1580 } |
1569 fDrawBuffer->setClip(fClip); | 1581 fDrawBuffer->setClip(fClip); |
1570 return fDrawBuffer; | 1582 return fDrawBuffer; |
1571 } | 1583 } |
1572 | 1584 |
1573 /* | 1585 /* |
1574 * This method finds a path renderer that can draw the specified path on | 1586 * This method finds a path renderer that can draw the specified path on |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1640 SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, false, | 1652 SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, false, |
1641 DRAW_BUFFER_IBPOOL_BUFFER_SIZE, | 1653 DRAW_BUFFER_IBPOOL_BUFFER_SIZE, |
1642 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); | 1654 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); |
1643 | 1655 |
1644 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, | 1656 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, |
1645 fDrawBufferVBAllocPool, | 1657 fDrawBufferVBAllocPool, |
1646 fDrawBufferIBAllocPool)); | 1658 fDrawBufferIBAllocPool)); |
1647 } | 1659 } |
1648 | 1660 |
1649 GrDrawTarget* GrContext::getTextTarget() { | 1661 GrDrawTarget* GrContext::getTextTarget() { |
1650 return this->prepareToDraw(NULL, NULL, NULL); | 1662 return this->prepareToDraw(NULL, NULL, NULL, NULL); |
1651 } | 1663 } |
1652 | 1664 |
1653 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { | 1665 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { |
1654 return fGpu->getQuadIndexBuffer(); | 1666 return fGpu->getQuadIndexBuffer(); |
1655 } | 1667 } |
1656 | 1668 |
1657 namespace { | 1669 namespace { |
1658 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { | 1670 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
1659 GrConfigConversionEffect::PMConversion pmToUPM; | 1671 GrConfigConversionEffect::PMConversion pmToUPM; |
1660 GrConfigConversionEffect::PMConversion upmToPM; | 1672 GrConfigConversionEffect::PMConversion upmToPM; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1724 fResourceCache2->printStats(); | 1736 fResourceCache2->printStats(); |
1725 } | 1737 } |
1726 #endif | 1738 #endif |
1727 | 1739 |
1728 #if GR_GPU_STATS | 1740 #if GR_GPU_STATS |
1729 const GrContext::GPUStats* GrContext::gpuStats() const { | 1741 const GrContext::GPUStats* GrContext::gpuStats() const { |
1730 return fGpu->gpuStats(); | 1742 return fGpu->gpuStats(); |
1731 } | 1743 } |
1732 #endif | 1744 #endif |
1733 | 1745 |
OLD | NEW |