| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrAAHairLinePathRenderer.h" | 8 #include "GrAAHairLinePathRenderer.h" |
| 9 | 9 |
| 10 #include "GrBatchTarget.h" | 10 #include "GrBatchTarget.h" |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 actualBounds.growToInclude(pos.fX, pos.fY); | 663 actualBounds.growToInclude(pos.fX, pos.fY); |
| 664 } | 664 } |
| 665 } | 665 } |
| 666 if (!first) { | 666 if (!first) { |
| 667 return tolDevBounds.contains(actualBounds); | 667 return tolDevBounds.contains(actualBounds); |
| 668 } | 668 } |
| 669 | 669 |
| 670 return true; | 670 return true; |
| 671 } | 671 } |
| 672 | 672 |
| 673 class AAHairlineBatch : public GrBatch { | 673 class AAHairlineBatch : public GrVertexBatch { |
| 674 public: | 674 public: |
| 675 struct Geometry { | 675 struct Geometry { |
| 676 GrColor fColor; | 676 GrColor fColor; |
| 677 uint8_t fCoverage; | 677 uint8_t fCoverage; |
| 678 SkMatrix fViewMatrix; | 678 SkMatrix fViewMatrix; |
| 679 SkPath fPath; | 679 SkPath fPath; |
| 680 SkIRect fDevClipBounds; | 680 SkIRect fDevClipBounds; |
| 681 }; | 681 }; |
| 682 | 682 |
| 683 static GrBatch* Create(const Geometry& geometry) { | 683 static GrDrawBatch* Create(const Geometry& geometry) { |
| 684 return SkNEW_ARGS(AAHairlineBatch, (geometry)); | 684 return SkNEW_ARGS(AAHairlineBatch, (geometry)); |
| 685 } | 685 } |
| 686 | 686 |
| 687 const char* name() const override { return "AAHairlineBatch"; } | 687 const char* name() const override { return "AAHairlineBatch"; } |
| 688 | 688 |
| 689 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 689 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
| 690 // When this is called on a batch, there is only one geometry bundle | 690 // When this is called on a batch, there is only one geometry bundle |
| 691 out->setKnownFourComponents(fGeoData[0].fColor); | 691 out->setKnownFourComponents(fGeoData[0].fColor); |
| 692 } | 692 } |
| 693 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 693 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 // compute bounds | 725 // compute bounds |
| 726 fBounds = geometry.fPath.getBounds(); | 726 fBounds = geometry.fPath.getBounds(); |
| 727 geometry.fViewMatrix.mapRect(&fBounds); | 727 geometry.fViewMatrix.mapRect(&fBounds); |
| 728 | 728 |
| 729 // This is b.c. hairlines are notionally infinitely thin so without expa
nsion | 729 // This is b.c. hairlines are notionally infinitely thin so without expa
nsion |
| 730 // two overlapping lines could be reordered even though they hit the sam
e pixels. | 730 // two overlapping lines could be reordered even though they hit the sam
e pixels. |
| 731 fBounds.outset(0.5f, 0.5f); | 731 fBounds.outset(0.5f, 0.5f); |
| 732 } | 732 } |
| 733 | 733 |
| 734 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 734 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
| 735 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipel
ine(), t->bounds(), | 735 AAHairlineBatch* that = t->cast<AAHairlineBatch>(); |
| 736 caps)) { | 736 |
| 737 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
| 738 that->bounds(), caps)) { |
| 737 return false; | 739 return false; |
| 738 } | 740 } |
| 739 | 741 |
| 740 AAHairlineBatch* that = t->cast<AAHairlineBatch>(); | |
| 741 | |
| 742 if (this->viewMatrix().hasPerspective() != that->viewMatrix().hasPerspec
tive()) { | 742 if (this->viewMatrix().hasPerspective() != that->viewMatrix().hasPerspec
tive()) { |
| 743 return false; | 743 return false; |
| 744 } | 744 } |
| 745 | 745 |
| 746 // We go to identity if we don't have perspective | 746 // We go to identity if we don't have perspective |
| 747 if (this->viewMatrix().hasPerspective() && | 747 if (this->viewMatrix().hasPerspective() && |
| 748 !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { | 748 !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 749 return false; | 749 return false; |
| 750 } | 750 } |
| 751 | 751 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 GrVertices verts; | 943 GrVertices verts; |
| 944 verts.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, qu
adsIndexBuffer, | 944 verts.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, qu
adsIndexBuffer, |
| 945 firstVertex, kQuadNumVertices, kIdxsPerQuad,
conicCount, | 945 firstVertex, kQuadNumVertices, kIdxsPerQuad,
conicCount, |
| 946 kQuadsNumInIdxBuffer); | 946 kQuadsNumInIdxBuffer); |
| 947 batchTarget->draw(verts); | 947 batchTarget->draw(verts); |
| 948 } | 948 } |
| 949 } | 949 } |
| 950 } | 950 } |
| 951 } | 951 } |
| 952 | 952 |
| 953 static GrBatch* create_hairline_batch(GrColor color, | 953 static GrDrawBatch* create_hairline_batch(GrColor color, |
| 954 const SkMatrix& viewMatrix, | 954 const SkMatrix& viewMatrix, |
| 955 const SkPath& path, | 955 const SkPath& path, |
| 956 const GrStrokeInfo& stroke, | 956 const GrStrokeInfo& stroke, |
| 957 const SkIRect& devClipBounds) { | 957 const SkIRect& devClipBounds) { |
| 958 SkScalar hairlineCoverage; | 958 SkScalar hairlineCoverage; |
| 959 uint8_t newCoverage = 0xff; | 959 uint8_t newCoverage = 0xff; |
| 960 if (GrPathRenderer::IsStrokeHairlineOrEquivalent(stroke, viewMatrix, &hairli
neCoverage)) { | 960 if (GrPathRenderer::IsStrokeHairlineOrEquivalent(stroke, viewMatrix, &hairli
neCoverage)) { |
| 961 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); | 961 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
| 962 } | 962 } |
| 963 | 963 |
| 964 AAHairlineBatch::Geometry geometry; | 964 AAHairlineBatch::Geometry geometry; |
| 965 geometry.fColor = color; | 965 geometry.fColor = color; |
| 966 geometry.fCoverage = newCoverage; | 966 geometry.fCoverage = newCoverage; |
| 967 geometry.fViewMatrix = viewMatrix; | 967 geometry.fViewMatrix = viewMatrix; |
| 968 geometry.fPath = path; | 968 geometry.fPath = path; |
| 969 geometry.fDevClipBounds = devClipBounds; | 969 geometry.fDevClipBounds = devClipBounds; |
| 970 | 970 |
| 971 return AAHairlineBatch::Create(geometry); | 971 return AAHairlineBatch::Create(geometry); |
| 972 } | 972 } |
| 973 | 973 |
| 974 bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) { | 974 bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) { |
| 975 SkIRect devClipBounds; | 975 SkIRect devClipBounds; |
| 976 args.fPipelineBuilder->clip().getConservativeBounds(args.fPipelineBuilder->g
etRenderTarget(), | 976 args.fPipelineBuilder->clip().getConservativeBounds(args.fPipelineBuilder->g
etRenderTarget(), |
| 977 &devClipBounds); | 977 &devClipBounds); |
| 978 | 978 |
| 979 SkAutoTUnref<GrBatch> batch(create_hairline_batch(args.fColor, *args.fViewMa
trix, *args.fPath, | 979 SkAutoTUnref<GrDrawBatch> batch(create_hairline_batch(args.fColor, *args.fVi
ewMatrix, *args.fPath, |
| 980 *args.fStroke, devClipBoun
ds)); | 980 *args.fStroke, devClip
Bounds)); |
| 981 args.fTarget->drawBatch(*args.fPipelineBuilder, batch); | 981 args.fTarget->drawBatch(*args.fPipelineBuilder, batch); |
| 982 | 982 |
| 983 return true; | 983 return true; |
| 984 } | 984 } |
| 985 | 985 |
| 986 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 986 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 987 | 987 |
| 988 #ifdef GR_TEST_UTILS | 988 #ifdef GR_TEST_UTILS |
| 989 | 989 |
| 990 BATCH_TEST_DEFINE(AAHairlineBatch) { | 990 DRAW_BATCH_TEST_DEFINE(AAHairlineBatch) { |
| 991 GrColor color = GrRandomColor(random); | 991 GrColor color = GrRandomColor(random); |
| 992 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 992 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 993 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); | 993 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); |
| 994 SkPath path = GrTest::TestPath(random); | 994 SkPath path = GrTest::TestPath(random); |
| 995 SkIRect devClipBounds; | 995 SkIRect devClipBounds; |
| 996 devClipBounds.setEmpty(); | 996 devClipBounds.setEmpty(); |
| 997 return create_hairline_batch(color, viewMatrix, path, stroke, devClipBounds)
; | 997 return create_hairline_batch(color, viewMatrix, path, stroke, devClipBounds)
; |
| 998 } | 998 } |
| 999 | 999 |
| 1000 #endif | 1000 #endif |
| OLD | NEW |