Home | History | Annotate | Download | only in ccpr
      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 GrCCQuadraticShader_DEFINED
      9 #define GrCCQuadraticShader_DEFINED
     10 
     11 #include "ccpr/GrCCCoverageProcessor.h"
     12 
     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].
     21  * (Use GrCCGeometry::quadraticTo().)
     22  */
     23 class GrCCQuadraticShader : public GrCCCoverageProcessor::Shader {
     24 public:
     25     void emitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* wind,
     26                        const char** outHull4) const override;
     27 
     28     void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code,
     29                         const char* position, const char* coverage,
     30                         const char* cornerCoverage) override;
     31 
     32     void onEmitFragmentCode(GrGLSLFPFragmentBuilder*, const char* outputCoverage) const override;
     33 
     34 private:
     35     void calcHullCoverage(SkString* code, const char* coordAndGrad, const char* d,
     36                           const char* outputCoverage) const;
     37 
     38     const GrShaderVar fQCoordMatrix{"qcoord_matrix", kFloat2x2_GrSLType};
     39     const GrShaderVar fQCoord0{"qcoord0", kFloat2_GrSLType};
     40     const GrShaderVar fEdgeDistanceEquation{"edge_distance_equation", kFloat3_GrSLType};
     41     GrGLSLVarying fCoord_fGrad;
     42     GrGLSLVarying fEdge_fWind_fCorner;
     43 };
     44 
     45 #endif
     46