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 | |
Michael Ludwig | fd4f4df | 2019-05-29 09:51:09 -0400 | [diff] [blame] | 8 | #include "src/gpu/ops/GrQuadPerEdgeAA.h" |
| 9 | |
Michael Ludwig | fb7ba52 | 2019-10-29 15:33:34 -0400 | [diff] [blame] | 10 | #include "include/private/SkVx.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrVertexWriter.h" |
| 12 | #include "src/gpu/SkGr.h" |
Michael Ludwig | fb7ba52 | 2019-10-29 15:33:34 -0400 | [diff] [blame] | 13 | #include "src/gpu/geometry/GrQuadUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/glsl/GrGLSLColorSpaceXformHelper.h" |
| 15 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 16 | #include "src/gpu/glsl/GrGLSLGeometryProcessor.h" |
| 17 | #include "src/gpu/glsl/GrGLSLPrimitiveProcessor.h" |
| 18 | #include "src/gpu/glsl/GrGLSLVarying.h" |
| 19 | #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h" |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 20 | |
Michael Ludwig | f995c05 | 2018-11-26 15:24:29 -0500 | [diff] [blame] | 21 | |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 22 | namespace { |
| 23 | |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 24 | // Writes four vertices in triangle strip order, including the additional data for local |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 25 | // coordinates, geometry + texture domains, color, and coverage as needed to satisfy the vertex spec |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 26 | static void write_quad(GrVertexWriter* vb, const GrQuadPerEdgeAA::VertexSpec& spec, |
Michael Ludwig | fb7ba52 | 2019-10-29 15:33:34 -0400 | [diff] [blame] | 27 | GrQuadPerEdgeAA::CoverageMode mode, const skvx::Vec<4, float>& coverage, |
| 28 | SkPMColor4f color4f, const SkRect& geomDomain, const SkRect& texDomain, |
| 29 | const GrQuad& deviceQuad, const GrQuad& localQuad) { |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 30 | static constexpr auto If = GrVertexWriter::If<float>; |
| 31 | |
Michael Ludwig | 553e9a9 | 2018-11-29 12:38:35 -0500 | [diff] [blame] | 32 | for (int i = 0; i < 4; ++i) { |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 33 | // save position, this is a float2 or float3 or float4 depending on the combination of |
| 34 | // perspective and coverage mode. |
Michael Ludwig | fb7ba52 | 2019-10-29 15:33:34 -0400 | [diff] [blame] | 35 | vb->write(deviceQuad.x(i), deviceQuad.y(i), |
| 36 | If(spec.deviceQuadType() == GrQuad::Type::kPerspective, deviceQuad.w(i)), |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 37 | If(mode == GrQuadPerEdgeAA::CoverageMode::kWithPosition, coverage[i])); |
Michael Ludwig | 4921dc3 | 2018-12-03 14:57:29 +0000 | [diff] [blame] | 38 | |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 39 | // save color |
| 40 | if (spec.hasVertexColors()) { |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 41 | bool wide = spec.colorType() == GrQuadPerEdgeAA::ColorType::kHalf; |
Michael Ludwig | e6266a2 | 2019-03-07 11:24:32 -0500 | [diff] [blame] | 42 | vb->write(GrVertexColor( |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 43 | color4f * (mode == GrQuadPerEdgeAA::CoverageMode::kWithColor ? coverage[i] : 1.f), |
| 44 | wide)); |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | // save local position |
| 48 | if (spec.hasLocalCoords()) { |
Michael Ludwig | fb7ba52 | 2019-10-29 15:33:34 -0400 | [diff] [blame] | 49 | vb->write(localQuad.x(i), localQuad.y(i), |
| 50 | If(spec.localQuadType() == GrQuad::Type::kPerspective, localQuad.w(i))); |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 51 | } |
| 52 | |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 53 | // save the geometry domain |
| 54 | if (spec.requiresGeometryDomain()) { |
| 55 | vb->write(geomDomain); |
| 56 | } |
| 57 | |
| 58 | // save the texture domain |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 59 | if (spec.hasDomain()) { |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 60 | vb->write(texDomain); |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 65 | } // anonymous namespace |
| 66 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 67 | namespace GrQuadPerEdgeAA { |
| 68 | |
Robert Phillips | c554dcf | 2019-10-28 11:43:55 -0400 | [diff] [blame] | 69 | IndexBufferOption CalcIndexBufferOption(GrAAType aa, int numQuads) { |
| 70 | if (aa == GrAAType::kCoverage) { |
| 71 | return IndexBufferOption::kPictureFramed; |
| 72 | } else if (numQuads > 1) { |
| 73 | return IndexBufferOption::kIndexedRects; |
| 74 | } else { |
| 75 | return IndexBufferOption::kTriStrips; |
| 76 | } |
| 77 | } |
| 78 | |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 79 | // This is a more elaborate version of SkPMColor4fNeedsWideColor that allows "no color" for white |
| 80 | ColorType MinColorType(SkPMColor4f color, GrClampType clampType, const GrCaps& caps) { |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 81 | if (color == SK_PMColor4fWHITE) { |
| 82 | return ColorType::kNone; |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 83 | } else { |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 84 | return SkPMColor4fNeedsWideColor(color, clampType, caps) ? ColorType::kHalf |
| 85 | : ColorType::kByte; |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 89 | ////////////////// Tessellate Implementation |
| 90 | |
Michael Ludwig | de4c58c | 2019-06-04 09:12:59 -0400 | [diff] [blame] | 91 | void* Tessellate(void* vertices, const VertexSpec& spec, const GrQuad& deviceQuad, |
| 92 | const SkPMColor4f& color4f, const GrQuad& localQuad, const SkRect& domain, |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 93 | GrQuadAAFlags aaFlags) { |
Michael Ludwig | 41f395d | 2019-05-23 13:59:45 -0400 | [diff] [blame] | 94 | SkASSERT(deviceQuad.quadType() <= spec.deviceQuadType()); |
| 95 | SkASSERT(!spec.hasLocalCoords() || localQuad.quadType() <= spec.localQuadType()); |
| 96 | |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 97 | GrQuadPerEdgeAA::CoverageMode mode = spec.coverageMode(); |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 98 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 99 | GrVertexWriter vb{vertices}; |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 100 | if (spec.usesCoverageAA()) { |
| 101 | SkASSERT(mode == CoverageMode::kWithPosition || mode == CoverageMode::kWithColor); |
Michael Ludwig | fb7ba52 | 2019-10-29 15:33:34 -0400 | [diff] [blame] | 102 | // Must calculate inner and outer quadrilaterals for the vertex coverage ramps, and possibly |
| 103 | // a geometry domain |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 104 | SkRect geomDomain; |
Michael Ludwig | fb7ba52 | 2019-10-29 15:33:34 -0400 | [diff] [blame] | 105 | if (spec.requiresGeometryDomain()) { |
| 106 | geomDomain = deviceQuad.bounds(); |
| 107 | geomDomain.outset(0.5f, 0.5f); // account for AA expansion |
Michael Ludwig | e6266a2 | 2019-03-07 11:24:32 -0500 | [diff] [blame] | 108 | } |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 109 | |
Michael Ludwig | fb7ba52 | 2019-10-29 15:33:34 -0400 | [diff] [blame] | 110 | // TODO(michaelludwig) - Update TessellateHelper to select processing functions based on the |
| 111 | // vertexspec once per op, and then burn through all quads with the selected function ptr. |
| 112 | GrQuadUtils::TessellationHelper helper(deviceQuad, |
| 113 | spec.hasLocalCoords() ? &localQuad : nullptr); |
| 114 | |
| 115 | // Write inner vertices first |
| 116 | GrQuad aaDeviceQuad, aaLocalQuad; |
| 117 | helper.inset(aaFlags, &aaDeviceQuad, &aaLocalQuad); |
| 118 | write_quad(&vb, spec, mode, helper.pixelCoverage(), color4f, geomDomain, domain, |
| 119 | aaDeviceQuad, aaLocalQuad); |
| 120 | |
| 121 | // Then outer vertices, which use 0.f for their coverage |
| 122 | helper.outset(aaFlags, &aaDeviceQuad, &aaLocalQuad); |
| 123 | write_quad(&vb, spec, mode, 0.f, color4f, geomDomain, domain, aaDeviceQuad, aaLocalQuad); |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 124 | } else { |
| 125 | // No outsetting needed, just write a single quad with full coverage |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 126 | SkASSERT(mode == CoverageMode::kNone && !spec.requiresGeometryDomain()); |
Michael Ludwig | fb7ba52 | 2019-10-29 15:33:34 -0400 | [diff] [blame] | 127 | write_quad(&vb, spec, mode, 1.f, color4f, SkRect::MakeEmpty(), domain, |
| 128 | deviceQuad, localQuad); |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 129 | } |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 130 | |
| 131 | return vb.fPtr; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 132 | } |
Michael Ludwig | 20e909e | 2018-10-30 10:43:57 -0400 | [diff] [blame] | 133 | |
Robert Phillips | fd0c3b5 | 2019-11-01 08:44:42 -0400 | [diff] [blame^] | 134 | sk_sp<const GrBuffer> GetIndexBuffer(GrMeshDrawOp::Target* target, |
| 135 | IndexBufferOption indexBufferOption) { |
Robert Phillips | ee08d52 | 2019-10-28 16:34:44 -0400 | [diff] [blame] | 136 | auto resourceProvider = target->resourceProvider(); |
| 137 | |
Robert Phillips | fd0c3b5 | 2019-11-01 08:44:42 -0400 | [diff] [blame^] | 138 | switch (indexBufferOption) { |
| 139 | case IndexBufferOption::kPictureFramed: return resourceProvider->refAAQuadIndexBuffer(); |
| 140 | case IndexBufferOption::kIndexedRects: return resourceProvider->refNonAAQuadIndexBuffer(); |
| 141 | case IndexBufferOption::kTriStrips: // fall through |
| 142 | default: return nullptr; |
| 143 | } |
| 144 | } |
Robert Phillips | c554dcf | 2019-10-28 11:43:55 -0400 | [diff] [blame] | 145 | |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 146 | |
Robert Phillips | fd0c3b5 | 2019-11-01 08:44:42 -0400 | [diff] [blame^] | 147 | void ConfigureMesh(GrMesh* mesh, const VertexSpec& spec, |
| 148 | int runningQuadCount, int quadsInDraw, int maxVerts, |
| 149 | sk_sp<const GrBuffer> vertexBuffer, |
| 150 | sk_sp<const GrBuffer> indexBuffer, int absVertBufferOffset) { |
| 151 | SkASSERT(vertexBuffer); |
Robert Phillips | c554dcf | 2019-10-28 11:43:55 -0400 | [diff] [blame] | 152 | |
Robert Phillips | fd0c3b5 | 2019-11-01 08:44:42 -0400 | [diff] [blame^] | 153 | if (spec.indexBufferOption() == IndexBufferOption::kTriStrips) { |
| 154 | SkASSERT(!indexBuffer); |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 155 | |
Robert Phillips | fd0c3b5 | 2019-11-01 08:44:42 -0400 | [diff] [blame^] | 156 | mesh->setPrimitiveType(GrPrimitiveType::kTriangleStrip); |
| 157 | mesh->setNonIndexedNonInstanced(4); |
| 158 | int offset = absVertBufferOffset + |
| 159 | runningQuadCount * GrResourceProvider::NumVertsPerNonAAQuad(); |
| 160 | mesh->setVertexData(std::move(vertexBuffer), offset); |
| 161 | return; |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Robert Phillips | fd0c3b5 | 2019-11-01 08:44:42 -0400 | [diff] [blame^] | 164 | SkASSERT(spec.indexBufferOption() == IndexBufferOption::kPictureFramed || |
| 165 | spec.indexBufferOption() == IndexBufferOption::kIndexedRects); |
| 166 | SkASSERT(indexBuffer); |
| 167 | |
| 168 | int baseIndex, numIndicesToDraw; |
| 169 | |
| 170 | if (spec.indexBufferOption() == IndexBufferOption::kPictureFramed) { |
| 171 | SkASSERT(runningQuadCount + quadsInDraw <= GrResourceProvider::MaxNumAAQuads()); |
| 172 | // AA uses 8 vertices and 30 indices per quad, basically nested rectangles |
| 173 | baseIndex = runningQuadCount * GrResourceProvider::NumIndicesPerAAQuad(); |
| 174 | numIndicesToDraw = quadsInDraw * GrResourceProvider::NumIndicesPerAAQuad(); |
| 175 | } else { |
| 176 | SkASSERT(runningQuadCount + quadsInDraw <= GrResourceProvider::MaxNumNonAAQuads()); |
| 177 | // Non-AA uses 4 vertices and 6 indices per quad |
| 178 | baseIndex = runningQuadCount * GrResourceProvider::NumIndicesPerNonAAQuad(); |
| 179 | numIndicesToDraw = quadsInDraw * GrResourceProvider::NumIndicesPerNonAAQuad(); |
| 180 | } |
| 181 | |
| 182 | mesh->setPrimitiveType(GrPrimitiveType::kTriangles); |
| 183 | mesh->setIndexed(std::move(indexBuffer), numIndicesToDraw, baseIndex, 0, maxVerts-1, |
| 184 | GrPrimitiveRestart::kNo); |
| 185 | mesh->setVertexData(std::move(vertexBuffer), absVertBufferOffset); |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 186 | } |
| 187 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 188 | ////////////////// VertexSpec Implementation |
Michael Ludwig | 20e909e | 2018-10-30 10:43:57 -0400 | [diff] [blame] | 189 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 190 | int VertexSpec::deviceDimensionality() const { |
Michael Ludwig | de4c58c | 2019-06-04 09:12:59 -0400 | [diff] [blame] | 191 | return this->deviceQuadType() == GrQuad::Type::kPerspective ? 3 : 2; |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | int VertexSpec::localDimensionality() const { |
Michael Ludwig | de4c58c | 2019-06-04 09:12:59 -0400 | [diff] [blame] | 195 | return fHasLocalCoords ? (this->localQuadType() == GrQuad::Type::kPerspective ? 3 : 2) : 0; |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 196 | } |
| 197 | |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 198 | CoverageMode VertexSpec::coverageMode() const { |
| 199 | if (this->usesCoverageAA()) { |
| 200 | if (this->compatibleWithCoverageAsAlpha() && this->hasVertexColors() && |
| 201 | !this->requiresGeometryDomain()) { |
| 202 | // Using a geometric domain acts as a second source of coverage and folding |
| 203 | // the original coverage into color makes it impossible to apply the color's |
| 204 | // alpha to the geometric domain's coverage when the original shape is clipped. |
| 205 | return CoverageMode::kWithColor; |
| 206 | } else { |
| 207 | return CoverageMode::kWithPosition; |
| 208 | } |
| 209 | } else { |
| 210 | return CoverageMode::kNone; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | // This needs to stay in sync w/ QuadPerEdgeAAGeometryProcessor::initializeAttrs |
| 215 | size_t VertexSpec::vertexSize() const { |
| 216 | bool needsPerspective = (this->deviceDimensionality() == 3); |
| 217 | CoverageMode coverageMode = this->coverageMode(); |
| 218 | |
| 219 | size_t count = 0; |
| 220 | |
| 221 | if (coverageMode == CoverageMode::kWithPosition) { |
| 222 | if (needsPerspective) { |
| 223 | count += GrVertexAttribTypeSize(kFloat4_GrVertexAttribType); |
| 224 | } else { |
| 225 | count += GrVertexAttribTypeSize(kFloat2_GrVertexAttribType) + |
| 226 | GrVertexAttribTypeSize(kFloat_GrVertexAttribType); |
| 227 | } |
| 228 | } else { |
| 229 | if (needsPerspective) { |
| 230 | count += GrVertexAttribTypeSize(kFloat3_GrVertexAttribType); |
| 231 | } else { |
| 232 | count += GrVertexAttribTypeSize(kFloat2_GrVertexAttribType); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | if (this->requiresGeometryDomain()) { |
| 237 | count += GrVertexAttribTypeSize(kFloat4_GrVertexAttribType); |
| 238 | } |
| 239 | |
| 240 | count += this->localDimensionality() * GrVertexAttribTypeSize(kFloat_GrVertexAttribType); |
| 241 | |
| 242 | if (ColorType::kByte == this->colorType()) { |
| 243 | count += GrVertexAttribTypeSize(kUByte4_norm_GrVertexAttribType); |
| 244 | } else if (ColorType::kHalf == this->colorType()) { |
| 245 | count += GrVertexAttribTypeSize(kHalf4_GrVertexAttribType); |
| 246 | } |
| 247 | |
| 248 | if (this->hasDomain()) { |
| 249 | count += GrVertexAttribTypeSize(kFloat4_GrVertexAttribType); |
| 250 | } |
| 251 | |
| 252 | return count; |
| 253 | } |
| 254 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 255 | ////////////////// Geometry Processor Implementation |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 256 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 257 | class QuadPerEdgeAAGeometryProcessor : public GrGeometryProcessor { |
| 258 | public: |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 259 | using Saturate = GrTextureOp::Saturate; |
Michael Ludwig | 20e909e | 2018-10-30 10:43:57 -0400 | [diff] [blame] | 260 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 261 | static sk_sp<GrGeometryProcessor> Make(const VertexSpec& spec) { |
| 262 | return sk_sp<QuadPerEdgeAAGeometryProcessor>(new QuadPerEdgeAAGeometryProcessor(spec)); |
Michael Ludwig | 20e909e | 2018-10-30 10:43:57 -0400 | [diff] [blame] | 263 | } |
| 264 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 265 | static sk_sp<GrGeometryProcessor> Make(const VertexSpec& vertexSpec, const GrShaderCaps& caps, |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 266 | const GrBackendFormat& backendFormat, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 267 | const GrSamplerState& samplerState, |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 268 | const GrSwizzle& swizzle, uint32_t extraSamplerKey, |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 269 | sk_sp<GrColorSpaceXform> textureColorSpaceXform, |
| 270 | Saturate saturate) { |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 271 | return sk_sp<QuadPerEdgeAAGeometryProcessor>(new QuadPerEdgeAAGeometryProcessor( |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 272 | vertexSpec, caps, backendFormat, samplerState, swizzle, extraSamplerKey, |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 273 | std::move(textureColorSpaceXform), saturate)); |
Michael Ludwig | 20e909e | 2018-10-30 10:43:57 -0400 | [diff] [blame] | 274 | } |
| 275 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 276 | const char* name() const override { return "QuadPerEdgeAAGeometryProcessor"; } |
Michael Ludwig | 024e262 | 2018-11-30 13:25:55 -0500 | [diff] [blame] | 277 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 278 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override { |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 279 | // texturing, device-dimensions are single bit flags |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 280 | uint32_t x = (fTexDomain.isInitialized() ? 0 : 0x1) |
| 281 | | (fSampler.isInitialized() ? 0 : 0x2) |
| 282 | | (fNeedsPerspective ? 0 : 0x4) |
| 283 | | (fSaturate == Saturate::kNo ? 0 : 0x8); |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 284 | // local coords require 2 bits (3 choices), 00 for none, 01 for 2d, 10 for 3d |
| 285 | if (fLocalCoord.isInitialized()) { |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 286 | x |= kFloat3_GrVertexAttribType == fLocalCoord.cpuType() ? 0x10 : 0x20; |
Brian Osman | 78dc72c | 2018-12-03 13:20:43 +0000 | [diff] [blame] | 287 | } |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 288 | // similar for colors, 00 for none, 01 for bytes, 10 for half-floats |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 289 | if (fColor.isInitialized()) { |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 290 | x |= kUByte4_norm_GrVertexAttribType == fColor.cpuType() ? 0x40 : 0x80; |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 291 | } |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 292 | // and coverage mode, 00 for none, 01 for withposition, 10 for withcolor, 11 for |
| 293 | // position+geomdomain |
| 294 | SkASSERT(!fGeomDomain.isInitialized() || fCoverageMode == CoverageMode::kWithPosition); |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 295 | if (fCoverageMode != CoverageMode::kNone) { |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 296 | x |= fGeomDomain.isInitialized() |
| 297 | ? 0x300 |
| 298 | : (CoverageMode::kWithPosition == fCoverageMode ? 0x100 : 0x200); |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | b->add32(GrColorSpaceXform::XformKey(fTextureColorSpaceXform.get())); |
| 302 | b->add32(x); |
Brian Osman | 78dc72c | 2018-12-03 13:20:43 +0000 | [diff] [blame] | 303 | } |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 304 | |
| 305 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps& caps) const override { |
| 306 | class GLSLProcessor : public GrGLSLGeometryProcessor { |
| 307 | public: |
| 308 | void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& proc, |
| 309 | FPCoordTransformIter&& transformIter) override { |
| 310 | const auto& gp = proc.cast<QuadPerEdgeAAGeometryProcessor>(); |
| 311 | if (gp.fLocalCoord.isInitialized()) { |
| 312 | this->setTransformDataHelper(SkMatrix::I(), pdman, &transformIter); |
| 313 | } |
| 314 | fTextureColorSpaceXformHelper.setData(pdman, gp.fTextureColorSpaceXform.get()); |
| 315 | } |
| 316 | |
| 317 | private: |
| 318 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
| 319 | using Interpolation = GrGLSLVaryingHandler::Interpolation; |
| 320 | |
| 321 | const auto& gp = args.fGP.cast<QuadPerEdgeAAGeometryProcessor>(); |
| 322 | fTextureColorSpaceXformHelper.emitCode(args.fUniformHandler, |
| 323 | gp.fTextureColorSpaceXform.get()); |
| 324 | |
| 325 | args.fVaryingHandler->emitAttributes(gp); |
| 326 | |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 327 | if (gp.fCoverageMode == CoverageMode::kWithPosition) { |
| 328 | // Strip last channel from the vertex attribute to remove coverage and get the |
| 329 | // actual position |
| 330 | if (gp.fNeedsPerspective) { |
| 331 | args.fVertBuilder->codeAppendf("float3 position = %s.xyz;", |
| 332 | gp.fPosition.name()); |
| 333 | } else { |
| 334 | args.fVertBuilder->codeAppendf("float2 position = %s.xy;", |
| 335 | gp.fPosition.name()); |
| 336 | } |
| 337 | gpArgs->fPositionVar = {"position", |
| 338 | gp.fNeedsPerspective ? kFloat3_GrSLType |
| 339 | : kFloat2_GrSLType, |
| 340 | GrShaderVar::kNone_TypeModifier}; |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 341 | } else { |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 342 | // No coverage to eliminate |
| 343 | gpArgs->fPositionVar = gp.fPosition.asShaderVar(); |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 344 | } |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 345 | |
| 346 | // Handle local coordinates if they exist |
| 347 | if (gp.fLocalCoord.isInitialized()) { |
| 348 | // NOTE: If the only usage of local coordinates is for the inline texture fetch |
| 349 | // before FPs, then there are no registered FPCoordTransforms and this ends up |
| 350 | // emitting nothing, so there isn't a duplication of local coordinates |
| 351 | this->emitTransforms(args.fVertBuilder, |
| 352 | args.fVaryingHandler, |
| 353 | args.fUniformHandler, |
| 354 | gp.fLocalCoord.asShaderVar(), |
| 355 | args.fFPCoordTransformHandler); |
| 356 | } |
| 357 | |
| 358 | // Solid color before any texturing gets modulated in |
| 359 | if (gp.fColor.isInitialized()) { |
Michael Ludwig | 3d2753e | 2019-03-29 14:36:32 -0400 | [diff] [blame] | 360 | SkASSERT(gp.fCoverageMode != CoverageMode::kWithColor || !gp.fNeedsPerspective); |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 361 | // The color cannot be flat if the varying coverage has been modulated into it |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 362 | args.fVaryingHandler->addPassThroughAttribute(gp.fColor, args.fOutputColor, |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 363 | gp.fCoverageMode == CoverageMode::kWithColor ? |
| 364 | Interpolation::kInterpolated : Interpolation::kCanBeFlat); |
| 365 | } else { |
| 366 | // Output color must be initialized to something |
| 367 | args.fFragBuilder->codeAppendf("%s = half4(1);", args.fOutputColor); |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | // If there is a texture, must also handle texture coordinates and reading from |
| 371 | // the texture in the fragment shader before continuing to fragment processors. |
| 372 | if (gp.fSampler.isInitialized()) { |
| 373 | // Texture coordinates clamped by the domain on the fragment shader; if the GP |
| 374 | // has a texture, it's guaranteed to have local coordinates |
| 375 | args.fFragBuilder->codeAppend("float2 texCoord;"); |
| 376 | if (gp.fLocalCoord.cpuType() == kFloat3_GrVertexAttribType) { |
| 377 | // Can't do a pass through since we need to perform perspective division |
| 378 | GrGLSLVarying v(gp.fLocalCoord.gpuType()); |
| 379 | args.fVaryingHandler->addVarying(gp.fLocalCoord.name(), &v); |
| 380 | args.fVertBuilder->codeAppendf("%s = %s;", |
| 381 | v.vsOut(), gp.fLocalCoord.name()); |
| 382 | args.fFragBuilder->codeAppendf("texCoord = %s.xy / %s.z;", |
| 383 | v.fsIn(), v.fsIn()); |
| 384 | } else { |
| 385 | args.fVaryingHandler->addPassThroughAttribute(gp.fLocalCoord, "texCoord"); |
| 386 | } |
| 387 | |
| 388 | // Clamp the now 2D localCoordName variable by the domain if it is provided |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 389 | if (gp.fTexDomain.isInitialized()) { |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 390 | args.fFragBuilder->codeAppend("float4 domain;"); |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 391 | args.fVaryingHandler->addPassThroughAttribute(gp.fTexDomain, "domain", |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 392 | Interpolation::kCanBeFlat); |
| 393 | args.fFragBuilder->codeAppend( |
| 394 | "texCoord = clamp(texCoord, domain.xy, domain.zw);"); |
| 395 | } |
| 396 | |
| 397 | // Now modulate the starting output color by the texture lookup |
| 398 | args.fFragBuilder->codeAppendf("%s = ", args.fOutputColor); |
| 399 | args.fFragBuilder->appendTextureLookupAndModulate( |
| 400 | args.fOutputColor, args.fTexSamplers[0], "texCoord", kFloat2_GrSLType, |
| 401 | &fTextureColorSpaceXformHelper); |
| 402 | args.fFragBuilder->codeAppend(";"); |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 403 | if (gp.fSaturate == Saturate::kYes) { |
| 404 | args.fFragBuilder->codeAppendf("%s = saturate(%s);", |
| 405 | args.fOutputColor, args.fOutputColor); |
| 406 | } |
| 407 | } else { |
| 408 | // Saturate is only intended for use with a proxy to account for the fact |
| 409 | // that GrTextureOp skips SkPaint conversion, which normally handles this. |
| 410 | SkASSERT(gp.fSaturate == Saturate::kNo); |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | // And lastly, output the coverage calculation code |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 414 | if (gp.fCoverageMode == CoverageMode::kWithPosition) { |
| 415 | GrGLSLVarying coverage(kFloat_GrSLType); |
| 416 | args.fVaryingHandler->addVarying("coverage", &coverage); |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 417 | if (gp.fNeedsPerspective) { |
Michael Ludwig | 3d2753e | 2019-03-29 14:36:32 -0400 | [diff] [blame] | 418 | // Multiply by "W" in the vertex shader, then by 1/w (sk_FragCoord.w) in |
| 419 | // the fragment shader to get screen-space linear coverage. |
| 420 | args.fVertBuilder->codeAppendf("%s = %s.w * %s.z;", |
| 421 | coverage.vsOut(), gp.fPosition.name(), |
| 422 | gp.fPosition.name()); |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 423 | args.fFragBuilder->codeAppendf("float coverage = %s * sk_FragCoord.w;", |
| 424 | coverage.fsIn()); |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 425 | } else { |
Jim Van Verth | d5d9c21 | 2019-05-02 10:22:10 -0400 | [diff] [blame] | 426 | args.fVertBuilder->codeAppendf("%s = %s;", |
| 427 | coverage.vsOut(), gp.fCoverage.name()); |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 428 | args.fFragBuilder->codeAppendf("float coverage = %s;", coverage.fsIn()); |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 429 | } |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 430 | |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 431 | if (gp.fGeomDomain.isInitialized()) { |
| 432 | // Calculate distance from sk_FragCoord to the 4 edges of the domain |
| 433 | // and clamp them to (0, 1). Use the minimum of these and the original |
| 434 | // coverage. This only has to be done in the exterior triangles, the |
| 435 | // interior of the quad geometry can never be clipped by the domain box. |
| 436 | args.fFragBuilder->codeAppend("float4 geoDomain;"); |
| 437 | args.fVaryingHandler->addPassThroughAttribute(gp.fGeomDomain, "geoDomain", |
| 438 | Interpolation::kCanBeFlat); |
| 439 | args.fFragBuilder->codeAppend( |
| 440 | "if (coverage < 0.5) {" |
| 441 | " float4 dists4 = clamp(float4(1, 1, -1, -1) * " |
| 442 | "(sk_FragCoord.xyxy - geoDomain), 0, 1);" |
| 443 | " float2 dists2 = dists4.xy * dists4.zw;" |
| 444 | " coverage = min(coverage, dists2.x * dists2.y);" |
| 445 | "}"); |
| 446 | } |
| 447 | |
| 448 | args.fFragBuilder->codeAppendf("%s = half4(half(coverage));", |
| 449 | args.fOutputCoverage); |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 450 | } else { |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 451 | // Set coverage to 1, since it's either non-AA or the coverage was already |
| 452 | // folded into the output color |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 453 | SkASSERT(!gp.fGeomDomain.isInitialized()); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 454 | args.fFragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage); |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | GrGLSLColorSpaceXformHelper fTextureColorSpaceXformHelper; |
| 458 | }; |
| 459 | return new GLSLProcessor; |
| 460 | } |
| 461 | |
| 462 | private: |
| 463 | QuadPerEdgeAAGeometryProcessor(const VertexSpec& spec) |
| 464 | : INHERITED(kQuadPerEdgeAAGeometryProcessor_ClassID) |
| 465 | , fTextureColorSpaceXform(nullptr) { |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 466 | SkASSERT(!spec.hasDomain()); |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 467 | this->initializeAttrs(spec); |
| 468 | this->setTextureSamplerCnt(0); |
| 469 | } |
| 470 | |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 471 | QuadPerEdgeAAGeometryProcessor(const VertexSpec& spec, |
| 472 | const GrShaderCaps& caps, |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 473 | const GrBackendFormat& backendFormat, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 474 | const GrSamplerState& samplerState, |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 475 | const GrSwizzle& swizzle, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 476 | uint32_t extraSamplerKey, |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 477 | sk_sp<GrColorSpaceXform> textureColorSpaceXform, |
| 478 | Saturate saturate) |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 479 | : INHERITED(kQuadPerEdgeAAGeometryProcessor_ClassID) |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 480 | , fSaturate(saturate) |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 481 | , fTextureColorSpaceXform(std::move(textureColorSpaceXform)) |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 482 | , fSampler(samplerState, backendFormat, swizzle, extraSamplerKey) { |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 483 | SkASSERT(spec.hasLocalCoords()); |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 484 | this->initializeAttrs(spec); |
| 485 | this->setTextureSamplerCnt(1); |
| 486 | } |
| 487 | |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 488 | // This needs to stay in sync w/ VertexSpec::vertexSize |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 489 | void initializeAttrs(const VertexSpec& spec) { |
| 490 | fNeedsPerspective = spec.deviceDimensionality() == 3; |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 491 | fCoverageMode = spec.coverageMode(); |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 492 | |
| 493 | if (fCoverageMode == CoverageMode::kWithPosition) { |
| 494 | if (fNeedsPerspective) { |
| 495 | fPosition = {"positionWithCoverage", kFloat4_GrVertexAttribType, kFloat4_GrSLType}; |
| 496 | } else { |
Jim Van Verth | d5d9c21 | 2019-05-02 10:22:10 -0400 | [diff] [blame] | 497 | fPosition = {"position", kFloat2_GrVertexAttribType, kFloat2_GrSLType}; |
| 498 | fCoverage = {"coverage", kFloat_GrVertexAttribType, kFloat_GrSLType}; |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 499 | } |
| 500 | } else { |
| 501 | if (fNeedsPerspective) { |
| 502 | fPosition = {"position", kFloat3_GrVertexAttribType, kFloat3_GrSLType}; |
| 503 | } else { |
| 504 | fPosition = {"position", kFloat2_GrVertexAttribType, kFloat2_GrSLType}; |
| 505 | } |
| 506 | } |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 507 | |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 508 | // Need a geometry domain when the quads are AA and not rectilinear, since their AA |
| 509 | // outsetting can go beyond a half pixel. |
| 510 | if (spec.requiresGeometryDomain()) { |
| 511 | fGeomDomain = {"geomDomain", kFloat4_GrVertexAttribType, kFloat4_GrSLType}; |
| 512 | } |
| 513 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 514 | int localDim = spec.localDimensionality(); |
| 515 | if (localDim == 3) { |
| 516 | fLocalCoord = {"localCoord", kFloat3_GrVertexAttribType, kFloat3_GrSLType}; |
| 517 | } else if (localDim == 2) { |
| 518 | fLocalCoord = {"localCoord", kFloat2_GrVertexAttribType, kFloat2_GrSLType}; |
| 519 | } // else localDim == 0 and attribute remains uninitialized |
| 520 | |
| 521 | if (ColorType::kByte == spec.colorType()) { |
| 522 | fColor = {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType}; |
| 523 | } else if (ColorType::kHalf == spec.colorType()) { |
| 524 | fColor = {"color", kHalf4_GrVertexAttribType, kHalf4_GrSLType}; |
| 525 | } |
| 526 | |
| 527 | if (spec.hasDomain()) { |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 528 | fTexDomain = {"texDomain", kFloat4_GrVertexAttribType, kFloat4_GrSLType}; |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 529 | } |
| 530 | |
Jim Van Verth | d5d9c21 | 2019-05-02 10:22:10 -0400 | [diff] [blame] | 531 | this->setVertexAttributes(&fPosition, 6); |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | const TextureSampler& onTextureSampler(int) const override { return fSampler; } |
| 535 | |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 536 | Attribute fPosition; // May contain coverage as last channel |
Jim Van Verth | d5d9c21 | 2019-05-02 10:22:10 -0400 | [diff] [blame] | 537 | Attribute fCoverage; // Used for non-perspective position to avoid Intel Metal issues |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 538 | Attribute fColor; // May have coverage modulated in if the FPs support it |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 539 | Attribute fLocalCoord; |
Michael Ludwig | dcfbe32 | 2019-04-01 14:55:54 -0400 | [diff] [blame] | 540 | Attribute fGeomDomain; // Screen-space bounding box on geometry+aa outset |
| 541 | Attribute fTexDomain; // Texture-space bounding box on local coords |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 542 | |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 543 | // The positions attribute may have coverage built into it, so float3 is an ambiguous type |
| 544 | // and may mean 2d with coverage, or 3d with no coverage |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 545 | bool fNeedsPerspective; |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 546 | // Should saturate() be called on the color? Only relevant when created with a texture. |
| 547 | Saturate fSaturate = Saturate::kNo; |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 548 | CoverageMode fCoverageMode; |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 549 | |
| 550 | // Color space will be null and fSampler.isInitialized() returns false when the GP is configured |
| 551 | // to skip texturing. |
| 552 | sk_sp<GrColorSpaceXform> fTextureColorSpaceXform; |
| 553 | TextureSampler fSampler; |
| 554 | |
| 555 | typedef GrGeometryProcessor INHERITED; |
| 556 | }; |
| 557 | |
| 558 | sk_sp<GrGeometryProcessor> MakeProcessor(const VertexSpec& spec) { |
| 559 | return QuadPerEdgeAAGeometryProcessor::Make(spec); |
| 560 | } |
| 561 | |
| 562 | sk_sp<GrGeometryProcessor> MakeTexturedProcessor(const VertexSpec& spec, const GrShaderCaps& caps, |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 563 | const GrBackendFormat& backendFormat, |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 564 | const GrSamplerState& samplerState, |
| 565 | const GrSwizzle& swizzle, uint32_t extraSamplerKey, |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 566 | sk_sp<GrColorSpaceXform> textureColorSpaceXform, |
| 567 | Saturate saturate) { |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 568 | return QuadPerEdgeAAGeometryProcessor::Make(spec, caps, backendFormat, samplerState, swizzle, |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 569 | extraSamplerKey, std::move(textureColorSpaceXform), |
| 570 | saturate); |
Michael Ludwig | 20e909e | 2018-10-30 10:43:57 -0400 | [diff] [blame] | 571 | } |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 572 | |
| 573 | } // namespace GrQuadPerEdgeAA |