joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 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 GrDrawVerticesBatch_DEFINED |
| 9 | #define GrDrawVerticesBatch_DEFINED |
| 10 | |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 11 | #include "GrColor.h" |
| 12 | #include "GrTypes.h" |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame^] | 13 | #include "GrVertexBatch.h" |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 14 | #include "SkMatrix.h" |
| 15 | #include "SkRect.h" |
| 16 | #include "SkTDArray.h" |
| 17 | |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 18 | class GrBatchTarget; |
| 19 | struct GrInitInvariantOutput; |
| 20 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 21 | class GrDrawVerticesBatch : public GrVertexBatch { |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 22 | public: |
| 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 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 31 | 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) { |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 37 | 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 | |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 48 | void initBatchTracker(const GrPipelineOptimizations&) override; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 49 | |
| 50 | void generateGeometry(GrBatchTarget* batchTarget) override; |
| 51 | |
| 52 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 53 | |
| 54 | private: |
| 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 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 78 | bool onCombineIfPossible(GrBatch* t, const GrCaps&) override; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 79 | |
| 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 |