Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 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 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 8 | #ifndef GrCCCubicShader_DEFINED |
| 9 | #define GrCCCubicShader_DEFINED |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 10 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 11 | #include "ccpr/GrCCCoverageProcessor.h" |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 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. |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 22 | * (Use GrCCGeometry::cubicTo().) |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 23 | */ |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 24 | class GrCCCubicShader : public GrCCCoverageProcessor::Shader { |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame] | 25 | public: |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 26 | void emitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* wind, |
Chris Dalton | 9713dcf | 2018-04-10 00:48:41 -0600 | [diff] [blame] | 27 | const char** outHull4) const override; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 28 | |
Chris Dalton | fe462ef | 2018-03-08 15:54:01 +0000 | [diff] [blame] | 29 | void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code, |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 30 | const char* position, const char* coverage, |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame] | 31 | const char* cornerCoverage) override; |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 32 | |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 33 | void onEmitFragmentCode(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const override; |
Chris Dalton | f510e26 | 2018-01-30 16:42:37 -0700 | [diff] [blame] | 34 | |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame] | 35 | private: |
| 36 | void calcHullCoverage(SkString* code, const char* klmAndEdge, const char* gradMatrix, |
| 37 | const char* outputCoverage) const; |
| 38 | |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 39 | const GrShaderVar fKLMMatrix{"klm_matrix", kFloat3x3_GrSLType}; |
| 40 | const GrShaderVar fEdgeDistanceEquation{"edge_distance_equation", kFloat3_GrSLType}; |
Chris Dalton | 4c23934 | 2018-04-05 18:43:40 -0600 | [diff] [blame] | 41 | GrGLSLVarying fKLM_fEdge; |
Chris Dalton | 90e8fb1 | 2017-12-22 02:24:53 -0700 | [diff] [blame] | 42 | GrGLSLVarying fGradMatrix; |
Chris Dalton | 21ba551 | 2018-03-21 17:20:21 -0600 | [diff] [blame] | 43 | GrGLSLVarying fCornerCoverage; |
Chris Dalton | baf3e78 | 2018-03-08 15:55:58 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
Chris Dalton | 6a3dbee | 2017-10-16 10:44:41 -0600 | [diff] [blame] | 46 | #endif |