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 | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 13 | #include "GrMeshDrawOp.h" |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 14 | #include "GrQuad.h" |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 15 | #include "GrSamplerState.h" |
| 16 | #include "GrTypesPriv.h" |
| 17 | #include "SkPoint.h" |
| 18 | #include "SkPoint3.h" |
| 19 | |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 20 | class GrCaps; |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 21 | class GrColorSpaceXform; |
| 22 | class GrShaderCaps; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 23 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 24 | namespace GrQuadPerEdgeAA { |
| 25 | |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 26 | enum class Domain : bool { kNo = false, kYes = true }; |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 27 | enum class ColorType { kNone, kByte, kHalf, kLast = kHalf }; |
| 28 | static const int kColorTypeCount = static_cast<int>(ColorType::kLast) + 1; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 29 | |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 30 | // Gets the minimum ColorType that can represent a color. |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 31 | ColorType MinColorType(SkPMColor4f, GrClampType, const GrCaps&); |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 32 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 33 | // Specifies the vertex configuration for an op that renders per-edge AA quads. The vertex |
| 34 | // order (when enabled) is device position, color, local position, domain, aa edge equations. |
| 35 | // This order matches the constructor argument order of VertexSpec and is the order that |
| 36 | // GPAttributes maintains. If hasLocalCoords is false, then the local quad type can be ignored. |
| 37 | struct VertexSpec { |
| 38 | public: |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 39 | VertexSpec(GrQuadType deviceQuadType, ColorType colorType, GrQuadType localQuadType, |
Brian Osman | 605c6d5 | 2019-03-15 12:10:35 -0400 | [diff] [blame] | 40 | bool hasLocalCoords, Domain domain, GrAAType aa, bool coverageAsAlpha) |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 41 | : fDeviceQuadType(static_cast<unsigned>(deviceQuadType)) |
| 42 | , fLocalQuadType(static_cast<unsigned>(localQuadType)) |
| 43 | , fHasLocalCoords(hasLocalCoords) |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 44 | , fColorType(static_cast<unsigned>(colorType)) |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 45 | , fHasDomain(static_cast<unsigned>(domain)) |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 46 | , fUsesCoverageAA(aa == GrAAType::kCoverage) |
Brian Osman | 605c6d5 | 2019-03-15 12:10:35 -0400 | [diff] [blame] | 47 | , fCompatibleWithCoverageAsAlpha(coverageAsAlpha) { } |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 48 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 49 | GrQuadType deviceQuadType() const { return static_cast<GrQuadType>(fDeviceQuadType); } |
| 50 | GrQuadType localQuadType() const { return static_cast<GrQuadType>(fLocalQuadType); } |
| 51 | bool hasLocalCoords() const { return fHasLocalCoords; } |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 52 | ColorType colorType() const { return static_cast<ColorType>(fColorType); } |
| 53 | bool hasVertexColors() const { return ColorType::kNone != this->colorType(); } |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 54 | bool hasDomain() const { return fHasDomain; } |
| 55 | bool usesCoverageAA() const { return fUsesCoverageAA; } |
Brian Osman | 605c6d5 | 2019-03-15 12:10:35 -0400 | [diff] [blame] | 56 | bool compatibleWithCoverageAsAlpha() const { return fCompatibleWithCoverageAsAlpha; } |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 57 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 58 | // Will always be 2 or 3 |
| 59 | int deviceDimensionality() const; |
| 60 | // Will always be 0 if hasLocalCoords is false, otherwise will be 2 or 3 |
| 61 | int localDimensionality() const; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 62 | |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 63 | int verticesPerQuad() const { return fUsesCoverageAA ? 8 : 4; } |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 64 | private: |
| 65 | static_assert(kGrQuadTypeCount <= 4, "GrQuadType doesn't fit in 2 bits"); |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 66 | static_assert(kColorTypeCount <= 4, "Color doesn't fit in 2 bits"); |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 67 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 68 | unsigned fDeviceQuadType: 2; |
| 69 | unsigned fLocalQuadType: 2; |
| 70 | unsigned fHasLocalCoords: 1; |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 71 | unsigned fColorType : 2; |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 72 | unsigned fHasDomain: 1; |
| 73 | unsigned fUsesCoverageAA: 1; |
Brian Osman | 605c6d5 | 2019-03-15 12:10:35 -0400 | [diff] [blame] | 74 | unsigned fCompatibleWithCoverageAsAlpha: 1; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 75 | }; |
| 76 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 77 | sk_sp<GrGeometryProcessor> MakeProcessor(const VertexSpec& spec); |
Michael Ludwig | 20e909e | 2018-10-30 10:43:57 -0400 | [diff] [blame] | 78 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 79 | sk_sp<GrGeometryProcessor> MakeTexturedProcessor(const VertexSpec& spec, |
| 80 | const GrShaderCaps& caps, GrTextureType textureType, GrPixelConfig textureConfig, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 81 | const GrSamplerState& samplerState, uint32_t extraSamplerKey, |
| 82 | sk_sp<GrColorSpaceXform> textureColorSpaceXform); |
Michael Ludwig | 20e909e | 2018-10-30 10:43:57 -0400 | [diff] [blame] | 83 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 84 | // Fill vertices with the vertex data needed to represent the given quad. The device position, |
| 85 | // local coords, vertex color, domain, and edge coefficients will be written and/or computed |
| 86 | // based on the configuration in the vertex spec; if that attribute is disabled in the spec, |
| 87 | // then its corresponding function argument is ignored. |
| 88 | // |
| 89 | // Returns the advanced pointer in vertices. |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 90 | void* Tessellate(void* vertices, const VertexSpec& spec, const GrPerspQuad& deviceQuad, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 91 | const SkPMColor4f& color, const GrPerspQuad& localQuad, const SkRect& domain, |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 92 | GrQuadAAFlags aa); |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 93 | |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 94 | // The mesh will have its index data configured to meet the expectations of the Tessellate() |
| 95 | // function, but it the calling code must handle filling a vertex buffer via Tessellate() and |
| 96 | // then assigning it to the returned mesh. |
| 97 | // |
| 98 | // Returns false if the index data could not be allocated. |
| 99 | bool ConfigureMeshIndices(GrMeshDrawOp::Target* target, GrMesh* mesh, const VertexSpec& spec, |
| 100 | int quadCount); |
| 101 | |
| 102 | static constexpr int kNumAAQuadsInIndexBuffer = 512; |
| 103 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 104 | } // namespace GrQuadPerEdgeAA |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 105 | |
| 106 | #endif // GrQuadPerEdgeAA_DEFINED |