Line data Source code
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 "GrRenderTargetContext.h"
14 : #include "GrTypes.h"
15 : #include "SkMatrix.h"
16 : #include "SkRect.h"
17 : #include "SkTDArray.h"
18 : #include "SkVertices.h"
19 :
20 : class GrOpFlushState;
21 : class SkVertices;
22 : struct GrInitInvariantOutput;
23 :
24 0 : class GrDrawVerticesOp final : public GrLegacyMeshDrawOp {
25 : public:
26 0 : DEFINE_OP_CLASS_ID
27 :
28 : enum {
29 : kIgnoreTexCoords_VerticesFlag = 1 << 0,
30 : kIgnoreColors_VerticesFlag = 1 << 1,
31 : };
32 :
33 : /**
34 : * The 'color' param is used if the 'colors' array is null. 'bounds' is the bounds of the
35 : * 'positions' array (in local space prior to application of 'viewMatrix'). If 'indices' is null
36 : * then 'indexCnt' must be zero and vice versa. In this case the vertices are indexed as 0, 1,
37 : * ..., 'vertexCount' - 1. 'localCoords' are optional and if null the vertex positions are used
38 : * as local coords. 'colorArrayType' specifies whether the colors are premul GrColors or
39 : * unpremul SkColors.
40 : */
41 : static std::unique_ptr<GrLegacyMeshDrawOp> Make(
42 : GrColor color, GrPrimitiveType primitiveType, const SkMatrix& viewMatrix,
43 : const SkPoint* positions, int vertexCount, const uint16_t* indices, int indexCount,
44 : const uint32_t* colors, const SkPoint* localCoords, const SkRect& bounds,
45 : GrRenderTargetContext::ColorArrayType colorArrayType);
46 :
47 : /**
48 : * Draw a SkVertices. The GrColor param is used if the vertices lack per-vertex color or 'flags'
49 : * indicates that the per-vertex color should be ignored. The 'flags' options are those
50 : * specified by SkCanvas::VerticesFlags. If the vertices lack local coords or 'flags' indicates
51 : * that they should be ignored then the vertex positions are used as local coords.
52 : */
53 : static std::unique_ptr<GrLegacyMeshDrawOp> Make(GrColor color, sk_sp<SkVertices>,
54 : const SkMatrix& viewMatrix);
55 :
56 0 : const char* name() const override { return "DrawVerticesOp"; }
57 :
58 0 : SkString dumpInfo() const override {
59 0 : SkString string;
60 0 : string.appendf("PrimType: %d, MeshCount %d, VCount: %d, ICount: %d\n", fPrimitiveType,
61 0 : fMeshes.count(), fVertexCount, fIndexCount);
62 0 : string.append(DumpPipelineInfo(*this->pipeline()));
63 0 : string.append(INHERITED::dumpInfo());
64 0 : return string;
65 : }
66 :
67 : private:
68 : GrDrawVerticesOp(sk_sp<SkVertices>, GrPrimitiveType, GrColor,
69 : GrRenderTargetContext::ColorArrayType, const SkMatrix& viewMatrix,
70 : uint32_t flags = 0);
71 :
72 : void getProcessorAnalysisInputs(GrProcessorAnalysisColor* color,
73 : GrProcessorAnalysisCoverage* coverage) const override;
74 : void applyPipelineOptimizations(const PipelineOptimizations&) override;
75 : void onPrepareDraws(Target*) const override;
76 :
77 : sk_sp<GrGeometryProcessor> makeGP(bool* hasColorAttribute, bool* hasLocalCoordAttribute) const;
78 :
79 0 : GrPrimitiveType primitiveType() const { return fPrimitiveType; }
80 0 : bool combinablePrimitive() const {
81 0 : return kTriangles_GrPrimitiveType == fPrimitiveType ||
82 0 : kLines_GrPrimitiveType == fPrimitiveType ||
83 0 : kPoints_GrPrimitiveType == fPrimitiveType;
84 : }
85 :
86 : bool onCombineIfPossible(GrOp* t, const GrCaps&) override;
87 :
88 0 : struct Mesh {
89 : GrColor fColor; // Used if this->hasPerVertexColors() is false.
90 : sk_sp<SkVertices> fVertices;
91 : SkMatrix fViewMatrix;
92 : uint32_t fFlags;
93 :
94 0 : bool hasExplicitLocalCoords() const {
95 0 : return fVertices->hasTexCoords() && !(kIgnoreTexCoords_VerticesFlag & fFlags);
96 : }
97 :
98 0 : bool hasPerVertexColors() const {
99 0 : return fVertices->hasColors() && !(kIgnoreColors_VerticesFlag & fFlags);
100 : }
101 : };
102 :
103 0 : bool isIndexed() const {
104 : // Consistency enforced in onCombineIfPossible.
105 0 : return fMeshes[0].fVertices->hasIndices();
106 : }
107 :
108 0 : bool requiresPerVertexColors() const {
109 0 : return SkToBool(kRequiresPerVertexColors_Flag & fFlags);
110 : }
111 :
112 0 : bool anyMeshHasExplicitLocalCoords() const {
113 0 : return SkToBool(kAnyMeshHasExplicitLocalCoords & fFlags);
114 : }
115 :
116 0 : bool pipelineRequiresLocalCoords() const {
117 0 : return SkToBool(kPipelineRequiresLocalCoords_Flag & fFlags);
118 : }
119 :
120 0 : bool hasMultipleViewMatrices() const {
121 0 : return SkToBool(kHasMultipleViewMatrices_Flag & fFlags);
122 : }
123 :
124 : enum Flags {
125 : kRequiresPerVertexColors_Flag = 0x1,
126 : kAnyMeshHasExplicitLocalCoords = 0x2,
127 : kPipelineRequiresLocalCoords_Flag = 0x4,
128 : kHasMultipleViewMatrices_Flag = 0x8
129 :
130 : };
131 :
132 : // GrPrimitiveType is more expressive than fVertices.mode() so it is used instead and we ignore
133 : // the SkVertices mode (though fPrimitiveType may have been inferred from it).
134 : GrPrimitiveType fPrimitiveType;
135 : uint32_t fFlags;
136 : int fVertexCount;
137 : int fIndexCount;
138 : GrRenderTargetContext::ColorArrayType fColorArrayType;
139 : SkSTArray<1, Mesh, true> fMeshes;
140 :
141 : typedef GrLegacyMeshDrawOp INHERITED;
142 : };
143 :
144 : #endif
|