blob: 680b41fbac72e37c6996c46401219ab79a172941 [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"
13#include "GrTypes.h"
14#include "SkMatrix.h"
15#include "SkRect.h"
16#include "SkTDArray.h"
17
18class GrOpFlushState;
19struct GrInitInvariantOutput;
20
21class GrDrawVerticesOp final : public GrMeshDrawOp {
22public:
23 DEFINE_OP_CLASS_ID
24
Brian Salomonf8334782017-01-03 09:42:58 -050025 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 Salomonfc527d22016-12-14 21:07:01 -050033 }
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 Salomonfc527d22016-12-14 21:07:01 -050046private:
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 Salomon92aee3d2016-12-21 09:20:25 -050052 void getPipelineAnalysisInput(GrPipelineAnalysisDrawOpInput* input) const override;
53 void applyPipelineOptimizations(const GrPipelineOptimizations&) override;
Brian Salomonfc527d22016-12-14 21:07:01 -050054 void onPrepareDraws(Target*) const override;
Brian Salomonfc527d22016-12-14 21:07:01 -050055
56 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
Brian Salomon53e4c3c2016-12-21 11:38:53 -050057 bool combinablePrimitive() const {
Brian Salomonfc527d22016-12-14 21:07:01 -050058 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 Salomonfc527d22016-12-14 21:07:01 -050078
79 SkSTArray<1, Mesh, true> fMeshes;
80
81 typedef GrMeshDrawOp INHERITED;
82};
83
84#endif