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