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 "src/gpu/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::cubicTo().)
23 */
24class GrCCCubicShader : public GrCCCoverageProcessor::Shader {
25public:
26 void emitSetupCode(
27 GrGLSLVertexGeoBuilder*, const char* pts, const char** outHull4) const override;
28
29 void onEmitVaryings(
30 GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code, const char* position,
31 const char* coverage, const char* cornerCoverage, const char* wind) override;
32
33 void emitFragmentCoverageCode(
34 GrGLSLFPFragmentBuilder*, const char* outputCoverage) const override;
35
36 void emitSampleMaskCode(GrGLSLFPFragmentBuilder*) const override;
37
38private:
39 void calcHullCoverage(SkString* code, const char* klmAndEdge, const char* gradMatrix,
40 const char* outputCoverage) const;
41
42 const GrShaderVar fKLMMatrix{"klm_matrix", kFloat3x3_GrSLType};
43 GrGLSLVarying fKLM_fEdge;
44 GrGLSLVarying fGradMatrix;
45 GrGLSLVarying fCornerCoverage;
46};
47
48#endif
49