blob: 220aca1ee2d1d138d2f7b44a4461f08432be7cda [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 GrCCCubicShader_DEFINED
9#define GrCCCubicShader_DEFINED
Chris Dalton6a3dbee2017-10-16 10:44:41 -060010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/ccpr/GrCCCoverageProcessor.h"
Chris Dalton6a3dbee2017-10-16 10:44:41 -060012
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.
Chris Dalton21ba5512018-03-21 17:20:21 -060022 * (Use GrCCGeometry::cubicTo().)
Chris Dalton6a3dbee2017-10-16 10:44:41 -060023 */
Chris Dalton383a2ef2018-01-08 17:21:41 -050024class GrCCCubicShader : public GrCCCoverageProcessor::Shader {
Chris Dalton4c239342018-04-05 18:43:40 -060025public:
Chris Dalton84d36cd2019-04-17 14:47:17 -060026 void emitSetupCode(
27 GrGLSLVertexGeoBuilder*, const char* pts, const char** outHull4) const override;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060028
Chris Dalton84d36cd2019-04-17 14:47:17 -060029 void onEmitVaryings(
30 GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code, const char* position,
31 const char* coverage, const char* cornerCoverage, const char* wind) override;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060032
Chris Dalton21ba5512018-03-21 17:20:21 -060033 void onEmitFragmentCode(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const override;
Chris Daltonf510e262018-01-30 16:42:37 -070034
Chris Dalton4c239342018-04-05 18:43:40 -060035private:
36 void calcHullCoverage(SkString* code, const char* klmAndEdge, const char* gradMatrix,
37 const char* outputCoverage) const;
38
Chris Dalton21ba5512018-03-21 17:20:21 -060039 const GrShaderVar fKLMMatrix{"klm_matrix", kFloat3x3_GrSLType};
Chris Dalton4c239342018-04-05 18:43:40 -060040 GrGLSLVarying fKLM_fEdge;
Chris Dalton90e8fb12017-12-22 02:24:53 -070041 GrGLSLVarying fGradMatrix;
Chris Dalton21ba5512018-03-21 17:20:21 -060042 GrGLSLVarying fCornerCoverage;
Chris Daltonbaf3e782018-03-08 15:55:58 +000043};
44
Chris Dalton6a3dbee2017-10-16 10:44:41 -060045#endif