• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/private/SkSLLayout.h"
12 #include "include/sksl/SkSLPosition.h"
13 
14 namespace SkSL {
15 
16 namespace dsl {
17 
18 class DSLLayout {
19 public:
DSLLayout()20     DSLLayout() {}
21 
22     DSLLayout& originUpperLeft(Position pos = {}) {
23         return this->flag(SkSL::Layout::kOriginUpperLeft_Flag, "origin_upper_left", pos);
24     }
25 
26     DSLLayout& pushConstant(Position pos = {}) {
27         return this->flag(SkSL::Layout::kPushConstant_Flag, "push_constant", pos);
28     }
29 
30     DSLLayout& blendSupportAllEquations(Position pos = {}) {
31         return this->flag(SkSL::Layout::kBlendSupportAllEquations_Flag,
32                           "blend_support_all_equations", pos);
33     }
34 
35     DSLLayout& color(Position pos = {}) {
36         return this->flag(SkSL::Layout::kColor_Flag, "color", pos);
37     }
38 
39     DSLLayout& location(int location, Position pos = {}) {
40         return this->intValue(&fSkSLLayout.fLocation, location, SkSL::Layout::kLocation_Flag,
41                               "location", pos);
42     }
43 
44     DSLLayout& offset(int offset, Position pos = {}) {
45         return this->intValue(&fSkSLLayout.fOffset, offset, SkSL::Layout::kOffset_Flag, "offset",
46                               pos);
47     }
48 
49     DSLLayout& binding(int binding, Position pos = {}) {
50         return this->intValue(&fSkSLLayout.fBinding, binding, SkSL::Layout::kBinding_Flag,
51                               "binding", pos);
52     }
53 
54     DSLLayout& texture(int texture, Position pos = {}) {
55         return this->intValue(&fSkSLLayout.fTexture, texture, SkSL::Layout::kTexture_Flag,
56                               "texture", pos);
57     }
58 
59     DSLLayout& sampler(int sampler, Position pos = {}) {
60         return this->intValue(&fSkSLLayout.fSampler, sampler, SkSL::Layout::kSampler_Flag,
61                               "sampler", pos);
62     }
63 
64     DSLLayout& index(int index, Position pos = {}) {
65         return this->intValue(&fSkSLLayout.fIndex, index, SkSL::Layout::kIndex_Flag, "index", pos);
66     }
67 
68     DSLLayout& set(int set, Position pos = {}) {
69         return this->intValue(&fSkSLLayout.fSet, set, SkSL::Layout::kSet_Flag, "set", pos);
70     }
71 
72     DSLLayout& builtin(int builtin, Position pos = {}) {
73         return this->intValue(&fSkSLLayout.fBuiltin, builtin, SkSL::Layout::kBuiltin_Flag,
74                               "builtin", pos);
75     }
76 
77     DSLLayout& inputAttachmentIndex(int inputAttachmentIndex,
78                                     Position pos = {}) {
79         return this->intValue(&fSkSLLayout.fInputAttachmentIndex, inputAttachmentIndex,
80                               SkSL::Layout::kInputAttachmentIndex_Flag, "input_attachment_index",
81                               pos);
82     }
83 
84     DSLLayout& spirv(Position pos = {}) {
85         return this->flag(SkSL::Layout::kSPIRV_Flag, "spirv", pos);
86     }
87 
88     DSLLayout& metal(Position pos = {}) {
89         return this->flag(SkSL::Layout::kMetal_Flag, "metal", pos);
90     }
91 
92     DSLLayout& gl(Position pos = {}) {
93         return this->flag(SkSL::Layout::kGL_Flag, "gl", pos);
94     }
95 
96     DSLLayout& wgsl(Position pos = {}) {
97         return this->flag(SkSL::Layout::kWGSL_Flag, "wgsl", pos);
98     }
99 
100 private:
DSLLayout(SkSL::Layout skslLayout)101     explicit DSLLayout(SkSL::Layout skslLayout)
102         : fSkSLLayout(skslLayout) {}
103 
104     DSLLayout& flag(SkSL::Layout::Flag mask, const char* name, Position pos);
105 
106     DSLLayout& intValue(int* target, int value, SkSL::Layout::Flag flag, const char* name,
107                         Position pos);
108 
109     SkSL::Layout fSkSLLayout;
110 
111     friend class DSLModifiers;
112 };
113 
114 } // namespace dsl
115 
116 } // namespace SkSL
117 
118 #endif
119