blob: cb8712ef1258f1e55f85ff17a158f29dad2404cc [file] [log] [blame]
Ethan Nicholas762466e2017-06-29 10:03:38 -04001/*
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
Ethan Nicholas130fb3f2018-02-01 12:14:34 -050010#include "SkSLParser.h"
Ethan Nicholas762466e2017-06-29 10:03:38 -040011#include "SkSLUtil.h"
Ethan Nicholasaae47c82017-11-10 15:34:03 -050012#include "ir/SkSLEnum.h"
Ethan Nicholas762466e2017-06-29 10:03:38 -040013#include "ir/SkSLFunctionDeclaration.h"
14#include "ir/SkSLFunctionDefinition.h"
15#include "ir/SkSLSection.h"
16#include "ir/SkSLVarDeclarations.h"
17
Michael Ludwiga4275592018-08-31 10:52:47 -040018#include <set>
19
Ethan Nicholas762466e2017-06-29 10:03:38 -040020namespace SkSL {
21
Ethan Nicholasc9472af2017-10-10 16:30:21 -040022HCodeGenerator::HCodeGenerator(const Context* context, const Program* program,
23 ErrorReporter* errors, String name, OutputStream* out)
Ethan Nicholas762466e2017-06-29 10:03:38 -040024: INHERITED(program, errors, out)
Ethan Nicholasc9472af2017-10-10 16:30:21 -040025, fContext(*context)
Ethan Nicholas762466e2017-06-29 10:03:38 -040026, fName(std::move(name))
27, fFullName(String::printf("Gr%s", fName.c_str()))
28, fSectionAndParameterHelper(*program, *errors) {}
29
Ethan Nicholasd608c092017-10-26 09:30:08 -040030String HCodeGenerator::ParameterType(const Context& context, const Type& type,
31 const Layout& layout) {
Ethan Nicholas78aceb22018-08-31 16:13:58 -040032 Layout::CType ctype = ParameterCType(context, type, layout);
33 if (ctype != Layout::CType::kDefault) {
34 return Layout::CTypeToStr(ctype);
35 }
36 return type.name();
37}
38
39Layout::CType HCodeGenerator::ParameterCType(const Context& context, const Type& type,
40 const Layout& layout) {
41 if (layout.fCType != Layout::CType::kDefault) {
Ethan Nicholasd608c092017-10-26 09:30:08 -040042 return layout.fCType;
Ethan Nicholas78aceb22018-08-31 16:13:58 -040043 }
44 if (type == *context.fFloat_Type || type == *context.fHalf_Type) {
45 return Layout::CType::kFloat;
Michael Ludwiga4275592018-08-31 10:52:47 -040046 } else if (type == *context.fInt_Type ||
47 type == *context.fShort_Type ||
48 type == *context.fByte_Type) {
Ethan Nicholas78aceb22018-08-31 16:13:58 -040049 return Layout::CType::kInt32;
Ethan Nicholasc9472af2017-10-10 16:30:21 -040050 } else if (type == *context.fFloat2_Type || type == *context.fHalf2_Type) {
Ethan Nicholas78aceb22018-08-31 16:13:58 -040051 return Layout::CType::kSkPoint;
Michael Ludwiga4275592018-08-31 10:52:47 -040052 } else if (type == *context.fInt2_Type ||
53 type == *context.fShort2_Type ||
54 type == *context.fByte2_Type) {
Ethan Nicholas78aceb22018-08-31 16:13:58 -040055 return Layout::CType::kSkIPoint;
Ruiqi Maob609e6d2018-07-17 10:19:38 -040056 } else if (type == *context.fInt4_Type ||
57 type == *context.fShort4_Type ||
58 type == *context.fByte4_Type) {
Ethan Nicholas78aceb22018-08-31 16:13:58 -040059 return Layout::CType::kSkIRect;
Ethan Nicholasc9472af2017-10-10 16:30:21 -040060 } else if (type == *context.fFloat4_Type || type == *context.fHalf4_Type) {
Ethan Nicholas78aceb22018-08-31 16:13:58 -040061 return Layout::CType::kSkRect;
Michael Ludwiga4275592018-08-31 10:52:47 -040062 } else if (type == *context.fFloat3x3_Type || type == *context.fHalf3x3_Type) {
Ethan Nicholas78aceb22018-08-31 16:13:58 -040063 return Layout::CType::kSkMatrix;
Ethan Nicholasc9472af2017-10-10 16:30:21 -040064 } else if (type == *context.fFloat4x4_Type || type == *context.fHalf4x4_Type) {
Ethan Nicholas78aceb22018-08-31 16:13:58 -040065 return Layout::CType::kSkMatrix44;
Ethan Nicholas762466e2017-06-29 10:03:38 -040066 } else if (type.kind() == Type::kSampler_Kind) {
Ethan Nicholas78aceb22018-08-31 16:13:58 -040067 return Layout::CType::kGrTextureProxy;
Ethan Nicholasc9472af2017-10-10 16:30:21 -040068 } else if (type == *context.fFragmentProcessor_Type) {
Ethan Nicholas78aceb22018-08-31 16:13:58 -040069 return Layout::CType::kGrFragmentProcessor;
Ethan Nicholas762466e2017-06-29 10:03:38 -040070 }
Ethan Nicholas78aceb22018-08-31 16:13:58 -040071 return Layout::CType::kDefault;
Ethan Nicholas762466e2017-06-29 10:03:38 -040072}
73
Ethan Nicholasd608c092017-10-26 09:30:08 -040074String HCodeGenerator::FieldType(const Context& context, const Type& type,
75 const Layout& layout) {
Ethan Nicholas762466e2017-06-29 10:03:38 -040076 if (type.kind() == Type::kSampler_Kind) {
77 return "TextureSampler";
Ethan Nicholasc9472af2017-10-10 16:30:21 -040078 } else if (type == *context.fFragmentProcessor_Type) {
79 // we don't store fragment processors in fields, they get registered via
80 // registerChildProcessor instead
Ethan Nicholasd9d33c32018-06-12 11:05:59 -040081 SkASSERT(false);
Ethan Nicholasc9472af2017-10-10 16:30:21 -040082 return "<error>";
Ethan Nicholas762466e2017-06-29 10:03:38 -040083 }
Ethan Nicholasd608c092017-10-26 09:30:08 -040084 return ParameterType(context, type, layout);
Ethan Nicholas762466e2017-06-29 10:03:38 -040085}
86
Michael Ludwiga4275592018-08-31 10:52:47 -040087String HCodeGenerator::AccessType(const Context& context, const Type& type,
88 const Layout& layout) {
Michael Ludwig72efd802018-08-31 13:26:19 -040089 static const std::set<String> primitiveTypes = { "int32_t", "float", "bool", "SkPMColor" };
Michael Ludwiga4275592018-08-31 10:52:47 -040090
91 String fieldType = FieldType(context, type, layout);
92 bool isPrimitive = primitiveTypes.find(fieldType) != primitiveTypes.end();
93 if (isPrimitive) {
94 return fieldType;
95 } else {
96 return String::printf("const %s&", fieldType.c_str());
97 }
98}
99
Ethan Nicholas762466e2017-06-29 10:03:38 -0400100void HCodeGenerator::writef(const char* s, va_list va) {
101 static constexpr int BUFFER_SIZE = 1024;
Ethan Nicholas9fb036f2017-07-05 16:19:09 -0400102 va_list copy;
103 va_copy(copy, va);
Ethan Nicholas762466e2017-06-29 10:03:38 -0400104 char buffer[BUFFER_SIZE];
105 int length = vsnprintf(buffer, BUFFER_SIZE, s, va);
106 if (length < BUFFER_SIZE) {
107 fOut->write(buffer, length);
108 } else {
109 std::unique_ptr<char[]> heap(new char[length + 1]);
Ethan Nicholas9fb036f2017-07-05 16:19:09 -0400110 vsprintf(heap.get(), s, copy);
Ethan Nicholas762466e2017-06-29 10:03:38 -0400111 fOut->write(heap.get(), length);
112 }
Greg Kaiser27f83022019-02-11 08:32:13 -0800113 va_end(copy);
Ethan Nicholas762466e2017-06-29 10:03:38 -0400114}
115
116void HCodeGenerator::writef(const char* s, ...) {
117 va_list va;
118 va_start(va, s);
119 this->writef(s, va);
120 va_end(va);
121}
122
123bool HCodeGenerator::writeSection(const char* name, const char* prefix) {
Ethan Nicholas68990be2017-07-13 09:36:52 -0400124 const Section* s = fSectionAndParameterHelper.getSection(name);
125 if (s) {
126 this->writef("%s%s", prefix, s->fText.c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400127 return true;
128 }
129 return false;
130}
131
132void HCodeGenerator::writeExtraConstructorParams(const char* separator) {
133 // super-simple parse, just assume the last token before a comma is the name of a parameter
134 // (which is true as long as there are no multi-parameter template types involved). Will replace
135 // this with something more robust if the need arises.
Ethan Nicholas68990be2017-07-13 09:36:52 -0400136 const Section* section = fSectionAndParameterHelper.getSection(CONSTRUCTOR_PARAMS_SECTION);
137 if (section) {
138 const char* s = section->fText.c_str();
Ethan Nicholas762466e2017-06-29 10:03:38 -0400139 #define BUFFER_SIZE 64
140 char lastIdentifier[BUFFER_SIZE];
141 int lastIdentifierLength = 0;
142 bool foundBreak = false;
143 while (*s) {
144 char c = *s;
145 ++s;
146 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
147 c == '_') {
148 if (foundBreak) {
149 lastIdentifierLength = 0;
150 foundBreak = false;
151 }
Ethan Nicholasd9d33c32018-06-12 11:05:59 -0400152 SkASSERT(lastIdentifierLength < BUFFER_SIZE);
Ethan Nicholas762466e2017-06-29 10:03:38 -0400153 lastIdentifier[lastIdentifierLength] = c;
154 ++lastIdentifierLength;
155 } else {
156 foundBreak = true;
157 if (c == ',') {
Ethan Nicholasd9d33c32018-06-12 11:05:59 -0400158 SkASSERT(lastIdentifierLength < BUFFER_SIZE);
Ethan Nicholas762466e2017-06-29 10:03:38 -0400159 lastIdentifier[lastIdentifierLength] = 0;
160 this->writef("%s%s", separator, lastIdentifier);
161 separator = ", ";
162 } else if (c != ' ' && c != '\t' && c != '\n' && c != '\r') {
163 lastIdentifierLength = 0;
164 }
165 }
166 }
167 if (lastIdentifierLength) {
Ethan Nicholasd9d33c32018-06-12 11:05:59 -0400168 SkASSERT(lastIdentifierLength < BUFFER_SIZE);
Ethan Nicholas762466e2017-06-29 10:03:38 -0400169 lastIdentifier[lastIdentifierLength] = 0;
170 this->writef("%s%s", separator, lastIdentifier);
171 }
172 }
173}
174
175void HCodeGenerator::writeMake() {
176 const char* separator;
177 if (!this->writeSection(MAKE_SECTION)) {
Brian Salomonaff329b2017-08-11 09:40:37 -0400178 this->writef(" static std::unique_ptr<GrFragmentProcessor> Make(");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400179 separator = "";
Ethan Nicholas68990be2017-07-13 09:36:52 -0400180 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholasd608c092017-10-26 09:30:08 -0400181 this->writef("%s%s %s", separator, ParameterType(fContext, param->fType,
182 param->fModifiers.fLayout).c_str(),
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700183 String(param->fName).c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400184 separator = ", ";
185 }
186 this->writeSection(CONSTRUCTOR_PARAMS_SECTION, separator);
187 this->writef(") {\n"
Brian Salomonaff329b2017-08-11 09:40:37 -0400188 " return std::unique_ptr<GrFragmentProcessor>(new %s(",
Ethan Nicholas762466e2017-06-29 10:03:38 -0400189 fFullName.c_str());
190 separator = "";
Ethan Nicholas68990be2017-07-13 09:36:52 -0400191 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400192 if (param->fType == *fContext.fFragmentProcessor_Type) {
Robert Phillips7a59f232017-11-08 15:31:30 -0500193 this->writef("%sstd::move(%s)", separator, String(param->fName).c_str());
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400194 } else {
195 this->writef("%s%s", separator, String(param->fName).c_str());
196 }
Ethan Nicholas762466e2017-06-29 10:03:38 -0400197 separator = ", ";
198 }
199 this->writeExtraConstructorParams(separator);
200 this->writef("));\n"
201 " }\n");
202 }
203}
204
Ethan Nicholas68990be2017-07-13 09:36:52 -0400205void HCodeGenerator::failOnSection(const char* section, const char* msg) {
206 std::vector<const Section*> s = fSectionAndParameterHelper.getSections(section);
207 if (s.size()) {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700208 fErrors.error(s[0]->fOffset, String("@") + section + " " + msg);
Ethan Nicholas68990be2017-07-13 09:36:52 -0400209 }
210}
211
Ethan Nicholas762466e2017-06-29 10:03:38 -0400212void HCodeGenerator::writeConstructor() {
213 if (this->writeSection(CONSTRUCTOR_SECTION)) {
Ethan Nicholas68990be2017-07-13 09:36:52 -0400214 const char* msg = "may not be present when constructor is overridden";
215 this->failOnSection(CONSTRUCTOR_CODE_SECTION, msg);
216 this->failOnSection(CONSTRUCTOR_PARAMS_SECTION, msg);
Ethan Nicholas68990be2017-07-13 09:36:52 -0400217 this->failOnSection(INITIALIZERS_SECTION, msg);
218 this->failOnSection(OPTIMIZATION_FLAGS_SECTION, msg);
Robert Phillips1e8501e2018-03-23 15:00:20 -0400219 return;
Ethan Nicholas762466e2017-06-29 10:03:38 -0400220 }
221 this->writef(" %s(", fFullName.c_str());
222 const char* separator = "";
Ethan Nicholas68990be2017-07-13 09:36:52 -0400223 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholasd608c092017-10-26 09:30:08 -0400224 this->writef("%s%s %s", separator, ParameterType(fContext, param->fType,
225 param->fModifiers.fLayout).c_str(),
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700226 String(param->fName).c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400227 separator = ", ";
228 }
229 this->writeSection(CONSTRUCTOR_PARAMS_SECTION, separator);
230 this->writef(")\n"
Ethan Nicholasabff9562017-10-09 10:54:08 -0400231 " : INHERITED(k%s_ClassID", fFullName.c_str());
232 if (!this->writeSection(OPTIMIZATION_FLAGS_SECTION, ", (OptimizationFlags) ")) {
233 this->writef(", kNone_OptimizationFlags");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400234 }
235 this->writef(")");
236 this->writeSection(INITIALIZERS_SECTION, "\n , ");
Ethan Nicholas68990be2017-07-13 09:36:52 -0400237 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700238 String nameString(param->fName);
239 const char* name = nameString.c_str();
Ethan Nicholas762466e2017-06-29 10:03:38 -0400240 if (param->fType.kind() == Type::kSampler_Kind) {
Ethan Nicholas68990be2017-07-13 09:36:52 -0400241 this->writef("\n , %s(std::move(%s)", FieldName(name).c_str(), name);
242 for (const Section* s : fSectionAndParameterHelper.getSections(
243 SAMPLER_PARAMS_SECTION)) {
244 if (s->fArgument == name) {
245 this->writef(", %s", s->fText.c_str());
246 }
247 }
248 this->writef(")");
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400249 } else if (param->fType == *fContext.fFragmentProcessor_Type) {
250 // do nothing
Ethan Nicholas762466e2017-06-29 10:03:38 -0400251 } else {
252 this->writef("\n , %s(%s)", FieldName(name).c_str(), name);
253 }
254 }
Ethan Nicholas929a6812018-08-06 14:56:59 -0400255 const auto transforms = fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION);
256 for (size_t i = 0; i < transforms.size(); ++i) {
257 const Section& s = *transforms[i];
258 String field = CoordTransformName(s.fArgument.c_str(), i);
259 if (s.fArgument.size()) {
260 this->writef("\n , %s(%s, %s.proxy())", field.c_str(), s.fText.c_str(),
261 FieldName(s.fArgument.c_str()).c_str());
262 }
263 else {
264 this->writef("\n , %s(%s)", field.c_str(), s.fText.c_str());
265 }
Ethan Nicholas68990be2017-07-13 09:36:52 -0400266 }
Ethan Nicholas762466e2017-06-29 10:03:38 -0400267 this->writef(" {\n");
268 this->writeSection(CONSTRUCTOR_CODE_SECTION);
Brian Salomonf7dcd762018-07-30 14:48:15 -0400269 int samplerCount = 0;
Ethan Nicholas68990be2017-07-13 09:36:52 -0400270 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholas762466e2017-06-29 10:03:38 -0400271 if (param->fType.kind() == Type::kSampler_Kind) {
Brian Salomonf7dcd762018-07-30 14:48:15 -0400272 ++samplerCount;
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400273 } else if (param->fType == *fContext.fFragmentProcessor_Type) {
274 this->writef(" this->registerChildProcessor(std::move(%s));",
275 String(param->fName).c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400276 }
277 }
Brian Salomonf7dcd762018-07-30 14:48:15 -0400278 if (samplerCount) {
279 this->writef(" this->setTextureSamplerCnt(%d);", samplerCount);
280 }
Ethan Nicholas929a6812018-08-06 14:56:59 -0400281 for (size_t i = 0; i < transforms.size(); ++i) {
282 const Section& s = *transforms[i];
283 String field = CoordTransformName(s.fArgument.c_str(), i);
284 this->writef(" this->addCoordTransform(&%s);\n", field.c_str());
Ethan Nicholas68990be2017-07-13 09:36:52 -0400285 }
Ethan Nicholasabff9562017-10-09 10:54:08 -0400286 this->writef(" }\n");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400287}
288
289void HCodeGenerator::writeFields() {
290 this->writeSection(FIELDS_SECTION);
Ethan Nicholas68990be2017-07-13 09:36:52 -0400291 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400292 if (param->fType == *fContext.fFragmentProcessor_Type) {
293 continue;
294 }
Ethan Nicholasd608c092017-10-26 09:30:08 -0400295 this->writef(" %s %s;\n", FieldType(fContext, param->fType,
296 param->fModifiers.fLayout).c_str(),
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700297 FieldName(String(param->fName).c_str()).c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400298 }
Ethan Nicholas929a6812018-08-06 14:56:59 -0400299 const auto transforms = fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION);
300 for (size_t i = 0; i < transforms.size(); ++i) {
301 const Section& s = *transforms[i];
302 this->writef(" GrCoordTransform %s;\n",
303 CoordTransformName(s.fArgument.c_str(), i).c_str());
Ethan Nicholas68990be2017-07-13 09:36:52 -0400304 }
Ethan Nicholas762466e2017-06-29 10:03:38 -0400305}
306
Ethan Nicholas130fb3f2018-02-01 12:14:34 -0500307String HCodeGenerator::GetHeader(const Program& program, ErrorReporter& errors) {
308 SymbolTable types(&errors);
309 Parser parser(program.fSource->c_str(), program.fSource->length(), types, errors);
310 for (;;) {
311 Token header = parser.nextRawToken();
312 switch (header.fKind) {
313 case Token::WHITESPACE:
314 break;
315 case Token::BLOCK_COMMENT:
316 return String(program.fSource->c_str() + header.fOffset, header.fLength);
317 default:
318 return "";
319 }
320 }
321}
322
Ethan Nicholas762466e2017-06-29 10:03:38 -0400323bool HCodeGenerator::generateCode() {
Ethan Nicholas130fb3f2018-02-01 12:14:34 -0500324 this->writef("%s\n", GetHeader(fProgram, fErrors).c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400325 this->writef(kFragmentProcessorHeader, fFullName.c_str());
326 this->writef("#ifndef %s_DEFINED\n"
Ethan Nicholas9fb036f2017-07-05 16:19:09 -0400327 "#define %s_DEFINED\n",
328 fFullName.c_str(),
329 fFullName.c_str());
Greg Daniel3e8c3452018-04-06 10:37:55 -0400330 this->writef("#include \"SkTypes.h\"\n");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400331 this->writeSection(HEADER_SECTION);
Ethan Nicholas9fb036f2017-07-05 16:19:09 -0400332 this->writef("#include \"GrFragmentProcessor.h\"\n"
Brian Osman1cb41712017-10-19 12:54:52 -0400333 "#include \"GrCoordTransform.h\"\n");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400334 this->writef("class %s : public GrFragmentProcessor {\n"
335 "public:\n",
336 fFullName.c_str());
Ethan Nicholas3c6ae622018-04-24 13:06:09 -0400337 for (const auto& p : fProgram) {
338 if (ProgramElement::kEnum_Kind == p.fKind && !((Enum&) p).fBuiltin) {
339 this->writef("%s\n", p.description().c_str());
Ethan Nicholasaae47c82017-11-10 15:34:03 -0500340 }
341 }
Ethan Nicholase9d172a2017-11-20 12:12:24 -0500342 this->writeSection(CLASS_SECTION);
Ethan Nicholas68990be2017-07-13 09:36:52 -0400343 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400344 if (param->fType.kind() == Type::kSampler_Kind ||
345 param->fType.kind() == Type::kOther_Kind) {
Ethan Nicholas762466e2017-06-29 10:03:38 -0400346 continue;
347 }
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700348 String nameString(param->fName);
349 const char* name = nameString.c_str();
Ethan Nicholas9fb036f2017-07-05 16:19:09 -0400350 this->writef(" %s %s() const { return %s; }\n",
Michael Ludwiga4275592018-08-31 10:52:47 -0400351 AccessType(fContext, param->fType, param->fModifiers.fLayout).c_str(), name,
Ethan Nicholasd608c092017-10-26 09:30:08 -0400352 FieldName(name).c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400353 }
354 this->writeMake();
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400355 this->writef(" %s(const %s& src);\n"
Brian Salomonaff329b2017-08-11 09:40:37 -0400356 " std::unique_ptr<GrFragmentProcessor> clone() const override;\n"
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400357 " const char* name() const override { return \"%s\"; }\n"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400358 "private:\n",
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400359 fFullName.c_str(), fFullName.c_str(), fName.c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400360 this->writeConstructor();
361 this->writef(" GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;\n"
362 " void onGetGLSLProcessorKey(const GrShaderCaps&,"
363 "GrProcessorKeyBuilder*) const override;\n"
Brian Salomonf7dcd762018-07-30 14:48:15 -0400364 " bool onIsEqual(const GrFragmentProcessor&) const override;\n");
365 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
366 if (param->fType.kind() == Type::kSampler_Kind) {
367 this->writef(" const TextureSampler& onTextureSampler(int) const override;");
368 break;
369 }
370 }
371 this->writef(" GR_DECLARE_FRAGMENT_PROCESSOR_TEST\n");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400372 this->writeFields();
373 this->writef(" typedef GrFragmentProcessor INHERITED;\n"
Ethan Nicholas9fb036f2017-07-05 16:19:09 -0400374 "};\n");
375 this->writeSection(HEADER_END_SECTION);
Greg Daniel3e8c3452018-04-06 10:37:55 -0400376 this->writef("#endif\n");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400377 return 0 == fErrors.errorCount();
378}
379
380} // namespace