• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 /**************************************************************************************************
9  *** This file was autogenerated from GrAARectEffect.fp; do not modify.
10  **************************************************************************************************/
11 #include "GrAARectEffect.h"
12 #include "glsl/GrGLSLFragmentProcessor.h"
13 #include "glsl/GrGLSLFragmentShaderBuilder.h"
14 #include "glsl/GrGLSLProgramBuilder.h"
15 #include "GrTexture.h"
16 #include "SkSLCPP.h"
17 #include "SkSLUtil.h"
18 class GrGLSLAARectEffect : public GrGLSLFragmentProcessor {
19 public:
GrGLSLAARectEffect()20     GrGLSLAARectEffect() {}
emitCode(EmitArgs & args)21     void emitCode(EmitArgs& args) override {
22         GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
23         const GrAARectEffect& _outer = args.fFp.cast<GrAARectEffect>();
24         (void)_outer;
25         auto edgeType = _outer.edgeType();
26         (void)edgeType;
27         auto rect = _outer.rect();
28         (void)rect;
29         prevRect = float4(-1.0);
30         fRectUniformVar = args.fUniformHandler->addUniform(
31                 kFragment_GrShaderFlag, kFloat4_GrSLType, kDefault_GrSLPrecision, "rectUniform");
32         fragBuilder->codeAppendf(
33                 "float4 prevRect = float4(%f, %f, %f, %f);\nhalf alpha;\n@switch (%d) {\n    case "
34                 "0:\n    case 2:\n        alpha = half(all(greaterThan(float4(sk_FragCoord.xy, "
35                 "%s.zw), float4(%s.xy, sk_FragCoord.xy))) ? 1 : 0);\n        break;\n    "
36                 "default:\n        half xSub, ySub;\n        xSub = half(min(sk_FragCoord.x - "
37                 "%s.x, 0.0));\n        xSub += half(min(%s.z - sk_FragCoord.x, 0.0));\n        "
38                 "ySub = half(min(sk_FragCoord.y - %s.y, 0.0));\n        ySub += half(min(%s.w - "
39                 "sk_FragCoord.y, 0.0));\n        alpha = half((1",
40                 prevRect.left(),
41                 prevRect.top(),
42                 prevRect.right(),
43                 prevRect.bottom(),
44                 (int)_outer.edgeType(),
45                 args.fUniformHandler->getUniformCStr(fRectUniformVar),
46                 args.fUniformHandler->getUniformCStr(fRectUniformVar),
47                 args.fUniformHandler->getUniformCStr(fRectUniformVar),
48                 args.fUniformHandler->getUniformCStr(fRectUniformVar),
49                 args.fUniformHandler->getUniformCStr(fRectUniformVar),
50                 args.fUniformHandler->getUniformCStr(fRectUniformVar));
51         fragBuilder->codeAppendf(
52                 ".0 + max(float(xSub), -1.0)) * (1.0 + max(float(ySub), -1.0)));\n}\n@if (%d == 2 "
53                 "|| %d == 3) {\n    alpha = half(1.0 - float(alpha));\n}\n%s = %s * alpha;\n",
54                 (int)_outer.edgeType(),
55                 (int)_outer.edgeType(),
56                 args.fOutputColor,
57                 args.fInputColor);
58     }
59 
60 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)61     void onSetData(const GrGLSLProgramDataManager& pdman,
62                    const GrFragmentProcessor& _proc) override {
63         const GrAARectEffect& _outer = _proc.cast<GrAARectEffect>();
64         auto edgeType = _outer.edgeType();
65         (void)edgeType;
66         auto rect = _outer.rect();
67         (void)rect;
68         UniformHandle& rectUniform = fRectUniformVar;
69         (void)rectUniform;
70 
71         const SkRect& newRect = GrProcessorEdgeTypeIsAA(edgeType) ? rect.makeInset(.5f, .5f) : rect;
72         if (newRect != prevRect) {
73             pdman.set4f(rectUniform, newRect.fLeft, newRect.fTop, newRect.fRight, newRect.fBottom);
74             prevRect = newRect;
75         }
76     }
77     SkRect prevRect = float4(0);
78     UniformHandle fRectUniformVar;
79 };
onCreateGLSLInstance() const80 GrGLSLFragmentProcessor* GrAARectEffect::onCreateGLSLInstance() const {
81     return new GrGLSLAARectEffect();
82 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const83 void GrAARectEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
84                                            GrProcessorKeyBuilder* b) const {
85     b->add32((int32_t)fEdgeType);
86 }
onIsEqual(const GrFragmentProcessor & other) const87 bool GrAARectEffect::onIsEqual(const GrFragmentProcessor& other) const {
88     const GrAARectEffect& that = other.cast<GrAARectEffect>();
89     (void)that;
90     if (fEdgeType != that.fEdgeType) return false;
91     if (fRect != that.fRect) return false;
92     return true;
93 }
GrAARectEffect(const GrAARectEffect & src)94 GrAARectEffect::GrAARectEffect(const GrAARectEffect& src)
95         : INHERITED(kGrAARectEffect_ClassID, src.optimizationFlags())
96         , fEdgeType(src.fEdgeType)
97         , fRect(src.fRect) {}
clone() const98 std::unique_ptr<GrFragmentProcessor> GrAARectEffect::clone() const {
99     return std::unique_ptr<GrFragmentProcessor>(new GrAARectEffect(*this));
100 }
101 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrAARectEffect);
102 #if GR_TEST_UTILS
TestCreate(GrProcessorTestData * d)103 std::unique_ptr<GrFragmentProcessor> GrAARectEffect::TestCreate(GrProcessorTestData* d) {
104     SkRect rect = SkRect::MakeLTRB(d->fRandom->nextSScalar1(),
105                                    d->fRandom->nextSScalar1(),
106                                    d->fRandom->nextSScalar1(),
107                                    d->fRandom->nextSScalar1());
108     std::unique_ptr<GrFragmentProcessor> fp;
109     do {
110         GrClipEdgeType edgeType =
111                 static_cast<GrClipEdgeType>(d->fRandom->nextULessThan(kGrClipEdgeTypeCnt));
112 
113         fp = GrAARectEffect::Make(edgeType, rect);
114     } while (nullptr == fp);
115     return fp;
116 }
117 #endif
118