Chris Dalton | 6a3dbee | 2017-10-16 10:44: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 | |
| 8 | #ifndef GrCCPRQuadraticShader_DEFINED |
| 9 | #define GrCCPRQuadraticShader_DEFINED |
| 10 | |
| 11 | #include "ccpr/GrCCPRCoverageProcessor.h" |
| 12 | |
| 13 | /** |
| 14 | * This class renders the coverage of closed quadratic curves using the techniques outlined in |
| 15 | * "Resolution Independent Curve Rendering using Programmable Graphics Hardware" by Charles Loop and |
| 16 | * Jim Blinn: |
| 17 | * |
| 18 | * https://www.microsoft.com/en-us/research/wp-content/uploads/2005/01/p1000-loop.pdf |
| 19 | * |
| 20 | * The provided curves must be monotonic with respect to the vector of their closing edge [P2 - P0]. |
| 21 | * (Use GrCCPRGeometry.) |
| 22 | */ |
| 23 | class GrCCPRQuadraticShader : public GrCCPRCoverageProcessor::Shader { |
| 24 | protected: |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 25 | void emitSetupCode(GrGLSLShaderBuilder*, const char* pts, const char* segmentId, |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 26 | const char* wind, GeometryVars*) const final; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 27 | |
| 28 | virtual void onEmitSetupCode(GrGLSLShaderBuilder*, const char* pts, const char* segmentId, |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 29 | GeometryVars*) const = 0; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 30 | |
| 31 | WindHandling onEmitVaryings(GrGLSLVaryingHandler*, SkString* code, const char* position, |
| 32 | const char* coverage, const char* wind) final; |
| 33 | |
| 34 | virtual void onEmitVaryings(GrGLSLVaryingHandler*, SkString* code) = 0; |
| 35 | |
Chris Dalton | 2737288 | 2017-12-08 13:34:21 -0700 | [diff] [blame^] | 36 | const GrShaderVar fCanonicalMatrix{"canonical_matrix", kFloat3x3_GrSLType}; |
| 37 | const GrShaderVar fEdgeDistanceEquation{"edge_distance_equation", kFloat3_GrSLType}; |
| 38 | GrGLSLVarying fXYD{kFloat3_GrSLType, GrGLSLVarying::Scope::kGeoToFrag}; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | /** |
| 42 | * This pass draws a conservative raster hull around the quadratic bezier curve, computes the |
| 43 | * curve's coverage using the gradient-based AA technique outlined in the Loop/Blinn paper, and |
| 44 | * uses simple distance-to-edge to subtract out coverage for the flat closing edge [P2 -> P0]. Since |
| 45 | * the provided curves are monotonic, this will get every pixel right except the two corners. |
| 46 | */ |
| 47 | class GrCCPRQuadraticHullShader : public GrCCPRQuadraticShader { |
| 48 | int getNumSegments() const final { return 4; } // 4 wedges. |
| 49 | |
| 50 | GeometryType getGeometryType() const override { return GeometryType::kHull; } |
| 51 | void onEmitSetupCode(GrGLSLShaderBuilder*, const char* pts, const char* wedgeId, |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 52 | GeometryVars*) const override; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 53 | void onEmitVaryings(GrGLSLVaryingHandler*, SkString* code) override; |
| 54 | void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override; |
| 55 | |
Chris Dalton | 2737288 | 2017-12-08 13:34:21 -0700 | [diff] [blame^] | 56 | GrGLSLVarying fGrad{kFloat2_GrSLType, GrGLSLVarying::Scope::kGeoToFrag}; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * This pass fixes the corners of a closed quadratic segment with soft MSAA. |
| 61 | */ |
| 62 | class GrCCPRQuadraticCornerShader : public GrCCPRQuadraticShader { |
| 63 | int getNumSegments() const final { return 2; } // 2 corners. |
| 64 | |
| 65 | GeometryType getGeometryType() const override { return GeometryType::kCorners; } |
| 66 | void onEmitSetupCode(GrGLSLShaderBuilder*, const char* pts, const char* cornerId, |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 67 | GeometryVars*) const override; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 68 | void onEmitVaryings(GrGLSLVaryingHandler*, SkString* code) override; |
| 69 | void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override; |
| 70 | |
Chris Dalton | 2737288 | 2017-12-08 13:34:21 -0700 | [diff] [blame^] | 71 | GrGLSLVarying fdXYDdx{kFloat3_GrSLType, GrGLSLVarying::Scope::kGeoToFrag}; |
| 72 | GrGLSLVarying fdXYDdy{kFloat3_GrSLType, GrGLSLVarying::Scope::kGeoToFrag}; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | #endif |