Chromium Code Reviews| Index: src/sksl/SkSLGLSLCodeGenerator.h |
| diff --git a/src/sksl/SkSLGLSLCodeGenerator.h b/src/sksl/SkSLGLSLCodeGenerator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..335e966a8dd9dc88a7cb39143ca7dd5d0ba5676d |
| --- /dev/null |
| +++ b/src/sksl/SkSLGLSLCodeGenerator.h |
| @@ -0,0 +1,179 @@ |
| +/* |
| + * Copyright 2016 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#ifndef SKSL_GLSLCODEGENERATOR |
| +#define SKSL_GLSLCODEGENERATOR |
| + |
| +#include <stack> |
| +#include <tuple> |
| +#include <unordered_map> |
| + |
| +#include "SkSLCodeGenerator.h" |
| +#include "ir/SkSLBinaryExpression.h" |
| +#include "ir/SkSLBoolLiteral.h" |
| +#include "ir/SkSLConstructor.h" |
| +#include "ir/SkSLDoStatement.h" |
| +#include "ir/SkSLExtension.h" |
| +#include "ir/SkSLFloatLiteral.h" |
| +#include "ir/SkSLIfStatement.h" |
| +#include "ir/SkSLIndexExpression.h" |
| +#include "ir/SkSLInterfaceBlock.h" |
| +#include "ir/SkSLIntLiteral.h" |
| +#include "ir/SkSLFieldAccess.h" |
| +#include "ir/SkSLForStatement.h" |
| +#include "ir/SkSLFunctionCall.h" |
| +#include "ir/SkSLFunctionDeclaration.h" |
| +#include "ir/SkSLFunctionDefinition.h" |
| +#include "ir/SkSLPrefixExpression.h" |
| +#include "ir/SkSLPostfixExpression.h" |
| +#include "ir/SkSLProgramElement.h" |
| +#include "ir/SkSLReturnStatement.h" |
| +#include "ir/SkSLStatement.h" |
| +#include "ir/SkSLSwizzle.h" |
| +#include "ir/SkSLTernaryExpression.h" |
| +#include "ir/SkSLVarDeclaration.h" |
| +#include "ir/SkSLVarDeclarationStatement.h" |
| +#include "ir/SkSLVariableReference.h" |
| +#include "ir/SkSLWhileStatement.h" |
| + |
| +namespace SkSL { |
| + |
| +#define kLast_Capability SpvCapabilityMultiViewport |
| + |
| +struct GLCaps { |
| + int fVersion; |
| + enum { |
| + kGL_Standard, |
| + kGLES_Standard |
| + } fStandard; |
| +}; |
| + |
| +/** |
| + * Converts a Program into GLSL code. |
| + */ |
| +class GLSLCodeGenerator : public CodeGenerator { |
| +public: |
| + enum Precedence { |
| + kParentheses_Precedence = 1, |
| + kPostfix_Precedence = 2, |
| + kPrefix_Precedence = 3, |
| + kMultiplicative_Precedence = 4, |
| + kAdditive_Precedence = 5, |
| + kShift_Precedence = 6, |
| + kRelational_Precedence = 7, |
| + kEquality_Precedence = 8, |
| + kBitwiseAnd_Precedence = 9, |
| + kBitwiseXor_Precedence = 10, |
| + kBitwiseOr_Precedence = 11, |
| + kLogicalAnd_Precedence = 12, |
| + kLogicalXor_Precedence = 13, |
| + kLogicalOr_Precedence = 14, |
| + kTernary_Precedence = 15, |
| + kAssignment_Precedence = 16, |
| + kSequence_Precedence = 17, |
| + kTopLevel_Precedence = 18 |
| + }; |
| + |
| + GLSLCodeGenerator(const Context* context, GLCaps caps) |
| + : fContext(*context) |
| + , fCaps(caps) |
| + , fIndentation(0) |
| + , fAtLineStart(true) {} |
| + |
| + void generateCode(Program& program, std::ostream& out) override; |
| + |
| +private: |
| + void write(const char* s); |
| + |
| + void writeLine(); |
| + |
| + void writeLine(const char* s); |
| + |
| + void write(std::string s); |
| + |
| + void writeLine(std::string s); |
| + |
| + void write(std::string& s); |
|
dogben
2016/07/31 23:20:20
nit: seems like "void write(const std::string& s);
ethannicholas
2016/08/02 16:13:17
Fixed.
|
| + |
| + void writeLine(std::string& s); |
| + |
| + void writeStruct(const Type& type); |
| + |
| + void writeProgramElement(ProgramElement& pe); |
|
dogben
2016/07/31 23:20:20
This method doesn't seem to be implemented or used
ethannicholas
2016/08/02 16:13:17
Fixed.
|
| + |
| + void writeExtension(Extension& ext); |
|
dogben
2016/07/31 23:20:20
nit: seems odd that some methods take const ref an
ethannicholas
2016/08/02 16:13:18
Fixed.
|
| + |
| + void writeInterfaceBlock(InterfaceBlock& intf); |
| + |
| + void writeFunctionStart(const FunctionDeclaration& f); |
| + |
| + void writeFunctionDeclaration(const FunctionDeclaration& f); |
| + |
| + void writeFunction(const FunctionDefinition& f); |
| + |
| + void writeLayout(const Layout& layout); |
| + |
| + void writeModifiers(const Modifiers& modifiers); |
| + |
| + void writeGlobalVars(VarDeclaration& vs); |
| + |
| + void writeVarDeclaration(VarDeclaration& decl); |
| + |
| + void writeVariableReference(VariableReference& ref); |
| + |
| + void writeExpression(Expression& expr, Precedence parentPrecedence); |
| + |
| + void writeIntrinsicCall(FunctionCall& c); |
| + |
| + void writeFunctionCall(FunctionCall& c); |
| + |
| + void writeConstructor(Constructor& c); |
| + |
| + void writeFieldAccess(FieldAccess& f); |
| + |
| + void writeSwizzle(Swizzle& swizzle); |
| + |
| + void writeBinaryExpression(BinaryExpression& b, Precedence parentPrecedence); |
| + |
| + void writeTernaryExpression(TernaryExpression& t, Precedence parentPrecedence); |
| + |
| + void writeIndexExpression(IndexExpression& expr); |
| + |
| + void writePrefixExpression(PrefixExpression& p); |
| + |
| + void writePostfixExpression(PostfixExpression& p); |
| + |
| + void writeBoolLiteral(BoolLiteral& b); |
| + |
| + void writeIntLiteral(IntLiteral& i); |
| + |
| + void writeFloatLiteral(FloatLiteral& f); |
| + |
| + void writeStatement(Statement& s); |
| + |
| + void writeBlock(Block& b); |
| + |
| + void writeIfStatement(IfStatement& stmt); |
| + |
| + void writeForStatement(ForStatement& f); |
| + |
| + void writeWhileStatement(WhileStatement& w); |
| + |
| + void writeDoStatement(DoStatement& d); |
| + |
| + void writeReturnStatement(ReturnStatement& r); |
| + |
| + const Context& fContext; |
| + const GLCaps fCaps; |
| + std::ostream* fOut; |
| + int fIndentation; |
| + bool fAtLineStart; |
| +}; |
| + |
| +} |
| + |
| +#endif |