| OLD | NEW |
| (Empty) |
| 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" | |
| 12 | |
| 13 /* | |
| 14 * A simple batch only for testing purposes which actually doesn't batch at all,
but can fit into | |
| 15 * the batch pipeline and generate arbitrary geometry | |
| 16 */ | |
| 17 class GrTestBatch : public GrBatch { | |
| 18 public: | |
| 19 struct Geometry { | |
| 20 GrColor fColor; | |
| 21 }; | |
| 22 | |
| 23 virtual const char* name() const SK_OVERRIDE = 0; | |
| 24 | |
| 25 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE { | |
| 26 // When this is called on a batch, there is only one geometry bundle | |
| 27 out->setUnknownFourComponents(); | |
| 28 } | |
| 29 | |
| 30 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E { | |
| 31 out->setUnknownSingleComponent(); | |
| 32 } | |
| 33 | |
| 34 void initBatchOpt(const GrBatchOpt& batchOpt) {} | |
| 35 | |
| 36 void initBatchTracker(const GrPipelineInfo& init) SK_OVERRIDE { | |
| 37 // Handle any color overrides | |
| 38 if (init.fColorIgnored) { | |
| 39 this->geoData(0)->fColor = GrColor_ILLEGAL; | |
| 40 } else if (GrColor_ILLEGAL != init.fOverrideColor) { | |
| 41 this->geoData(0)->fColor = init.fOverrideColor; | |
| 42 } | |
| 43 | |
| 44 // setup batch properties | |
| 45 fBatch.fColorIgnored = init.fColorIgnored; | |
| 46 fBatch.fColor = this->geoData(0)->fColor; | |
| 47 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; | |
| 48 fBatch.fCoverageIgnored = init.fCoverageIgnored; | |
| 49 } | |
| 50 | |
| 51 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) SK_OVERRIDE { | |
| 52 batchTarget->initDraw(fGeometryProcessor, pipeline); | |
| 53 | |
| 54 // TODO this is hacky, but the only way we have to initialize the GP is
to use the | |
| 55 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | |
| 56 // everywhere we can remove this nastiness | |
| 57 GrPipelineInfo init; | |
| 58 init.fColorIgnored = fBatch.fColorIgnored; | |
| 59 init.fOverrideColor = GrColor_ILLEGAL; | |
| 60 init.fCoverageIgnored = fBatch.fCoverageIgnored; | |
| 61 init.fUsesLocalCoords = fBatch.fUsesLocalCoords; | |
| 62 fGeometryProcessor->initBatchTracker(batchTarget->currentBatchTracker(),
init); | |
| 63 | |
| 64 this->onGenerateGeometry(batchTarget, pipeline); | |
| 65 } | |
| 66 | |
| 67 protected: | |
| 68 GrTestBatch(const GrGeometryProcessor* gp) { | |
| 69 fGeometryProcessor.reset(SkRef(gp)); | |
| 70 } | |
| 71 | |
| 72 const GrGeometryProcessor* geometryProcessor() const { return fGeometryProce
ssor; } | |
| 73 | |
| 74 private: | |
| 75 virtual Geometry* geoData(int index) = 0; | |
| 76 | |
| 77 bool onCombineIfPossible(GrBatch* t) SK_OVERRIDE { | |
| 78 return false; | |
| 79 } | |
| 80 | |
| 81 virtual void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline
* pipeline) = 0; | |
| 82 | |
| 83 struct BatchTracker { | |
| 84 GrColor fColor; | |
| 85 bool fUsesLocalCoords; | |
| 86 bool fColorIgnored; | |
| 87 bool fCoverageIgnored; | |
| 88 }; | |
| 89 | |
| 90 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; | |
| 91 BatchTracker fBatch; | |
| 92 }; | |
| 93 | |
| 94 #endif | |
| OLD | NEW |