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 | |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame^] | 8 | #ifndef GrDrawAtlasOp_DEFINED |
| 9 | #define GrDrawAtlasOp_DEFINED |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 10 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 11 | #include "GrColor.h" |
| 12 | #include "GrDefaultGeoProcFactory.h" |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 13 | #include "GrMeshDrawOp.h" |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 14 | |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame^] | 15 | class GrDrawAtlasOp final : public GrMeshDrawOp { |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 16 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 17 | DEFINE_OP_CLASS_ID |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 18 | |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame^] | 19 | static sk_sp<GrDrawOp> Make(GrColor color, const SkMatrix& viewMatrix, int spriteCount, |
| 20 | const SkRSXform* xforms, const SkRect* rects, |
| 21 | const SkColor* colors) { |
| 22 | return sk_sp<GrDrawOp>( |
| 23 | new GrDrawAtlasOp(color, viewMatrix, spriteCount, xforms, rects, colors)); |
| 24 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 25 | |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame^] | 26 | const char* name() const override { return "DrawAtlasOp"; } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 27 | |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 28 | SkString dumpInfo() const override { |
| 29 | SkString string; |
| 30 | for (const auto& geo : fGeoData) { |
| 31 | string.appendf("Color: 0x%08x, Quads: %d\n", geo.fColor, geo.fVerts.count() / 4); |
| 32 | } |
| 33 | string.append(DumpPipelineInfo(*this->pipeline())); |
| 34 | string.append(INHERITED::dumpInfo()); |
| 35 | return string; |
| 36 | } |
| 37 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 38 | void computePipelineOptimizations(GrInitInvariantOutput* color, |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 39 | GrInitInvariantOutput* coverage, |
| 40 | GrBatchToXPOverrides* overrides) const override { |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame^] | 41 | // When this is called there is only one atlas draw. |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 42 | if (this->hasColors()) { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 43 | color->setUnknownFourComponents(); |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 44 | } else { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 45 | color->setKnownFourComponents(fGeoData[0].fColor); |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 46 | } |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 47 | coverage->setKnownSingleComponent(0xff); |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 48 | } |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 49 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 50 | private: |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame^] | 51 | GrDrawAtlasOp(GrColor color, const SkMatrix& viewMatrix, int spriteCount, |
| 52 | const SkRSXform* xforms, const SkRect* rects, const SkColor* colors); |
| 53 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 54 | void onPrepareDraws(Target*) const override; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 55 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 56 | void initBatchTracker(const GrXPOverridesForBatch&) override; |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 57 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 58 | GrColor color() const { return fColor; } |
| 59 | bool colorIgnored() const { return fColorIgnored; } |
| 60 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
| 61 | bool hasColors() const { return fHasColors; } |
jvanverth | 5a4d235 | 2015-08-12 08:15:31 -0700 | [diff] [blame] | 62 | int quadCount() const { return fQuadCount; } |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 63 | bool coverageIgnored() const { return fCoverageIgnored; } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 64 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 65 | bool onCombineIfPossible(GrOp* t, const GrCaps&) override; |
bsalomon | 0432dd6 | 2016-06-30 07:19:27 -0700 | [diff] [blame] | 66 | |
| 67 | struct Geometry { |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame^] | 68 | GrColor fColor; |
bsalomon | 0432dd6 | 2016-06-30 07:19:27 -0700 | [diff] [blame] | 69 | SkTArray<uint8_t, true> fVerts; |
| 70 | }; |
| 71 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 72 | SkSTArray<1, Geometry, true> fGeoData; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 73 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 74 | SkMatrix fViewMatrix; |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame^] | 75 | GrColor fColor; |
| 76 | int fQuadCount; |
| 77 | bool fColorIgnored; |
| 78 | bool fCoverageIgnored; |
| 79 | bool fHasColors; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 80 | |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 81 | typedef GrMeshDrawOp INHERITED; |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | #endif |