Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 8 | #ifndef GrCCCoverageProcessor_DEFINED |
| 9 | #define GrCCCoverageProcessor_DEFINED |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 10 | |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 11 | #include "GrCaps.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 12 | #include "GrGeometryProcessor.h" |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 13 | #include "GrPipeline.h" |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 14 | #include "GrShaderCaps.h" |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 15 | #include "SkNx.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 16 | #include "glsl/GrGLSLGeometryProcessor.h" |
| 17 | #include "glsl/GrGLSLVarying.h" |
| 18 | |
Chris Dalton | 6028361 | 2018-02-14 13:38:14 -0700 | [diff] [blame] | 19 | class GrGLSLFPFragmentBuilder; |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 20 | class GrGLSLVertexGeoBuilder; |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 21 | class GrMesh; |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 22 | class GrOpFlushState; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 23 | |
| 24 | /** |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 25 | * This is the geometry processor for the simple convex primitive shapes (triangles and closed, |
| 26 | * convex bezier curves) from which ccpr paths are composed. The output is a single-channel alpha |
| 27 | * value, positive for clockwise shapes and negative for counter-clockwise, that indicates coverage. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 28 | * |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 29 | * The caller is responsible to draw all primitives as produced by GrCCGeometry into a cleared, |
| 30 | * floating point, alpha-only render target using SkBlendMode::kPlus. Once all of a path's |
| 31 | * primitives have been drawn, the render target contains a composite coverage count that can then |
| 32 | * be used to draw the path (see GrCCPathProcessor). |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 33 | * |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 34 | * To draw primitives, use appendMesh() and draw() (defined below). |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 35 | */ |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 36 | class GrCCCoverageProcessor : public GrGeometryProcessor { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 37 | public: |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 38 | enum class PrimitiveType { |
| 39 | kTriangles, |
| 40 | kQuadratics, |
| 41 | kCubics, |
| 42 | }; |
| 43 | static const char* PrimitiveTypeName(PrimitiveType); |
| 44 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 45 | // Defines a single primitive shape with 3 input points (i.e. Triangles and Quadratics). |
| 46 | // X,Y point values are transposed. |
| 47 | struct TriPointInstance { |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 48 | float fX[3]; |
| 49 | float fY[3]; |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 50 | |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 51 | void set(const SkPoint[3], const Sk2f& trans); |
| 52 | void set(const SkPoint&, const SkPoint&, const SkPoint&, const Sk2f& trans); |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 53 | }; |
| 54 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 55 | // Defines a single primitive shape with 4 input points, or 3 input points plus a W parameter |
| 56 | // duplicated in both 4th components (i.e. Cubics or Triangles with a custom winding number). |
| 57 | // X,Y point values are transposed. |
| 58 | struct QuadPointInstance { |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 59 | float fX[4]; |
| 60 | float fY[4]; |
| 61 | |
| 62 | void set(const SkPoint[4], float dx, float dy); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 63 | void set(const SkPoint&, const SkPoint&, const SkPoint&, const Sk2f& trans, float w); |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 64 | }; |
Chris Dalton | baf3e78 | 2018-03-08 15:55:58 +0000 | [diff] [blame] | 65 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 66 | enum class WindMethod : bool { |
| 67 | kCrossProduct, // Calculate wind = +/-1 by sign of the cross product. |
| 68 | kInstanceData // Instance data provides custom, signed wind values of any magnitude. |
| 69 | // (For tightly-wound tessellated triangles.) |
| 70 | }; |
| 71 | |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 72 | GrCCCoverageProcessor(GrResourceProvider* rp, PrimitiveType type, WindMethod windMethod) |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 73 | : INHERITED(kGrCCCoverageProcessor_ClassID) |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 74 | , fPrimitiveType(type) |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 75 | , fWindMethod(windMethod) |
| 76 | , fImpl(rp->caps()->shaderCaps()->geometryShaderSupport() ? Impl::kGeometryShader |
| 77 | : Impl::kVertexShader) { |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 78 | if (Impl::kGeometryShader == fImpl) { |
| 79 | this->initGS(); |
| 80 | } else { |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 81 | this->initVS(rp); |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 82 | } |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 85 | // GrPrimitiveProcessor overrides. |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 86 | const char* name() const override { return PrimitiveTypeName(fPrimitiveType); } |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 87 | SkString dumpInfo() const override { |
| 88 | return SkStringPrintf("%s\n%s", this->name(), this->INHERITED::dumpInfo().c_str()); |
| 89 | } |
| 90 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
| 91 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override; |
| 92 | |
| 93 | #ifdef SK_DEBUG |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 94 | // Increases the 1/2 pixel AA bloat by a factor of debugBloat. |
| 95 | void enableDebugBloat(float debugBloat) { fDebugBloat = debugBloat; } |
| 96 | bool debugBloatEnabled() const { return fDebugBloat > 0; } |
| 97 | float debugBloat() const { SkASSERT(this->debugBloatEnabled()); return fDebugBloat; } |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 98 | #endif |
| 99 | |
Chris Dalton | 8738cf4 | 2018-03-09 11:57:40 -0700 | [diff] [blame] | 100 | // Appends a GrMesh that will draw the provided instances. The instanceBuffer must be an array |
| 101 | // of either TriPointInstance or QuadPointInstance, depending on this processor's RendererPass, |
| 102 | // with coordinates in the desired shape's final atlas-space position. |
| 103 | void appendMesh(GrBuffer* instanceBuffer, int instanceCount, int baseInstance, |
| 104 | SkTArray<GrMesh>* out) const { |
| 105 | if (Impl::kGeometryShader == fImpl) { |
| 106 | this->appendGSMesh(instanceBuffer, instanceCount, baseInstance, out); |
| 107 | } else { |
| 108 | this->appendVSMesh(instanceBuffer, instanceCount, baseInstance, out); |
| 109 | } |
| 110 | } |
| 111 | |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 112 | void draw(GrOpFlushState*, const GrPipeline&, const GrMesh[], const GrPipeline::DynamicState[], |
| 113 | int meshCount, const SkRect& drawBounds) const; |
| 114 | |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 115 | // The Shader provides code to calculate each pixel's coverage in a RenderPass. It also |
| 116 | // provides details about shape-specific geometry. |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 117 | class Shader { |
| 118 | public: |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 119 | // Called before generating geometry. Subclasses may set up internal member variables during |
| 120 | // this time that will be needed during onEmitVaryings (e.g. transformation matrices). |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 121 | // |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 122 | // If the optional 'tighterHull' parameter is not null and gets filled out by the subclass, |
| 123 | // the the Impl will generate geometry around those points rather than the input points. |
| 124 | virtual void emitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* wind, |
| 125 | const char** tighterHull = nullptr) const {} |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 126 | |
| 127 | void emitVaryings(GrGLSLVaryingHandler* varyingHandler, GrGLSLVarying::Scope scope, |
Chris Dalton | 04a1de5 | 2018-03-14 02:04:09 -0600 | [diff] [blame] | 128 | SkString* code, const char* position, const char* coverage, |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame^] | 129 | const char* cornerCoverage) { |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 130 | SkASSERT(GrGLSLVarying::Scope::kVertToGeo != scope); |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame^] | 131 | this->onEmitVaryings(varyingHandler, scope, code, position, coverage, cornerCoverage); |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 132 | } |
Chris Dalton | 622650a | 2018-03-07 17:30:10 -0700 | [diff] [blame] | 133 | |
Chris Dalton | 0a79381 | 2018-03-07 11:18:30 -0700 | [diff] [blame] | 134 | void emitFragmentCode(const GrCCCoverageProcessor&, GrGLSLFPFragmentBuilder*, |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 135 | const char* skOutputColor, const char* skOutputCoverage) const; |
| 136 | |
Chris Dalton | baf3e78 | 2018-03-08 15:55:58 +0000 | [diff] [blame] | 137 | // Defines an equation ("dot(float3(pt, 1), distance_equation)") that is -1 on the outside |
| 138 | // border of a conservative raster edge and 0 on the inside. 'leftPt' and 'rightPt' must be |
| 139 | // ordered clockwise. |
| 140 | static void EmitEdgeDistanceEquation(GrGLSLVertexGeoBuilder*, const char* leftPt, |
| 141 | const char* rightPt, |
| 142 | const char* outputDistanceEquation); |
| 143 | |
Chris Dalton | 0a79381 | 2018-03-07 11:18:30 -0700 | [diff] [blame] | 144 | // Calculates an edge's coverage at a conservative raster vertex. The edge is defined by two |
| 145 | // clockwise-ordered points, 'leftPt' and 'rightPt'. 'rasterVertexDir' is a pair of +/-1 |
| 146 | // values that point in the direction of conservative raster bloat, starting from an |
| 147 | // endpoint. |
| 148 | // |
| 149 | // Coverage values ramp from -1 (completely outside the edge) to 0 (completely inside). |
| 150 | static void CalcEdgeCoverageAtBloatVertex(GrGLSLVertexGeoBuilder*, const char* leftPt, |
| 151 | const char* rightPt, const char* rasterVertexDir, |
| 152 | const char* outputCoverage); |
| 153 | |
Chris Dalton | 8738cf4 | 2018-03-09 11:57:40 -0700 | [diff] [blame] | 154 | // Calculates an edge's coverage at two conservative raster vertices. |
| 155 | // (See CalcEdgeCoverageAtBloatVertex). |
| 156 | static void CalcEdgeCoveragesAtBloatVertices(GrGLSLVertexGeoBuilder*, const char* leftPt, |
| 157 | const char* rightPt, const char* bloatDir1, |
| 158 | const char* bloatDir2, |
| 159 | const char* outputCoverages); |
| 160 | |
Chris Dalton | 04a1de5 | 2018-03-14 02:04:09 -0600 | [diff] [blame] | 161 | // Corner boxes require an additional "attenuation" varying that is multiplied by the |
| 162 | // regular (linearly-interpolated) coverage. This function calculates the attenuation value |
| 163 | // to use in the single, outermost vertex. The remaining three vertices of the corner box |
| 164 | // all use an attenuation value of 1. |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame^] | 165 | static void CalcCornerAttenuation(GrGLSLVertexGeoBuilder*, const char* leftDir, |
| 166 | const char* rightDir, const char* outputAttenuation); |
Chris Dalton | 04a1de5 | 2018-03-14 02:04:09 -0600 | [diff] [blame] | 167 | |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 168 | virtual ~Shader() {} |
| 169 | |
| 170 | protected: |
Chris Dalton | 622650a | 2018-03-07 17:30:10 -0700 | [diff] [blame] | 171 | // Here the subclass adds its internal varyings to the handler and produces code to |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 172 | // initialize those varyings from a given position and coverage values. |
Chris Dalton | 622650a | 2018-03-07 17:30:10 -0700 | [diff] [blame] | 173 | // |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 174 | // NOTE: the coverage values are signed appropriately for wind. |
| 175 | // 'coverage' will only be +1 or -1 on curves. |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 176 | virtual void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code, |
Chris Dalton | 04a1de5 | 2018-03-14 02:04:09 -0600 | [diff] [blame] | 177 | const char* position, const char* coverage, |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame^] | 178 | const char* cornerCoverage) = 0; |
Chris Dalton | 622650a | 2018-03-07 17:30:10 -0700 | [diff] [blame] | 179 | |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 180 | // Emits the fragment code that calculates a pixel's signed coverage value. |
Chris Dalton | baf3e78 | 2018-03-08 15:55:58 +0000 | [diff] [blame] | 181 | virtual void onEmitFragmentCode(GrGLSLFPFragmentBuilder*, |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 182 | const char* outputCoverage) const = 0; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 183 | |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 184 | // Returns the name of a Shader's internal varying at the point where where its value is |
| 185 | // assigned. This is intended to work whether called for a vertex or a geometry shader. |
| 186 | const char* OutName(const GrGLSLVarying& varying) const { |
| 187 | using Scope = GrGLSLVarying::Scope; |
| 188 | SkASSERT(Scope::kVertToGeo != varying.scope()); |
| 189 | return Scope::kGeoToFrag == varying.scope() ? varying.gsOut() : varying.vsOut(); |
| 190 | } |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame^] | 191 | |
| 192 | // Our friendship with GrGLSLShaderBuilder does not propogate to subclasses. |
| 193 | inline static SkString& AccessCodeString(GrGLSLShaderBuilder* s) { return s->code(); } |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 194 | }; |
| 195 | |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame^] | 196 | private: |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 197 | class GSImpl; |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 198 | class GSTriangleHullImpl; |
| 199 | class GSCurveHullImpl; |
| 200 | class GSCornerImpl; |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 201 | class VSImpl; |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame^] | 202 | class TriangleShader; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 203 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 204 | // Slightly undershoot a bloat radius of 0.5 so vertices that fall on integer boundaries don't |
| 205 | // accidentally bleed into neighbor pixels. |
| 206 | static constexpr float kAABloatRadius = 0.491111f; |
| 207 | |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 208 | // Number of bezier points for curves, or 3 for triangles. |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 209 | int numInputPoints() const { return PrimitiveType::kCubics == fPrimitiveType ? 4 : 3; } |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 210 | |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 211 | enum class Impl : bool { |
| 212 | kGeometryShader, |
| 213 | kVertexShader |
| 214 | }; |
| 215 | |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 216 | // Geometry shader backend draws primitives in two subpasses. |
| 217 | enum class GSSubpass : bool { |
| 218 | kHulls, |
| 219 | kCorners |
| 220 | }; |
| 221 | |
| 222 | GrCCCoverageProcessor(const GrCCCoverageProcessor& proc, GSSubpass subpass) |
| 223 | : INHERITED(kGrCCCoverageProcessor_ClassID) |
| 224 | , fPrimitiveType(proc.fPrimitiveType) |
| 225 | , fWindMethod(proc.fWindMethod) |
| 226 | , fImpl(Impl::kGeometryShader) |
| 227 | SkDEBUGCODE(, fDebugBloat(proc.fDebugBloat)) |
| 228 | , fGSSubpass(subpass) { |
| 229 | SkASSERT(Impl::kGeometryShader == proc.fImpl); |
| 230 | this->initGS(); |
| 231 | } |
| 232 | |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 233 | void initGS(); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 234 | void initVS(GrResourceProvider*); |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 235 | |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 236 | void appendGSMesh(GrBuffer* instanceBuffer, int instanceCount, int baseInstance, |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 237 | SkTArray<GrMesh>* out) const; |
| 238 | void appendVSMesh(GrBuffer* instanceBuffer, int instanceCount, int baseInstance, |
| 239 | SkTArray<GrMesh>* out) const; |
| 240 | |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 241 | GrGLSLPrimitiveProcessor* createGSImpl(std::unique_ptr<Shader>) const; |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 242 | GrGLSLPrimitiveProcessor* createVSImpl(std::unique_ptr<Shader>) const; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 243 | |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 244 | const PrimitiveType fPrimitiveType; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 245 | const WindMethod fWindMethod; |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 246 | const Impl fImpl; |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 247 | SkDEBUGCODE(float fDebugBloat = 0); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 248 | |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 249 | // Used by GSImpl. |
| 250 | const GSSubpass fGSSubpass = GSSubpass::kHulls; |
| 251 | |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 252 | // Used by VSImpl. |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 253 | sk_sp<const GrBuffer> fVSVertexBuffer; |
| 254 | sk_sp<const GrBuffer> fVSIndexBuffer; |
| 255 | int fVSNumIndicesPerInstance; |
| 256 | GrPrimitiveType fVSTriangleType; |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 257 | |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 258 | typedef GrGeometryProcessor INHERITED; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 259 | }; |
| 260 | |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 261 | inline const char* GrCCCoverageProcessor::PrimitiveTypeName(PrimitiveType type) { |
| 262 | switch (type) { |
| 263 | case PrimitiveType::kTriangles: return "kTriangles"; |
| 264 | case PrimitiveType::kQuadratics: return "kQuadratics"; |
| 265 | case PrimitiveType::kCubics: return "kCubics"; |
| 266 | } |
| 267 | SK_ABORT("Invalid PrimitiveType"); |
| 268 | return ""; |
| 269 | } |
| 270 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 271 | inline void GrCCCoverageProcessor::TriPointInstance::set(const SkPoint p[3], const Sk2f& trans) { |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 272 | this->set(p[0], p[1], p[2], trans); |
| 273 | } |
| 274 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 275 | inline void GrCCCoverageProcessor::TriPointInstance::set(const SkPoint& p0, const SkPoint& p1, |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 276 | const SkPoint& p2, const Sk2f& trans) { |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 277 | Sk2f P0 = Sk2f::Load(&p0) + trans; |
| 278 | Sk2f P1 = Sk2f::Load(&p1) + trans; |
| 279 | Sk2f P2 = Sk2f::Load(&p2) + trans; |
| 280 | Sk2f::Store3(this, P0, P1, P2); |
| 281 | } |
| 282 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 283 | inline void GrCCCoverageProcessor::QuadPointInstance::set(const SkPoint p[4], float dx, float dy) { |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 284 | Sk4f X,Y; |
| 285 | Sk4f::Load2(p, &X, &Y); |
| 286 | (X + dx).store(&fX); |
| 287 | (Y + dy).store(&fY); |
| 288 | } |
| 289 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 290 | inline void GrCCCoverageProcessor::QuadPointInstance::set(const SkPoint& p0, const SkPoint& p1, |
| 291 | const SkPoint& p2, const Sk2f& trans, |
| 292 | float w) { |
| 293 | Sk2f P0 = Sk2f::Load(&p0) + trans; |
| 294 | Sk2f P1 = Sk2f::Load(&p1) + trans; |
| 295 | Sk2f P2 = Sk2f::Load(&p2) + trans; |
| 296 | Sk2f W = Sk2f(w); |
| 297 | Sk2f::Store4(this, P0, P1, P2, W); |
| 298 | } |
| 299 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 300 | #endif |