Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 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 | #include "SkSLHCodeGenerator.h" |
| 9 | |
| 10 | #include "SkSLUtil.h" |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame^] | 11 | #include "ir/SkSLEnum.h" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 12 | #include "ir/SkSLFunctionDeclaration.h" |
| 13 | #include "ir/SkSLFunctionDefinition.h" |
| 14 | #include "ir/SkSLSection.h" |
| 15 | #include "ir/SkSLVarDeclarations.h" |
| 16 | |
| 17 | namespace SkSL { |
| 18 | |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 19 | HCodeGenerator::HCodeGenerator(const Context* context, const Program* program, |
| 20 | ErrorReporter* errors, String name, OutputStream* out) |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 21 | : INHERITED(program, errors, out) |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 22 | , fContext(*context) |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 23 | , fName(std::move(name)) |
| 24 | , fFullName(String::printf("Gr%s", fName.c_str())) |
| 25 | , fSectionAndParameterHelper(*program, *errors) {} |
| 26 | |
Ethan Nicholas | d608c09 | 2017-10-26 09:30:08 -0400 | [diff] [blame] | 27 | String HCodeGenerator::ParameterType(const Context& context, const Type& type, |
| 28 | const Layout& layout) { |
| 29 | if (layout.fCType != "") { |
| 30 | return layout.fCType; |
| 31 | } else if (type == *context.fFloat_Type || type == *context.fHalf_Type) { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 32 | return "float"; |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 33 | } else if (type == *context.fFloat2_Type || type == *context.fHalf2_Type) { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 34 | return "SkPoint"; |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 35 | } else if (type == *context.fInt4_Type || type == *context.fShort4_Type) { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 36 | return "SkIRect"; |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 37 | } else if (type == *context.fFloat4_Type || type == *context.fHalf4_Type) { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 38 | return "SkRect"; |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 39 | } else if (type == *context.fFloat4x4_Type || type == *context.fHalf4x4_Type) { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 40 | return "SkMatrix44"; |
| 41 | } else if (type.kind() == Type::kSampler_Kind) { |
| 42 | return "sk_sp<GrTextureProxy>"; |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 43 | } else if (type == *context.fFragmentProcessor_Type) { |
| 44 | return "std::unique_ptr<GrFragmentProcessor>"; |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 45 | } |
| 46 | return type.name(); |
| 47 | } |
| 48 | |
Ethan Nicholas | d608c09 | 2017-10-26 09:30:08 -0400 | [diff] [blame] | 49 | String HCodeGenerator::FieldType(const Context& context, const Type& type, |
| 50 | const Layout& layout) { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 51 | if (type.kind() == Type::kSampler_Kind) { |
| 52 | return "TextureSampler"; |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 53 | } else if (type == *context.fFragmentProcessor_Type) { |
| 54 | // we don't store fragment processors in fields, they get registered via |
| 55 | // registerChildProcessor instead |
| 56 | ASSERT(false); |
| 57 | return "<error>"; |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 58 | } |
Ethan Nicholas | d608c09 | 2017-10-26 09:30:08 -0400 | [diff] [blame] | 59 | return ParameterType(context, type, layout); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void HCodeGenerator::writef(const char* s, va_list va) { |
| 63 | static constexpr int BUFFER_SIZE = 1024; |
Ethan Nicholas | 9fb036f | 2017-07-05 16:19:09 -0400 | [diff] [blame] | 64 | va_list copy; |
| 65 | va_copy(copy, va); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 66 | char buffer[BUFFER_SIZE]; |
| 67 | int length = vsnprintf(buffer, BUFFER_SIZE, s, va); |
| 68 | if (length < BUFFER_SIZE) { |
| 69 | fOut->write(buffer, length); |
| 70 | } else { |
| 71 | std::unique_ptr<char[]> heap(new char[length + 1]); |
Ethan Nicholas | 9fb036f | 2017-07-05 16:19:09 -0400 | [diff] [blame] | 72 | vsprintf(heap.get(), s, copy); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 73 | fOut->write(heap.get(), length); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void HCodeGenerator::writef(const char* s, ...) { |
| 78 | va_list va; |
| 79 | va_start(va, s); |
| 80 | this->writef(s, va); |
| 81 | va_end(va); |
| 82 | } |
| 83 | |
| 84 | bool HCodeGenerator::writeSection(const char* name, const char* prefix) { |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 85 | const Section* s = fSectionAndParameterHelper.getSection(name); |
| 86 | if (s) { |
| 87 | this->writef("%s%s", prefix, s->fText.c_str()); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 88 | return true; |
| 89 | } |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | void HCodeGenerator::writeExtraConstructorParams(const char* separator) { |
| 94 | // super-simple parse, just assume the last token before a comma is the name of a parameter |
| 95 | // (which is true as long as there are no multi-parameter template types involved). Will replace |
| 96 | // this with something more robust if the need arises. |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 97 | const Section* section = fSectionAndParameterHelper.getSection(CONSTRUCTOR_PARAMS_SECTION); |
| 98 | if (section) { |
| 99 | const char* s = section->fText.c_str(); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 100 | #define BUFFER_SIZE 64 |
| 101 | char lastIdentifier[BUFFER_SIZE]; |
| 102 | int lastIdentifierLength = 0; |
| 103 | bool foundBreak = false; |
| 104 | while (*s) { |
| 105 | char c = *s; |
| 106 | ++s; |
| 107 | if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || |
| 108 | c == '_') { |
| 109 | if (foundBreak) { |
| 110 | lastIdentifierLength = 0; |
| 111 | foundBreak = false; |
| 112 | } |
| 113 | ASSERT(lastIdentifierLength < BUFFER_SIZE); |
| 114 | lastIdentifier[lastIdentifierLength] = c; |
| 115 | ++lastIdentifierLength; |
| 116 | } else { |
| 117 | foundBreak = true; |
| 118 | if (c == ',') { |
| 119 | ASSERT(lastIdentifierLength < BUFFER_SIZE); |
| 120 | lastIdentifier[lastIdentifierLength] = 0; |
| 121 | this->writef("%s%s", separator, lastIdentifier); |
| 122 | separator = ", "; |
| 123 | } else if (c != ' ' && c != '\t' && c != '\n' && c != '\r') { |
| 124 | lastIdentifierLength = 0; |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | if (lastIdentifierLength) { |
| 129 | ASSERT(lastIdentifierLength < BUFFER_SIZE); |
| 130 | lastIdentifier[lastIdentifierLength] = 0; |
| 131 | this->writef("%s%s", separator, lastIdentifier); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | void HCodeGenerator::writeMake() { |
| 137 | const char* separator; |
| 138 | if (!this->writeSection(MAKE_SECTION)) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 139 | this->writef(" static std::unique_ptr<GrFragmentProcessor> Make("); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 140 | separator = ""; |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 141 | for (const auto& param : fSectionAndParameterHelper.getParameters()) { |
Ethan Nicholas | d608c09 | 2017-10-26 09:30:08 -0400 | [diff] [blame] | 142 | this->writef("%s%s %s", separator, ParameterType(fContext, param->fType, |
| 143 | param->fModifiers.fLayout).c_str(), |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 144 | String(param->fName).c_str()); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 145 | separator = ", "; |
| 146 | } |
| 147 | this->writeSection(CONSTRUCTOR_PARAMS_SECTION, separator); |
| 148 | this->writef(") {\n" |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 149 | " return std::unique_ptr<GrFragmentProcessor>(new %s(", |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 150 | fFullName.c_str()); |
| 151 | separator = ""; |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 152 | for (const auto& param : fSectionAndParameterHelper.getParameters()) { |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 153 | if (param->fType == *fContext.fFragmentProcessor_Type) { |
Robert Phillips | 7a59f23 | 2017-11-08 15:31:30 -0500 | [diff] [blame] | 154 | this->writef("%sstd::move(%s)", separator, String(param->fName).c_str()); |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 155 | } else { |
| 156 | this->writef("%s%s", separator, String(param->fName).c_str()); |
| 157 | } |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 158 | separator = ", "; |
| 159 | } |
| 160 | this->writeExtraConstructorParams(separator); |
| 161 | this->writef("));\n" |
| 162 | " }\n"); |
| 163 | } |
| 164 | } |
| 165 | |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 166 | void HCodeGenerator::failOnSection(const char* section, const char* msg) { |
| 167 | std::vector<const Section*> s = fSectionAndParameterHelper.getSections(section); |
| 168 | if (s.size()) { |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 169 | fErrors.error(s[0]->fOffset, String("@") + section + " " + msg); |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 173 | void HCodeGenerator::writeConstructor() { |
| 174 | if (this->writeSection(CONSTRUCTOR_SECTION)) { |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 175 | const char* msg = "may not be present when constructor is overridden"; |
| 176 | this->failOnSection(CONSTRUCTOR_CODE_SECTION, msg); |
| 177 | this->failOnSection(CONSTRUCTOR_PARAMS_SECTION, msg); |
| 178 | this->failOnSection(COORD_TRANSFORM_SECTION, msg); |
| 179 | this->failOnSection(INITIALIZERS_SECTION, msg); |
| 180 | this->failOnSection(OPTIMIZATION_FLAGS_SECTION, msg); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 181 | } |
| 182 | this->writef(" %s(", fFullName.c_str()); |
| 183 | const char* separator = ""; |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 184 | for (const auto& param : fSectionAndParameterHelper.getParameters()) { |
Ethan Nicholas | d608c09 | 2017-10-26 09:30:08 -0400 | [diff] [blame] | 185 | this->writef("%s%s %s", separator, ParameterType(fContext, param->fType, |
| 186 | param->fModifiers.fLayout).c_str(), |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 187 | String(param->fName).c_str()); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 188 | separator = ", "; |
| 189 | } |
| 190 | this->writeSection(CONSTRUCTOR_PARAMS_SECTION, separator); |
| 191 | this->writef(")\n" |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 192 | " : INHERITED(k%s_ClassID", fFullName.c_str()); |
| 193 | if (!this->writeSection(OPTIMIZATION_FLAGS_SECTION, ", (OptimizationFlags) ")) { |
| 194 | this->writef(", kNone_OptimizationFlags"); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 195 | } |
| 196 | this->writef(")"); |
| 197 | this->writeSection(INITIALIZERS_SECTION, "\n , "); |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 198 | for (const auto& param : fSectionAndParameterHelper.getParameters()) { |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 199 | String nameString(param->fName); |
| 200 | const char* name = nameString.c_str(); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 201 | if (param->fType.kind() == Type::kSampler_Kind) { |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 202 | this->writef("\n , %s(std::move(%s)", FieldName(name).c_str(), name); |
| 203 | for (const Section* s : fSectionAndParameterHelper.getSections( |
| 204 | SAMPLER_PARAMS_SECTION)) { |
| 205 | if (s->fArgument == name) { |
| 206 | this->writef(", %s", s->fText.c_str()); |
| 207 | } |
| 208 | } |
| 209 | this->writef(")"); |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 210 | } else if (param->fType == *fContext.fFragmentProcessor_Type) { |
| 211 | // do nothing |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 212 | } else { |
| 213 | this->writef("\n , %s(%s)", FieldName(name).c_str(), name); |
| 214 | } |
| 215 | } |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 216 | for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) { |
| 217 | String field = FieldName(s->fArgument.c_str()); |
| 218 | this->writef("\n , %sCoordTransform(%s, %s.proxy())", field.c_str(), s->fText.c_str(), |
| 219 | field.c_str()); |
| 220 | } |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 221 | this->writef(" {\n"); |
| 222 | this->writeSection(CONSTRUCTOR_CODE_SECTION); |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 223 | for (const auto& param : fSectionAndParameterHelper.getParameters()) { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 224 | if (param->fType.kind() == Type::kSampler_Kind) { |
| 225 | this->writef(" this->addTextureSampler(&%s);\n", |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 226 | FieldName(String(param->fName).c_str()).c_str()); |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 227 | } else if (param->fType == *fContext.fFragmentProcessor_Type) { |
| 228 | this->writef(" this->registerChildProcessor(std::move(%s));", |
| 229 | String(param->fName).c_str()); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 230 | } |
| 231 | } |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 232 | for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) { |
| 233 | String field = FieldName(s->fArgument.c_str()); |
| 234 | this->writef(" this->addCoordTransform(&%sCoordTransform);\n", field.c_str()); |
| 235 | } |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 236 | this->writef(" }\n"); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void HCodeGenerator::writeFields() { |
| 240 | this->writeSection(FIELDS_SECTION); |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 241 | for (const auto& param : fSectionAndParameterHelper.getParameters()) { |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 242 | if (param->fType == *fContext.fFragmentProcessor_Type) { |
| 243 | continue; |
| 244 | } |
Ethan Nicholas | d608c09 | 2017-10-26 09:30:08 -0400 | [diff] [blame] | 245 | this->writef(" %s %s;\n", FieldType(fContext, param->fType, |
| 246 | param->fModifiers.fLayout).c_str(), |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 247 | FieldName(String(param->fName).c_str()).c_str()); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 248 | } |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 249 | for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) { |
| 250 | this->writef(" GrCoordTransform %sCoordTransform;\n", |
| 251 | FieldName(s->fArgument.c_str()).c_str()); |
| 252 | } |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | bool HCodeGenerator::generateCode() { |
| 256 | this->writef(kFragmentProcessorHeader, fFullName.c_str()); |
| 257 | this->writef("#ifndef %s_DEFINED\n" |
Ethan Nicholas | 9fb036f | 2017-07-05 16:19:09 -0400 | [diff] [blame] | 258 | "#define %s_DEFINED\n", |
| 259 | fFullName.c_str(), |
| 260 | fFullName.c_str()); |
Ethan Nicholas | ceb4d48 | 2017-07-10 15:40:20 -0400 | [diff] [blame] | 261 | this->writef("#include \"SkTypes.h\"\n" |
| 262 | "#if SK_SUPPORT_GPU\n"); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 263 | this->writeSection(HEADER_SECTION); |
Ethan Nicholas | 9fb036f | 2017-07-05 16:19:09 -0400 | [diff] [blame] | 264 | this->writef("#include \"GrFragmentProcessor.h\"\n" |
Brian Osman | 1cb4171 | 2017-10-19 12:54:52 -0400 | [diff] [blame] | 265 | "#include \"GrCoordTransform.h\"\n"); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 266 | this->writef("class %s : public GrFragmentProcessor {\n" |
| 267 | "public:\n", |
| 268 | fFullName.c_str()); |
| 269 | this->writeSection(CLASS_SECTION); |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame^] | 270 | for (const auto& p : fProgram.fElements) { |
| 271 | if (ProgramElement::kEnum_Kind == p->fKind && !((Enum&) *p).fBuiltin) { |
| 272 | this->writef("%s\n", p->description().c_str()); |
| 273 | } |
| 274 | } |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 275 | for (const auto& param : fSectionAndParameterHelper.getParameters()) { |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 276 | if (param->fType.kind() == Type::kSampler_Kind || |
| 277 | param->fType.kind() == Type::kOther_Kind) { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 278 | continue; |
| 279 | } |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 280 | String nameString(param->fName); |
| 281 | const char* name = nameString.c_str(); |
Ethan Nicholas | 9fb036f | 2017-07-05 16:19:09 -0400 | [diff] [blame] | 282 | this->writef(" %s %s() const { return %s; }\n", |
Ethan Nicholas | d608c09 | 2017-10-26 09:30:08 -0400 | [diff] [blame] | 283 | FieldType(fContext, param->fType, param->fModifiers.fLayout).c_str(), name, |
| 284 | FieldName(name).c_str()); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 285 | } |
| 286 | this->writeMake(); |
Ethan Nicholas | f57c0d6 | 2017-07-31 11:18:22 -0400 | [diff] [blame] | 287 | this->writef(" %s(const %s& src);\n" |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 288 | " std::unique_ptr<GrFragmentProcessor> clone() const override;\n" |
Ethan Nicholas | f57c0d6 | 2017-07-31 11:18:22 -0400 | [diff] [blame] | 289 | " const char* name() const override { return \"%s\"; }\n" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 290 | "private:\n", |
Ethan Nicholas | f57c0d6 | 2017-07-31 11:18:22 -0400 | [diff] [blame] | 291 | fFullName.c_str(), fFullName.c_str(), fName.c_str()); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 292 | this->writeConstructor(); |
| 293 | this->writef(" GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;\n" |
| 294 | " void onGetGLSLProcessorKey(const GrShaderCaps&," |
| 295 | "GrProcessorKeyBuilder*) const override;\n" |
| 296 | " bool onIsEqual(const GrFragmentProcessor&) const override;\n" |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 297 | " GR_DECLARE_FRAGMENT_PROCESSOR_TEST\n"); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 298 | this->writeFields(); |
| 299 | this->writef(" typedef GrFragmentProcessor INHERITED;\n" |
Ethan Nicholas | 9fb036f | 2017-07-05 16:19:09 -0400 | [diff] [blame] | 300 | "};\n"); |
| 301 | this->writeSection(HEADER_END_SECTION); |
Ethan Nicholas | ceb4d48 | 2017-07-10 15:40:20 -0400 | [diff] [blame] | 302 | this->writef("#endif\n" |
| 303 | "#endif\n"); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 304 | return 0 == fErrors.errorCount(); |
| 305 | } |
| 306 | |
| 307 | } // namespace |