1 /* 2 * Copyright 2016 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_INTERFACEBLOCK 9 #define SKSL_INTERFACEBLOCK 10 11 #include "SkSLProgramElement.h" 12 #include "SkSLSymbolTable.h" 13 #include "SkSLVarDeclarations.h" 14 15 namespace SkSL { 16 17 /** 18 * An interface block, as in: 19 * 20 * out gl_PerVertex { 21 * layout(builtin=0) vec4 gl_Position; 22 * layout(builtin=1) float gl_PointSize; 23 * }; 24 * 25 * At the IR level, this is represented by a single variable of struct type. 26 */ 27 struct InterfaceBlock : public ProgramElement { 28 InterfaceBlock(Position position, const Variable* var, String typeName, String instanceName, 29 std::vector<std::unique_ptr<Expression>> sizes, 30 std::shared_ptr<SymbolTable> typeOwner) 31 : INHERITED(position, kInterfaceBlock_Kind) 32 , fVariable(*var) 33 , fTypeName(std::move(typeName)) 34 , fInstanceName(std::move(instanceName)) 35 , fSizes(std::move(sizes)) 36 , fTypeOwner(typeOwner) {} 37 38 String description() const override { 39 String result = fVariable.fModifiers.description() + fTypeName + " {\n"; 40 const Type* structType = &fVariable.fType; 41 while (structType->kind() == Type::kArray_Kind) { 42 structType = &structType->componentType(); 43 } 44 for (const auto& f : structType->fields()) { 45 result += f.description() + "\n"; 46 } 47 result += "}"; 48 if (fInstanceName.size()) { 49 result += " " + fInstanceName; 50 for (const auto& size : fSizes) { 51 result += "["; 52 if (size) { 53 result += size->description(); 54 } 55 result += "]"; 56 } 57 } 58 return result + ";"; 59 } 60 61 const Variable& fVariable; 62 const String fTypeName; 63 const String fInstanceName; 64 const std::vector<std::unique_ptr<Expression>> fSizes; 65 const std::shared_ptr<SymbolTable> fTypeOwner; 66 67 typedef ProgramElement INHERITED; 68 }; 69 70 } // namespace 71 72 #endif 73