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 | |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame^] | 24 | SkString dumpInfo() const override { |
| 25 | SkString string; |
| 26 | for (const auto& geo : fGeoData) { |
| 27 | string.appendf("Color: 0x%08x, Quads: %d\n", geo.fColor, geo.fVerts.count() / 4); |
| 28 | } |
| 29 | string.append(DumpPipelineInfo(*this->pipeline())); |
| 30 | string.append(INHERITED::dumpInfo()); |
| 31 | return string; |
| 32 | } |
| 33 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 34 | void computePipelineOptimizations(GrInitInvariantOutput* color, |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 35 | GrInitInvariantOutput* coverage, |
| 36 | GrBatchToXPOverrides* overrides) const override { |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 37 | // When this is called on a batch, there is only one geometry bundle |
| 38 | if (this->hasColors()) { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 39 | color->setUnknownFourComponents(); |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 40 | } else { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 41 | color->setKnownFourComponents(fGeoData[0].fColor); |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 42 | } |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 43 | coverage->setKnownSingleComponent(0xff); |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 44 | } |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 45 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 46 | private: |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 47 | void onPrepareDraws(Target*) const override; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 48 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 49 | void initBatchTracker(const GrXPOverridesForBatch&) override; |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 50 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 51 | GrColor color() const { return fColor; } |
| 52 | bool colorIgnored() const { return fColorIgnored; } |
| 53 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
| 54 | bool hasColors() const { return fHasColors; } |
jvanverth | 5a4d235 | 2015-08-12 08:15:31 -0700 | [diff] [blame] | 55 | int quadCount() const { return fQuadCount; } |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 56 | bool coverageIgnored() const { return fCoverageIgnored; } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 57 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 58 | bool onCombineIfPossible(GrBatch* t, const GrCaps&) override; |
bsalomon | 0432dd6 | 2016-06-30 07:19:27 -0700 | [diff] [blame] | 59 | |
| 60 | struct Geometry { |
| 61 | GrColor fColor; |
| 62 | SkTArray<uint8_t, true> fVerts; |
| 63 | }; |
| 64 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 65 | SkSTArray<1, Geometry, true> fGeoData; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 66 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 67 | SkMatrix fViewMatrix; |
| 68 | GrColor fColor; |
jvanverth | 5a4d235 | 2015-08-12 08:15:31 -0700 | [diff] [blame] | 69 | int fQuadCount; |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 70 | bool fColorIgnored; |
| 71 | bool fCoverageIgnored; |
| 72 | bool fHasColors; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 73 | |
| 74 | typedef GrVertexBatch INHERITED; |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | #endif |