blob: 38b1a47e6c2677bb0ce49b6f437b656e45581730 [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 Salomonfc527d22016-12-14 21:07:01 -050014#include "GrTypes.h"
15#include "SkMatrix.h"
16#include "SkRect.h"
17#include "SkTDArray.h"
18
19class GrOpFlushState;
20struct GrInitInvariantOutput;
21
22class GrDrawVerticesOp final : public GrMeshDrawOp {
23public:
24 DEFINE_OP_CLASS_ID
25
Brian Salomonf8334782017-01-03 09:42:58 -050026 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 Salomon3de0aee2017-01-29 09:34:17 -050029 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 Salomonfc527d22016-12-14 21:07:01 -050035 }
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 Salomonfc527d22016-12-14 21:07:01 -050048private:
49 GrDrawVerticesOp(GrColor color, GrPrimitiveType primitiveType, const SkMatrix& viewMatrix,
50 const SkPoint* positions, int vertexCount, const uint16_t* indices,
Brian Salomon3de0aee2017-01-29 09:34:17 -050051 int indexCount, const uint32_t* colors, const SkPoint* localCoords,
52 const SkRect& bounds, GrRenderTargetContext::ColorArrayType colorArrayType);
Brian Salomonfc527d22016-12-14 21:07:01 -050053
Brian Salomon92aee3d2016-12-21 09:20:25 -050054 void getPipelineAnalysisInput(GrPipelineAnalysisDrawOpInput* input) const override;
55 void applyPipelineOptimizations(const GrPipelineOptimizations&) override;
Brian Salomonfc527d22016-12-14 21:07:01 -050056 void onPrepareDraws(Target*) const override;
Brian Salomonfc527d22016-12-14 21:07:01 -050057
58 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
Brian Salomon53e4c3c2016-12-21 11:38:53 -050059 bool combinablePrimitive() const {
Brian Salomonfc527d22016-12-14 21:07:01 -050060 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 Salomon3de0aee2017-01-29 09:34:17 -050071 SkTDArray<uint32_t> fColors;
Brian Salomonfc527d22016-12-14 21:07:01 -050072 SkTDArray<SkPoint> fLocalCoords;
73 };
74
75 GrPrimitiveType fPrimitiveType;
76 SkMatrix fViewMatrix;
77 bool fVariableColor;
78 int fVertexCount;
79 int fIndexCount;
Brian Salomon3de0aee2017-01-29 09:34:17 -050080 GrRenderTargetContext::ColorArrayType fColorArrayType;
Brian Salomonfc527d22016-12-14 21:07:01 -050081
82 SkSTArray<1, Mesh, true> fMeshes;
83
84 typedef GrMeshDrawOp INHERITED;
85};
86
87#endif