blob: 4bcb7bc1597db7842215b699ed7e988fd20e5c24 [file] [log] [blame]
joshualitt95964c62015-02-11 13:45:50 -08001/*
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"
bsalomon72e3ae42015-04-28 08:08:46 -070012#include "GrVertexBuffer.h"
joshualitt95964c62015-02-11 13:45:50 -080013
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 */
18class GrTestBatch : public GrBatch {
19public:
20 struct Geometry {
21 GrColor fColor;
22 };
23
mtklein36352bf2015-03-25 18:17:31 -070024 virtual const char* name() const override = 0;
joshualitt95964c62015-02-11 13:45:50 -080025
mtklein36352bf2015-03-25 18:17:31 -070026 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
joshualitt95964c62015-02-11 13:45:50 -080027 // When this is called on a batch, there is only one geometry bundle
joshualitt88c23fc2015-05-13 14:18:07 -070028 out->setKnownFourComponents(this->geoData(0)->fColor);
joshualitt95964c62015-02-11 13:45:50 -080029 }
30
mtklein36352bf2015-03-25 18:17:31 -070031 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
joshualitt95964c62015-02-11 13:45:50 -080032 out->setUnknownSingleComponent();
33 }
34
mtklein36352bf2015-03-25 18:17:31 -070035 void initBatchTracker(const GrPipelineInfo& init) override {
joshualitt95964c62015-02-11 13:45:50 -080036 // Handle any color overrides
bsalomon7765a472015-07-08 11:26:37 -070037 if (!init.readsColor()) {
joshualitt95964c62015-02-11 13:45:50 -080038 this->geoData(0)->fColor = GrColor_ILLEGAL;
joshualitt95964c62015-02-11 13:45:50 -080039 }
bsalomon7765a472015-07-08 11:26:37 -070040 init.getOverrideColorIfSet(&this->geoData(0)->fColor);
joshualitt95964c62015-02-11 13:45:50 -080041
42 // setup batch properties
bsalomon7765a472015-07-08 11:26:37 -070043 fBatch.fColorIgnored = !init.readsColor();
joshualitt95964c62015-02-11 13:45:50 -080044 fBatch.fColor = this->geoData(0)->fColor;
bsalomon7765a472015-07-08 11:26:37 -070045 fBatch.fUsesLocalCoords = init.readsLocalCoords();
46 fBatch.fCoverageIgnored = !init.readsCoverage();
joshualitt95964c62015-02-11 13:45:50 -080047 }
48
bsalomonfb1141a2015-08-06 08:52:49 -070049 void generateGeometry(GrBatchTarget* batchTarget) override {
50 batchTarget->initDraw(fGeometryProcessor, this->pipeline());
joshualitt95964c62015-02-11 13:45:50 -080051
bsalomonfb1141a2015-08-06 08:52:49 -070052 this->onGenerateGeometry(batchTarget);
joshualitt95964c62015-02-11 13:45:50 -080053 }
54
55protected:
joshualitt99c7c072015-05-01 13:43:30 -070056 GrTestBatch(const GrGeometryProcessor* gp, const SkRect& bounds) {
joshualitt95964c62015-02-11 13:45:50 -080057 fGeometryProcessor.reset(SkRef(gp));
joshualitt99c7c072015-05-01 13:43:30 -070058
59 this->setBounds(bounds);
joshualitt95964c62015-02-11 13:45:50 -080060 }
61
62 const GrGeometryProcessor* geometryProcessor() const { return fGeometryProcessor; }
63
64private:
65 virtual Geometry* geoData(int index) = 0;
joshualitt88c23fc2015-05-13 14:18:07 -070066 virtual const Geometry* geoData(int index) const = 0;
joshualitt95964c62015-02-11 13:45:50 -080067
mtklein36352bf2015-03-25 18:17:31 -070068 bool onCombineIfPossible(GrBatch* t) override {
joshualitt95964c62015-02-11 13:45:50 -080069 return false;
70 }
71
bsalomonfb1141a2015-08-06 08:52:49 -070072 virtual void onGenerateGeometry(GrBatchTarget* batchTarget) = 0;
joshualitt95964c62015-02-11 13:45:50 -080073
74 struct BatchTracker {
75 GrColor fColor;
76 bool fUsesLocalCoords;
77 bool fColorIgnored;
78 bool fCoverageIgnored;
79 };
80
joshualitt95964c62015-02-11 13:45:50 -080081 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor;
82 BatchTracker fBatch;
83};
84
85#endif