blob: 6d35c0d0e9dbc17efd43d2b2d2ff2d2ce6b022ce [file] [log] [blame]
Brian Salomonfc527d22016-12-14 21:07:01 -05001/*
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 Salomon3de0aee2017-01-29 09:34:17 -050013#include "GrRenderTargetContext.h"
Brian Salomonc2f42542017-07-12 14:11:22 -040014#include "GrSimpleMeshDrawOpHelper.h"
Brian Salomonfc527d22016-12-14 21:07:01 -050015#include "GrTypes.h"
16#include "SkMatrix.h"
17#include "SkRect.h"
18#include "SkTDArray.h"
Brian Salomon199fb872017-02-06 09:41:10 -050019#include "SkVertices.h"
Brian Salomonfc527d22016-12-14 21:07:01 -050020
21class GrOpFlushState;
Brian Salomon199fb872017-02-06 09:41:10 -050022class SkVertices;
Brian Salomonfc527d22016-12-14 21:07:01 -050023struct GrInitInvariantOutput;
24
Brian Salomonc2f42542017-07-12 14:11:22 -040025class GrDrawVerticesOp final : public GrMeshDrawOp {
26private:
27 using Helper = GrSimpleMeshDrawOpHelper;
28
Brian Salomonfc527d22016-12-14 21:07:01 -050029public:
30 DEFINE_OP_CLASS_ID
31
Brian Salomon199fb872017-02-06 09:41:10 -050032 /**
Brian Salomonc2f42542017-07-12 14:11:22 -040033 * 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 Osman08a50e02018-06-15 15:06:48 -040036 * specified.
Brian Salomon199fb872017-02-06 09:41:10 -050037 */
Robert Phillips7c525e62018-06-12 10:11:12 -040038 static std::unique_ptr<GrDrawOp> Make(GrContext* context,
39 GrPaint&&,
40 sk_sp<SkVertices>,
41 const SkMatrix& viewMatrix,
42 GrAAType,
Robert Phillips7c525e62018-06-12 10:11:12 -040043 sk_sp<GrColorSpaceXform>,
Brian Salomonc2f42542017-07-12 14:11:22 -040044 GrPrimitiveType* overridePrimType = nullptr);
45
46 GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, GrColor, sk_sp<SkVertices>,
Brian Osman08a50e02018-06-15 15:06:48 -040047 GrPrimitiveType, GrAAType, sk_sp<GrColorSpaceXform>,
Brian Salomonc2f42542017-07-12 14:11:22 -040048 const SkMatrix& viewMatrix);
Brian Salomonfc527d22016-12-14 21:07:01 -050049
50 const char* name() const override { return "DrawVerticesOp"; }
51
Robert Phillipsf1748f52017-09-14 14:11:24 -040052 void visitProxies(const VisitProxyFunc& func) const override {
Robert Phillipsb493eeb2017-09-13 13:10:52 -040053 fHelper.visitProxies(func);
54 }
55
Brian Salomonc2f42542017-07-12 14:11:22 -040056 SkString dumpInfo() const override;
57
58 FixedFunctionFlags fixedFunctionFlags() const override;
59
Brian Osman9a725dd2017-09-20 09:53:22 -040060 RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip,
61 GrPixelConfigIsClamped dstIsClamped) override;
Brian Salomonfc527d22016-12-14 21:07:01 -050062
Brian Salomonfc527d22016-12-14 21:07:01 -050063private:
Brian Osmanae0c50c2017-05-25 16:56:34 -040064 enum class ColorArrayType {
65 kPremulGrColor,
66 kSkColor,
67 };
68
Brian Salomon91326c32017-08-09 16:02:19 -040069 void onPrepareDraws(Target*) override;
Brian Salomonfc527d22016-12-14 21:07:01 -050070
Brian Salomon199fb872017-02-06 09:41:10 -050071 sk_sp<GrGeometryProcessor> makeGP(bool* hasColorAttribute, bool* hasLocalCoordAttribute) const;
72
Brian Salomonfc527d22016-12-14 21:07:01 -050073 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
Brian Salomon53e4c3c2016-12-21 11:38:53 -050074 bool combinablePrimitive() const {
Chris Dalton3809bab2017-06-13 10:55:06 -060075 return GrPrimitiveType::kTriangles == fPrimitiveType ||
76 GrPrimitiveType::kLines == fPrimitiveType ||
77 GrPrimitiveType::kPoints == fPrimitiveType;
Brian Salomonfc527d22016-12-14 21:07:01 -050078 }
79
80 bool onCombineIfPossible(GrOp* t, const GrCaps&) override;
81
82 struct Mesh {
Brian Salomon199fb872017-02-06 09:41:10 -050083 GrColor fColor; // Used if this->hasPerVertexColors() is false.
84 sk_sp<SkVertices> fVertices;
Brian Salomon3f363692017-02-02 21:05:19 -050085 SkMatrix fViewMatrix;
Brian Osman8a030552017-05-23 15:03:18 -040086 bool fIgnoreTexCoords;
87 bool fIgnoreColors;
Brian Salomon199fb872017-02-06 09:41:10 -050088
89 bool hasExplicitLocalCoords() const {
Brian Osman8a030552017-05-23 15:03:18 -040090 return fVertices->hasTexCoords() && !fIgnoreTexCoords;
Brian Salomon199fb872017-02-06 09:41:10 -050091 }
92
93 bool hasPerVertexColors() const {
Brian Osman8a030552017-05-23 15:03:18 -040094 return fVertices->hasColors() && !fIgnoreColors;
Brian Salomon199fb872017-02-06 09:41:10 -050095 }
Brian Salomonfc527d22016-12-14 21:07:01 -050096 };
97
Brian Salomon199fb872017-02-06 09:41:10 -050098 bool isIndexed() const {
99 // Consistency enforced in onCombineIfPossible.
Mike Reedaa9e3322017-03-16 14:38:48 -0400100 return fMeshes[0].fVertices->hasIndices();
Brian Salomon199fb872017-02-06 09:41:10 -0500101 }
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 Salomon199fb872017-02-06 09:41:10 -0500111 bool hasMultipleViewMatrices() const {
112 return SkToBool(kHasMultipleViewMatrices_Flag & fFlags);
113 }
114
115 enum Flags {
116 kRequiresPerVertexColors_Flag = 0x1,
117 kAnyMeshHasExplicitLocalCoords = 0x2,
Brian Salomonc2f42542017-07-12 14:11:22 -0400118 kHasMultipleViewMatrices_Flag = 0x4
Brian Salomon199fb872017-02-06 09:41:10 -0500119
120 };
121
Brian Salomonc2f42542017-07-12 14:11:22 -0400122 Helper fHelper;
123 SkSTArray<1, Mesh, true> fMeshes;
Brian Salomon199fb872017-02-06 09:41:10 -0500124 // 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 Salomonfc527d22016-12-14 21:07:01 -0500126 GrPrimitiveType fPrimitiveType;
Brian Salomon199fb872017-02-06 09:41:10 -0500127 uint32_t fFlags;
Brian Salomonfc527d22016-12-14 21:07:01 -0500128 int fVertexCount;
129 int fIndexCount;
Brian Osmanae0c50c2017-05-25 16:56:34 -0400130 ColorArrayType fColorArrayType;
Brian Osmanfa6d8652017-05-31 09:37:27 -0400131 sk_sp<GrColorSpaceXform> fColorSpaceXform;
Brian Salomonfc527d22016-12-14 21:07:01 -0500132
Brian Salomonc2f42542017-07-12 14:11:22 -0400133 typedef GrMeshDrawOp INHERITED;
Brian Salomonfc527d22016-12-14 21:07:01 -0500134};
135
136#endif