blob: 9b2faf3d3dbafbd14a3f856a7fe3abb7805bddc6 [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
bsalomon75398562015-08-17 12:55:38 -070018class GrBatchFlushState;
joshualitt2771b562015-08-07 12:46:26 -070019struct GrInitInvariantOutput;
20
bsalomonabd30f52015-08-13 13:34:48 -070021class GrDrawVerticesBatch : public GrVertexBatch {
joshualitt2771b562015-08-07 12:46:26 -070022public:
reed1b55a962015-09-17 20:16:13 -070023 DEFINE_BATCH_CLASS_ID
24
joshualitt2771b562015-08-07 12:46:26 -070025 struct Geometry {
bsalomon14eaaa62015-09-24 07:01:26 -070026 GrColor fColor; // Only used if there are no per-vertex colors
joshualitt2771b562015-08-07 12:46:26 -070027 SkTDArray<SkPoint> fPositions;
28 SkTDArray<uint16_t> fIndices;
29 SkTDArray<GrColor> fColors;
30 SkTDArray<SkPoint> fLocalCoords;
31 };
32
bsalomonabd30f52015-08-13 13:34:48 -070033 static GrDrawBatch* Create(const Geometry& geometry, GrPrimitiveType primitiveType,
34 const SkMatrix& viewMatrix,
35 const SkPoint* positions, int vertexCount,
36 const uint16_t* indices, int indexCount,
37 const GrColor* colors, const SkPoint* localCoords,
38 const SkRect& bounds) {
halcanary385fe4d2015-08-26 13:07:48 -070039 return new GrDrawVerticesBatch(geometry, primitiveType, viewMatrix, positions, vertexCount,
40 indices, indexCount, colors, localCoords, bounds);
joshualitt2771b562015-08-07 12:46:26 -070041 }
42
43 const char* name() const override { return "DrawVerticesBatch"; }
44
ethannicholasff210322015-11-24 12:10:10 -080045 void computePipelineOptimizations(GrInitInvariantOutput* color,
46 GrInitInvariantOutput* coverage,
47 GrBatchToXPOverrides* overrides) const override;
joshualitt2771b562015-08-07 12:46:26 -070048
joshualitt2771b562015-08-07 12:46:26 -070049 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
50
51private:
joshualitt144c3c82015-11-30 12:30:13 -080052 void onPrepareDraws(Target*) const override;
ethannicholasff210322015-11-24 12:10:10 -080053 void initBatchTracker(const GrXPOverridesForBatch&) override;
bsalomon75398562015-08-17 12:55:38 -070054
joshualitt2771b562015-08-07 12:46:26 -070055 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
bsalomon14eaaa62015-09-24 07:01:26 -070061 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
joshualitt2771b562015-08-07 12:46:26 -070062 bool batchablePrimitiveType() const {
bsalomon14eaaa62015-09-24 07:01:26 -070063 return kTriangles_GrPrimitiveType == fPrimitiveType ||
64 kLines_GrPrimitiveType == fPrimitiveType ||
65 kPoints_GrPrimitiveType == fPrimitiveType;
joshualitt2771b562015-08-07 12:46:26 -070066 }
joshualitt2771b562015-08-07 12:46:26 -070067
bsalomoncb02b382015-08-12 11:14:50 -070068 bool onCombineIfPossible(GrBatch* t, const GrCaps&) override;
joshualitt2771b562015-08-07 12:46:26 -070069
bsalomon14eaaa62015-09-24 07:01:26 -070070 GrPrimitiveType fPrimitiveType;
71 SkMatrix fViewMatrix;
72 bool fVariableColor;
73 int fVertexCount;
74 int fIndexCount;
75 bool fCoverageIgnored; // comes from initBatchTracker.
joshualitt2771b562015-08-07 12:46:26 -070076
joshualitt2771b562015-08-07 12:46:26 -070077 SkSTArray<1, Geometry, true> fGeoData;
reed1b55a962015-09-17 20:16:13 -070078
79 typedef GrVertexBatch INHERITED;
joshualitt2771b562015-08-07 12:46:26 -070080};
81
82#endif