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