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 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 18 | class GrBatchFlushState; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 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: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 23 | DEFINE_BATCH_CLASS_ID |
| 24 | |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 25 | struct Geometry { |
bsalomon | 14eaaa6 | 2015-09-24 07:01:26 -0700 | [diff] [blame] | 26 | GrColor fColor; // Only used if there are no per-vertex colors |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 27 | SkTDArray<SkPoint> fPositions; |
| 28 | SkTDArray<uint16_t> fIndices; |
| 29 | SkTDArray<GrColor> fColors; |
| 30 | SkTDArray<SkPoint> fLocalCoords; |
| 31 | }; |
| 32 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 33 | 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) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 39 | return new GrDrawVerticesBatch(geometry, primitiveType, viewMatrix, positions, vertexCount, |
| 40 | indices, indexCount, colors, localCoords, bounds); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | const char* name() const override { return "DrawVerticesBatch"; } |
| 44 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 45 | void computePipelineOptimizations(GrInitInvariantOutput* color, |
| 46 | GrInitInvariantOutput* coverage, |
| 47 | GrBatchToXPOverrides* overrides) const override; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 48 | |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 49 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 50 | |
| 51 | private: |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 52 | void onPrepareDraws(Target*) const override; |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 53 | void initBatchTracker(const GrXPOverridesForBatch&) override; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 54 | |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 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 | |
bsalomon | 14eaaa6 | 2015-09-24 07:01:26 -0700 | [diff] [blame] | 61 | GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 62 | bool batchablePrimitiveType() const { |
bsalomon | 14eaaa6 | 2015-09-24 07:01:26 -0700 | [diff] [blame] | 63 | return kTriangles_GrPrimitiveType == fPrimitiveType || |
| 64 | kLines_GrPrimitiveType == fPrimitiveType || |
| 65 | kPoints_GrPrimitiveType == fPrimitiveType; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 66 | } |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 67 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 68 | bool onCombineIfPossible(GrBatch* t, const GrCaps&) override; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 69 | |
bsalomon | 14eaaa6 | 2015-09-24 07:01:26 -0700 | [diff] [blame] | 70 | GrPrimitiveType fPrimitiveType; |
| 71 | SkMatrix fViewMatrix; |
| 72 | bool fVariableColor; |
| 73 | int fVertexCount; |
| 74 | int fIndexCount; |
| 75 | bool fCoverageIgnored; // comes from initBatchTracker. |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 76 | |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 77 | SkSTArray<1, Geometry, true> fGeoData; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 78 | |
| 79 | typedef GrVertexBatch INHERITED; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | #endif |