2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrTestBatch_DEFINED
9 #define GrTestBatch_DEFINED
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
17 class GrTestBatch : public GrBatch {
23 virtual const char* name() const SK_OVERRIDE = 0;
25 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE {
26 // When this is called on a batch, there is only one geometry bundle
27 if (fGeometryProcessor->hasVertexColor()) {
28 out->setUnknownFourComponents();
30 out->setKnownFourComponents(fGeometryProcessor->color());
34 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRIDE {
35 out->setUnknownSingleComponent();
38 void initBatchTracker(const GrPipelineInfo& init) SK_OVERRIDE {
39 // Handle any color overrides
40 if (init.fColorIgnored) {
41 this->geoData(0)->fColor = GrColor_ILLEGAL;
42 } else if (GrColor_ILLEGAL != init.fOverrideColor) {
43 this->geoData(0)->fColor = init.fOverrideColor;
46 // setup batch properties
47 fBatch.fColorIgnored = init.fColorIgnored;
48 fBatch.fColor = this->geoData(0)->fColor;
49 fBatch.fUsesLocalCoords = init.fUsesLocalCoords;
50 fBatch.fCoverageIgnored = init.fCoverageIgnored;
53 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) SK_OVERRIDE {
54 batchTarget->initDraw(fGeometryProcessor, pipeline);
56 // TODO this is hacky, but the only way we have to initialize the GP is to use the
57 // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch
58 // everywhere we can remove this nastiness
60 init.fColorIgnored = fBatch.fColorIgnored;
61 init.fOverrideColor = GrColor_ILLEGAL;
62 init.fCoverageIgnored = fBatch.fCoverageIgnored;
63 init.fUsesLocalCoords = fBatch.fUsesLocalCoords;
64 fGeometryProcessor->initBatchTracker(batchTarget->currentBatchTracker(), init);
66 this->onGenerateGeometry(batchTarget, pipeline);
70 GrTestBatch(const GrGeometryProcessor* gp) {
71 fGeometryProcessor.reset(SkRef(gp));
74 const GrGeometryProcessor* geometryProcessor() const { return fGeometryProcessor; }
77 virtual Geometry* geoData(int index) = 0;
79 bool onCombineIfPossible(GrBatch* t) SK_OVERRIDE {
83 virtual void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) = 0;
87 bool fUsesLocalCoords;
89 bool fCoverageIgnored;
92 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor;