blob: 09fe01c1b4f4322d1ae84749bf690a413e11d8ea [file] [log] [blame]
Chris Dalton6a3dbee2017-10-16 10:44:41 -06001/*
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 Dalton383a2ef2018-01-08 17:21:41 -05008#ifndef GrCCQuadraticShader_DEFINED
9#define GrCCQuadraticShader_DEFINED
Chris Dalton6a3dbee2017-10-16 10:44:41 -060010
Chris Dalton383a2ef2018-01-08 17:21:41 -050011#include "ccpr/GrCCCoverageProcessor.h"
Chris Dalton6a3dbee2017-10-16 10:44:41 -060012
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 Dalton383a2ef2018-01-08 17:21:41 -050021 * (Use GrCCGeometry.)
Chris Dalton6a3dbee2017-10-16 10:44:41 -060022 */
Chris Dalton383a2ef2018-01-08 17:21:41 -050023class GrCCQuadraticShader : public GrCCCoverageProcessor::Shader {
Chris Dalton6a3dbee2017-10-16 10:44:41 -060024protected:
Chris Dalton1fbdb612017-12-12 12:48:47 -070025 void emitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
Chris Daltonc17bf322017-10-24 10:59:03 -060026 const char* wind, GeometryVars*) const final;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060027
Chris Dalton1fbdb612017-12-12 12:48:47 -070028 virtual void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
Chris Daltonc17bf322017-10-24 10:59:03 -060029 GeometryVars*) const = 0;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060030
Chris Dalton90e8fb12017-12-22 02:24:53 -070031 WindHandling onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code,
32 const char* position, const char* coverage, const char* wind) final;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060033
Chris Dalton90e8fb12017-12-22 02:24:53 -070034 virtual void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) {}
Chris Dalton6a3dbee2017-10-16 10:44:41 -060035
Chris Dalton27372882017-12-08 13:34:21 -070036 const GrShaderVar fCanonicalMatrix{"canonical_matrix", kFloat3x3_GrSLType};
37 const GrShaderVar fEdgeDistanceEquation{"edge_distance_equation", kFloat3_GrSLType};
Chris Dalton90e8fb12017-12-22 02:24:53 -070038 GrGLSLVarying fXYD;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060039};
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 Dalton383a2ef2018-01-08 17:21:41 -050047class GrCCQuadraticHullShader : public GrCCQuadraticShader {
Chris Dalton1fbdb612017-12-12 12:48:47 -070048 void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
Chris Daltonc17bf322017-10-24 10:59:03 -060049 GeometryVars*) const override;
Chris Dalton90e8fb12017-12-22 02:24:53 -070050 void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060051 void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override;
52
Chris Dalton90e8fb12017-12-22 02:24:53 -070053 GrGLSLVarying fGrad;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060054};
55
56/**
57 * This pass fixes the corners of a closed quadratic segment with soft MSAA.
58 */
Chris Dalton383a2ef2018-01-08 17:21:41 -050059class GrCCQuadraticCornerShader : public GrCCQuadraticShader {
Chris Dalton1fbdb612017-12-12 12:48:47 -070060 void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
Chris Daltonc17bf322017-10-24 10:59:03 -060061 GeometryVars*) const override;
Chris Dalton90e8fb12017-12-22 02:24:53 -070062 void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060063 void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override;
64
Chris Dalton90e8fb12017-12-22 02:24:53 -070065 GrGLSLVarying fdXYDdx;
66 GrGLSLVarying fdXYDdy;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060067};
68
69#endif