blob: 6d35c0d0e9dbc17efd43d2b2d2ff2d2ce6b022ce [file] [log] [blame]
* Copyright 2015 Google Inc.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
#ifndef GrDrawVerticesOp_DEFINED
#define GrDrawVerticesOp_DEFINED
#include "GrColor.h"
#include "GrMeshDrawOp.h"
#include "GrRenderTargetContext.h"
#include "GrSimpleMeshDrawOpHelper.h"
#include "GrTypes.h"
#include "SkMatrix.h"
#include "SkRect.h"
#include "SkTDArray.h"
#include "SkVertices.h"
class GrOpFlushState;
class SkVertices;
struct GrInitInvariantOutput;
class GrDrawVerticesOp final : public GrMeshDrawOp {
using Helper = GrSimpleMeshDrawOpHelper;
* Draw a SkVertices. The GrPaint param's color is used if the vertices lack per-vertex color.
* If the vertices lack local coords then the vertex positions are used as local coords. The
* primitive type drawn is derived from the SkVertices object, unless overridePrimType is
* specified.
static std::unique_ptr<GrDrawOp> Make(GrContext* context,
const SkMatrix& viewMatrix,
GrPrimitiveType* overridePrimType = nullptr);
GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, GrColor, sk_sp<SkVertices>,
GrPrimitiveType, GrAAType, sk_sp<GrColorSpaceXform>,
const SkMatrix& viewMatrix);
const char* name() const override { return "DrawVerticesOp"; }
void visitProxies(const VisitProxyFunc& func) const override {
SkString dumpInfo() const override;
FixedFunctionFlags fixedFunctionFlags() const override;
RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip,
GrPixelConfigIsClamped dstIsClamped) override;
enum class ColorArrayType {
void onPrepareDraws(Target*) override;
sk_sp<GrGeometryProcessor> makeGP(bool* hasColorAttribute, bool* hasLocalCoordAttribute) const;
GrPrimitiveType primitiveType() const { return fPrimitiveType; }
bool combinablePrimitive() const {
return GrPrimitiveType::kTriangles == fPrimitiveType ||
GrPrimitiveType::kLines == fPrimitiveType ||
GrPrimitiveType::kPoints == fPrimitiveType;
bool onCombineIfPossible(GrOp* t, const GrCaps&) override;
struct Mesh {
GrColor fColor; // Used if this->hasPerVertexColors() is false.
sk_sp<SkVertices> fVertices;
SkMatrix fViewMatrix;
bool fIgnoreTexCoords;
bool fIgnoreColors;
bool hasExplicitLocalCoords() const {
return fVertices->hasTexCoords() && !fIgnoreTexCoords;
bool hasPerVertexColors() const {
return fVertices->hasColors() && !fIgnoreColors;
bool isIndexed() const {
// Consistency enforced in onCombineIfPossible.
return fMeshes[0].fVertices->hasIndices();
bool requiresPerVertexColors() const {
return SkToBool(kRequiresPerVertexColors_Flag & fFlags);
bool anyMeshHasExplicitLocalCoords() const {
return SkToBool(kAnyMeshHasExplicitLocalCoords & fFlags);
bool hasMultipleViewMatrices() const {
return SkToBool(kHasMultipleViewMatrices_Flag & fFlags);
enum Flags {
kRequiresPerVertexColors_Flag = 0x1,
kAnyMeshHasExplicitLocalCoords = 0x2,
kHasMultipleViewMatrices_Flag = 0x4
Helper fHelper;
SkSTArray<1, Mesh, true> fMeshes;
// GrPrimitiveType is more expressive than fVertices.mode() so it is used instead and we ignore
// the SkVertices mode (though fPrimitiveType may have been inferred from it).
GrPrimitiveType fPrimitiveType;
uint32_t fFlags;
int fVertexCount;
int fIndexCount;
ColorArrayType fColorArrayType;
sk_sp<GrColorSpaceXform> fColorSpaceXform;
typedef GrMeshDrawOp INHERITED;