jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrDrawAtlasBatch_DEFINED |
| 9 | #define GrDrawAtlasBatch_DEFINED |
| 10 | |
| 11 | #include "GrBatch.h" |
| 12 | #include "GrColor.h" |
| 13 | #include "GrDefaultGeoProcFactory.h" |
| 14 | |
| 15 | class GrDrawAtlasBatch : public GrBatch { |
| 16 | public: |
| 17 | struct Geometry { |
jvanverth | 5a4d235 | 2015-08-12 08:15:31 -0700 | [diff] [blame^] | 18 | GrColor fColor; |
| 19 | SkTArray<uint8_t, true> fVerts; |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 20 | }; |
| 21 | |
jvanverth | 5a4d235 | 2015-08-12 08:15:31 -0700 | [diff] [blame^] | 22 | static GrBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix, int spriteCount, |
| 23 | const SkRSXform* xforms, const SkRect* rects, const SkColor* colors) { |
| 24 | return SkNEW_ARGS(GrDrawAtlasBatch, (geometry, viewMatrix, spriteCount, |
| 25 | xforms, rects, colors)); |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | const char* name() const override { return "DrawAtlasBatch"; } |
| 29 | |
| 30 | void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
| 31 | // When this is called on a batch, there is only one geometry bundle |
| 32 | if (this->hasColors()) { |
| 33 | out->setUnknownFourComponents(); |
| 34 | } else { |
| 35 | out->setKnownFourComponents(fGeoData[0].fColor); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 40 | out->setKnownSingleComponent(0xff); |
| 41 | } |
| 42 | |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 43 | void initBatchTracker(const GrPipelineOptimizations&) override; |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 44 | void generateGeometry(GrBatchTarget* batchTarget) override; |
| 45 | |
| 46 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 47 | |
| 48 | private: |
jvanverth | 5a4d235 | 2015-08-12 08:15:31 -0700 | [diff] [blame^] | 49 | GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& viewMatrix, int spriteCount, |
| 50 | const SkRSXform* xforms, const SkRect* rects, const SkColor* colors); |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 51 | |
| 52 | GrColor color() const { return fColor; } |
| 53 | bool colorIgnored() const { return fColorIgnored; } |
| 54 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
| 55 | bool hasColors() const { return fHasColors; } |
jvanverth | 5a4d235 | 2015-08-12 08:15:31 -0700 | [diff] [blame^] | 56 | int quadCount() const { return fQuadCount; } |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 57 | bool coverageIgnored() const { return fCoverageIgnored; } |
| 58 | |
| 59 | bool onCombineIfPossible(GrBatch* t) override; |
| 60 | SkSTArray<1, Geometry, true> fGeoData; |
| 61 | |
| 62 | SkMatrix fViewMatrix; |
| 63 | GrColor fColor; |
jvanverth | 5a4d235 | 2015-08-12 08:15:31 -0700 | [diff] [blame^] | 64 | int fQuadCount; |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 65 | bool fColorIgnored; |
| 66 | bool fCoverageIgnored; |
| 67 | bool fHasColors; |
| 68 | }; |
| 69 | |
| 70 | #endif |