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