blob: ee92816e4b0d164998a2c8d44d4f64e27a20b1fa [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
ethannicholasff210322015-11-24 12:10:10 -080029 void computePipelineOptimizations(GrInitInvariantOutput* color,
30 GrInitInvariantOutput* coverage,
31 GrBatchToXPOverrides* overrides) const override {
joshualitt95964c62015-02-11 13:45:50 -080032 // When this is called on a batch, there is only one geometry bundle
ethannicholasff210322015-11-24 12:10:10 -080033 color->setKnownFourComponents(this->geoData(0)->fColor);
34 coverage->setUnknownSingleComponent();
joshualitt95964c62015-02-11 13:45:50 -080035 }
36
ethannicholasff210322015-11-24 12:10:10 -080037 void initBatchTracker(const GrXPOverridesForBatch& overrides) override {
joshualitt95964c62015-02-11 13:45:50 -080038 // Handle any color overrides
ethannicholasff210322015-11-24 12:10:10 -080039 if (!overrides.readsColor()) {
joshualitt95964c62015-02-11 13:45:50 -080040 this->geoData(0)->fColor = GrColor_ILLEGAL;
joshualitt95964c62015-02-11 13:45:50 -080041 }
ethannicholasff210322015-11-24 12:10:10 -080042 overrides.getOverrideColorIfSet(&this->geoData(0)->fColor);
joshualitt95964c62015-02-11 13:45:50 -080043
44 // setup batch properties
ethannicholasff210322015-11-24 12:10:10 -080045 fBatch.fColorIgnored = !overrides.readsColor();
joshualitt95964c62015-02-11 13:45:50 -080046 fBatch.fColor = this->geoData(0)->fColor;
ethannicholasff210322015-11-24 12:10:10 -080047 fBatch.fUsesLocalCoords = overrides.readsLocalCoords();
48 fBatch.fCoverageIgnored = !overrides.readsCoverage();
joshualitt95964c62015-02-11 13:45:50 -080049 }
50
joshualitt95964c62015-02-11 13:45:50 -080051protected:
reed1b55a962015-09-17 20:16:13 -070052 GrTestBatch(uint32_t classID, const GrGeometryProcessor* gp, const SkRect& bounds)
53 : INHERITED(classID) {
joshualitt95964c62015-02-11 13:45:50 -080054 fGeometryProcessor.reset(SkRef(gp));
joshualitt99c7c072015-05-01 13:43:30 -070055
56 this->setBounds(bounds);
joshualitt95964c62015-02-11 13:45:50 -080057 }
58
59 const GrGeometryProcessor* geometryProcessor() const { return fGeometryProcessor; }
60
61private:
joshualitt144c3c82015-11-30 12:30:13 -080062 void onPrepareDraws(Target* target) const override {
bsalomon75398562015-08-17 12:55:38 -070063 target->initDraw(fGeometryProcessor, this->pipeline());
64 this->generateGeometry(target);
65 }
66
joshualitt95964c62015-02-11 13:45:50 -080067 virtual Geometry* geoData(int index) = 0;
joshualitt88c23fc2015-05-13 14:18:07 -070068 virtual const Geometry* geoData(int index) const = 0;
joshualitt95964c62015-02-11 13:45:50 -080069
bsalomoncb02b382015-08-12 11:14:50 -070070 bool onCombineIfPossible(GrBatch* t, const GrCaps&) override {
joshualitt95964c62015-02-11 13:45:50 -080071 return false;
72 }
73
joshualitt144c3c82015-11-30 12:30:13 -080074 virtual void generateGeometry(Target*) const = 0;
joshualitt95964c62015-02-11 13:45:50 -080075
76 struct BatchTracker {
77 GrColor fColor;
78 bool fUsesLocalCoords;
79 bool fColorIgnored;
80 bool fCoverageIgnored;
81 };
82
joshualitt95964c62015-02-11 13:45:50 -080083 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor;
84 BatchTracker fBatch;
reed1b55a962015-09-17 20:16:13 -070085
86 typedef GrVertexBatch INHERITED;
joshualitt95964c62015-02-11 13:45:50 -080087};
88
89#endif