joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [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 GrTestBatch_DEFINED |
| 9 | #define GrTestBatch_DEFINED |
| 10 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 11 | #include "GrBatchFlushState.h" |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 12 | #include "GrGeometryProcessor.h" |
bsalomon | 72e3ae4 | 2015-04-28 08:08:46 -0700 | [diff] [blame] | 13 | #include "GrVertexBuffer.h" |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 14 | |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 15 | #include "batches/GrVertexBatch.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 16 | |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 17 | /* |
| 18 | * A simple batch only for testing purposes which actually doesn't batch at all, but can fit into |
| 19 | * the batch pipeline and generate arbitrary geometry |
| 20 | */ |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 21 | class GrTestBatch : public GrVertexBatch { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 22 | public: |
| 23 | struct Geometry { |
| 24 | GrColor fColor; |
| 25 | }; |
| 26 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 27 | virtual const char* name() const override = 0; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 28 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 29 | void computePipelineOptimizations(GrInitInvariantOutput* color, |
| 30 | GrInitInvariantOutput* coverage, |
| 31 | GrBatchToXPOverrides* overrides) const override { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 32 | // When this is called on a batch, there is only one geometry bundle |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 33 | color->setKnownFourComponents(this->geoData(0)->fColor); |
| 34 | coverage->setUnknownSingleComponent(); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 35 | } |
| 36 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 37 | void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 38 | // Handle any color overrides |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 39 | if (!overrides.readsColor()) { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 40 | this->geoData(0)->fColor = GrColor_ILLEGAL; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 41 | } |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 42 | overrides.getOverrideColorIfSet(&this->geoData(0)->fColor); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 43 | |
| 44 | // setup batch properties |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 45 | fBatch.fColorIgnored = !overrides.readsColor(); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 46 | fBatch.fColor = this->geoData(0)->fColor; |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 47 | fBatch.fUsesLocalCoords = overrides.readsLocalCoords(); |
| 48 | fBatch.fCoverageIgnored = !overrides.readsCoverage(); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 49 | } |
| 50 | |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 51 | protected: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 52 | GrTestBatch(uint32_t classID, const GrGeometryProcessor* gp, const SkRect& bounds) |
| 53 | : INHERITED(classID) { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 54 | fGeometryProcessor.reset(SkRef(gp)); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 55 | |
| 56 | this->setBounds(bounds); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | const GrGeometryProcessor* geometryProcessor() const { return fGeometryProcessor; } |
| 60 | |
| 61 | private: |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 62 | void onPrepareDraws(Target* target) const override { |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 63 | target->initDraw(fGeometryProcessor, this->pipeline()); |
| 64 | this->generateGeometry(target); |
| 65 | } |
| 66 | |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 67 | virtual Geometry* geoData(int index) = 0; |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 68 | virtual const Geometry* geoData(int index) const = 0; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 69 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 70 | bool onCombineIfPossible(GrBatch* t, const GrCaps&) override { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 71 | return false; |
| 72 | } |
| 73 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 74 | virtual void generateGeometry(Target*) const = 0; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 75 | |
| 76 | struct BatchTracker { |
| 77 | GrColor fColor; |
| 78 | bool fUsesLocalCoords; |
| 79 | bool fColorIgnored; |
| 80 | bool fCoverageIgnored; |
| 81 | }; |
| 82 | |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 83 | SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; |
| 84 | BatchTracker fBatch; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 85 | |
| 86 | typedef GrVertexBatch INHERITED; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | #endif |