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 GrConstColorProcessor.fp; do not modify.
10 **************************************************************************************************/
11#include "GrConstColorProcessor.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 GrGLSLConstColorProcessor : public GrGLSLFragmentProcessor {
20public:
21 GrGLSLConstColorProcessor() {}
22 void emitCode(EmitArgs& args) override {
23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
24 const GrConstColorProcessor& _outer = args.fFp.cast<GrConstColorProcessor>();
25 (void)_outer;
26 auto color = _outer.color;
27 (void)color;
28 auto mode = _outer.mode;
29 (void)mode;
30 colorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
31 kHalf4_GrSLType, "color");
32 fragBuilder->codeAppendf(
33 "@switch (%d) {\n case 0:\n %s = %s;\n break;\n case 1:\n "
34 " %s = %s * %s;\n break;\n case 2:\n %s = %s.w * %s;\n "
35 "break;\n}\n",
36 (int)_outer.mode, args.fOutputColor, args.fUniformHandler->getUniformCStr(colorVar),
37 args.fOutputColor, args.fInputColor, args.fUniformHandler->getUniformCStr(colorVar),
38 args.fOutputColor, args.fInputColor,
39 args.fUniformHandler->getUniformCStr(colorVar));
40 }
41
42private:
43 void onSetData(const GrGLSLProgramDataManager& pdman,
44 const GrFragmentProcessor& _proc) override {
45 const GrConstColorProcessor& _outer = _proc.cast<GrConstColorProcessor>();
46 {
47 const SkPMColor4f& colorValue = _outer.color;
48 if (colorPrev != colorValue) {
49 colorPrev = colorValue;
50 pdman.set4fv(colorVar, 1, colorValue.vec());
51 }
52 }
53 }
54 SkPMColor4f colorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
55 UniformHandle colorVar;
56};
57GrGLSLFragmentProcessor* GrConstColorProcessor::onCreateGLSLInstance() const {
58 return new GrGLSLConstColorProcessor();
59}
60void GrConstColorProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
61 GrProcessorKeyBuilder* b) const {
62 b->add32((int32_t)mode);
63}
64bool GrConstColorProcessor::onIsEqual(const GrFragmentProcessor& other) const {
65 const GrConstColorProcessor& that = other.cast<GrConstColorProcessor>();
66 (void)that;
67 if (color != that.color) return false;
68 if (mode != that.mode) return false;
69 return true;
70}
71GrConstColorProcessor::GrConstColorProcessor(const GrConstColorProcessor& src)
72 : INHERITED(kGrConstColorProcessor_ClassID, src.optimizationFlags())
73 , color(src.color)
74 , mode(src.mode) {}
75std::unique_ptr<GrFragmentProcessor> GrConstColorProcessor::clone() const {
76 return std::unique_ptr<GrFragmentProcessor>(new GrConstColorProcessor(*this));
77}
78GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConstColorProcessor);
79#if GR_TEST_UTILS
80std::unique_ptr<GrFragmentProcessor> GrConstColorProcessor::TestCreate(GrProcessorTestData* d) {
81 SkPMColor4f color;
82 int colorPicker = d->fRandom->nextULessThan(3);
83 switch (colorPicker) {
84 case 0: {
85 uint32_t a = d->fRandom->nextULessThan(0x100);
86 uint32_t r = d->fRandom->nextULessThan(a + 1);
87 uint32_t g = d->fRandom->nextULessThan(a + 1);
88 uint32_t b = d->fRandom->nextULessThan(a + 1);
89 color = SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(r, g, b, a));
90 break;
91 }
92 case 1:
93 color = SK_PMColor4fTRANSPARENT;
94 break;
95 case 2:
96 uint32_t c = d->fRandom->nextULessThan(0x100);
97 color = SkPMColor4f::FromBytes_RGBA(c | (c << 8) | (c << 16) | (c << 24));
98 break;
99 }
100 InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputModeCnt));
101 return GrConstColorProcessor::Make(color, mode);
102}
103#endif
104