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 | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 14 | #include "GrSimpleMeshDrawOpHelper.h" |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 15 | #include "GrTypes.h" |
| 16 | #include "SkMatrix.h" |
| 17 | #include "SkRect.h" |
| 18 | #include "SkTDArray.h" |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 19 | #include "SkVertices.h" |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 20 | |
| 21 | class GrOpFlushState; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 22 | class SkVertices; |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 23 | struct GrInitInvariantOutput; |
| 24 | |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 25 | class GrDrawVerticesOp final : public GrMeshDrawOp { |
| 26 | private: |
| 27 | using Helper = GrSimpleMeshDrawOpHelper; |
| 28 | |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 29 | public: |
| 30 | DEFINE_OP_CLASS_ID |
| 31 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 32 | /** |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 33 | * Draw a SkVertices. The GrPaint param's color is used if the vertices lack per-vertex color. |
| 34 | * If the vertices lack local coords then the vertex positions are used as local coords. The |
| 35 | * primitive type drawn is derived from the SkVertices object, unless overridePrimType is |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 36 | * specified. |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 37 | */ |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 38 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, |
| 39 | GrPaint&&, |
| 40 | sk_sp<SkVertices>, |
| 41 | const SkMatrix& viewMatrix, |
| 42 | GrAAType, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 43 | sk_sp<GrColorSpaceXform>, |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 44 | GrPrimitiveType* overridePrimType = nullptr); |
| 45 | |
| 46 | GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, GrColor, sk_sp<SkVertices>, |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 47 | GrPrimitiveType, GrAAType, sk_sp<GrColorSpaceXform>, |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 48 | const SkMatrix& viewMatrix); |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 49 | |
| 50 | const char* name() const override { return "DrawVerticesOp"; } |
| 51 | |
Robert Phillips | f1748f5 | 2017-09-14 14:11:24 -0400 | [diff] [blame] | 52 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 53 | fHelper.visitProxies(func); |
| 54 | } |
| 55 | |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 56 | SkString dumpInfo() const override; |
| 57 | |
| 58 | FixedFunctionFlags fixedFunctionFlags() const override; |
| 59 | |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 60 | RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip, |
| 61 | GrPixelConfigIsClamped dstIsClamped) override; |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 62 | |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 63 | private: |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 64 | enum class ColorArrayType { |
| 65 | kPremulGrColor, |
| 66 | kSkColor, |
| 67 | }; |
| 68 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 69 | void onPrepareDraws(Target*) override; |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 70 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 71 | sk_sp<GrGeometryProcessor> makeGP(bool* hasColorAttribute, bool* hasLocalCoordAttribute) const; |
| 72 | |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 73 | GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
Brian Salomon | 53e4c3c | 2016-12-21 11:38:53 -0500 | [diff] [blame] | 74 | bool combinablePrimitive() const { |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 75 | return GrPrimitiveType::kTriangles == fPrimitiveType || |
| 76 | GrPrimitiveType::kLines == fPrimitiveType || |
| 77 | GrPrimitiveType::kPoints == fPrimitiveType; |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | bool onCombineIfPossible(GrOp* t, const GrCaps&) override; |
| 81 | |
| 82 | struct Mesh { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 83 | GrColor fColor; // Used if this->hasPerVertexColors() is false. |
| 84 | sk_sp<SkVertices> fVertices; |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 85 | SkMatrix fViewMatrix; |
Brian Osman | 8a03055 | 2017-05-23 15:03:18 -0400 | [diff] [blame] | 86 | bool fIgnoreTexCoords; |
| 87 | bool fIgnoreColors; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 88 | |
| 89 | bool hasExplicitLocalCoords() const { |
Brian Osman | 8a03055 | 2017-05-23 15:03:18 -0400 | [diff] [blame] | 90 | return fVertices->hasTexCoords() && !fIgnoreTexCoords; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | bool hasPerVertexColors() const { |
Brian Osman | 8a03055 | 2017-05-23 15:03:18 -0400 | [diff] [blame] | 94 | return fVertices->hasColors() && !fIgnoreColors; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 95 | } |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 96 | }; |
| 97 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 98 | bool isIndexed() const { |
| 99 | // Consistency enforced in onCombineIfPossible. |
Mike Reed | aa9e332 | 2017-03-16 14:38:48 -0400 | [diff] [blame] | 100 | return fMeshes[0].fVertices->hasIndices(); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | bool requiresPerVertexColors() const { |
| 104 | return SkToBool(kRequiresPerVertexColors_Flag & fFlags); |
| 105 | } |
| 106 | |
| 107 | bool anyMeshHasExplicitLocalCoords() const { |
| 108 | return SkToBool(kAnyMeshHasExplicitLocalCoords & fFlags); |
| 109 | } |
| 110 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 111 | bool hasMultipleViewMatrices() const { |
| 112 | return SkToBool(kHasMultipleViewMatrices_Flag & fFlags); |
| 113 | } |
| 114 | |
| 115 | enum Flags { |
| 116 | kRequiresPerVertexColors_Flag = 0x1, |
| 117 | kAnyMeshHasExplicitLocalCoords = 0x2, |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 118 | kHasMultipleViewMatrices_Flag = 0x4 |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 119 | |
| 120 | }; |
| 121 | |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 122 | Helper fHelper; |
| 123 | SkSTArray<1, Mesh, true> fMeshes; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 124 | // GrPrimitiveType is more expressive than fVertices.mode() so it is used instead and we ignore |
| 125 | // the SkVertices mode (though fPrimitiveType may have been inferred from it). |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 126 | GrPrimitiveType fPrimitiveType; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 127 | uint32_t fFlags; |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 128 | int fVertexCount; |
| 129 | int fIndexCount; |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 130 | ColorArrayType fColorArrayType; |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 131 | sk_sp<GrColorSpaceXform> fColorSpaceXform; |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 132 | |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 133 | typedef GrMeshDrawOp INHERITED; |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | #endif |