OLD | NEW |
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 |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 } | 840 } |
841 } | 841 } |
842 } | 842 } |
843 | 843 |
844 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 844 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
845 | 845 |
846 private: | 846 private: |
847 AAConvexPathBatch(const Geometry& geometry) { | 847 AAConvexPathBatch(const Geometry& geometry) { |
848 this->initClassID<AAConvexPathBatch>(); | 848 this->initClassID<AAConvexPathBatch>(); |
849 fGeoData.push_back(geometry); | 849 fGeoData.push_back(geometry); |
| 850 |
| 851 // compute bounds |
| 852 this->setBounds(geometry.fPath.getBounds()); |
| 853 geometry.fViewMatrix.mapRect(this->getBounds()); |
850 } | 854 } |
851 | 855 |
852 bool onCombineIfPossible(GrBatch* t) override { | 856 bool onCombineIfPossible(GrBatch* t) override { |
853 AAConvexPathBatch* that = t->cast<AAConvexPathBatch>(); | 857 AAConvexPathBatch* that = t->cast<AAConvexPathBatch>(); |
854 | 858 |
855 if (this->color() != that->color()) { | 859 if (this->color() != that->color()) { |
856 return false; | 860 return false; |
857 } | 861 } |
858 | 862 |
859 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 863 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
860 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { | 864 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { |
861 return false; | 865 return false; |
862 } | 866 } |
863 | 867 |
864 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 868 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; |
| 869 this->joinBounds(that->bounds()); |
865 return true; | 870 return true; |
866 } | 871 } |
867 | 872 |
868 GrColor color() const { return fBatch.fColor; } | 873 GrColor color() const { return fBatch.fColor; } |
869 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 874 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
870 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | 875 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
871 | 876 |
872 struct BatchTracker { | 877 struct BatchTracker { |
873 GrColor fColor; | 878 GrColor fColor; |
874 bool fUsesLocalCoords; | 879 bool fUsesLocalCoords; |
875 bool fColorIgnored; | 880 bool fColorIgnored; |
876 bool fCoverageIgnored; | 881 bool fCoverageIgnored; |
877 }; | 882 }; |
878 | 883 |
879 BatchTracker fBatch; | 884 BatchTracker fBatch; |
880 SkSTArray<1, Geometry, true> fGeoData; | 885 SkSTArray<1, Geometry, true> fGeoData; |
881 }; | 886 }; |
882 | 887 |
883 bool GrAAConvexPathRenderer::onDrawPath(GrDrawTarget* target, | 888 bool GrAAConvexPathRenderer::onDrawPath(GrDrawTarget* target, |
884 GrPipelineBuilder* pipelineBuilder, | 889 GrPipelineBuilder* pipelineBuilder, |
885 GrColor color, | 890 GrColor color, |
886 const SkMatrix& vm, | 891 const SkMatrix& vm, |
887 const SkPath& path, | 892 const SkPath& path, |
888 const GrStrokeInfo&, | 893 const GrStrokeInfo&, |
889 bool antiAlias) { | 894 bool antiAlias) { |
890 if (path.isEmpty()) { | 895 if (path.isEmpty()) { |
891 return true; | 896 return true; |
892 } | 897 } |
893 | 898 |
894 // We outset our vertices one pixel and add one more pixel for precision. | |
895 // TODO create tighter bounds when we start reordering. | |
896 SkRect devRect = path.getBounds(); | |
897 vm.mapRect(&devRect); | |
898 devRect.outset(2, 2); | |
899 | |
900 AAConvexPathBatch::Geometry geometry; | 899 AAConvexPathBatch::Geometry geometry; |
901 geometry.fColor = color; | 900 geometry.fColor = color; |
902 geometry.fViewMatrix = vm; | 901 geometry.fViewMatrix = vm; |
903 geometry.fPath = path; | 902 geometry.fPath = path; |
904 | 903 |
905 SkAutoTUnref<GrBatch> batch(AAConvexPathBatch::Create(geometry)); | 904 SkAutoTUnref<GrBatch> batch(AAConvexPathBatch::Create(geometry)); |
906 target->drawBatch(pipelineBuilder, batch, &devRect); | 905 target->drawBatch(pipelineBuilder, batch); |
907 | 906 |
908 return true; | 907 return true; |
909 | 908 |
910 } | 909 } |
OLD | NEW |