Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 1 | /* |
| 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 Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 12 | #include "GrGeometryProcessor.h" |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 13 | #include "GrQuad.h" |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 14 | #include "GrSamplerState.h" |
| 15 | #include "GrTypesPriv.h" |
| 16 | #include "SkPoint.h" |
| 17 | #include "SkPoint3.h" |
| 18 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 19 | class GrColorSpaceXform; |
| 20 | class GrShaderCaps; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 21 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 22 | namespace GrQuadPerEdgeAA { |
| 23 | |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 24 | enum class Domain : bool { kNo = false, kYes = true }; |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 25 | enum class ColorType { kNone, kByte, kHalf, kLast = kHalf }; |
| 26 | static const int kColorTypeCount = static_cast<int>(ColorType::kLast) + 1; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 27 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 28 | // 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 Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 34 | VertexSpec(GrQuadType deviceQuadType, ColorType colorType, GrQuadType localQuadType, |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 35 | bool hasLocalCoords, Domain domain, GrAAType aa) |
| 36 | : fDeviceQuadType(static_cast<unsigned>(deviceQuadType)) |
| 37 | , fLocalQuadType(static_cast<unsigned>(localQuadType)) |
| 38 | , fHasLocalCoords(hasLocalCoords) |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 39 | , fColorType(static_cast<unsigned>(colorType)) |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 40 | , fHasDomain(static_cast<unsigned>(domain)) |
| 41 | , fUsesCoverageAA(aa == GrAAType::kCoverage) { } |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 42 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 43 | GrQuadType deviceQuadType() const { return static_cast<GrQuadType>(fDeviceQuadType); } |
| 44 | GrQuadType localQuadType() const { return static_cast<GrQuadType>(fLocalQuadType); } |
| 45 | bool hasLocalCoords() const { return fHasLocalCoords; } |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 46 | ColorType colorType() const { return static_cast<ColorType>(fColorType); } |
| 47 | bool hasVertexColors() const { return ColorType::kNone != this->colorType(); } |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 48 | bool hasDomain() const { return fHasDomain; } |
| 49 | bool usesCoverageAA() const { return fUsesCoverageAA; } |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 50 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 51 | // 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 Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 55 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 56 | private: |
| 57 | static_assert(kGrQuadTypeCount <= 4, "GrQuadType doesn't fit in 2 bits"); |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 58 | static_assert(kColorTypeCount <= 4, "Color doesn't fit in 2 bits"); |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 59 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 60 | unsigned fDeviceQuadType: 2; |
| 61 | unsigned fLocalQuadType: 2; |
| 62 | unsigned fHasLocalCoords: 1; |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 63 | unsigned fColorType : 2; |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 64 | unsigned fHasDomain: 1; |
| 65 | unsigned fUsesCoverageAA: 1; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 66 | }; |
| 67 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 68 | sk_sp<GrGeometryProcessor> MakeProcessor(const VertexSpec& spec); |
Michael Ludwig | 20e909e | 2018-10-30 10:43:57 -0400 | [diff] [blame] | 69 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 70 | sk_sp<GrGeometryProcessor> MakeTexturedProcessor(const VertexSpec& spec, |
| 71 | const GrShaderCaps& caps, GrTextureType textureType, GrPixelConfig textureConfig, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame^] | 72 | const GrSamplerState& samplerState, uint32_t extraSamplerKey, |
| 73 | sk_sp<GrColorSpaceXform> textureColorSpaceXform); |
Michael Ludwig | 20e909e | 2018-10-30 10:43:57 -0400 | [diff] [blame] | 74 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 75 | // 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 Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 81 | void* Tessellate(void* vertices, const VertexSpec& spec, const GrPerspQuad& deviceQuad, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 82 | const SkPMColor4f& color, const GrPerspQuad& localQuad, const SkRect& domain, |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 83 | GrQuadAAFlags aa); |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 84 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 85 | } // namespace GrQuadPerEdgeAA |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 86 | |
| 87 | #endif // GrQuadPerEdgeAA_DEFINED |