blob: 5e9628bc16e92d143b191d49ba1ee7bf8084d686 [file] [log] [blame]
joshualitt2771b562015-08-07 12:46:26 -07001/*
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 GrDrawVerticesBatch_DEFINED
9#define GrDrawVerticesBatch_DEFINED
10
joshualitt2771b562015-08-07 12:46:26 -070011#include "GrColor.h"
12#include "GrTypes.h"
bsalomon16b99132015-08-13 14:55:50 -070013#include "GrVertexBatch.h"
joshualitt2771b562015-08-07 12:46:26 -070014#include "SkMatrix.h"
15#include "SkRect.h"
16#include "SkTDArray.h"
17
joshualitt2771b562015-08-07 12:46:26 -070018class GrBatchTarget;
19struct GrInitInvariantOutput;
20
bsalomonabd30f52015-08-13 13:34:48 -070021class GrDrawVerticesBatch : public GrVertexBatch {
joshualitt2771b562015-08-07 12:46:26 -070022public:
23 struct Geometry {
24 GrColor fColor;
25 SkTDArray<SkPoint> fPositions;
26 SkTDArray<uint16_t> fIndices;
27 SkTDArray<GrColor> fColors;
28 SkTDArray<SkPoint> fLocalCoords;
29 };
30
bsalomonabd30f52015-08-13 13:34:48 -070031 static GrDrawBatch* Create(const Geometry& geometry, GrPrimitiveType primitiveType,
32 const SkMatrix& viewMatrix,
33 const SkPoint* positions, int vertexCount,
34 const uint16_t* indices, int indexCount,
35 const GrColor* colors, const SkPoint* localCoords,
36 const SkRect& bounds) {
joshualitt2771b562015-08-07 12:46:26 -070037 return SkNEW_ARGS(GrDrawVerticesBatch, (geometry, primitiveType, viewMatrix, positions,
38 vertexCount, indices, indexCount, colors,
39 localCoords, bounds));
40 }
41
42 const char* name() const override { return "DrawVerticesBatch"; }
43
44 void getInvariantOutputColor(GrInitInvariantOutput* out) const override;
45
46 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override;
47
bsalomon91d844d2015-08-10 10:47:29 -070048 void initBatchTracker(const GrPipelineOptimizations&) override;
joshualitt2771b562015-08-07 12:46:26 -070049
50 void generateGeometry(GrBatchTarget* batchTarget) override;
51
52 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
53
54private:
55 GrDrawVerticesBatch(const Geometry& geometry, GrPrimitiveType primitiveType,
56 const SkMatrix& viewMatrix,
57 const SkPoint* positions, int vertexCount,
58 const uint16_t* indices, int indexCount,
59 const GrColor* colors, const SkPoint* localCoords, const SkRect& bounds);
60
61 GrPrimitiveType primitiveType() const { return fBatch.fPrimitiveType; }
62 bool batchablePrimitiveType() const {
63 return kTriangles_GrPrimitiveType == fBatch.fPrimitiveType ||
64 kLines_GrPrimitiveType == fBatch.fPrimitiveType ||
65 kPoints_GrPrimitiveType == fBatch.fPrimitiveType;
66 }
67 GrColor color() const { return fBatch.fColor; }
68 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
69 bool colorIgnored() const { return fBatch.fColorIgnored; }
70 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; }
71 bool hasColors() const { return fBatch.fHasColors; }
72 bool hasIndices() const { return fBatch.fHasIndices; }
73 bool hasLocalCoords() const { return fBatch.fHasLocalCoords; }
74 int vertexCount() const { return fBatch.fVertexCount; }
75 int indexCount() const { return fBatch.fIndexCount; }
76 bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
77
bsalomoncb02b382015-08-12 11:14:50 -070078 bool onCombineIfPossible(GrBatch* t, const GrCaps&) override;
joshualitt2771b562015-08-07 12:46:26 -070079
80 struct BatchTracker {
81 GrPrimitiveType fPrimitiveType;
82 SkMatrix fViewMatrix;
83 GrColor fColor;
84 bool fUsesLocalCoords;
85 bool fColorIgnored;
86 bool fCoverageIgnored;
87 bool fHasColors;
88 bool fHasIndices;
89 bool fHasLocalCoords;
90 int fVertexCount;
91 int fIndexCount;
92 };
93
94 BatchTracker fBatch;
95 SkSTArray<1, Geometry, true> fGeoData;
96};
97
98#endif