blob: d8986b681659303c6ebfbd41f06ea49c4a4c70c2 [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
bsalomon72e3ae42015-04-28 08:08:46 -070011#include "GrVertexBuffer.h"
joshualitt95964c62015-02-11 13:45:50 -080012
joshualitt74417822015-08-07 11:42:16 -070013#include "batches/GrBatch.h"
14
joshualitt95964c62015-02-11 13:45:50 -080015/*
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 */
bsalomonabd30f52015-08-13 13:34:48 -070019class GrTestBatch : public GrVertexBatch {
joshualitt95964c62015-02-11 13:45:50 -080020public:
21 struct Geometry {
22 GrColor fColor;
23 };
24
mtklein36352bf2015-03-25 18:17:31 -070025 virtual const char* name() const override = 0;
joshualitt95964c62015-02-11 13:45:50 -080026
mtklein36352bf2015-03-25 18:17:31 -070027 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
joshualitt95964c62015-02-11 13:45:50 -080028 // When this is called on a batch, there is only one geometry bundle
joshualitt88c23fc2015-05-13 14:18:07 -070029 out->setKnownFourComponents(this->geoData(0)->fColor);
joshualitt95964c62015-02-11 13:45:50 -080030 }
31
mtklein36352bf2015-03-25 18:17:31 -070032 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
joshualitt95964c62015-02-11 13:45:50 -080033 out->setUnknownSingleComponent();
34 }
35
bsalomon91d844d2015-08-10 10:47:29 -070036 void initBatchTracker(const GrPipelineOptimizations& opt) override {
joshualitt95964c62015-02-11 13:45:50 -080037 // Handle any color overrides
bsalomon91d844d2015-08-10 10:47:29 -070038 if (!opt.readsColor()) {
joshualitt95964c62015-02-11 13:45:50 -080039 this->geoData(0)->fColor = GrColor_ILLEGAL;
joshualitt95964c62015-02-11 13:45:50 -080040 }
bsalomon91d844d2015-08-10 10:47:29 -070041 opt.getOverrideColorIfSet(&this->geoData(0)->fColor);
joshualitt95964c62015-02-11 13:45:50 -080042
43 // setup batch properties
bsalomon91d844d2015-08-10 10:47:29 -070044 fBatch.fColorIgnored = !opt.readsColor();
joshualitt95964c62015-02-11 13:45:50 -080045 fBatch.fColor = this->geoData(0)->fColor;
bsalomon91d844d2015-08-10 10:47:29 -070046 fBatch.fUsesLocalCoords = opt.readsLocalCoords();
47 fBatch.fCoverageIgnored = !opt.readsCoverage();
joshualitt95964c62015-02-11 13:45:50 -080048 }
49
bsalomonfb1141a2015-08-06 08:52:49 -070050 void generateGeometry(GrBatchTarget* batchTarget) override {
51 batchTarget->initDraw(fGeometryProcessor, this->pipeline());
joshualitt95964c62015-02-11 13:45:50 -080052
bsalomonfb1141a2015-08-06 08:52:49 -070053 this->onGenerateGeometry(batchTarget);
joshualitt95964c62015-02-11 13:45:50 -080054 }
55
56protected:
joshualitt99c7c072015-05-01 13:43:30 -070057 GrTestBatch(const GrGeometryProcessor* gp, const SkRect& bounds) {
joshualitt95964c62015-02-11 13:45:50 -080058 fGeometryProcessor.reset(SkRef(gp));
joshualitt99c7c072015-05-01 13:43:30 -070059
60 this->setBounds(bounds);
joshualitt95964c62015-02-11 13:45:50 -080061 }
62
63 const GrGeometryProcessor* geometryProcessor() const { return fGeometryProcessor; }
64
65private:
66 virtual Geometry* geoData(int index) = 0;
joshualitt88c23fc2015-05-13 14:18:07 -070067 virtual const Geometry* geoData(int index) const = 0;
joshualitt95964c62015-02-11 13:45:50 -080068
bsalomoncb02b382015-08-12 11:14:50 -070069 bool onCombineIfPossible(GrBatch* t, const GrCaps&) override {
joshualitt95964c62015-02-11 13:45:50 -080070 return false;
71 }
72
bsalomonfb1141a2015-08-06 08:52:49 -070073 virtual void onGenerateGeometry(GrBatchTarget* batchTarget) = 0;
joshualitt95964c62015-02-11 13:45:50 -080074
75 struct BatchTracker {
76 GrColor fColor;
77 bool fUsesLocalCoords;
78 bool fColorIgnored;
79 bool fCoverageIgnored;
80 };
81
joshualitt95964c62015-02-11 13:45:50 -080082 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor;
83 BatchTracker fBatch;
84};
85
86#endif