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 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 11 | #include "GrColor.h" |
| 12 | #include "GrDefaultGeoProcFactory.h" |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 13 | #include "GrVertexBatch.h" |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 14 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 15 | class GrDrawAtlasBatch : public GrVertexBatch { |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 16 | public: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 17 | DEFINE_BATCH_CLASS_ID |
| 18 | |
bsalomon | 0432dd6 | 2016-06-30 07:19:27 -0700 | [diff] [blame^] | 19 | GrDrawAtlasBatch(GrColor color, const SkMatrix& viewMatrix, int spriteCount, |
| 20 | const SkRSXform* xforms, const SkRect* rects, const SkColor* colors); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 21 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 22 | const char* name() const override { return "DrawAtlasBatch"; } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 23 | |
| 24 | void computePipelineOptimizations(GrInitInvariantOutput* color, |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 25 | GrInitInvariantOutput* coverage, |
| 26 | GrBatchToXPOverrides* overrides) const override { |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 27 | // When this is called on a batch, there is only one geometry bundle |
| 28 | if (this->hasColors()) { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 29 | color->setUnknownFourComponents(); |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 30 | } else { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 31 | color->setKnownFourComponents(fGeoData[0].fColor); |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 32 | } |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 33 | coverage->setKnownSingleComponent(0xff); |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 34 | } |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 35 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 36 | private: |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 37 | void onPrepareDraws(Target*) const override; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 38 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 39 | void initBatchTracker(const GrXPOverridesForBatch&) override; |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 40 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 41 | GrColor color() const { return fColor; } |
| 42 | bool colorIgnored() const { return fColorIgnored; } |
| 43 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
| 44 | bool hasColors() const { return fHasColors; } |
jvanverth | 5a4d235 | 2015-08-12 08:15:31 -0700 | [diff] [blame] | 45 | int quadCount() const { return fQuadCount; } |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 46 | bool coverageIgnored() const { return fCoverageIgnored; } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 47 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 48 | bool onCombineIfPossible(GrBatch* t, const GrCaps&) override; |
bsalomon | 0432dd6 | 2016-06-30 07:19:27 -0700 | [diff] [blame^] | 49 | |
| 50 | struct Geometry { |
| 51 | GrColor fColor; |
| 52 | SkTArray<uint8_t, true> fVerts; |
| 53 | }; |
| 54 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 55 | SkSTArray<1, Geometry, true> fGeoData; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 56 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 57 | SkMatrix fViewMatrix; |
| 58 | GrColor fColor; |
jvanverth | 5a4d235 | 2015-08-12 08:15:31 -0700 | [diff] [blame] | 59 | int fQuadCount; |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 60 | bool fColorIgnored; |
| 61 | bool fCoverageIgnored; |
| 62 | bool fHasColors; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 63 | |
| 64 | typedef GrVertexBatch INHERITED; |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | #endif |