OLD | NEW |
| (Empty) |
1 /* | |
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 "GrVertexBuffer.h" | |
12 | |
13 #include "batches/GrBatch.h" | |
14 | |
15 /* | |
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 */ | |
19 class GrTestBatch : public GrBatch { | |
20 public: | |
21 struct Geometry { | |
22 GrColor fColor; | |
23 }; | |
24 | |
25 virtual const char* name() const override = 0; | |
26 | |
27 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | |
28 // When this is called on a batch, there is only one geometry bundle | |
29 out->setKnownFourComponents(this->geoData(0)->fColor); | |
30 } | |
31 | |
32 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | |
33 out->setUnknownSingleComponent(); | |
34 } | |
35 | |
36 void initBatchTracker(const GrPipelineInfo& init) override { | |
37 // Handle any color overrides | |
38 if (!init.readsColor()) { | |
39 this->geoData(0)->fColor = GrColor_ILLEGAL; | |
40 } | |
41 init.getOverrideColorIfSet(&this->geoData(0)->fColor); | |
42 | |
43 // setup batch properties | |
44 fBatch.fColorIgnored = !init.readsColor(); | |
45 fBatch.fColor = this->geoData(0)->fColor; | |
46 fBatch.fUsesLocalCoords = init.readsLocalCoords(); | |
47 fBatch.fCoverageIgnored = !init.readsCoverage(); | |
48 } | |
49 | |
50 void generateGeometry(GrBatchTarget* batchTarget) override { | |
51 batchTarget->initDraw(fGeometryProcessor, this->pipeline()); | |
52 | |
53 this->onGenerateGeometry(batchTarget); | |
54 } | |
55 | |
56 protected: | |
57 GrTestBatch(const GrGeometryProcessor* gp, const SkRect& bounds) { | |
58 fGeometryProcessor.reset(SkRef(gp)); | |
59 | |
60 this->setBounds(bounds); | |
61 } | |
62 | |
63 const GrGeometryProcessor* geometryProcessor() const { return fGeometryProce
ssor; } | |
64 | |
65 private: | |
66 virtual Geometry* geoData(int index) = 0; | |
67 virtual const Geometry* geoData(int index) const = 0; | |
68 | |
69 bool onCombineIfPossible(GrBatch* t) override { | |
70 return false; | |
71 } | |
72 | |
73 virtual void onGenerateGeometry(GrBatchTarget* batchTarget) = 0; | |
74 | |
75 struct BatchTracker { | |
76 GrColor fColor; | |
77 bool fUsesLocalCoords; | |
78 bool fColorIgnored; | |
79 bool fCoverageIgnored; | |
80 }; | |
81 | |
82 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; | |
83 BatchTracker fBatch; | |
84 }; | |
85 | |
86 #endif | |
OLD | NEW |