blob: bf29b6444f4810abda7ae5dd31b16e216ef9adf9 [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 Dalton21ba5512018-03-21 17:20:21 -060021 * (Use GrCCGeometry::quadraticTo().)
Chris Dalton6a3dbee2017-10-16 10:44:41 -060022 */
Chris Dalton383a2ef2018-01-08 17:21:41 -050023class GrCCQuadraticShader : public GrCCCoverageProcessor::Shader {
Chris Dalton4c239342018-04-05 18:43:40 -060024public:
Chris Dalton21ba5512018-03-21 17:20:21 -060025 void emitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* wind,
Chris Dalton9713dcf2018-04-10 00:48:41 -060026 const char** outHull4) const override;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060027
Chris Daltonfe462ef2018-03-08 15:54:01 +000028 void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code,
Chris Dalton21ba5512018-03-21 17:20:21 -060029 const char* position, const char* coverage,
Chris Dalton4c239342018-04-05 18:43:40 -060030 const char* cornerCoverage) override;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060031
Chris Dalton21ba5512018-03-21 17:20:21 -060032 void onEmitFragmentCode(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const override;
Chris Daltonf510e262018-01-30 16:42:37 -070033
Chris Dalton4c239342018-04-05 18:43:40 -060034private:
35 void calcHullCoverage(SkString* code, const char* coordAndGrad, const char* d,
36 const char* outputCoverage) const;
37
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};
Chris Dalton4c239342018-04-05 18:43:40 -060041 GrGLSLVarying fCoord_fGrad;
42 GrGLSLVarying fEdge_fWind_fCorner;
Chris Dalton6a3dbee2017-10-16 10:44:41 -060043};
44
45#endif