blob: 0f6da5f5c48a681779c4055337f112461845f200 [file] [log] [blame]
Ethan Nicholas762466e2017-06-29 10:03:38 -04001/*
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 SKSL_CPPCODEGENERATOR
9#define SKSL_CPPCODEGENERATOR
10
11#include "SkSLGLSLCodeGenerator.h"
12#include "SkSLSectionAndParameterHelper.h"
13
14#include <set>
15
16namespace SkSL {
17
18class CPPCodeGenerator : public GLSLCodeGenerator {
19public:
20 CPPCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors,
21 String name, OutputStream* out);
22
23 bool generateCode() override;
24
25private:
26 void writef(const char* s, va_list va) SKSL_PRINTF_LIKE(2, 0);
27
28 void writef(const char* s, ...) SKSL_PRINTF_LIKE(2, 3);
29
30 void writeSection(const char* name, const char* prefix = "");
31
32 void writeHeader() override;
33
34 void writePrecisionModifier() override;
35
36 void writeBinaryExpression(const BinaryExpression& b, Precedence parentPrecedence) override;
37
38 void writeIndexExpression(const IndexExpression& i) override;
39
40 void writeVariableReference(const VariableReference& ref) override;
41
Ethan Nicholasceb4d482017-07-10 15:40:20 -040042 String getSamplerHandle(const Variable& var);
43
44 void writeFunctionCall(const FunctionCall& c) override;
45
Ethan Nicholas762466e2017-06-29 10:03:38 -040046 void writeFunction(const FunctionDefinition& f) override;
47
48 void writeSetting(const Setting& s) override;
49
50 void writeProgramElement(const ProgramElement& p) override;
51
52 void addUniform(const Variable& var);
53
54 // writes a printf escape that will be filled in at runtime by the given C++ expression string
55 void writeRuntimeValue(const Type& type, const String& cppCode);
56
57 void writeVarInitializer(const Variable& var, const Expression& value) override;
58
59 void writePrivateVars();
60
61 void writePrivateVarValues();
62
63 bool writeEmitCode(std::vector<const Variable*>& uniforms);
64
65 void writeSetData(std::vector<const Variable*>& uniforms);
66
67 void writeGetKey();
68
69 void writeTest();
70
71 String fName;
72 String fFullName;
73 SectionAndParameterHelper fSectionAndParameterHelper;
74 String fExtraEmitCodeCode;
75 std::vector<String> fFormatArgs;
76 std::set<int> fWrittenTransformedCoords;
77 bool fNeedColorSpaceHelper = false;
78
79 typedef GLSLCodeGenerator INHERITED;
80};
81
82}
83
84#endif