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 GrCCCubicShader_DEFINED
9 #define GrCCCubicShader_DEFINED
10 
11 #include "ccpr/GrCCCoverageProcessor.h"
12 
13 /**
14  * This class renders the coverage of convex closed cubic segments 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 curve segments must be convex, monotonic with respect to the vector of their closing
21  * edge [P3 - P0], and must not contain or be near any inflection points or loop intersections.
22  * (Use GrCCGeometry.)
23  */
24 class GrCCCubicShader : public GrCCCoverageProcessor::Shader {
25 protected:
26     void emitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
27                        const char* wind, GeometryVars*) const final;
28     virtual void onEmitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
29                                  GeometryVars*) const {}
30 
31     void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code,
32                         const char* position, const char* inputCoverage, const char* wind) final;
33     virtual void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) = 0;
34 
35     void onEmitFragmentCode(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const final;
36     virtual void emitCoverage(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const = 0;
37 
38     GrShaderVar fKLMMatrix{"klm_matrix", kFloat3x3_GrSLType};
39     GrShaderVar fEdgeDistanceEquation{"edge_distance_equation", kFloat3_GrSLType};
40     GrGLSLVarying fKLMD;
41 };
42 
43 class GrCCCubicHullShader : public GrCCCubicShader {
44     void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code) override;
45     void emitCoverage(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const override;
46 
47     GrGLSLVarying fGradMatrix;
48 };
49 
50 class GrCCCubicCornerShader : public GrCCCubicShader {
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 fdKLMDdx;
57     GrGLSLVarying fdKLMDdy;
58 };
59 
60 #endif
61