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: |
| 25 | int getNumInputPoints() const final { return 3; } |
| 26 | |
| 27 | void appendInputPointFetch(const GrCCPRCoverageProcessor&, GrGLSLShaderBuilder*, |
| 28 | const TexelBufferHandle& pointsBuffer, |
| 29 | const char* pointId) const override; |
| 30 | |
| 31 | void emitWind(GrGLSLShaderBuilder*, const char* pts, const char* rtAdjust, |
| 32 | const char* outputWind) const final; |
| 33 | |
| 34 | void emitSetupCode(GrGLSLShaderBuilder*, const char* pts, const char* segmentId, |
| 35 | const char* bloat, const char* wind, const char* rtAdjust, |
| 36 | GeometryVars*) const final; |
| 37 | |
| 38 | virtual void onEmitSetupCode(GrGLSLShaderBuilder*, const char* pts, const char* segmentId, |
| 39 | const char* rtAdjust, GeometryVars*) const = 0; |
| 40 | |
| 41 | WindHandling onEmitVaryings(GrGLSLVaryingHandler*, SkString* code, const char* position, |
| 42 | const char* coverage, const char* wind) final; |
| 43 | |
| 44 | virtual void onEmitVaryings(GrGLSLVaryingHandler*, SkString* code) = 0; |
| 45 | |
| 46 | const GrShaderVar fCanonicalMatrix{"canonical_matrix", kFloat3x3_GrSLType}; |
| 47 | const GrShaderVar fCanonicalDerivatives{"canonical_derivatives", kFloat2x2_GrSLType}; |
| 48 | const GrShaderVar fEdgeDistanceEquation{"edge_distance_equation", kFloat3_GrSLType}; |
| 49 | GrGLSLGeoToFrag fXYD{kFloat3_GrSLType}; |
| 50 | }; |
| 51 | |
| 52 | /** |
| 53 | * This pass draws a conservative raster hull around the quadratic bezier curve, computes the |
| 54 | * curve's coverage using the gradient-based AA technique outlined in the Loop/Blinn paper, and |
| 55 | * uses simple distance-to-edge to subtract out coverage for the flat closing edge [P2 -> P0]. Since |
| 56 | * the provided curves are monotonic, this will get every pixel right except the two corners. |
| 57 | */ |
| 58 | class GrCCPRQuadraticHullShader : public GrCCPRQuadraticShader { |
| 59 | int getNumSegments() const final { return 4; } // 4 wedges. |
| 60 | |
| 61 | GeometryType getGeometryType() const override { return GeometryType::kHull; } |
| 62 | void onEmitSetupCode(GrGLSLShaderBuilder*, const char* pts, const char* wedgeId, |
| 63 | const char* rtAdjust, GeometryVars*) const override; |
| 64 | void onEmitVaryings(GrGLSLVaryingHandler*, SkString* code) override; |
| 65 | void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override; |
| 66 | |
| 67 | GrGLSLGeoToFrag fGrad{kFloat2_GrSLType}; |
| 68 | }; |
| 69 | |
| 70 | /** |
| 71 | * This pass fixes the corners of a closed quadratic segment with soft MSAA. |
| 72 | */ |
| 73 | class GrCCPRQuadraticCornerShader : public GrCCPRQuadraticShader { |
| 74 | int getNumSegments() const final { return 2; } // 2 corners. |
| 75 | |
| 76 | GeometryType getGeometryType() const override { return GeometryType::kCorners; } |
| 77 | void onEmitSetupCode(GrGLSLShaderBuilder*, const char* pts, const char* cornerId, |
| 78 | const char* rtAdjust, GeometryVars*) const override; |
| 79 | void onEmitVaryings(GrGLSLVaryingHandler*, SkString* code) override; |
| 80 | void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override; |
| 81 | |
| 82 | const GrShaderVar fEdgeDistanceDerivatives{"edge_distance_derivatives", kFloat2_GrSLType}; |
| 83 | GrGLSLGeoToFrag fdXYDdx{kFloat3_GrSLType}; |
| 84 | GrGLSLGeoToFrag fdXYDdy{kFloat3_GrSLType}; |
| 85 | }; |
| 86 | |
| 87 | #endif |