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 11 #include "GrColor.h" 12 #include "GrTypes.h" 13 #include "GrVertexBatch.h" 14 #include "SkMatrix.h" 15 #include "SkRect.h" 16 #include "SkTDArray.h" 17 18 class GrBatchFlushState; 19 struct GrInitInvariantOutput; 20 21 class GrDrawVerticesBatch : public GrVertexBatch { 22 public: 23 DEFINE_BATCH_CLASS_ID 24 25 struct Geometry { 26 GrColor fColor; // Only used if there are no per-vertex colors 27 SkTDArray<SkPoint> fPositions; 28 SkTDArray<uint16_t> fIndices; 29 SkTDArray<GrColor> fColors; 30 SkTDArray<SkPoint> fLocalCoords; 31 }; 32 Create(const Geometry & geometry,GrPrimitiveType primitiveType,const SkMatrix & viewMatrix,const SkPoint * positions,int vertexCount,const uint16_t * indices,int indexCount,const GrColor * colors,const SkPoint * localCoords,const SkRect & bounds)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) { 39 return new GrDrawVerticesBatch(geometry, primitiveType, viewMatrix, positions, vertexCount, 40 indices, indexCount, colors, localCoords, bounds); 41 } 42 name()43 const char* name() const override { return "DrawVerticesBatch"; } 44 45 void computePipelineOptimizations(GrInitInvariantOutput* color, 46 GrInitInvariantOutput* coverage, 47 GrBatchToXPOverrides* overrides) const override; 48 geoData()49 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 50 51 private: 52 void onPrepareDraws(Target*) const override; 53 void initBatchTracker(const GrXPOverridesForBatch&) override; 54 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 primitiveType()61 GrPrimitiveType primitiveType() const { return fPrimitiveType; } batchablePrimitiveType()62 bool batchablePrimitiveType() const { 63 return kTriangles_GrPrimitiveType == fPrimitiveType || 64 kLines_GrPrimitiveType == fPrimitiveType || 65 kPoints_GrPrimitiveType == fPrimitiveType; 66 } 67 68 bool onCombineIfPossible(GrBatch* t, const GrCaps&) override; 69 70 GrPrimitiveType fPrimitiveType; 71 SkMatrix fViewMatrix; 72 bool fVariableColor; 73 int fVertexCount; 74 int fIndexCount; 75 bool fCoverageIgnored; // comes from initBatchTracker. 76 77 SkSTArray<1, Geometry, true> fGeoData; 78 79 typedef GrVertexBatch INHERITED; 80 }; 81 82 #endif 83