blob: 68e798cdcd35c9eb1685b51cecb995f7a28125e1 [file] [log] [blame]
Michael Ludwig460eb5e2018-10-29 11:09:29 -04001/*
2 * Copyright 2018 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 GrQuadPerEdgeAA_DEFINED
9#define GrQuadPerEdgeAA_DEFINED
10
11#include "GrColor.h"
Michael Ludwig467994d2018-12-03 14:58:31 +000012#include "GrGeometryProcessor.h"
Michael Ludwigc182b942018-11-16 10:27:51 -050013#include "GrQuad.h"
Michael Ludwig460eb5e2018-10-29 11:09:29 -040014#include "GrSamplerState.h"
15#include "GrTypesPriv.h"
16#include "SkPoint.h"
17#include "SkPoint3.h"
18
Michael Ludwig467994d2018-12-03 14:58:31 +000019class GrColorSpaceXform;
20class GrShaderCaps;
Michael Ludwig460eb5e2018-10-29 11:09:29 -040021
Michael Ludwigc182b942018-11-16 10:27:51 -050022namespace GrQuadPerEdgeAA {
23
Michael Ludwig460eb5e2018-10-29 11:09:29 -040024 enum class Domain : bool { kNo = false, kYes = true };
Brian Osman3d139a42018-11-19 10:42:10 -050025 enum class ColorType { kNone, kByte, kHalf, kLast = kHalf };
26 static const int kColorTypeCount = static_cast<int>(ColorType::kLast) + 1;
Michael Ludwig460eb5e2018-10-29 11:09:29 -040027
Michael Ludwigc182b942018-11-16 10:27:51 -050028 // Specifies the vertex configuration for an op that renders per-edge AA quads. The vertex
29 // order (when enabled) is device position, color, local position, domain, aa edge equations.
30 // This order matches the constructor argument order of VertexSpec and is the order that
31 // GPAttributes maintains. If hasLocalCoords is false, then the local quad type can be ignored.
32 struct VertexSpec {
33 public:
Brian Osman3d139a42018-11-19 10:42:10 -050034 VertexSpec(GrQuadType deviceQuadType, ColorType colorType, GrQuadType localQuadType,
Michael Ludwigc182b942018-11-16 10:27:51 -050035 bool hasLocalCoords, Domain domain, GrAAType aa)
36 : fDeviceQuadType(static_cast<unsigned>(deviceQuadType))
37 , fLocalQuadType(static_cast<unsigned>(localQuadType))
38 , fHasLocalCoords(hasLocalCoords)
Brian Osman3d139a42018-11-19 10:42:10 -050039 , fColorType(static_cast<unsigned>(colorType))
Michael Ludwigc182b942018-11-16 10:27:51 -050040 , fHasDomain(static_cast<unsigned>(domain))
41 , fUsesCoverageAA(aa == GrAAType::kCoverage) { }
Michael Ludwig460eb5e2018-10-29 11:09:29 -040042
Michael Ludwigc182b942018-11-16 10:27:51 -050043 GrQuadType deviceQuadType() const { return static_cast<GrQuadType>(fDeviceQuadType); }
44 GrQuadType localQuadType() const { return static_cast<GrQuadType>(fLocalQuadType); }
45 bool hasLocalCoords() const { return fHasLocalCoords; }
Brian Osman3d139a42018-11-19 10:42:10 -050046 ColorType colorType() const { return static_cast<ColorType>(fColorType); }
47 bool hasVertexColors() const { return ColorType::kNone != this->colorType(); }
Michael Ludwigc182b942018-11-16 10:27:51 -050048 bool hasDomain() const { return fHasDomain; }
49 bool usesCoverageAA() const { return fUsesCoverageAA; }
Michael Ludwig460eb5e2018-10-29 11:09:29 -040050
Michael Ludwigc182b942018-11-16 10:27:51 -050051 // Will always be 2 or 3
52 int deviceDimensionality() const;
53 // Will always be 0 if hasLocalCoords is false, otherwise will be 2 or 3
54 int localDimensionality() const;
Michael Ludwig460eb5e2018-10-29 11:09:29 -040055
Michael Ludwigc182b942018-11-16 10:27:51 -050056 private:
57 static_assert(kGrQuadTypeCount <= 4, "GrQuadType doesn't fit in 2 bits");
Brian Osman3d139a42018-11-19 10:42:10 -050058 static_assert(kColorTypeCount <= 4, "Color doesn't fit in 2 bits");
Michael Ludwig460eb5e2018-10-29 11:09:29 -040059
Michael Ludwigc182b942018-11-16 10:27:51 -050060 unsigned fDeviceQuadType: 2;
61 unsigned fLocalQuadType: 2;
62 unsigned fHasLocalCoords: 1;
Brian Osman3d139a42018-11-19 10:42:10 -050063 unsigned fColorType : 2;
Michael Ludwigc182b942018-11-16 10:27:51 -050064 unsigned fHasDomain: 1;
65 unsigned fUsesCoverageAA: 1;
Michael Ludwig460eb5e2018-10-29 11:09:29 -040066 };
67
Michael Ludwig467994d2018-12-03 14:58:31 +000068 sk_sp<GrGeometryProcessor> MakeProcessor(const VertexSpec& spec);
Michael Ludwig20e909e2018-10-30 10:43:57 -040069
Michael Ludwig467994d2018-12-03 14:58:31 +000070 sk_sp<GrGeometryProcessor> MakeTexturedProcessor(const VertexSpec& spec,
71 const GrShaderCaps& caps, GrTextureType textureType, GrPixelConfig textureConfig,
Greg Daniel7a82edf2018-12-04 10:54:34 -050072 const GrSamplerState& samplerState, uint32_t extraSamplerKey,
73 sk_sp<GrColorSpaceXform> textureColorSpaceXform);
Michael Ludwig20e909e2018-10-30 10:43:57 -040074
Michael Ludwigc182b942018-11-16 10:27:51 -050075 // Fill vertices with the vertex data needed to represent the given quad. The device position,
76 // local coords, vertex color, domain, and edge coefficients will be written and/or computed
77 // based on the configuration in the vertex spec; if that attribute is disabled in the spec,
78 // then its corresponding function argument is ignored.
79 //
80 // Returns the advanced pointer in vertices.
Michael Ludwigc182b942018-11-16 10:27:51 -050081 void* Tessellate(void* vertices, const VertexSpec& spec, const GrPerspQuad& deviceQuad,
Brian Osman3d139a42018-11-19 10:42:10 -050082 const SkPMColor4f& color, const GrPerspQuad& localQuad, const SkRect& domain,
Michael Ludwigc182b942018-11-16 10:27:51 -050083 GrQuadAAFlags aa);
Michael Ludwig460eb5e2018-10-29 11:09:29 -040084
Michael Ludwigc182b942018-11-16 10:27:51 -050085} // namespace GrQuadPerEdgeAA
Michael Ludwig460eb5e2018-10-29 11:09:29 -040086
87#endif // GrQuadPerEdgeAA_DEFINED