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 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 8 | #ifndef GrCCQuadraticShader_DEFINED |
| 9 | #define GrCCQuadraticShader_DEFINED |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 10 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 11 | #include "ccpr/GrCCCoverageProcessor.h" |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 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]. |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 21 | * (Use GrCCGeometry.) |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 22 | */ |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 23 | class GrCCQuadraticShader : public GrCCCoverageProcessor::Shader { |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 24 | protected: |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 25 | void emitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID, |
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 | |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 28 | virtual void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID, |
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 | |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 31 | WindHandling onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code, |
| 32 | const char* position, const char* coverage, const char* wind) final; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 33 | |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 34 | virtual void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) {} |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 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}; |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 38 | GrGLSLVarying fXYD; |
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 | */ |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 47 | class GrCCQuadraticHullShader : public GrCCQuadraticShader { |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 48 | void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID, |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 49 | GeometryVars*) const override; |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 50 | void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 51 | void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override; |
| 52 | |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 53 | GrGLSLVarying fGrad; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | /** |
| 57 | * This pass fixes the corners of a closed quadratic segment with soft MSAA. |
| 58 | */ |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 59 | class GrCCQuadraticCornerShader : public GrCCQuadraticShader { |
Chris Dalton | 1fbdb61 | 2017-12-12 12:48:47 -0700 | [diff] [blame] | 60 | void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID, |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 61 | GeometryVars*) const override; |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 62 | void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 63 | void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override; |
| 64 | |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 65 | GrGLSLVarying fdXYDdx; |
| 66 | GrGLSLVarying fdXYDdy; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | #endif |