blob: bc84396b2de2981e48742a1aa1023f68288739ac [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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"
ethannicholas22f939e2016-10-13 13:25:34 -070012#include "SkSLVarDeclarations.h"
ethannicholasb3058bd2016-07-01 08:22:01 -070013
14namespace SkSL {
15
16/**
17 * An interface block, as in:
18 *
19 * out gl_PerVertex {
20 * layout(builtin=0) vec4 gl_Position;
21 * layout(builtin=1) float gl_PointSize;
22 * };
23 *
24 * At the IR level, this is represented by a single variable of struct type.
25 */
26struct InterfaceBlock : public ProgramElement {
ethannicholasd598f792016-07-25 10:08:54 -070027 InterfaceBlock(Position position, const Variable& var, std::shared_ptr<SymbolTable> typeOwner)
ethannicholasb3058bd2016-07-01 08:22:01 -070028 : INHERITED(position, kInterfaceBlock_Kind)
ethannicholasd598f792016-07-25 10:08:54 -070029 , fVariable(std::move(var))
30 , fTypeOwner(typeOwner) {
31 ASSERT(fVariable.fType.kind() == Type::kStruct_Kind);
ethannicholasb3058bd2016-07-01 08:22:01 -070032 }
33
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050034 SkString description() const override {
35 SkString result = fVariable.fModifiers.description() + fVariable.fName + " {\n";
ethannicholasd598f792016-07-25 10:08:54 -070036 for (size_t i = 0; i < fVariable.fType.fields().size(); i++) {
37 result += fVariable.fType.fields()[i].description() + "\n";
ethannicholasb3058bd2016-07-01 08:22:01 -070038 }
39 result += "};";
40 return result;
41 }
42
ethannicholasd598f792016-07-25 10:08:54 -070043 const Variable& fVariable;
44 const std::shared_ptr<SymbolTable> fTypeOwner;
ethannicholasb3058bd2016-07-01 08:22:01 -070045
46 typedef ProgramElement INHERITED;
47};
48
49} // namespace
50
51#endif