Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [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 GrDrawVerticesOp_DEFINED |
| 9 | #define GrDrawVerticesOp_DEFINED |
| 10 | |
| 11 | #include "GrColor.h" |
| 12 | #include "GrMeshDrawOp.h" |
| 13 | #include "GrTypes.h" |
| 14 | #include "SkMatrix.h" |
| 15 | #include "SkRect.h" |
| 16 | #include "SkTDArray.h" |
| 17 | |
| 18 | class GrOpFlushState; |
| 19 | struct GrInitInvariantOutput; |
| 20 | |
| 21 | class GrDrawVerticesOp final : public GrMeshDrawOp { |
| 22 | public: |
| 23 | DEFINE_OP_CLASS_ID |
| 24 | |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 25 | static std::unique_ptr<GrDrawOp> Make(GrColor color, GrPrimitiveType primitiveType, |
| 26 | const SkMatrix& viewMatrix, const SkPoint* positions, |
| 27 | int vertexCount, const uint16_t* indices, int indexCount, |
| 28 | const GrColor* colors, const SkPoint* localCoords, |
| 29 | const SkRect& bounds) { |
| 30 | return std::unique_ptr<GrDrawOp>( |
| 31 | new GrDrawVerticesOp(color, primitiveType, viewMatrix, positions, vertexCount, |
| 32 | indices, indexCount, colors, localCoords, bounds)); |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | const char* name() const override { return "DrawVerticesOp"; } |
| 36 | |
| 37 | SkString dumpInfo() const override { |
| 38 | SkString string; |
| 39 | string.appendf("PrimType: %d, VarColor: %d, VCount: %d, ICount: %d\n", fPrimitiveType, |
| 40 | fVariableColor, fVertexCount, fIndexCount); |
| 41 | string.append(DumpPipelineInfo(*this->pipeline())); |
| 42 | string.append(INHERITED::dumpInfo()); |
| 43 | return string; |
| 44 | } |
| 45 | |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 46 | private: |
| 47 | GrDrawVerticesOp(GrColor color, GrPrimitiveType primitiveType, const SkMatrix& viewMatrix, |
| 48 | const SkPoint* positions, int vertexCount, const uint16_t* indices, |
| 49 | int indexCount, const GrColor* colors, const SkPoint* localCoords, |
| 50 | const SkRect& bounds); |
| 51 | |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 52 | void getPipelineAnalysisInput(GrPipelineAnalysisDrawOpInput* input) const override; |
| 53 | void applyPipelineOptimizations(const GrPipelineOptimizations&) override; |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 54 | void onPrepareDraws(Target*) const override; |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 55 | |
| 56 | GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
Brian Salomon | 53e4c3c | 2016-12-21 11:38:53 -0500 | [diff] [blame] | 57 | bool combinablePrimitive() const { |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 58 | return kTriangles_GrPrimitiveType == fPrimitiveType || |
| 59 | kLines_GrPrimitiveType == fPrimitiveType || |
| 60 | kPoints_GrPrimitiveType == fPrimitiveType; |
| 61 | } |
| 62 | |
| 63 | bool onCombineIfPossible(GrOp* t, const GrCaps&) override; |
| 64 | |
| 65 | struct Mesh { |
| 66 | GrColor fColor; // Only used if there are no per-vertex colors |
| 67 | SkTDArray<SkPoint> fPositions; |
| 68 | SkTDArray<uint16_t> fIndices; |
| 69 | SkTDArray<GrColor> fColors; |
| 70 | SkTDArray<SkPoint> fLocalCoords; |
| 71 | }; |
| 72 | |
| 73 | GrPrimitiveType fPrimitiveType; |
| 74 | SkMatrix fViewMatrix; |
| 75 | bool fVariableColor; |
| 76 | int fVertexCount; |
| 77 | int fIndexCount; |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 78 | |
| 79 | SkSTArray<1, Mesh, true> fMeshes; |
| 80 | |
| 81 | typedef GrMeshDrawOp INHERITED; |
| 82 | }; |
| 83 | |
| 84 | #endif |