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