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 // texels in the resampled image are copies of texels from | 308 // texels in the resampled image are copies of texels from |
309 // the original. | 309 // the original. |
310 GrTextureParams params(SkShader::kClamp_TileMode, | 310 GrTextureParams params(SkShader::kClamp_TileMode, |
311 filter ? GrTextureParams::kBilerp_FilterMode : | 311 filter ? GrTextureParams::kBilerp_FilterMode : |
312 GrTextureParams::kNone_FilterMode); | 312 GrTextureParams::kNone_FilterMode); |
313 drawState.addColorTextureProcessor(clampedTexture, SkMatrix::I(), params ); | 313 drawState.addColorTextureProcessor(clampedTexture, SkMatrix::I(), params ); |
314 | 314 |
315 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | | 315 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
316 GrDefaultGeoProcFactory::kLocalCoord_GPType; | 316 GrDefaultGeoProcFactory::kLocalCoord_GPType; |
317 SkAutoTUnref<const GrGeometryProcessor> gp( | 317 SkAutoTUnref<const GrGeometryProcessor> gp( |
318 GrDefaultGeoProcFactory::Create(GrColor_WHITE, flags)); | 318 GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE)); |
319 | 319 |
320 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, gp->getVertexStrid e(), 0); | 320 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, gp->getVertexStrid e(), 0); |
321 SkASSERT(gp->getVertexStride() == 2 * sizeof(SkPoint)); | 321 SkASSERT(gp->getVertexStride() == 2 * sizeof(SkPoint)); |
322 | 322 |
323 if (arg.succeeded()) { | 323 if (arg.succeeded()) { |
324 SkPoint* verts = (SkPoint*) arg.vertices(); | 324 SkPoint* verts = (SkPoint*) arg.vertices(); |
325 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(SkPoint)); | 325 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(SkPoint)); |
326 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); | 326 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); |
327 fDrawBuffer->drawNonIndexed(&drawState, gp, kTriangleFan_GrPrimitive Type, 0, 4); | 327 fDrawBuffer->drawNonIndexed(&drawState, gp, kTriangleFan_GrPrimitive Type, 0, 4); |
328 } | 328 } |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 | 533 |
534 void GrContext::clear(const SkIRect* rect, | 534 void GrContext::clear(const SkIRect* rect, |
535 const GrColor color, | 535 const GrColor color, |
536 bool canIgnoreRect, | 536 bool canIgnoreRect, |
537 GrRenderTarget* renderTarget) { | 537 GrRenderTarget* renderTarget) { |
538 ASSERT_OWNED_RESOURCE(renderTarget); | 538 ASSERT_OWNED_RESOURCE(renderTarget); |
539 SkASSERT(renderTarget); | 539 SkASSERT(renderTarget); |
540 | 540 |
541 AutoCheckFlush acf(this); | 541 AutoCheckFlush acf(this); |
542 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); | 542 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); |
543 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, &acf); | 543 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, &acf); |
544 if (NULL == target) { | 544 if (NULL == target) { |
545 return; | 545 return; |
546 } | 546 } |
547 target->clear(rect, color, canIgnoreRect, renderTarget); | 547 target->clear(rect, color, canIgnoreRect, renderTarget); |
548 } | 548 } |
549 | 549 |
550 void GrContext::drawPaint(const GrPaint& origPaint, const SkMatrix& viewMatrix) { | 550 void GrContext::drawPaint(const GrPaint& origPaint, const SkMatrix& viewMatrix) { |
551 // 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 |
552 // don't overflow fixed-point implementations | 552 // don't overflow fixed-point implementations |
553 SkRect r; | 553 SkRect r; |
(...skipping 22 matching lines...) Expand all Loading... | |
576 this->drawRect(*paint, viewMatrix, r); | 576 this->drawRect(*paint, viewMatrix, r); |
577 } else { | 577 } else { |
578 SkMatrix localMatrix; | 578 SkMatrix localMatrix; |
579 if (!viewMatrix.invert(&localMatrix)) { | 579 if (!viewMatrix.invert(&localMatrix)) { |
580 SkDebugf("Could not invert matrix\n"); | 580 SkDebugf("Could not invert matrix\n"); |
581 return; | 581 return; |
582 } | 582 } |
583 | 583 |
584 AutoCheckFlush acf(this); | 584 AutoCheckFlush acf(this); |
585 GrDrawState drawState; | 585 GrDrawState drawState; |
586 GrDrawTarget* target = this->prepareToDraw(&drawState, paint, &SkMatrix: :I(), &acf); | 586 GrDrawTarget* target = this->prepareToDraw(&drawState, paint, &acf); |
587 if (NULL == target) { | 587 if (NULL == target) { |
588 return; | 588 return; |
589 } | 589 } |
590 | 590 |
591 GR_CREATE_TRACE_MARKER("GrContext::drawPaintWithPerspective", target); | 591 GR_CREATE_TRACE_MARKER("GrContext::drawPaintWithPerspective", target); |
592 target->drawRect(&drawState, paint->getColor(), r, NULL, &localMatrix); | 592 target->drawRect(&drawState, paint->getColor(), SkMatrix::I(), r, NULL, &localMatrix); |
593 } | 593 } |
594 } | 594 } |
595 | 595 |
596 #ifdef SK_DEVELOPER | 596 #ifdef SK_DEVELOPER |
597 void GrContext::dumpFontCache() const { | 597 void GrContext::dumpFontCache() const { |
598 fFontCache->dump(); | 598 fFontCache->dump(); |
599 } | 599 } |
600 #endif | 600 #endif |
601 | 601 |
602 //////////////////////////////////////////////////////////////////////////////// | 602 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
685 const GrStrokeInfo* strokeInfo) { | 685 const GrStrokeInfo* strokeInfo) { |
686 if (strokeInfo && strokeInfo->isDashed()) { | 686 if (strokeInfo && strokeInfo->isDashed()) { |
687 SkPath path; | 687 SkPath path; |
688 path.addRect(rect); | 688 path.addRect(rect); |
689 this->drawPath(paint, viewMatrix, path, *strokeInfo); | 689 this->drawPath(paint, viewMatrix, path, *strokeInfo); |
690 return; | 690 return; |
691 } | 691 } |
692 | 692 |
693 AutoCheckFlush acf(this); | 693 AutoCheckFlush acf(this); |
694 GrDrawState drawState; | 694 GrDrawState drawState; |
695 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); | 695 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
696 if (NULL == target) { | 696 if (NULL == target) { |
697 return; | 697 return; |
698 } | 698 } |
699 | 699 |
700 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); | 700 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); |
701 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid th(); | 701 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid th(); |
702 SkMatrix matrix = drawState.getViewMatrix(); | |
703 | 702 |
704 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking | 703 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking |
705 // cases where the RT is fully inside a stroke. | 704 // cases where the RT is fully inside a stroke. |
706 if (width < 0) { | 705 if (width < 0) { |
707 SkRect rtRect; | 706 SkRect rtRect; |
708 drawState.getRenderTarget()->getBoundsRect(&rtRect); | 707 drawState.getRenderTarget()->getBoundsRect(&rtRect); |
709 SkRect clipSpaceRTRect = rtRect; | 708 SkRect clipSpaceRTRect = rtRect; |
710 bool checkClip = false; | 709 bool checkClip = false; |
711 if (this->getClip()) { | 710 if (this->getClip()) { |
712 checkClip = true; | 711 checkClip = true; |
713 clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->fOrigin.fX), | 712 clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->fOrigin.fX), |
714 SkIntToScalar(this->getClip()->fOrigin.fY)); | 713 SkIntToScalar(this->getClip()->fOrigin.fY)); |
715 } | 714 } |
716 // Does the clip contain the entire RT? | 715 // Does the clip contain the entire RT? |
717 if (!checkClip || target->getClip()->fClipStack->quickContains(clipSpace RTRect)) { | 716 if (!checkClip || target->getClip()->fClipStack->quickContains(clipSpace RTRect)) { |
718 SkMatrix invM; | 717 SkMatrix invM; |
719 if (!matrix.invert(&invM)) { | 718 if (!viewMatrix.invert(&invM)) { |
720 return; | 719 return; |
721 } | 720 } |
722 // Does the rect bound the RT? | 721 // Does the rect bound the RT? |
723 SkPoint srcSpaceRTQuad[4]; | 722 SkPoint srcSpaceRTQuad[4]; |
724 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); | 723 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
725 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && | 724 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
726 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && | 725 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
727 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && | 726 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
728 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { | 727 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { |
729 // Will it blend? | 728 // Will it blend? |
730 GrColor clearColor; | 729 GrColor clearColor; |
731 if (paint.isOpaqueAndConstantColor(&clearColor)) { | 730 if (paint.isOpaqueAndConstantColor(&clearColor)) { |
732 target->clear(NULL, clearColor, true, fRenderTarget); | 731 target->clear(NULL, clearColor, true, fRenderTarget); |
733 return; | 732 return; |
734 } | 733 } |
735 } | 734 } |
736 } | 735 } |
737 } | 736 } |
738 | 737 |
739 GrColor color = paint.getColor(); | 738 GrColor color = paint.getColor(); |
740 SkRect devBoundRect; | 739 SkRect devBoundRect; |
741 bool needAA = paint.isAntiAlias() && !drawState.getRenderTarget()->isMultisa mpled(); | 740 bool needAA = paint.isAntiAlias() && !drawState.getRenderTarget()->isMultisa mpled(); |
742 bool doAA = needAA && apply_aa_to_rect(target, &drawState, &devBoundRect, re ct, width, matrix, | 741 bool doAA = needAA && apply_aa_to_rect(target, &drawState, &devBoundRect, re ct, width, |
743 color); | 742 viewMatrix, color); |
744 | 743 |
745 if (doAA) { | 744 if (doAA) { |
746 SkMatrix invert; | 745 SkMatrix invert; |
747 if (!drawState.getViewMatrix().invert(&invert)) { | 746 if (!viewMatrix.invert(&invert)) { |
748 return; | 747 return; |
749 } | 748 } |
750 GrDrawState::AutoViewMatrixRestore avmr(&drawState); | |
751 | 749 |
752 if (width >= 0) { | 750 if (width >= 0) { |
753 const SkStrokeRec& strokeRec = strokeInfo->getStrokeRec(); | 751 const SkStrokeRec& strokeRec = strokeInfo->getStrokeRec(); |
754 fAARectRenderer->strokeAARect(target, | 752 fAARectRenderer->strokeAARect(target, |
755 &drawState, | 753 &drawState, |
756 color, | 754 color, |
755 viewMatrix, | |
757 invert, | 756 invert, |
bsalomon
2014/12/29 20:26:58
Seems like every caller of the public drawing func
| |
758 rect, | 757 rect, |
759 matrix, | |
760 devBoundRect, | 758 devBoundRect, |
761 strokeRec); | 759 strokeRec); |
762 } else { | 760 } else { |
763 // filled AA rect | 761 // filled AA rect |
764 fAARectRenderer->fillAARect(target, &drawState, color, invert, rect, matrix, | 762 fAARectRenderer->fillAARect(target, |
763 &drawState, | |
764 color, | |
765 viewMatrix, | |
766 invert, | |
767 rect, | |
765 devBoundRect); | 768 devBoundRect); |
766 } | 769 } |
767 return; | 770 return; |
768 } | 771 } |
769 | 772 |
770 if (width >= 0) { | 773 if (width >= 0) { |
771 // TODO: consider making static vertex buffers for these cases. | 774 // TODO: consider making static vertex buffers for these cases. |
772 // Hairline could be done by just adding closing vertex to | 775 // Hairline could be done by just adding closing vertex to |
773 // unitSquareVertexBuffer() | 776 // unitSquareVertexBuffer() |
774 | 777 |
775 static const int worstCaseVertCount = 10; | 778 static const int worstCaseVertCount = 10; |
776 SkAutoTUnref<const GrGeometryProcessor> gp(GrDefaultGeoProcFactory::Crea te(color)); | 779 SkAutoTUnref<const GrGeometryProcessor> gp( |
780 GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPositi on_GPType, | |
781 color, | |
782 viewMatrix, | |
783 SkMatrix::I())); | |
777 GrDrawTarget::AutoReleaseGeometry geo(target, | 784 GrDrawTarget::AutoReleaseGeometry geo(target, |
778 worstCaseVertCount, | 785 worstCaseVertCount, |
779 gp->getVertexStride(), | 786 gp->getVertexStride(), |
780 0); | 787 0); |
781 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 788 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
782 | 789 |
783 if (!geo.succeeded()) { | 790 if (!geo.succeeded()) { |
784 SkDebugf("Failed to get space for vertices!\n"); | 791 SkDebugf("Failed to get space for vertices!\n"); |
785 return; | 792 return; |
786 } | 793 } |
(...skipping 13 matching lines...) Expand all Loading... | |
800 vertex[0].set(rect.fLeft, rect.fTop); | 807 vertex[0].set(rect.fLeft, rect.fTop); |
801 vertex[1].set(rect.fRight, rect.fTop); | 808 vertex[1].set(rect.fRight, rect.fTop); |
802 vertex[2].set(rect.fRight, rect.fBottom); | 809 vertex[2].set(rect.fRight, rect.fBottom); |
803 vertex[3].set(rect.fLeft, rect.fBottom); | 810 vertex[3].set(rect.fLeft, rect.fBottom); |
804 vertex[4].set(rect.fLeft, rect.fTop); | 811 vertex[4].set(rect.fLeft, rect.fTop); |
805 } | 812 } |
806 | 813 |
807 target->drawNonIndexed(&drawState, gp, primType, 0, vertCount); | 814 target->drawNonIndexed(&drawState, gp, primType, 0, vertCount); |
808 } else { | 815 } else { |
809 // filled BW rect | 816 // filled BW rect |
810 target->drawSimpleRect(&drawState, color, rect); | 817 target->drawSimpleRect(&drawState, color, viewMatrix, rect); |
811 } | 818 } |
812 } | 819 } |
813 | 820 |
814 void GrContext::drawNonAARectToRect(const GrPaint& paint, | 821 void GrContext::drawNonAARectToRect(const GrPaint& paint, |
815 const SkMatrix& viewMatrix, | 822 const SkMatrix& viewMatrix, |
816 const SkRect& rectToDraw, | 823 const SkRect& rectToDraw, |
817 const SkRect& localRect, | 824 const SkRect& localRect, |
818 const SkMatrix* localMatrix) { | 825 const SkMatrix* localMatrix) { |
819 AutoCheckFlush acf(this); | 826 AutoCheckFlush acf(this); |
820 GrDrawState drawState; | 827 GrDrawState drawState; |
821 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); | 828 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
822 if (NULL == target) { | 829 if (NULL == target) { |
823 return; | 830 return; |
824 } | 831 } |
825 | 832 |
826 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); | 833 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
827 | 834 |
828 target->drawRect(&drawState, paint.getColor(), rectToDraw, &localRect, local Matrix); | 835 target->drawRect(&drawState, paint.getColor(), viewMatrix, rectToDraw, &loca lRect, localMatrix); |
829 } | 836 } |
830 | 837 |
831 static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords , | 838 static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords , |
832 const GrColor* colors, | 839 const GrColor* colors, |
833 int* colorOffset, | 840 int* colorOffset, |
834 int* texOffset, | 841 int* texOffset, |
835 GrColor color) { | 842 GrColor color, |
843 const SkMatrix& viewMatr ix) { | |
836 *texOffset = -1; | 844 *texOffset = -1; |
837 *colorOffset = -1; | 845 *colorOffset = -1; |
838 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; | 846 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; |
839 if (texCoords && colors) { | 847 if (texCoords && colors) { |
840 *colorOffset = sizeof(SkPoint); | 848 *colorOffset = sizeof(SkPoint); |
841 *texOffset = sizeof(SkPoint) + sizeof(GrColor); | 849 *texOffset = sizeof(SkPoint) + sizeof(GrColor); |
842 flags |= GrDefaultGeoProcFactory::kColor_GPType | | 850 flags |= GrDefaultGeoProcFactory::kColor_GPType | |
843 GrDefaultGeoProcFactory::kLocalCoord_GPType; | 851 GrDefaultGeoProcFactory::kLocalCoord_GPType; |
844 } else if (texCoords) { | 852 } else if (texCoords) { |
845 *texOffset = sizeof(SkPoint); | 853 *texOffset = sizeof(SkPoint); |
846 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; | 854 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
847 } else if (colors) { | 855 } else if (colors) { |
848 *colorOffset = sizeof(SkPoint); | 856 *colorOffset = sizeof(SkPoint); |
849 flags |= GrDefaultGeoProcFactory::kColor_GPType; | 857 flags |= GrDefaultGeoProcFactory::kColor_GPType; |
850 } | 858 } |
851 return GrDefaultGeoProcFactory::Create(color, flags); | 859 return GrDefaultGeoProcFactory::Create(flags, color, viewMatrix, SkMatrix::I ()); |
852 } | 860 } |
853 | 861 |
854 void GrContext::drawVertices(const GrPaint& paint, | 862 void GrContext::drawVertices(const GrPaint& paint, |
855 const SkMatrix& viewMatrix, | 863 const SkMatrix& viewMatrix, |
856 GrPrimitiveType primitiveType, | 864 GrPrimitiveType primitiveType, |
857 int vertexCount, | 865 int vertexCount, |
858 const SkPoint positions[], | 866 const SkPoint positions[], |
859 const SkPoint texCoords[], | 867 const SkPoint texCoords[], |
860 const GrColor colors[], | 868 const GrColor colors[], |
861 const uint16_t indices[], | 869 const uint16_t indices[], |
862 int indexCount) { | 870 int indexCount) { |
863 AutoCheckFlush acf(this); | 871 AutoCheckFlush acf(this); |
864 GrDrawState drawState; | 872 GrDrawState drawState; |
865 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e | 873 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e |
866 | 874 |
867 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); | 875 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
868 if (NULL == target) { | 876 if (NULL == target) { |
869 return; | 877 return; |
870 } | 878 } |
871 | 879 |
872 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); | 880 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
873 | 881 |
874 int colorOffset = -1, texOffset = -1; | 882 int colorOffset = -1, texOffset = -1; |
875 SkAutoTUnref<const GrGeometryProcessor> gp( | 883 SkAutoTUnref<const GrGeometryProcessor> gp( |
876 set_vertex_attributes(texCoords, colors, &colorOffset, &texOffset, p aint.getColor())); | 884 set_vertex_attributes(texCoords, colors, &colorOffset, &texOffset, |
885 paint.getColor(), viewMatrix)); | |
877 | 886 |
878 size_t vertexStride = gp->getVertexStride(); | 887 size_t vertexStride = gp->getVertexStride(); |
879 SkASSERT(vertexStride == sizeof(SkPoint) + (SkToBool(texCoords) ? sizeof(SkP oint) : 0) | 888 SkASSERT(vertexStride == sizeof(SkPoint) + (SkToBool(texCoords) ? sizeof(SkP oint) : 0) |
880 + (SkToBool(colors) ? sizeof(GrColo r) : 0)); | 889 + (SkToBool(colors) ? sizeof(GrColo r) : 0)); |
881 if (!geo.set(target, vertexCount, vertexStride, indexCount)) { | 890 if (!geo.set(target, vertexCount, vertexStride, indexCount)) { |
882 SkDebugf("Failed to get space for vertices!\n"); | 891 SkDebugf("Failed to get space for vertices!\n"); |
883 return; | 892 return; |
884 } | 893 } |
885 void* curVertex = geo.vertices(); | 894 void* curVertex = geo.vertices(); |
886 | 895 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
921 | 930 |
922 if (strokeInfo.isDashed()) { | 931 if (strokeInfo.isDashed()) { |
923 SkPath path; | 932 SkPath path; |
924 path.addRRect(rrect); | 933 path.addRRect(rrect); |
925 this->drawPath(paint, viewMatrix, path, strokeInfo); | 934 this->drawPath(paint, viewMatrix, path, strokeInfo); |
926 return; | 935 return; |
927 } | 936 } |
928 | 937 |
929 AutoCheckFlush acf(this); | 938 AutoCheckFlush acf(this); |
930 GrDrawState drawState; | 939 GrDrawState drawState; |
931 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); | 940 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
932 if (NULL == target) { | 941 if (NULL == target) { |
933 return; | 942 return; |
934 } | 943 } |
935 | 944 |
936 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); | 945 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); |
937 | 946 |
938 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 947 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
939 | 948 |
940 GrColor color = paint.getColor(); | 949 GrColor color = paint.getColor(); |
941 if (!fOvalRenderer->drawRRect(target, &drawState, color, paint.isAntiAlias() , rrect, | 950 if (!fOvalRenderer->drawRRect(target, &drawState, color, viewMatrix, paint.i sAntiAlias(), rrect, |
942 strokeRec)) { | 951 strokeRec)) { |
943 SkPath path; | 952 SkPath path; |
944 path.addRRect(rrect); | 953 path.addRRect(rrect); |
945 this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAn tiAlias(), path, | 954 this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAn tiAlias(), path, |
946 strokeInfo); | 955 strokeInfo); |
947 } | 956 } |
948 } | 957 } |
949 | 958 |
950 /////////////////////////////////////////////////////////////////////////////// | 959 /////////////////////////////////////////////////////////////////////////////// |
951 | 960 |
952 void GrContext::drawDRRect(const GrPaint& paint, | 961 void GrContext::drawDRRect(const GrPaint& paint, |
953 const SkMatrix& viewMatrix, | 962 const SkMatrix& viewMatrix, |
954 const SkRRect& outer, | 963 const SkRRect& outer, |
955 const SkRRect& inner) { | 964 const SkRRect& inner) { |
956 if (outer.isEmpty()) { | 965 if (outer.isEmpty()) { |
957 return; | 966 return; |
958 } | 967 } |
959 | 968 |
960 AutoCheckFlush acf(this); | 969 AutoCheckFlush acf(this); |
961 GrDrawState drawState; | 970 GrDrawState drawState; |
962 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); | 971 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
963 | 972 |
964 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); | 973 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); |
965 | 974 |
966 GrColor color = paint.getColor(); | 975 GrColor color = paint.getColor(); |
967 if (!fOvalRenderer->drawDRRect(target, &drawState, color, paint.isAntiAlias( ), outer, inner)) { | 976 if (!fOvalRenderer->drawDRRect(target, &drawState, color, viewMatrix, paint. isAntiAlias(), outer, inner)) { |
968 SkPath path; | 977 SkPath path; |
969 path.addRRect(inner); | 978 path.addRRect(inner); |
970 path.addRRect(outer); | 979 path.addRRect(outer); |
971 path.setFillType(SkPath::kEvenOdd_FillType); | 980 path.setFillType(SkPath::kEvenOdd_FillType); |
972 | 981 |
973 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); | 982 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); |
974 this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAn tiAlias(), path, | 983 this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAn tiAlias(), path, |
975 fillRec); | 984 fillRec); |
976 } | 985 } |
977 } | 986 } |
(...skipping 10 matching lines...) Expand all Loading... | |
988 | 997 |
989 if (strokeInfo.isDashed()) { | 998 if (strokeInfo.isDashed()) { |
990 SkPath path; | 999 SkPath path; |
991 path.addOval(oval); | 1000 path.addOval(oval); |
992 this->drawPath(paint, viewMatrix, path, strokeInfo); | 1001 this->drawPath(paint, viewMatrix, path, strokeInfo); |
993 return; | 1002 return; |
994 } | 1003 } |
995 | 1004 |
996 AutoCheckFlush acf(this); | 1005 AutoCheckFlush acf(this); |
997 GrDrawState drawState; | 1006 GrDrawState drawState; |
998 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); | 1007 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
999 if (NULL == target) { | 1008 if (NULL == target) { |
1000 return; | 1009 return; |
1001 } | 1010 } |
1002 | 1011 |
1003 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); | 1012 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); |
1004 | 1013 |
1005 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 1014 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
1006 | 1015 |
1007 GrColor color = paint.getColor(); | 1016 GrColor color = paint.getColor(); |
1008 if (!fOvalRenderer->drawOval(target, &drawState, color, paint.isAntiAlias(), oval, strokeRec)) { | 1017 if (!fOvalRenderer->drawOval(target, &drawState, color, viewMatrix, paint.is AntiAlias(), oval, |
1018 strokeRec)) { | |
1009 SkPath path; | 1019 SkPath path; |
1010 path.addOval(oval); | 1020 path.addOval(oval); |
1011 this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAn tiAlias(), path, | 1021 this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAn tiAlias(), path, |
1012 strokeInfo); | 1022 strokeInfo); |
1013 } | 1023 } |
1014 } | 1024 } |
1015 | 1025 |
1016 // Can 'path' be drawn as a pair of filled nested rectangles? | 1026 // Can 'path' be drawn as a pair of filled nested rectangles? |
1017 static bool is_nested_rects(GrDrawTarget* target, | 1027 static bool is_nested_rects(GrDrawTarget* target, |
1018 GrDrawState* drawState, | 1028 GrDrawState* drawState, |
1019 GrColor color, | 1029 GrColor color, |
1030 const SkMatrix& viewMatrix, | |
1020 const SkPath& path, | 1031 const SkPath& path, |
1021 const SkStrokeRec& stroke, | 1032 const SkStrokeRec& stroke, |
1022 SkRect rects[2]) { | 1033 SkRect rects[2]) { |
1023 SkASSERT(stroke.isFillStyle()); | 1034 SkASSERT(stroke.isFillStyle()); |
1024 | 1035 |
1025 if (path.isInverseFillType()) { | 1036 if (path.isInverseFillType()) { |
1026 return false; | 1037 return false; |
1027 } | 1038 } |
1028 | 1039 |
1029 // TODO: this restriction could be lifted if we were willing to apply | 1040 // TODO: this restriction could be lifted if we were willing to apply |
1030 // the matrix to all the points individually rather than just to the rect | 1041 // the matrix to all the points individually rather than just to the rect |
1031 if (!drawState->getViewMatrix().preservesAxisAlignment()) { | 1042 if (!viewMatrix.preservesAxisAlignment()) { |
1032 return false; | 1043 return false; |
1033 } | 1044 } |
1034 | 1045 |
1035 if (!drawState->canTweakAlphaForCoverage() && | 1046 if (!drawState->canTweakAlphaForCoverage() && |
1036 !drawState->canUseFracCoveragePrimProc(color, *target->caps())) { | 1047 !drawState->canUseFracCoveragePrimProc(color, *target->caps())) { |
1037 return false; | 1048 return false; |
1038 } | 1049 } |
1039 | 1050 |
1040 SkPath::Direction dirs[2]; | 1051 SkPath::Direction dirs[2]; |
1041 if (!path.isNestedRects(rects, dirs)) { | 1052 if (!path.isNestedRects(rects, dirs)) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1081 } | 1092 } |
1082 return; | 1093 return; |
1083 } | 1094 } |
1084 | 1095 |
1085 GrColor color = paint.getColor(); | 1096 GrColor color = paint.getColor(); |
1086 if (strokeInfo.isDashed()) { | 1097 if (strokeInfo.isDashed()) { |
1087 SkPoint pts[2]; | 1098 SkPoint pts[2]; |
1088 if (path.isLine(pts)) { | 1099 if (path.isLine(pts)) { |
1089 AutoCheckFlush acf(this); | 1100 AutoCheckFlush acf(this); |
1090 GrDrawState drawState; | 1101 GrDrawState drawState; |
1091 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &view Matrix, &acf); | 1102 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf) ; |
1092 if (NULL == target) { | 1103 if (NULL == target) { |
1093 return; | 1104 return; |
1094 } | 1105 } |
1095 | 1106 |
1096 if (GrDashingEffect::DrawDashLine(fGpu, target, &drawState, color, p ts, paint, | 1107 if (GrDashingEffect::DrawDashLine(fGpu, target, &drawState, color, v iewMatrix, pts, |
1097 strokeInfo)) { | 1108 paint, strokeInfo)) { |
1098 return; | 1109 return; |
1099 } | 1110 } |
1100 } | 1111 } |
1101 | 1112 |
1102 // Filter dashed path into new path with the dashing applied | 1113 // Filter dashed path into new path with the dashing applied |
1103 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); | 1114 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); |
1104 SkTLazy<SkPath> effectPath; | 1115 SkTLazy<SkPath> effectPath; |
1105 GrStrokeInfo newStrokeInfo(strokeInfo, false); | 1116 GrStrokeInfo newStrokeInfo(strokeInfo, false); |
1106 SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr(); | 1117 SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr(); |
1107 if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, in fo)) { | 1118 if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, in fo)) { |
1108 this->drawPath(paint, viewMatrix, *effectPath.get(), newStrokeInfo); | 1119 this->drawPath(paint, viewMatrix, *effectPath.get(), newStrokeInfo); |
1109 return; | 1120 return; |
1110 } | 1121 } |
1111 | 1122 |
1112 this->drawPath(paint, viewMatrix, path, newStrokeInfo); | 1123 this->drawPath(paint, viewMatrix, path, newStrokeInfo); |
1113 return; | 1124 return; |
1114 } | 1125 } |
1115 | 1126 |
1116 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. | 1127 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. |
1117 // Scratch textures can be recycled after they are returned to the texture | 1128 // Scratch textures can be recycled after they are returned to the texture |
1118 // cache. This presents a potential hazard for buffered drawing. However, | 1129 // cache. This presents a potential hazard for buffered drawing. However, |
1119 // the writePixels that uploads to the scratch will perform a flush so we're | 1130 // the writePixels that uploads to the scratch will perform a flush so we're |
1120 // OK. | 1131 // OK. |
1121 AutoCheckFlush acf(this); | 1132 AutoCheckFlush acf(this); |
1122 GrDrawState drawState; | 1133 GrDrawState drawState; |
1123 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); | 1134 GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
1124 if (NULL == target) { | 1135 if (NULL == target) { |
1125 return; | 1136 return; |
1126 } | 1137 } |
1127 | 1138 |
1128 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC onvex()); | 1139 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC onvex()); |
1129 | 1140 |
1130 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); | 1141 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
1131 | 1142 |
1132 bool useCoverageAA = paint.isAntiAlias() && !drawState.getRenderTarget()->is Multisampled(); | 1143 bool useCoverageAA = paint.isAntiAlias() && !drawState.getRenderTarget()->is Multisampled(); |
1133 | 1144 |
1134 if (useCoverageAA && strokeRec.getWidth() < 0 && !path.isConvex()) { | 1145 if (useCoverageAA && strokeRec.getWidth() < 0 && !path.isConvex()) { |
1135 // Concave AA paths are expensive - try to avoid them for special cases | 1146 // Concave AA paths are expensive - try to avoid them for special cases |
1136 SkRect rects[2]; | 1147 SkRect rects[2]; |
1137 | 1148 |
1138 if (is_nested_rects(target, &drawState, color, path, strokeRec, rects)) { | 1149 if (is_nested_rects(target, &drawState, color, viewMatrix, path, strokeR ec, rects)) { |
1139 SkMatrix origViewMatrix = drawState.getViewMatrix(); | |
1140 | |
1141 SkMatrix invert; | 1150 SkMatrix invert; |
1142 if (!drawState.getViewMatrix().invert(&invert)) { | 1151 if (!viewMatrix.invert(&invert)) { |
1143 return; | 1152 return; |
1144 } | 1153 } |
1145 GrDrawState::AutoViewMatrixRestore avmr(&drawState); | |
1146 | 1154 |
1147 fAARectRenderer->fillAANestedRects(target, &drawState, color, invert , rects, | 1155 fAARectRenderer->fillAANestedRects(target, &drawState, color, viewMa trix, invert,rects); |
1148 origViewMatrix); | |
1149 return; | 1156 return; |
1150 } | 1157 } |
1151 } | 1158 } |
1152 | 1159 |
1153 SkRect ovalRect; | 1160 SkRect ovalRect; |
1154 bool isOval = path.isOval(&ovalRect); | 1161 bool isOval = path.isOval(&ovalRect); |
1155 | 1162 |
1156 if (!isOval || path.isInverseFillType() | 1163 if (!isOval || path.isInverseFillType() || |
1157 || !fOvalRenderer->drawOval(target, &drawState, color, paint.isAntiAlias (), ovalRect, | 1164 !fOvalRenderer->drawOval(target, &drawState, color, viewMatrix, paint.is AntiAlias(), |
1158 strokeRec)) { | 1165 ovalRect, strokeRec)) { |
1159 this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAn tiAlias(), path, | 1166 this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAn tiAlias(), path, |
1160 strokeInfo); | 1167 strokeInfo); |
1161 } | 1168 } |
1162 } | 1169 } |
1163 | 1170 |
1164 void GrContext::internalDrawPath(GrDrawTarget* target, | 1171 void GrContext::internalDrawPath(GrDrawTarget* target, |
1165 GrDrawState* drawState, | 1172 GrDrawState* drawState, |
1166 const SkMatrix& viewMatrix, | 1173 const SkMatrix& viewMatrix, |
1167 GrColor color, | 1174 GrColor color, |
1168 bool useAA, | 1175 bool useAA, |
(...skipping 15 matching lines...) Expand all Loading... | |
1184 | 1191 |
1185 GrPathRendererChain::DrawType type = | 1192 GrPathRendererChain::DrawType type = |
1186 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : | 1193 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : |
1187 GrPathRendererChain::kColor_DrawType; | 1194 GrPathRendererChain::kColor_DrawType; |
1188 | 1195 |
1189 const SkPath* pathPtr = &path; | 1196 const SkPath* pathPtr = &path; |
1190 SkTLazy<SkPath> tmpPath; | 1197 SkTLazy<SkPath> tmpPath; |
1191 SkTCopyOnFirstWrite<SkStrokeRec> stroke(strokeInfo.getStrokeRec()); | 1198 SkTCopyOnFirstWrite<SkStrokeRec> stroke(strokeInfo.getStrokeRec()); |
1192 | 1199 |
1193 // Try a 1st time without stroking the path and without allowing the SW rend erer | 1200 // Try a 1st time without stroking the path and without allowing the SW rend erer |
1194 GrPathRenderer* pr = this->getPathRenderer(target, drawState, *pathPtr, *str oke, false, type); | 1201 GrPathRenderer* pr = this->getPathRenderer(target, drawState, viewMatrix, *p athPtr, *stroke, |
1202 false, type); | |
1195 | 1203 |
1196 if (NULL == pr) { | 1204 if (NULL == pr) { |
1197 if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*stroke, viewMatrix, N ULL)) { | 1205 if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*stroke, viewMatrix, N ULL)) { |
1198 // It didn't work the 1st time, so try again with the stroked path | 1206 // It didn't work the 1st time, so try again with the stroked path |
1199 if (stroke->applyToPath(tmpPath.init(), *pathPtr)) { | 1207 if (stroke->applyToPath(tmpPath.init(), *pathPtr)) { |
1200 pathPtr = tmpPath.get(); | 1208 pathPtr = tmpPath.get(); |
1201 stroke.writable()->setFillStyle(); | 1209 stroke.writable()->setFillStyle(); |
1202 if (pathPtr->isEmpty()) { | 1210 if (pathPtr->isEmpty()) { |
1203 return; | 1211 return; |
1204 } | 1212 } |
1205 } | 1213 } |
1206 } | 1214 } |
1207 | 1215 |
1208 // This time, allow SW renderer | 1216 // This time, allow SW renderer |
1209 pr = this->getPathRenderer(target, drawState, *pathPtr, *stroke, true, t ype); | 1217 pr = this->getPathRenderer(target, drawState, viewMatrix, *pathPtr, *str oke, true, type); |
1210 } | 1218 } |
1211 | 1219 |
1212 if (NULL == pr) { | 1220 if (NULL == pr) { |
1213 #ifdef SK_DEBUG | 1221 #ifdef SK_DEBUG |
1214 SkDebugf("Unable to find path renderer compatible with path.\n"); | 1222 SkDebugf("Unable to find path renderer compatible with path.\n"); |
1215 #endif | 1223 #endif |
1216 return; | 1224 return; |
1217 } | 1225 } |
1218 | 1226 |
1219 pr->drawPath(target, drawState, color, *pathPtr, *stroke, useCoverageAA); | 1227 pr->drawPath(target, drawState, color, viewMatrix, *pathPtr, *stroke, useCov erageAA); |
1220 } | 1228 } |
1221 | 1229 |
1222 //////////////////////////////////////////////////////////////////////////////// | 1230 //////////////////////////////////////////////////////////////////////////////// |
1223 | 1231 |
1224 void GrContext::flush(int flagsBitfield) { | 1232 void GrContext::flush(int flagsBitfield) { |
1225 if (NULL == fDrawBuffer) { | 1233 if (NULL == fDrawBuffer) { |
1226 return; | 1234 return; |
1227 } | 1235 } |
1228 | 1236 |
1229 if (kDiscard_FlushBit & flagsBitfield) { | 1237 if (kDiscard_FlushBit & flagsBitfield) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1344 } | 1352 } |
1345 | 1353 |
1346 SkMatrix matrix; | 1354 SkMatrix matrix; |
1347 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 1355 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
1348 | 1356 |
1349 // This function can be called in the midst of drawing another object (e.g., when uploading a | 1357 // This function can be called in the midst of drawing another object (e.g., when uploading a |
1350 // SW-rasterized clip while issuing a draw). So we push the current geometry state before | 1358 // SW-rasterized clip while issuing a draw). So we push the current geometry state before |
1351 // drawing a rect to the render target. | 1359 // drawing a rect to the render target. |
1352 // The bracket ensures we pop the stack if we wind up flushing below. | 1360 // The bracket ensures we pop the stack if we wind up flushing below. |
1353 { | 1361 { |
1354 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL, NULL); | 1362 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL); |
1355 GrDrawTarget::AutoGeometryPush agp(drawTarget); | 1363 GrDrawTarget::AutoGeometryPush agp(drawTarget); |
1356 | 1364 |
1357 GrDrawState drawState(matrix); | 1365 GrDrawState drawState; |
1358 drawState.addColorProcessor(fp); | 1366 drawState.addColorProcessor(fp); |
1359 drawState.setRenderTarget(renderTarget); | 1367 drawState.setRenderTarget(renderTarget); |
1360 drawTarget->drawSimpleRect(&drawState, GrColor_WHITE,SkRect::MakeWH(SkIn tToScalar(width), | 1368 drawTarget->drawSimpleRect(&drawState, GrColor_WHITE, matrix, |
1361 SkIn tToScalar(height))); | 1369 SkRect::MakeWH(SkIntToScalar(width), SkIntToS calar(height))); |
1362 } | 1370 } |
1363 | 1371 |
1364 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 1372 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
1365 this->flushSurfaceWrites(surface); | 1373 this->flushSurfaceWrites(surface); |
1366 } | 1374 } |
1367 | 1375 |
1368 return true; | 1376 return true; |
1369 } | 1377 } |
1370 | 1378 |
1371 // toggles between RGBA and BGRA | 1379 // toggles between RGBA and BGRA |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1472 // clear to the caller that a draw operation (i.e., drawSimpleRe ct) | 1480 // clear to the caller that a draw operation (i.e., drawSimpleRe ct) |
1473 // can be invoked in this method | 1481 // can be invoked in this method |
1474 { | 1482 { |
1475 GrDrawTarget::AutoGeometryPush agp(fDrawBuffer); | 1483 GrDrawTarget::AutoGeometryPush agp(fDrawBuffer); |
1476 GrDrawState drawState; | 1484 GrDrawState drawState; |
1477 SkASSERT(fp); | 1485 SkASSERT(fp); |
1478 drawState.addColorProcessor(fp); | 1486 drawState.addColorProcessor(fp); |
1479 | 1487 |
1480 drawState.setRenderTarget(tempTexture->asRenderTarget()); | 1488 drawState.setRenderTarget(tempTexture->asRenderTarget()); |
1481 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToSc alar(height)); | 1489 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToSc alar(height)); |
1482 fDrawBuffer->drawSimpleRect(&drawState, GrColor_WHITE, rect) ; | 1490 fDrawBuffer->drawSimpleRect(&drawState, GrColor_WHITE, SkMat rix::I(), rect); |
1483 // we want to read back from the scratch's origin | 1491 // we want to read back from the scratch's origin |
1484 left = 0; | 1492 left = 0; |
1485 top = 0; | 1493 top = 0; |
1486 target = tempTexture->asRenderTarget(); | 1494 target = tempTexture->asRenderTarget(); |
1487 } | 1495 } |
1488 this->flushSurfaceWrites(target); | 1496 this->flushSurfaceWrites(target); |
1489 } | 1497 } |
1490 } | 1498 } |
1491 } | 1499 } |
1492 | 1500 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1525 GrRenderTarget* rt = surface->asRenderTarget(); | 1533 GrRenderTarget* rt = surface->asRenderTarget(); |
1526 if (fGpu && rt) { | 1534 if (fGpu && rt) { |
1527 fGpu->resolveRenderTarget(rt); | 1535 fGpu->resolveRenderTarget(rt); |
1528 } | 1536 } |
1529 } | 1537 } |
1530 | 1538 |
1531 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { | 1539 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { |
1532 SkASSERT(renderTarget); | 1540 SkASSERT(renderTarget); |
1533 ASSERT_OWNED_RESOURCE(renderTarget); | 1541 ASSERT_OWNED_RESOURCE(renderTarget); |
1534 AutoCheckFlush acf(this); | 1542 AutoCheckFlush acf(this); |
1535 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, &acf); | 1543 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, &acf); |
1536 if (NULL == target) { | 1544 if (NULL == target) { |
1537 return; | 1545 return; |
1538 } | 1546 } |
1539 target->discard(renderTarget); | 1547 target->discard(renderTarget); |
1540 } | 1548 } |
1541 | 1549 |
1542 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe ct, | 1550 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe ct, |
1543 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { | 1551 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { |
1544 if (NULL == src || NULL == dst) { | 1552 if (NULL == src || NULL == dst) { |
1545 return; | 1553 return; |
1546 } | 1554 } |
1547 ASSERT_OWNED_RESOURCE(src); | 1555 ASSERT_OWNED_RESOURCE(src); |
1548 ASSERT_OWNED_RESOURCE(dst); | 1556 ASSERT_OWNED_RESOURCE(dst); |
1549 | 1557 |
1550 // Since we're going to the draw target and not GPU, no need to check kNoFlu sh | 1558 // Since we're going to the draw target and not GPU, no need to check kNoFlu sh |
1551 // here. | 1559 // here. |
1552 | 1560 |
1553 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, NULL); | 1561 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL); |
1554 if (NULL == target) { | 1562 if (NULL == target) { |
1555 return; | 1563 return; |
1556 } | 1564 } |
1557 target->copySurface(dst, src, srcRect, dstPoint); | 1565 target->copySurface(dst, src, srcRect, dstPoint); |
1558 | 1566 |
1559 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 1567 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
1560 this->flush(); | 1568 this->flush(); |
1561 } | 1569 } |
1562 } | 1570 } |
1563 | 1571 |
1564 void GrContext::flushSurfaceWrites(GrSurface* surface) { | 1572 void GrContext::flushSurfaceWrites(GrSurface* surface) { |
1565 if (surface->surfacePriv().hasPendingWrite()) { | 1573 if (surface->surfacePriv().hasPendingWrite()) { |
1566 this->flush(); | 1574 this->flush(); |
1567 } | 1575 } |
1568 } | 1576 } |
1569 | 1577 |
1570 GrDrawTarget* GrContext::prepareToDraw(GrDrawState* ds, | 1578 GrDrawTarget* GrContext::prepareToDraw(GrDrawState* ds, |
1571 const GrPaint* paint, | 1579 const GrPaint* paint, |
1572 const SkMatrix* viewMatrix, | |
1573 const AutoCheckFlush* acf) { | 1580 const AutoCheckFlush* acf) { |
1574 if (NULL == fGpu) { | 1581 if (NULL == fGpu) { |
1575 return NULL; | 1582 return NULL; |
1576 } | 1583 } |
1577 | 1584 |
1578 ASSERT_OWNED_RESOURCE(fRenderTarget.get()); | 1585 ASSERT_OWNED_RESOURCE(fRenderTarget.get()); |
1579 if (ds) { | 1586 if (ds) { |
1580 SkASSERT(viewMatrix); | |
1581 if (paint) { | 1587 if (paint) { |
1582 SkASSERT(acf); | 1588 SkASSERT(acf); |
1583 ds->setFromPaint(*paint, *viewMatrix, fRenderTarget.get()); | 1589 ds->setFromPaint(*paint, fRenderTarget.get()); |
1584 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK | 1590 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK |
1585 if ((paint->hasMask()) && | 1591 if ((paint->hasMask()) && |
1586 !fDrawState->canUseFracCoveragePrimProc(paint.getColor(), fGpu-> caps())) { | 1592 !fDrawState->canUseFracCoveragePrimProc(paint.getColor(), fGpu-> caps())) { |
1587 SkDebugf("Partial pixel coverage will be incorrectly blended.\n" ); | 1593 SkDebugf("Partial pixel coverage will be incorrectly blended.\n" ); |
1588 } | 1594 } |
1589 #endif | 1595 #endif |
1590 } else { | 1596 } else { |
1591 ds->reset(*viewMatrix); | 1597 ds->reset(); |
1592 ds->setRenderTarget(fRenderTarget.get()); | 1598 ds->setRenderTarget(fRenderTarget.get()); |
1593 } | 1599 } |
1594 ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->i sWideOpen()); | 1600 ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->i sWideOpen()); |
1595 } | 1601 } |
1596 fDrawBuffer->setClip(fClip); | 1602 fDrawBuffer->setClip(fClip); |
1597 return fDrawBuffer; | 1603 return fDrawBuffer; |
1598 } | 1604 } |
1599 | 1605 |
1600 /* | 1606 /* |
1601 * This method finds a path renderer that can draw the specified path on | 1607 * This method finds a path renderer that can draw the specified path on |
1602 * the provided target. | 1608 * the provided target. |
1603 * Due to its expense, the software path renderer has split out so it can | 1609 * Due to its expense, the software path renderer has split out so it can |
1604 * can be individually allowed/disallowed via the "allowSW" boolean. | 1610 * can be individually allowed/disallowed via the "allowSW" boolean. |
1605 */ | 1611 */ |
1606 GrPathRenderer* GrContext::getPathRenderer(const GrDrawTarget* target, | 1612 GrPathRenderer* GrContext::getPathRenderer(const GrDrawTarget* target, |
1607 const GrDrawState* drawState, | 1613 const GrDrawState* drawState, |
1614 const SkMatrix& viewMatrix, | |
1608 const SkPath& path, | 1615 const SkPath& path, |
1609 const SkStrokeRec& stroke, | 1616 const SkStrokeRec& stroke, |
1610 bool allowSW, | 1617 bool allowSW, |
1611 GrPathRendererChain::DrawType drawTyp e, | 1618 GrPathRendererChain::DrawType drawTyp e, |
1612 GrPathRendererChain::StencilSupport* stencilSupport) { | 1619 GrPathRendererChain::StencilSupport* stencilSupport) { |
1613 | 1620 |
1614 if (NULL == fPathRendererChain) { | 1621 if (NULL == fPathRendererChain) { |
1615 fPathRendererChain = SkNEW_ARGS(GrPathRendererChain, (this)); | 1622 fPathRendererChain = SkNEW_ARGS(GrPathRendererChain, (this)); |
1616 } | 1623 } |
1617 | 1624 |
1618 GrPathRenderer* pr = fPathRendererChain->getPathRenderer(target, | 1625 GrPathRenderer* pr = fPathRendererChain->getPathRenderer(target, |
1619 drawState, | 1626 drawState, |
1627 viewMatrix, | |
1620 path, | 1628 path, |
1621 stroke, | 1629 stroke, |
1622 drawType, | 1630 drawType, |
1623 stencilSupport); | 1631 stencilSupport); |
1624 | 1632 |
1625 if (NULL == pr && allowSW) { | 1633 if (NULL == pr && allowSW) { |
1626 if (NULL == fSoftwarePathRenderer) { | 1634 if (NULL == fSoftwarePathRenderer) { |
1627 fSoftwarePathRenderer = SkNEW_ARGS(GrSoftwarePathRenderer, (this)); | 1635 fSoftwarePathRenderer = SkNEW_ARGS(GrSoftwarePathRenderer, (this)); |
1628 } | 1636 } |
1629 pr = fSoftwarePathRenderer; | 1637 pr = fSoftwarePathRenderer; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1667 SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, false, | 1675 SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, false, |
1668 DRAW_BUFFER_IBPOOL_BUFFER_SIZE, | 1676 DRAW_BUFFER_IBPOOL_BUFFER_SIZE, |
1669 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); | 1677 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); |
1670 | 1678 |
1671 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, | 1679 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, |
1672 fDrawBufferVBAllocPool, | 1680 fDrawBufferVBAllocPool, |
1673 fDrawBufferIBAllocPool)); | 1681 fDrawBufferIBAllocPool)); |
1674 } | 1682 } |
1675 | 1683 |
1676 GrDrawTarget* GrContext::getTextTarget() { | 1684 GrDrawTarget* GrContext::getTextTarget() { |
1677 return this->prepareToDraw(NULL, NULL, NULL, NULL); | 1685 return this->prepareToDraw(NULL, NULL, NULL); |
1678 } | 1686 } |
1679 | 1687 |
1680 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { | 1688 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { |
1681 return fGpu->getQuadIndexBuffer(); | 1689 return fGpu->getQuadIndexBuffer(); |
1682 } | 1690 } |
1683 | 1691 |
1684 namespace { | 1692 namespace { |
1685 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { | 1693 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
1686 GrConfigConversionEffect::PMConversion pmToUPM; | 1694 GrConfigConversionEffect::PMConversion pmToUPM; |
1687 GrConfigConversionEffect::PMConversion upmToPM; | 1695 GrConfigConversionEffect::PMConversion upmToPM; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1751 fResourceCache2->printStats(); | 1759 fResourceCache2->printStats(); |
1752 } | 1760 } |
1753 #endif | 1761 #endif |
1754 | 1762 |
1755 #if GR_GPU_STATS | 1763 #if GR_GPU_STATS |
1756 const GrContext::GPUStats* GrContext::gpuStats() const { | 1764 const GrContext::GPUStats* GrContext::gpuStats() const { |
1757 return fGpu->gpuStats(); | 1765 return fGpu->gpuStats(); |
1758 } | 1766 } |
1759 #endif | 1767 #endif |
1760 | 1768 |
OLD | NEW |