blob: 02881c9668ed2c1d0a78355990a045b625baf52b [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
bsalomon75398562015-08-17 12:55:38 -070011#include "GrBatchFlushState.h"
bsalomon16b99132015-08-13 14:55:50 -070012#include "GrGeometryProcessor.h"
bsalomon72e3ae42015-04-28 08:08:46 -070013#include "GrVertexBuffer.h"
joshualitt95964c62015-02-11 13:45:50 -080014
bsalomon16b99132015-08-13 14:55:50 -070015#include "batches/GrVertexBatch.h"
joshualitt74417822015-08-07 11:42:16 -070016
joshualitt95964c62015-02-11 13:45:50 -080017/*
18 * A simple batch only for testing purposes which actually doesn't batch at all, but can fit into
19 * the batch pipeline and generate arbitrary geometry
20 */
bsalomonabd30f52015-08-13 13:34:48 -070021class GrTestBatch : public GrVertexBatch {
joshualitt95964c62015-02-11 13:45:50 -080022public:
23 struct Geometry {
24 GrColor fColor;
25 };
26
mtklein36352bf2015-03-25 18:17:31 -070027 virtual const char* name() const override = 0;
joshualitt95964c62015-02-11 13:45:50 -080028
mtklein36352bf2015-03-25 18:17:31 -070029 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
joshualitt95964c62015-02-11 13:45:50 -080030 // When this is called on a batch, there is only one geometry bundle
joshualitt88c23fc2015-05-13 14:18:07 -070031 out->setKnownFourComponents(this->geoData(0)->fColor);
joshualitt95964c62015-02-11 13:45:50 -080032 }
33
mtklein36352bf2015-03-25 18:17:31 -070034 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
joshualitt95964c62015-02-11 13:45:50 -080035 out->setUnknownSingleComponent();
36 }
37
bsalomon91d844d2015-08-10 10:47:29 -070038 void initBatchTracker(const GrPipelineOptimizations& opt) override {
joshualitt95964c62015-02-11 13:45:50 -080039 // Handle any color overrides
bsalomon91d844d2015-08-10 10:47:29 -070040 if (!opt.readsColor()) {
joshualitt95964c62015-02-11 13:45:50 -080041 this->geoData(0)->fColor = GrColor_ILLEGAL;
joshualitt95964c62015-02-11 13:45:50 -080042 }
bsalomon91d844d2015-08-10 10:47:29 -070043 opt.getOverrideColorIfSet(&this->geoData(0)->fColor);
joshualitt95964c62015-02-11 13:45:50 -080044
45 // setup batch properties
bsalomon91d844d2015-08-10 10:47:29 -070046 fBatch.fColorIgnored = !opt.readsColor();
joshualitt95964c62015-02-11 13:45:50 -080047 fBatch.fColor = this->geoData(0)->fColor;
bsalomon91d844d2015-08-10 10:47:29 -070048 fBatch.fUsesLocalCoords = opt.readsLocalCoords();
49 fBatch.fCoverageIgnored = !opt.readsCoverage();
joshualitt95964c62015-02-11 13:45:50 -080050 }
51
joshualitt95964c62015-02-11 13:45:50 -080052protected:
reed1b55a962015-09-17 20:16:13 -070053 GrTestBatch(uint32_t classID, const GrGeometryProcessor* gp, const SkRect& bounds)
54 : INHERITED(classID) {
joshualitt95964c62015-02-11 13:45:50 -080055 fGeometryProcessor.reset(SkRef(gp));
joshualitt99c7c072015-05-01 13:43:30 -070056
57 this->setBounds(bounds);
joshualitt95964c62015-02-11 13:45:50 -080058 }
59
60 const GrGeometryProcessor* geometryProcessor() const { return fGeometryProcessor; }
61
62private:
bsalomon75398562015-08-17 12:55:38 -070063 void onPrepareDraws(Target* target) override {
64 target->initDraw(fGeometryProcessor, this->pipeline());
65 this->generateGeometry(target);
66 }
67
joshualitt95964c62015-02-11 13:45:50 -080068 virtual Geometry* geoData(int index) = 0;
joshualitt88c23fc2015-05-13 14:18:07 -070069 virtual const Geometry* geoData(int index) const = 0;
joshualitt95964c62015-02-11 13:45:50 -080070
bsalomoncb02b382015-08-12 11:14:50 -070071 bool onCombineIfPossible(GrBatch* t, const GrCaps&) override {
joshualitt95964c62015-02-11 13:45:50 -080072 return false;
73 }
74
bsalomon75398562015-08-17 12:55:38 -070075 virtual void generateGeometry(Target*) = 0;
joshualitt95964c62015-02-11 13:45:50 -080076
77 struct BatchTracker {
78 GrColor fColor;
79 bool fUsesLocalCoords;
80 bool fColorIgnored;
81 bool fCoverageIgnored;
82 };
83
joshualitt95964c62015-02-11 13:45:50 -080084 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor;
85 BatchTracker fBatch;
reed1b55a962015-09-17 20:16:13 -070086
87 typedef GrVertexBatch INHERITED;
joshualitt95964c62015-02-11 13:45:50 -080088};
89
90#endif