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 | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 25 | void emitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID, |
Chris Dalton | baf3e78 | 2018-03-08 15:55:58 +0000 | [diff] [blame] | 26 | const char* wind, GeometryVars*) const final; |
| 27 | virtual void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID, |
| 28 | GeometryVars*) const = 0; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 29 | |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 30 | void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code, |
Chris Dalton | 04a1de5 | 2018-03-14 02:04:09 -0600 | [diff] [blame] | 31 | const char* position, const char* coverage, const char* attenuatedCoverage, |
| 32 | const char* wind) final; |
Chris Dalton | baf3e78 | 2018-03-08 15:55:58 +0000 | [diff] [blame] | 33 | virtual void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) {} |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 34 | |
Chris Dalton | baf3e78 | 2018-03-08 15:55:58 +0000 | [diff] [blame] | 35 | void onEmitFragmentCode(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const final; |
| 36 | virtual void emitCoverage(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const = 0; |
Chris Dalton | f510e26 | 2018-01-30 16:42:37 -0700 | [diff] [blame] | 37 | |
Chris Dalton | 52076d1 | 2018-03-21 12:14:10 -0600 | [diff] [blame^] | 38 | const GrShaderVar fQCoordMatrix{"qcoord_matrix", kFloat2x2_GrSLType}; |
| 39 | const GrShaderVar fQCoord0{"qcoord0", kFloat2_GrSLType}; |
Chris Dalton | baf3e78 | 2018-03-08 15:55:58 +0000 | [diff] [blame] | 40 | const GrShaderVar fEdgeDistanceEquation{"edge_distance_equation", kFloat3_GrSLType}; |
| 41 | GrGLSLVarying fXYDW; |
| 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * This pass draws a conservative raster hull around the quadratic bezier curve, computes the |
| 46 | * curve's coverage using the gradient-based AA technique outlined in the Loop/Blinn paper, and |
| 47 | * uses simple distance-to-edge to subtract out coverage for the flat closing edge [P2 -> P0]. Since |
| 48 | * the provided curves are monotonic, this will get every pixel right except the two corners. |
| 49 | */ |
| 50 | class GrCCQuadraticHullShader : public GrCCQuadraticShader { |
| 51 | void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID, |
| 52 | GeometryVars*) const override; |
| 53 | void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override; |
| 54 | void emitCoverage(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const override; |
| 55 | |
| 56 | GrGLSLVarying fGrad; |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * This pass fixes the corners of a closed quadratic segment with soft MSAA. |
| 61 | */ |
| 62 | class GrCCQuadraticCornerShader : public GrCCQuadraticShader { |
| 63 | void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID, |
| 64 | GeometryVars*) const override; |
| 65 | void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override; |
| 66 | void emitCoverage(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const override; |
| 67 | |
| 68 | GrGLSLVarying fdXYDdx; |
| 69 | GrGLSLVarying fdXYDdy; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | #endif |