blob: 8635ba4ba05449d960be0169c1a24b7ba72606c0 [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 Daltonfe462ef2018-03-08 15:54:01 +000025 void emitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
Chris Daltonbaf3e782018-03-08 15:55:58 +000026 const char* wind, GeometryVars*) const final;
27 virtual void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
28 GeometryVars*) const = 0;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060029
Chris Daltonfe462ef2018-03-08 15:54:01 +000030 void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code,
Chris Dalton04a1de52018-03-14 02:04:09 -060031 const char* position, const char* coverage, const char* attenuatedCoverage,
32 const char* wind) final;
Chris Daltonbaf3e782018-03-08 15:55:58 +000033 virtual void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) {}
Chris Dalton6a3dbee2017-10-16 10:44:41 -060034
Chris Daltonbaf3e782018-03-08 15:55:58 +000035 void onEmitFragmentCode(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const final;
36 virtual void emitCoverage(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const = 0;
Chris Daltonf510e262018-01-30 16:42:37 -070037
Chris Dalton52076d12018-03-21 12:14:10 -060038 const GrShaderVar fQCoordMatrix{"qcoord_matrix", kFloat2x2_GrSLType};
39 const GrShaderVar fQCoord0{"qcoord0", kFloat2_GrSLType};
Chris Daltonbaf3e782018-03-08 15:55:58 +000040 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 */
50class 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 */
62class 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 Dalton6a3dbee2017-10-16 10:44:41 -060070};
71
72#endif