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 GrRectBatch_DEFINED | 8 #ifndef GrRectBatch_DEFINED |
9 #define GrRectBatch_DEFINED | 9 #define GrRectBatch_DEFINED |
10 | 10 |
| 11 #include "GrBatch.h" |
11 #include "GrColor.h" | 12 #include "GrColor.h" |
12 | 13 |
13 class GrBatch; | 14 class GrBatchTarget; |
14 class SkMatrix; | 15 class SkMatrix; |
15 struct SkRect; | 16 struct SkRect; |
16 | 17 |
17 /* | 18 class GrRectBatch : public GrBatch { |
18 * A factory for returning batches which can draw rectangles. Right now this on
ly handles non-AA | 19 public: |
19 * rects | 20 struct Geometry { |
20 */ | 21 SkMatrix fViewMatrix; |
21 namespace GrRectBatch { | 22 SkRect fRect; |
| 23 SkRect fLocalRect; |
| 24 SkMatrix fLocalMatrix; |
| 25 GrColor fColor; |
| 26 bool fHasLocalRect; |
| 27 bool fHasLocalMatrix; |
| 28 }; |
22 | 29 |
23 GrBatch* Create(GrColor color, | 30 static GrBatch* Create(const Geometry& geometry) { |
24 const SkMatrix& viewMatrix, | 31 return SkNEW_ARGS(GrRectBatch, (geometry)); |
25 const SkRect& rect, | 32 } |
26 const SkRect* localRect, | |
27 const SkMatrix* localMatrix); | |
28 | 33 |
| 34 const char* name() const override { return "RectBatch"; } |
| 35 |
| 36 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
| 37 // When this is called on a batch, there is only one geometry bundle |
| 38 out->setKnownFourComponents(fGeoData[0].fColor); |
| 39 } |
| 40 |
| 41 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 42 out->setKnownSingleComponent(0xff); |
| 43 } |
| 44 |
| 45 void initBatchTracker(const GrPipelineInfo& init) override; |
| 46 |
| 47 void generateGeometry(GrBatchTarget* batchTarget) override; |
| 48 |
| 49 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 50 |
| 51 private: |
| 52 GrRectBatch(const Geometry& geometry) { |
| 53 this->initClassID<GrRectBatch>(); |
| 54 fGeoData.push_back(geometry); |
| 55 |
| 56 fBounds = geometry.fRect; |
| 57 geometry.fViewMatrix.mapRect(&fBounds); |
| 58 } |
| 59 |
| 60 GrColor color() const { return fBatch.fColor; } |
| 61 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 62 bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 63 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 64 const SkMatrix& localMatrix() const { return fGeoData[0].fLocalMatrix; } |
| 65 bool hasLocalRect() const { return fGeoData[0].fHasLocalRect; } |
| 66 bool hasLocalMatrix() const { return fGeoData[0].fHasLocalMatrix; } |
| 67 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } |
| 68 |
| 69 bool onCombineIfPossible(GrBatch* t) override; |
| 70 |
| 71 const GrGeometryProcessor* createRectGP(); |
| 72 |
| 73 struct BatchTracker { |
| 74 GrColor fColor; |
| 75 bool fUsesLocalCoords; |
| 76 bool fColorIgnored; |
| 77 bool fCoverageIgnored; |
| 78 }; |
| 79 |
| 80 BatchTracker fBatch; |
| 81 SkSTArray<1, Geometry, true> fGeoData; |
29 }; | 82 }; |
30 | 83 |
31 #endif | 84 #endif |
OLD | NEW |