| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #ifndef GrAAStrokeRectBatch_DEFINED | 8 #ifndef GrAAStrokeRectBatch_DEFINED |
| 9 #define GrAAStrokeRectBatch_DEFINED | 9 #define GrAAStrokeRectBatch_DEFINED |
| 10 | 10 |
| 11 #include "GrColor.h" | 11 #include "GrColor.h" |
| 12 #include "GrTypes.h" | |
| 13 #include "GrVertexBatch.h" | |
| 14 #include "SkMatrix.h" | |
| 15 #include "SkRect.h" | |
| 16 | 12 |
| 13 class GrDrawBatch; |
| 17 class GrResourceProvider; | 14 class GrResourceProvider; |
| 15 class SkMatrix; |
| 16 struct SkRect; |
| 18 | 17 |
| 19 class GrAAStrokeRectBatch : public GrVertexBatch { | 18 namespace GrAAStrokeRectBatch { |
| 20 public: | |
| 21 DEFINE_BATCH_CLASS_ID | |
| 22 | 19 |
| 23 // TODO support AA rotated stroke rects by copying around view matrices | 20 GrDrawBatch* Create(GrColor color, |
| 24 struct Geometry { | 21 const SkMatrix& viewMatrix, |
| 25 GrColor fColor; | 22 const SkRect& devOutside, |
| 26 SkRect fDevOutside; | 23 const SkRect& devOutsideAssist, |
| 27 SkRect fDevOutsideAssist; | 24 const SkRect& devInside, |
| 28 SkRect fDevInside; | 25 bool miterStroke); |
| 29 bool fMiterStroke; | |
| 30 }; | |
| 31 | 26 |
| 32 static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMat
rix) { | |
| 33 return new GrAAStrokeRectBatch(geometry, viewMatrix); | |
| 34 } | |
| 35 | |
| 36 const char* name() const override { return "AAStrokeRect"; } | |
| 37 | |
| 38 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | |
| 39 // When this is called on a batch, there is only one geometry bundle | |
| 40 out->setKnownFourComponents(fGeoData[0].fColor); | |
| 41 } | |
| 42 | |
| 43 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | |
| 44 out->setUnknownSingleComponent(); | |
| 45 } | |
| 46 | |
| 47 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | |
| 48 | |
| 49 private: | |
| 50 void onPrepareDraws(Target*) override; | |
| 51 void initBatchTracker(const GrPipelineOptimizations&) override; | |
| 52 | |
| 53 GrAAStrokeRectBatch(const Geometry& geometry, const SkMatrix& viewMatrix) | |
| 54 : INHERITED(ClassID()) { | |
| 55 fBatch.fViewMatrix = viewMatrix; | |
| 56 fGeoData.push_back(geometry); | |
| 57 | |
| 58 // If we have miterstroke then we inset devOutside and outset devOutside
Assist, so we need | |
| 59 // the join for proper bounds | |
| 60 fBounds = geometry.fDevOutside; | |
| 61 fBounds.join(geometry.fDevOutsideAssist); | |
| 62 } | |
| 63 | |
| 64 | |
| 65 static const int kMiterIndexCnt = 3 * 24; | |
| 66 static const int kMiterVertexCnt = 16; | |
| 67 static const int kNumMiterRectsInIndexBuffer = 256; | |
| 68 | |
| 69 static const int kBevelIndexCnt = 48 + 36 + 24; | |
| 70 static const int kBevelVertexCnt = 24; | |
| 71 static const int kNumBevelRectsInIndexBuffer = 256; | |
| 72 | |
| 73 static const GrIndexBuffer* GetIndexBuffer(GrResourceProvider* resourceProvi
der, | |
| 74 bool miterStroke); | |
| 75 | |
| 76 GrColor color() const { return fBatch.fColor; } | |
| 77 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | |
| 78 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } | |
| 79 bool colorIgnored() const { return fBatch.fColorIgnored; } | |
| 80 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } | |
| 81 bool miterStroke() const { return fBatch.fMiterStroke; } | |
| 82 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } | |
| 83 | |
| 84 bool onCombineIfPossible(GrBatch* t, const GrCaps&) override; | |
| 85 | |
| 86 void generateAAStrokeRectGeometry(void* vertices, | |
| 87 size_t offset, | |
| 88 size_t vertexStride, | |
| 89 int outerVertexNum, | |
| 90 int innerVertexNum, | |
| 91 GrColor color, | |
| 92 const SkRect& devOutside, | |
| 93 const SkRect& devOutsideAssist, | |
| 94 const SkRect& devInside, | |
| 95 bool miterStroke, | |
| 96 bool tweakAlphaForCoverage) const; | |
| 97 | |
| 98 struct BatchTracker { | |
| 99 SkMatrix fViewMatrix; | |
| 100 GrColor fColor; | |
| 101 bool fUsesLocalCoords; | |
| 102 bool fColorIgnored; | |
| 103 bool fCoverageIgnored; | |
| 104 bool fMiterStroke; | |
| 105 bool fCanTweakAlphaForCoverage; | |
| 106 }; | |
| 107 | |
| 108 BatchTracker fBatch; | |
| 109 SkSTArray<1, Geometry, true> fGeoData; | |
| 110 | |
| 111 typedef GrVertexBatch INHERITED; | |
| 112 }; | 27 }; |
| 113 | 28 |
| 114 | |
| 115 #endif | 29 #endif |
| OLD | NEW |