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