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, |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 40 | kWeightedTriangles, // Triangles (from the tessellator) whose winding magnitude > 1. |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 41 | kQuadratics, |
| 42 | kCubics, |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 43 | kConics |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 44 | }; |
| 45 | static const char* PrimitiveTypeName(PrimitiveType); |
| 46 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 47 | // Defines a single primitive shape with 3 input points (i.e. Triangles and Quadratics). |
| 48 | // X,Y point values are transposed. |
| 49 | struct TriPointInstance { |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 50 | float fX[3]; |
| 51 | float fY[3]; |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 52 | |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 53 | void set(const SkPoint[3], const Sk2f& trans); |
| 54 | void set(const SkPoint&, const SkPoint&, const SkPoint&, const Sk2f& trans); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 55 | void set(const Sk2f& P0, const Sk2f& P1, const Sk2f& P2, const Sk2f& trans); |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 56 | }; |
| 57 | |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 58 | // Defines a single primitive shape with 4 input points, or 3 input points plus a "weight" |
| 59 | // parameter duplicated in both lanes of the 4th input (i.e. Cubics, Conics, and Triangles with |
| 60 | // a weighted winding number). X,Y point values are transposed. |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 61 | struct QuadPointInstance { |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 62 | float fX[4]; |
| 63 | float fY[4]; |
| 64 | |
| 65 | void set(const SkPoint[4], float dx, float dy); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 66 | void setW(const SkPoint[3], const Sk2f& trans, float w); |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 67 | void setW(const SkPoint&, const SkPoint&, const SkPoint&, const Sk2f& trans, float w); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 68 | void setW(const Sk2f& P0, const Sk2f& P1, const Sk2f& P2, const Sk2f& trans, float w); |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 69 | }; |
Chris Dalton | baf3e78 | 2018-03-08 15:55:58 +0000 | [diff] [blame] | 70 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 71 | virtual void reset(PrimitiveType, GrResourceProvider*) = 0; |
| 72 | |
| 73 | PrimitiveType primitiveType() const { return fPrimitiveType; } |
| 74 | |
| 75 | // Number of bezier points for curves, or 3 for triangles. |
| 76 | int numInputPoints() const { return PrimitiveType::kCubics == fPrimitiveType ? 4 : 3; } |
| 77 | |
| 78 | bool isTriangles() const { |
| 79 | return PrimitiveType::kTriangles == fPrimitiveType || |
| 80 | PrimitiveType::kWeightedTriangles == fPrimitiveType; |
| 81 | } |
| 82 | |
| 83 | int hasInputWeight() const { |
| 84 | return PrimitiveType::kWeightedTriangles == fPrimitiveType || |
| 85 | PrimitiveType::kConics == fPrimitiveType; |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 88 | // GrPrimitiveProcessor overrides. |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 89 | const char* name() const override { return PrimitiveTypeName(fPrimitiveType); } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 90 | #ifdef SK_DEBUG |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 91 | SkString dumpInfo() const override { |
| 92 | return SkStringPrintf("%s\n%s", this->name(), this->INHERITED::dumpInfo().c_str()); |
| 93 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 94 | #endif |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 95 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override { |
| 96 | SkDEBUGCODE(this->getDebugBloatKey(b)); |
| 97 | b->add32((int)fPrimitiveType); |
| 98 | } |
| 99 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final; |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 100 | |
| 101 | #ifdef SK_DEBUG |
Chris Dalton | 8d38a7f | 2018-03-19 14:16:44 -0600 | [diff] [blame] | 102 | // Increases the 1/2 pixel AA bloat by a factor of debugBloat. |
| 103 | void enableDebugBloat(float debugBloat) { fDebugBloat = debugBloat; } |
| 104 | bool debugBloatEnabled() const { return fDebugBloat > 0; } |
| 105 | float debugBloat() const { SkASSERT(this->debugBloatEnabled()); return fDebugBloat; } |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 106 | void getDebugBloatKey(GrProcessorKeyBuilder* b) const { |
| 107 | uint32_t bloatBits; |
| 108 | memcpy(&bloatBits, &fDebugBloat, 4); |
| 109 | b->add32(bloatBits); |
| 110 | } |
Chris Dalton | 2326177 | 2017-12-10 16:41:45 -0700 | [diff] [blame] | 111 | #endif |
| 112 | |
Chris Dalton | 8738cf4 | 2018-03-09 11:57:40 -0700 | [diff] [blame] | 113 | // Appends a GrMesh that will draw the provided instances. The instanceBuffer must be an array |
| 114 | // of either TriPointInstance or QuadPointInstance, depending on this processor's RendererPass, |
| 115 | // with coordinates in the desired shape's final atlas-space position. |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 116 | virtual void appendMesh(sk_sp<const GrGpuBuffer> instanceBuffer, int instanceCount, |
| 117 | int baseInstance, SkTArray<GrMesh>* out) const = 0; |
Chris Dalton | 8738cf4 | 2018-03-09 11:57:40 -0700 | [diff] [blame] | 118 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 119 | virtual void draw(GrOpFlushState*, const GrPipeline&, const SkIRect scissorRects[], |
| 120 | const GrMesh[], int meshCount, const SkRect& drawBounds) const; |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 121 | |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 122 | // The Shader provides code to calculate each pixel's coverage in a RenderPass. It also |
| 123 | // provides details about shape-specific geometry. |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 124 | class Shader { |
| 125 | public: |
Chris Dalton | 84d36cd | 2019-04-17 14:47:17 -0600 | [diff] [blame^] | 126 | // Returns true if the Impl should not calculate the coverage argument for emitVaryings(). |
| 127 | // If true, then "coverage" will have a signed magnitude of 1. |
| 128 | virtual bool calculatesOwnEdgeCoverage() const { return false; } |
| 129 | |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 130 | // Called before generating geometry. Subclasses may set up internal member variables during |
| 131 | // this time that will be needed during onEmitVaryings (e.g. transformation matrices). |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 132 | // |
Chris Dalton | 9713dcf | 2018-04-10 00:48:41 -0600 | [diff] [blame] | 133 | // If the 'outHull4' parameter is provided, and there are not 4 input points, the subclass |
| 134 | // is required to fill it with the name of a 4-point hull around which the Impl can generate |
| 135 | // its geometry. If it is left unchanged, the Impl will use the regular input points. |
Chris Dalton | 84d36cd | 2019-04-17 14:47:17 -0600 | [diff] [blame^] | 136 | virtual void emitSetupCode( |
| 137 | GrGLSLVertexGeoBuilder*, const char* pts, const char** outHull4 = nullptr) const { |
Chris Dalton | 9713dcf | 2018-04-10 00:48:41 -0600 | [diff] [blame] | 138 | SkASSERT(!outHull4); |
| 139 | } |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 140 | |
Chris Dalton | 84d36cd | 2019-04-17 14:47:17 -0600 | [diff] [blame^] | 141 | void emitVaryings( |
| 142 | GrGLSLVaryingHandler* varyingHandler, GrGLSLVarying::Scope scope, SkString* code, |
| 143 | const char* position, const char* coverage, const char* cornerCoverage, |
| 144 | const char* wind) { |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 145 | SkASSERT(GrGLSLVarying::Scope::kVertToGeo != scope); |
Chris Dalton | 84d36cd | 2019-04-17 14:47:17 -0600 | [diff] [blame^] | 146 | this->onEmitVaryings( |
| 147 | varyingHandler, scope, code, position, coverage, cornerCoverage, wind); |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 148 | } |
Chris Dalton | 622650a | 2018-03-07 17:30:10 -0700 | [diff] [blame] | 149 | |
Chris Dalton | 0a79381 | 2018-03-07 11:18:30 -0700 | [diff] [blame] | 150 | void emitFragmentCode(const GrCCCoverageProcessor&, GrGLSLFPFragmentBuilder*, |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 151 | const char* skOutputColor, const char* skOutputCoverage) const; |
| 152 | |
Chris Dalton | 6f5e77a | 2018-04-23 21:14:42 -0600 | [diff] [blame] | 153 | // Calculates the winding direction of the input points (+1, -1, or 0). Wind for extremely |
| 154 | // thin triangles gets rounded to zero. |
| 155 | static void CalcWind(const GrCCCoverageProcessor&, GrGLSLVertexGeoBuilder*, const char* pts, |
| 156 | const char* outputWind); |
| 157 | |
Chris Dalton | 0a79381 | 2018-03-07 11:18:30 -0700 | [diff] [blame] | 158 | // Calculates an edge's coverage at a conservative raster vertex. The edge is defined by two |
| 159 | // clockwise-ordered points, 'leftPt' and 'rightPt'. 'rasterVertexDir' is a pair of +/-1 |
| 160 | // values that point in the direction of conservative raster bloat, starting from an |
| 161 | // endpoint. |
| 162 | // |
| 163 | // Coverage values ramp from -1 (completely outside the edge) to 0 (completely inside). |
| 164 | static void CalcEdgeCoverageAtBloatVertex(GrGLSLVertexGeoBuilder*, const char* leftPt, |
| 165 | const char* rightPt, const char* rasterVertexDir, |
| 166 | const char* outputCoverage); |
| 167 | |
Chris Dalton | 8738cf4 | 2018-03-09 11:57:40 -0700 | [diff] [blame] | 168 | // Calculates an edge's coverage at two conservative raster vertices. |
| 169 | // (See CalcEdgeCoverageAtBloatVertex). |
| 170 | static void CalcEdgeCoveragesAtBloatVertices(GrGLSLVertexGeoBuilder*, const char* leftPt, |
| 171 | const char* rightPt, const char* bloatDir1, |
| 172 | const char* bloatDir2, |
| 173 | const char* outputCoverages); |
| 174 | |
Chris Dalton | 04a1de5 | 2018-03-14 02:04:09 -0600 | [diff] [blame] | 175 | // Corner boxes require an additional "attenuation" varying that is multiplied by the |
| 176 | // regular (linearly-interpolated) coverage. This function calculates the attenuation value |
| 177 | // to use in the single, outermost vertex. The remaining three vertices of the corner box |
| 178 | // all use an attenuation value of 1. |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame] | 179 | static void CalcCornerAttenuation(GrGLSLVertexGeoBuilder*, const char* leftDir, |
| 180 | const char* rightDir, const char* outputAttenuation); |
Chris Dalton | 04a1de5 | 2018-03-14 02:04:09 -0600 | [diff] [blame] | 181 | |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 182 | virtual ~Shader() {} |
| 183 | |
| 184 | protected: |
Chris Dalton | 622650a | 2018-03-07 17:30:10 -0700 | [diff] [blame] | 185 | // 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] | 186 | // initialize those varyings from a given position and coverage values. |
Chris Dalton | 622650a | 2018-03-07 17:30:10 -0700 | [diff] [blame] | 187 | // |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 188 | // NOTE: the coverage values are signed appropriately for wind. |
| 189 | // 'coverage' will only be +1 or -1 on curves. |
Chris Dalton | 84d36cd | 2019-04-17 14:47:17 -0600 | [diff] [blame^] | 190 | virtual void onEmitVaryings( |
| 191 | GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code, const char* position, |
| 192 | const char* coverage, const char* cornerCoverage, const char* wind) = 0; |
Chris Dalton | 622650a | 2018-03-07 17:30:10 -0700 | [diff] [blame] | 193 | |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 194 | // Emits the fragment code that calculates a pixel's signed coverage value. |
Chris Dalton | baf3e78 | 2018-03-08 15:55:58 +0000 | [diff] [blame] | 195 | virtual void onEmitFragmentCode(GrGLSLFPFragmentBuilder*, |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 196 | const char* outputCoverage) const = 0; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 197 | |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 198 | // Returns the name of a Shader's internal varying at the point where where its value is |
| 199 | // assigned. This is intended to work whether called for a vertex or a geometry shader. |
| 200 | const char* OutName(const GrGLSLVarying& varying) const { |
| 201 | using Scope = GrGLSLVarying::Scope; |
| 202 | SkASSERT(Scope::kVertToGeo != varying.scope()); |
| 203 | return Scope::kGeoToFrag == varying.scope() ? varying.gsOut() : varying.vsOut(); |
| 204 | } |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame] | 205 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 206 | // Our friendship with GrGLSLShaderBuilder does not propagate to subclasses. |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame] | 207 | inline static SkString& AccessCodeString(GrGLSLShaderBuilder* s) { return s->code(); } |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 208 | }; |
| 209 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 210 | protected: |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 211 | // Slightly undershoot a bloat radius of 0.5 so vertices that fall on integer boundaries don't |
| 212 | // accidentally bleed into neighbor pixels. |
| 213 | static constexpr float kAABloatRadius = 0.491111f; |
| 214 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 215 | GrCCCoverageProcessor(ClassID classID) : INHERITED(classID) {} |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 216 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 217 | virtual GrGLSLPrimitiveProcessor* onCreateGLSLInstance(std::unique_ptr<Shader>) const = 0; |
Chris Dalton | 6f5e77a | 2018-04-23 21:14:42 -0600 | [diff] [blame] | 218 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 219 | // Our friendship with GrGLSLShaderBuilder does not propagate to subclasses. |
| 220 | inline static SkString& AccessCodeString(GrGLSLShaderBuilder* s) { return s->code(); } |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 221 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 222 | PrimitiveType fPrimitiveType; |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 223 | SkDEBUGCODE(float fDebugBloat = 0); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 224 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 225 | class TriangleShader; |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 226 | |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 227 | typedef GrGeometryProcessor INHERITED; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 228 | }; |
| 229 | |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 230 | inline const char* GrCCCoverageProcessor::PrimitiveTypeName(PrimitiveType type) { |
| 231 | switch (type) { |
| 232 | case PrimitiveType::kTriangles: return "kTriangles"; |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 233 | case PrimitiveType::kWeightedTriangles: return "kWeightedTriangles"; |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 234 | case PrimitiveType::kQuadratics: return "kQuadratics"; |
| 235 | case PrimitiveType::kCubics: return "kCubics"; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 236 | case PrimitiveType::kConics: return "kConics"; |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 237 | } |
| 238 | SK_ABORT("Invalid PrimitiveType"); |
| 239 | return ""; |
| 240 | } |
| 241 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 242 | inline void GrCCCoverageProcessor::TriPointInstance::set(const SkPoint p[3], const Sk2f& trans) { |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 243 | this->set(p[0], p[1], p[2], trans); |
| 244 | } |
| 245 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 246 | inline void GrCCCoverageProcessor::TriPointInstance::set(const SkPoint& p0, const SkPoint& p1, |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 247 | const SkPoint& p2, const Sk2f& trans) { |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 248 | Sk2f P0 = Sk2f::Load(&p0); |
| 249 | Sk2f P1 = Sk2f::Load(&p1); |
| 250 | Sk2f P2 = Sk2f::Load(&p2); |
| 251 | this->set(P0, P1, P2, trans); |
| 252 | } |
| 253 | |
| 254 | inline void GrCCCoverageProcessor::TriPointInstance::set(const Sk2f& P0, const Sk2f& P1, |
| 255 | const Sk2f& P2, const Sk2f& trans) { |
| 256 | Sk2f::Store3(this, P0 + trans, P1 + trans, P2 + trans); |
Chris Dalton | a3e9271 | 2017-12-04 11:45:51 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 259 | 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] | 260 | Sk4f X,Y; |
| 261 | Sk4f::Load2(p, &X, &Y); |
| 262 | (X + dx).store(&fX); |
| 263 | (Y + dy).store(&fY); |
| 264 | } |
| 265 | |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 266 | inline void GrCCCoverageProcessor::QuadPointInstance::setW(const SkPoint p[3], const Sk2f& trans, |
| 267 | float w) { |
| 268 | this->setW(p[0], p[1], p[2], trans, w); |
| 269 | } |
| 270 | |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 271 | inline void GrCCCoverageProcessor::QuadPointInstance::setW(const SkPoint& p0, const SkPoint& p1, |
| 272 | const SkPoint& p2, const Sk2f& trans, |
| 273 | float w) { |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 274 | Sk2f P0 = Sk2f::Load(&p0); |
| 275 | Sk2f P1 = Sk2f::Load(&p1); |
| 276 | Sk2f P2 = Sk2f::Load(&p2); |
| 277 | this->setW(P0, P1, P2, trans, w); |
| 278 | } |
| 279 | |
| 280 | inline void GrCCCoverageProcessor::QuadPointInstance::setW(const Sk2f& P0, const Sk2f& P1, |
| 281 | const Sk2f& P2, const Sk2f& trans, |
| 282 | float w) { |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 283 | Sk2f W = Sk2f(w); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 284 | Sk2f::Store4(this, P0 + trans, P1 + trans, P2 + trans, W); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 285 | } |
| 286 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 287 | #endif |