Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: src/gpu/GrAAConvexPathRenderer.cpp

Issue 1130883003: Enable GrAAConvexTessellator in GrAAConvexPathRenderer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Cleanup Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/skia_for_chromium_defines.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 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 "GrAAConvexPathRenderer.h" 9 #include "GrAAConvexPathRenderer.h"
10 10
11 #include "GrAAConvexTessellator.h"
11 #include "GrBatch.h" 12 #include "GrBatch.h"
12 #include "GrBatchTarget.h" 13 #include "GrBatchTarget.h"
13 #include "GrContext.h" 14 #include "GrContext.h"
15 #include "GrDefaultGeoProcFactory.h"
14 #include "GrDrawTargetCaps.h" 16 #include "GrDrawTargetCaps.h"
15 #include "GrGeometryProcessor.h" 17 #include "GrGeometryProcessor.h"
16 #include "GrInvariantOutput.h" 18 #include "GrInvariantOutput.h"
17 #include "GrPathUtils.h" 19 #include "GrPathUtils.h"
18 #include "GrProcessor.h" 20 #include "GrProcessor.h"
19 #include "GrPipelineBuilder.h" 21 #include "GrPipelineBuilder.h"
20 #include "GrStrokeInfo.h" 22 #include "GrStrokeInfo.h"
21 #include "SkGeometry.h" 23 #include "SkGeometry.h"
22 #include "SkString.h" 24 #include "SkString.h"
23 #include "SkTraceEvent.h" 25 #include "SkTraceEvent.h"
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 bool GrAAConvexPathRenderer::canDrawPath(const GrDrawTarget* target, 698 bool GrAAConvexPathRenderer::canDrawPath(const GrDrawTarget* target,
697 const GrPipelineBuilder*, 699 const GrPipelineBuilder*,
698 const SkMatrix& viewMatrix, 700 const SkMatrix& viewMatrix,
699 const SkPath& path, 701 const SkPath& path,
700 const GrStrokeInfo& stroke, 702 const GrStrokeInfo& stroke,
701 bool antiAlias) const { 703 bool antiAlias) const {
702 return (target->caps()->shaderCaps()->shaderDerivativeSupport() && antiAlias && 704 return (target->caps()->shaderCaps()->shaderDerivativeSupport() && antiAlias &&
703 stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex() ); 705 stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex() );
704 } 706 }
705 707
708 // extract the result vertices and indices from the GrAAConvexTessellator
709 static void extract_verts(const GrAAConvexTessellator& tess,
710 void* vertices,
711 size_t vertexStride,
712 GrColor color,
713 uint16_t* idxs,
714 bool tweakAlphaForCoverage) {
715 intptr_t verts = reinterpret_cast<intptr_t>(vertices);
716
717 for (int i = 0; i < tess.numPts(); ++i) {
718 *((SkPoint*)((intptr_t)verts + i * vertexStride)) = tess.point(i);
719 }
720
721 // Make 'verts' point to the colors
722 verts += sizeof(SkPoint);
723 for (int i = 0; i < tess.numPts(); ++i) {
724 SkASSERT(tess.depth(i) >= -0.5f && tess.depth(i) <= 0.5f);
725 if (tweakAlphaForCoverage) {
726 SkASSERT(SkScalarRoundToInt(255.0f * (tess.depth(i) + 0.5f)) <= 255) ;
727 unsigned scale = SkScalarRoundToInt(255.0f * (tess.depth(i) + 0.5f)) ;
728 GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, s cale);
729 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor;
730 } else {
731 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color;
732 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor) ) =
733 tess.depth(i ) + 0.5f;
734 }
735 }
736
737 for (int i = 0; i < tess.numIndices(); ++i) {
738 idxs[i] = tess.index(i);
739 }
740 }
741
742 static const GrGeometryProcessor* create_fill_gp(bool tweakAlphaForCoverage,
743 const SkMatrix& localMatrix) {
744 uint32_t flags = GrDefaultGeoProcFactory::kColor_GPType;
745 if (!tweakAlphaForCoverage) {
746 flags |= GrDefaultGeoProcFactory::kCoverage_GPType;
747 }
748
749 return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, SkMatrix::I(), localMatrix,
750 false, 0xff);
751 }
752
706 class AAConvexPathBatch : public GrBatch { 753 class AAConvexPathBatch : public GrBatch {
707 public: 754 public:
708 struct Geometry { 755 struct Geometry {
709 GrColor fColor; 756 GrColor fColor;
710 SkMatrix fViewMatrix; 757 SkMatrix fViewMatrix;
711 SkPath fPath; 758 SkPath fPath;
712 }; 759 };
713 760
714 static GrBatch* Create(const Geometry& geometry) { 761 static GrBatch* Create(const Geometry& geometry) {
715 return SkNEW_ARGS(AAConvexPathBatch, (geometry)); 762 return SkNEW_ARGS(AAConvexPathBatch, (geometry));
(...skipping 15 matching lines...) Expand all
731 fGeoData[0].fColor = GrColor_ILLEGAL; 778 fGeoData[0].fColor = GrColor_ILLEGAL;
732 } else if (GrColor_ILLEGAL != init.fOverrideColor) { 779 } else if (GrColor_ILLEGAL != init.fOverrideColor) {
733 fGeoData[0].fColor = init.fOverrideColor; 780 fGeoData[0].fColor = init.fOverrideColor;
734 } 781 }
735 782
736 // setup batch properties 783 // setup batch properties
737 fBatch.fColorIgnored = init.fColorIgnored; 784 fBatch.fColorIgnored = init.fColorIgnored;
738 fBatch.fColor = fGeoData[0].fColor; 785 fBatch.fColor = fGeoData[0].fColor;
739 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; 786 fBatch.fUsesLocalCoords = init.fUsesLocalCoords;
740 fBatch.fCoverageIgnored = init.fCoverageIgnored; 787 fBatch.fCoverageIgnored = init.fCoverageIgnored;
788 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe gmentMasks();
789 fBatch.fCanTweakAlphaForCoverage = init.fCanTweakAlphaForCoverage;
790 }
791
792 void generateGeometryLinesOnly(GrBatchTarget* batchTarget, const GrPipeline* pipeline) {
793 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
794
795 SkMatrix invert;
796 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
797 SkDebugf("Could not invert viewmatrix\n");
798 return;
799 }
800
801 // Setup GrGeometryProcessor
802 SkAutoTUnref<const GrGeometryProcessor> gp(
803 create_fill_gp(canTweakAlphaForC overage, invert));
804
805 batchTarget->initDraw(gp, pipeline);
806
807 // TODO remove this when batch is everywhere
808 GrPipelineInfo init;
809 init.fColorIgnored = fBatch.fColorIgnored;
810 init.fOverrideColor = GrColor_ILLEGAL;
811 init.fCoverageIgnored = fBatch.fCoverageIgnored;
812 init.fUsesLocalCoords = this->usesLocalCoords();
813 gp->initBatchTracker(batchTarget->currentBatchTracker(), init);
814
815 size_t vertexStride = gp->getVertexStride();
816
817 SkASSERT(canTweakAlphaForCoverage ?
818 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) :
819 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr));
820
821 GrAAConvexTessellator tess;
822
823 int instanceCount = fGeoData.count();
824
825 for (int i = 0; i < instanceCount; i++) {
826 tess.rewind();
827
828 Geometry& args = fGeoData[i];
829
830 if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
831 continue;
832 }
833
834 const GrVertexBuffer* vertexBuffer;
835 int firstVertex;
836
837 void* verts = batchTarget->makeVertSpace(vertexStride, tess.numPts() ,
838 &vertexBuffer, &firstVertex );
839 if (!verts) {
840 SkDebugf("Could not allocate vertices\n");
841 return;
842 }
843
844 const GrIndexBuffer* indexBuffer;
845 int firstIndex;
846
847 uint16_t* idxs = batchTarget->makeIndexSpace(tess.numIndices(),
848 &indexBuffer, &firstInde x);
849 if (!idxs) {
850 SkDebugf("Could not allocate indices\n");
851 return;
852 }
853
854 extract_verts(tess, verts, vertexStride, args.fColor, idxs, canTweak AlphaForCoverage);
855
856 GrVertices info;
857 info.initIndexed(kTriangles_GrPrimitiveType,
858 vertexBuffer, indexBuffer,
859 firstVertex, firstIndex,
860 tess.numPts(), tess.numIndices());
861 batchTarget->draw(info);
862 }
741 } 863 }
742 864
743 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline ) override { 865 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline ) override {
866 #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS
867 if (this->linesOnly()) {
868 this->generateGeometryLinesOnly(batchTarget, pipeline);
869 return;
870 }
871 #endif
872
744 int instanceCount = fGeoData.count(); 873 int instanceCount = fGeoData.count();
745 874
746 SkMatrix invert; 875 SkMatrix invert;
747 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { 876 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
748 SkDebugf("Could not invert viewmatrix\n"); 877 SkDebugf("Could not invert viewmatrix\n");
749 return; 878 return;
750 } 879 }
751 880
752 // Setup GrGeometryProcessor 881 // Setup GrGeometryProcessor
753 SkAutoTUnref<GrGeometryProcessor> quadProcessor(QuadEdgeEffect::Create(t his->color(), 882 SkAutoTUnref<GrGeometryProcessor> quadProcessor(QuadEdgeEffect::Create(t his->color(),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 974
846 if (this->color() != that->color()) { 975 if (this->color() != that->color()) {
847 return false; 976 return false;
848 } 977 }
849 978
850 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); 979 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords());
851 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi ewMatrix())) { 980 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi ewMatrix())) {
852 return false; 981 return false;
853 } 982 }
854 983
984 if (this->linesOnly() != that->linesOnly()) {
985 return false;
986 }
987
988 // In the event of two batches, one who can tweak, one who cannot, we ju st fall back to
989 // not tweaking
990 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage() ) {
991 fBatch.fCanTweakAlphaForCoverage = false;
992 }
993
855 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ; 994 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ;
856 this->joinBounds(that->bounds()); 995 this->joinBounds(that->bounds());
857 return true; 996 return true;
858 } 997 }
859 998
860 GrColor color() const { return fBatch.fColor; } 999 GrColor color() const { return fBatch.fColor; }
1000 bool linesOnly() const { return fBatch.fLinesOnly; }
861 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } 1001 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
1002 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover age; }
862 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } 1003 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; }
863 1004
864 struct BatchTracker { 1005 struct BatchTracker {
865 GrColor fColor; 1006 GrColor fColor;
866 bool fUsesLocalCoords; 1007 bool fUsesLocalCoords;
867 bool fColorIgnored; 1008 bool fColorIgnored;
868 bool fCoverageIgnored; 1009 bool fCoverageIgnored;
1010 bool fLinesOnly;
1011 bool fCanTweakAlphaForCoverage;
869 }; 1012 };
870 1013
871 BatchTracker fBatch; 1014 BatchTracker fBatch;
872 SkSTArray<1, Geometry, true> fGeoData; 1015 SkSTArray<1, Geometry, true> fGeoData;
873 }; 1016 };
874 1017
875 bool GrAAConvexPathRenderer::onDrawPath(GrDrawTarget* target, 1018 bool GrAAConvexPathRenderer::onDrawPath(GrDrawTarget* target,
876 GrPipelineBuilder* pipelineBuilder, 1019 GrPipelineBuilder* pipelineBuilder,
877 GrColor color, 1020 GrColor color,
878 const SkMatrix& vm, 1021 const SkMatrix& vm,
879 const SkPath& path, 1022 const SkPath& path,
880 const GrStrokeInfo&, 1023 const GrStrokeInfo&,
881 bool antiAlias) { 1024 bool antiAlias) {
882 if (path.isEmpty()) { 1025 if (path.isEmpty()) {
883 return true; 1026 return true;
884 } 1027 }
885 1028
886 AAConvexPathBatch::Geometry geometry; 1029 AAConvexPathBatch::Geometry geometry;
887 geometry.fColor = color; 1030 geometry.fColor = color;
888 geometry.fViewMatrix = vm; 1031 geometry.fViewMatrix = vm;
889 geometry.fPath = path; 1032 geometry.fPath = path;
890 1033
891 SkAutoTUnref<GrBatch> batch(AAConvexPathBatch::Create(geometry)); 1034 SkAutoTUnref<GrBatch> batch(AAConvexPathBatch::Create(geometry));
892 target->drawBatch(pipelineBuilder, batch); 1035 target->drawBatch(pipelineBuilder, batch);
893 1036
894 return true; 1037 return true;
895 1038
896 } 1039 }
OLDNEW
« no previous file with comments | « gyp/skia_for_chromium_defines.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698