blob: aa0c63773e920b4f935aee1b9f224a83065dca4d [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
bsalomond07a2792015-07-08 10:20:21 -070037 if (init.fColorIgnored) {
joshualitt95964c62015-02-11 13:45:50 -080038 this->geoData(0)->fColor = GrColor_ILLEGAL;
bsalomond07a2792015-07-08 10:20:21 -070039 } else if (GrColor_ILLEGAL != init.fOverrideColor) {
40 this->geoData(0)->fColor = init.fOverrideColor;
joshualitt95964c62015-02-11 13:45:50 -080041 }
42
43 // setup batch properties
bsalomond07a2792015-07-08 10:20:21 -070044 fBatch.fColorIgnored = init.fColorIgnored;
joshualitt95964c62015-02-11 13:45:50 -080045 fBatch.fColor = this->geoData(0)->fColor;
bsalomond07a2792015-07-08 10:20:21 -070046 fBatch.fUsesLocalCoords = init.fUsesLocalCoords;
47 fBatch.fCoverageIgnored = init.fCoverageIgnored;
joshualitt95964c62015-02-11 13:45:50 -080048 }
49
mtklein36352bf2015-03-25 18:17:31 -070050 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override {
joshualitt95964c62015-02-11 13:45:50 -080051 batchTarget->initDraw(fGeometryProcessor, pipeline);
52
joshualitt95964c62015-02-11 13:45:50 -080053 this->onGenerateGeometry(batchTarget, pipeline);
54 }
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
mtklein36352bf2015-03-25 18:17:31 -070069 bool onCombineIfPossible(GrBatch* t) override {
joshualitt95964c62015-02-11 13:45:50 -080070 return false;
71 }
72
73 virtual void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) = 0;
74
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