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 GrCCTriangleShader_DEFINED
      9 #define GrCCTriangleShader_DEFINED
     10 
     11 #include "ccpr/GrCCCoverageProcessor.h"
     12 
     13 /**
     14  * Steps 1 & 2: Draw the triangle's conservative raster hull with a coverage of +1, then smooth the
     15  *              edges by drawing the conservative rasters of all 3 edges and interpolating from
     16  *              coverage=-1 on the outside to coverage=0 on the inside. The Impl may choose to
     17  *              implement these steps in either one or two actual render passes.
     18  */
     19 class GrCCTriangleShader : public GrCCCoverageProcessor::Shader {
     20     void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code,
     21                         const char* position, const char* inputCoverage, const char* wind) override;
     22     void onEmitFragmentCode(GrGLSLPPFragmentBuilder*, const char* outputCoverage) const override;
     23 
     24     GrGLSLVarying fCoverageTimesWind;
     25 };
     26 
     27 /**
     28  * Step 3: Touch up the corner pixels. Here we fix the simple distance-to-edge coverage analysis
     29  *         done previously so that it takes into account the region that is outside both edges at
     30  *         the same time.
     31  */
     32 class GrCCTriangleCornerShader : public GrCCCoverageProcessor::Shader {
     33     void emitSetupCode(GrGLSLVertexGeoBuilder*, const char* pts, const char* repetitionID,
     34                        const char* wind, GeometryVars*) const override;
     35     void onEmitVaryings(GrGLSLVaryingHandler*, GrGLSLVarying::Scope, SkString* code,
     36                         const char* position, const char* inputCoverage, const char* wind) override;
     37     void onEmitFragmentCode(GrGLSLPPFragmentBuilder* f, const char* outputCoverage) const override;
     38 
     39     GrShaderVar fAABoxMatrices{"aa_box_matrices", kFloat2x2_GrSLType, 2};
     40     GrShaderVar fAABoxTranslates{"aa_box_translates", kFloat2_GrSLType, 2};
     41     GrShaderVar fGeoShaderBisects{"bisects", kFloat2_GrSLType, 2};
     42     GrGLSLVarying fCornerLocationInAABoxes;
     43     GrGLSLVarying fBisectInAABoxes;
     44     GrGLSLVarying fWindTimesHalf;
     45 };
     46 
     47 #endif
     48