• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SKSL_PIPELINESTAGECODEGENERATOR
9 #define SKSL_PIPELINESTAGECODEGENERATOR
10 
11 #include "src/sksl/SkSLGLSLCodeGenerator.h"
12 #include "src/sksl/SkSLSectionAndParameterHelper.h"
13 
14 #include <set>
15 
16 namespace SkSL {
17 
18 class PipelineStageCodeGenerator : public GLSLCodeGenerator {
19 public:
20     PipelineStageCodeGenerator(const Context* context, const Program* program,
21                                ErrorReporter* errors, OutputStream* out,
22                                std::vector<Compiler::FormatArg>* outFormatArgs);
23 
24 private:
25     void writef(const char* s, va_list va) SKSL_PRINTF_LIKE(2, 0);
26 
27     void writef(const char* s, ...) SKSL_PRINTF_LIKE(2, 3);
28 
29     bool writeSection(const char* name, const char* prefix = "");
30 
31     void writeHeader() override;
32 
33     bool usesPrecisionModifiers() const override;
34 
35     String getTypeName(const Type& type) override;
36 
37     void writeBinaryExpression(const BinaryExpression& b, Precedence parentPrecedence) override;
38 
39     void writeFunctionCall(const FunctionCall& c) override;
40 
41     void writeIntLiteral(const IntLiteral& i) override;
42 
43     void writeVariableReference(const VariableReference& ref) override;
44 
45     void writeIfStatement(const IfStatement& s) override;
46 
47     void writeSwitchStatement(const SwitchStatement& s) override;
48 
49     void writeFunction(const FunctionDefinition& f) override;
50 
51     void writeProgramElement(const ProgramElement& p) override;
52 
53     bool writeEmitCode(std::vector<const Variable*>& uniforms);
54 
55     String fName;
56     String fFullName;
57     SectionAndParameterHelper fSectionAndParameterHelper;
58     String fExtraEmitCodeCode;
59     std::set<int> fWrittenTransformedCoords;
60     std::vector<Compiler::FormatArg>* fFormatArgs;
61     const FunctionDeclaration* fCurrentFunction;
62 
63     typedef GLSLCodeGenerator INHERITED;
64 };
65 
66 }
67 
68 #endif
69