1 /* 2 * Copyright 2021 Google LLC. 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_DSL_LAYOUT 9 #define SKSL_DSL_LAYOUT 10 11 #include "include/sksl/DSLLayout.h" 12 13 #include "include/private/SkSLLayout.h" 14 #include "include/sksl/SkSLErrorReporter.h" 15 16 namespace SkSL { 17 18 namespace dsl { 19 20 class DSLLayout { 21 public: DSLLayout()22 DSLLayout() {} 23 24 DSLLayout& originUpperLeft(PositionInfo pos = PositionInfo::Capture()) { 25 return this->flag(SkSL::Layout::kOriginUpperLeft_Flag, "origin_upper_left", pos); 26 } 27 28 DSLLayout& pushConstant(PositionInfo pos = PositionInfo::Capture()) { 29 return this->flag(SkSL::Layout::kPushConstant_Flag, "push_constant", pos); 30 } 31 32 DSLLayout& blendSupportAllEquations(PositionInfo pos = PositionInfo::Capture()) { 33 return this->flag(SkSL::Layout::kBlendSupportAllEquations_Flag, 34 "blend_support_all_equations", pos); 35 } 36 37 DSLLayout& srgbUnpremul(PositionInfo pos = PositionInfo::Capture()) { 38 return this->flag(SkSL::Layout::kSRGBUnpremul_Flag, "srgb_unpremul", pos); 39 } 40 41 DSLLayout& location(int location, PositionInfo pos = PositionInfo::Capture()) { 42 return this->intValue(&fSkSLLayout.fLocation, location, SkSL::Layout::kLocation_Flag, 43 "location", pos); 44 } 45 46 DSLLayout& offset(int offset, PositionInfo pos = PositionInfo::Capture()) { 47 return this->intValue(&fSkSLLayout.fOffset, offset, SkSL::Layout::kOffset_Flag, "offset", 48 pos); 49 } 50 51 DSLLayout& binding(int binding, PositionInfo pos = PositionInfo::Capture()) { 52 return this->intValue(&fSkSLLayout.fBinding, binding, SkSL::Layout::kBinding_Flag, 53 "binding", pos); 54 } 55 56 DSLLayout& index(int index, PositionInfo pos = PositionInfo::Capture()) { 57 return this->intValue(&fSkSLLayout.fIndex, index, SkSL::Layout::kIndex_Flag, "index", pos); 58 } 59 60 DSLLayout& set(int set, PositionInfo pos = PositionInfo::Capture()) { 61 return this->intValue(&fSkSLLayout.fSet, set, SkSL::Layout::kSet_Flag, "set", pos); 62 } 63 64 DSLLayout& builtin(int builtin, PositionInfo pos = PositionInfo::Capture()) { 65 return this->intValue(&fSkSLLayout.fBuiltin, builtin, SkSL::Layout::kBuiltin_Flag, 66 "builtin", pos); 67 } 68 69 DSLLayout& inputAttachmentIndex(int inputAttachmentIndex, 70 PositionInfo pos = PositionInfo::Capture()) { 71 return this->intValue(&fSkSLLayout.fInputAttachmentIndex, inputAttachmentIndex, 72 SkSL::Layout::kInputAttachmentIndex_Flag, "input_attachment_index", 73 pos); 74 } 75 76 private: DSLLayout(SkSL::Layout skslLayout)77 explicit DSLLayout(SkSL::Layout skslLayout) 78 : fSkSLLayout(skslLayout) {} 79 80 DSLLayout& flag(SkSL::Layout::Flag mask, const char* name, PositionInfo pos); 81 82 DSLLayout& intValue(int* target, int value, SkSL::Layout::Flag flag, const char* name, 83 PositionInfo pos); 84 85 SkSL::Layout fSkSLLayout; 86 87 friend class DSLModifiers; 88 }; 89 90 } // namespace dsl 91 92 } // namespace SkSL 93 94 #endif 95