blob: 5d26a395492410730a329ffd7ae25a1cc0980100 [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
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 */
23class GrCCPRQuadraticShader : public GrCCPRCoverageProcessor::Shader {
24protected:
Chris Dalton6a3dbee2017-10-16 10:44:41 -060025 void emitSetupCode(GrGLSLShaderBuilder*, const char* pts, const char* segmentId,
Chris Daltonc17bf322017-10-24 10:59:03 -060026 const char* wind, GeometryVars*) const final;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060027
28 virtual void onEmitSetupCode(GrGLSLShaderBuilder*, const char* pts, const char* segmentId,
Chris Daltonc17bf322017-10-24 10:59:03 -060029 GeometryVars*) const = 0;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060030
31 WindHandling onEmitVaryings(GrGLSLVaryingHandler*, SkString* code, const char* position,
32 const char* coverage, const char* wind) final;
33
34 virtual void onEmitVaryings(GrGLSLVaryingHandler*, SkString* code) = 0;
35
Chris Dalton27372882017-12-08 13:34:21 -070036 const GrShaderVar fCanonicalMatrix{"canonical_matrix", kFloat3x3_GrSLType};
37 const GrShaderVar fEdgeDistanceEquation{"edge_distance_equation", kFloat3_GrSLType};
38 GrGLSLVarying fXYD{kFloat3_GrSLType, GrGLSLVarying::Scope::kGeoToFrag};
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 */
47class GrCCPRQuadraticHullShader : public GrCCPRQuadraticShader {
48 int getNumSegments() const final { return 4; } // 4 wedges.
49
50 GeometryType getGeometryType() const override { return GeometryType::kHull; }
51 void onEmitSetupCode(GrGLSLShaderBuilder*, const char* pts, const char* wedgeId,
Chris Daltonc17bf322017-10-24 10:59:03 -060052 GeometryVars*) const override;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060053 void onEmitVaryings(GrGLSLVaryingHandler*, SkString* code) override;
54 void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override;
55
Chris Dalton27372882017-12-08 13:34:21 -070056 GrGLSLVarying fGrad{kFloat2_GrSLType, GrGLSLVarying::Scope::kGeoToFrag};
Chris Dalton6a3dbee2017-10-16 10:44:41 -060057};
58
59/**
60 * This pass fixes the corners of a closed quadratic segment with soft MSAA.
61 */
62class GrCCPRQuadraticCornerShader : public GrCCPRQuadraticShader {
63 int getNumSegments() const final { return 2; } // 2 corners.
64
65 GeometryType getGeometryType() const override { return GeometryType::kCorners; }
66 void onEmitSetupCode(GrGLSLShaderBuilder*, const char* pts, const char* cornerId,
Chris Daltonc17bf322017-10-24 10:59:03 -060067 GeometryVars*) const override;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060068 void onEmitVaryings(GrGLSLVaryingHandler*, SkString* code) override;
69 void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override;
70
Chris Dalton27372882017-12-08 13:34:21 -070071 GrGLSLVarying fdXYDdx{kFloat3_GrSLType, GrGLSLVarying::Scope::kGeoToFrag};
72 GrGLSLVarying fdXYDdy{kFloat3_GrSLType, GrGLSLVarying::Scope::kGeoToFrag};
Chris Dalton6a3dbee2017-10-16 10:44:41 -060073};
74
75#endif