blob: 8c6b8f4f01d720d746e4c7b9b7cf96033ac4712c [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 }
113}
114
115void HCodeGenerator::writef(const char* s, ...) {
116 va_list va;
117 va_start(va, s);
118 this->writef(s, va);
119 va_end(va);
120}
121
122bool HCodeGenerator::writeSection(const char* name, const char* prefix) {
Ethan Nicholas68990be2017-07-13 09:36:52 -0400123 const Section* s = fSectionAndParameterHelper.getSection(name);
124 if (s) {
125 this->writef("%s%s", prefix, s->fText.c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400126 return true;
127 }
128 return false;
129}
130
131void HCodeGenerator::writeExtraConstructorParams(const char* separator) {
132 // super-simple parse, just assume the last token before a comma is the name of a parameter
133 // (which is true as long as there are no multi-parameter template types involved). Will replace
134 // this with something more robust if the need arises.
Ethan Nicholas68990be2017-07-13 09:36:52 -0400135 const Section* section = fSectionAndParameterHelper.getSection(CONSTRUCTOR_PARAMS_SECTION);
136 if (section) {
137 const char* s = section->fText.c_str();
Ethan Nicholas762466e2017-06-29 10:03:38 -0400138 #define BUFFER_SIZE 64
139 char lastIdentifier[BUFFER_SIZE];
140 int lastIdentifierLength = 0;
141 bool foundBreak = false;
142 while (*s) {
143 char c = *s;
144 ++s;
145 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
146 c == '_') {
147 if (foundBreak) {
148 lastIdentifierLength = 0;
149 foundBreak = false;
150 }
Ethan Nicholasd9d33c32018-06-12 11:05:59 -0400151 SkASSERT(lastIdentifierLength < BUFFER_SIZE);
Ethan Nicholas762466e2017-06-29 10:03:38 -0400152 lastIdentifier[lastIdentifierLength] = c;
153 ++lastIdentifierLength;
154 } else {
155 foundBreak = true;
156 if (c == ',') {
Ethan Nicholasd9d33c32018-06-12 11:05:59 -0400157 SkASSERT(lastIdentifierLength < BUFFER_SIZE);
Ethan Nicholas762466e2017-06-29 10:03:38 -0400158 lastIdentifier[lastIdentifierLength] = 0;
159 this->writef("%s%s", separator, lastIdentifier);
160 separator = ", ";
161 } else if (c != ' ' && c != '\t' && c != '\n' && c != '\r') {
162 lastIdentifierLength = 0;
163 }
164 }
165 }
166 if (lastIdentifierLength) {
Ethan Nicholasd9d33c32018-06-12 11:05:59 -0400167 SkASSERT(lastIdentifierLength < BUFFER_SIZE);
Ethan Nicholas762466e2017-06-29 10:03:38 -0400168 lastIdentifier[lastIdentifierLength] = 0;
169 this->writef("%s%s", separator, lastIdentifier);
170 }
171 }
172}
173
174void HCodeGenerator::writeMake() {
175 const char* separator;
176 if (!this->writeSection(MAKE_SECTION)) {
Brian Salomonaff329b2017-08-11 09:40:37 -0400177 this->writef(" static std::unique_ptr<GrFragmentProcessor> Make(");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400178 separator = "";
Ethan Nicholas68990be2017-07-13 09:36:52 -0400179 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholasd608c092017-10-26 09:30:08 -0400180 this->writef("%s%s %s", separator, ParameterType(fContext, param->fType,
181 param->fModifiers.fLayout).c_str(),
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700182 String(param->fName).c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400183 separator = ", ";
184 }
185 this->writeSection(CONSTRUCTOR_PARAMS_SECTION, separator);
186 this->writef(") {\n"
Brian Salomonaff329b2017-08-11 09:40:37 -0400187 " return std::unique_ptr<GrFragmentProcessor>(new %s(",
Ethan Nicholas762466e2017-06-29 10:03:38 -0400188 fFullName.c_str());
189 separator = "";
Ethan Nicholas68990be2017-07-13 09:36:52 -0400190 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400191 if (param->fType == *fContext.fFragmentProcessor_Type) {
Robert Phillips7a59f232017-11-08 15:31:30 -0500192 this->writef("%sstd::move(%s)", separator, String(param->fName).c_str());
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400193 } else {
194 this->writef("%s%s", separator, String(param->fName).c_str());
195 }
Ethan Nicholas762466e2017-06-29 10:03:38 -0400196 separator = ", ";
197 }
198 this->writeExtraConstructorParams(separator);
199 this->writef("));\n"
200 " }\n");
201 }
202}
203
Ethan Nicholas68990be2017-07-13 09:36:52 -0400204void HCodeGenerator::failOnSection(const char* section, const char* msg) {
205 std::vector<const Section*> s = fSectionAndParameterHelper.getSections(section);
206 if (s.size()) {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700207 fErrors.error(s[0]->fOffset, String("@") + section + " " + msg);
Ethan Nicholas68990be2017-07-13 09:36:52 -0400208 }
209}
210
Ethan Nicholas762466e2017-06-29 10:03:38 -0400211void HCodeGenerator::writeConstructor() {
212 if (this->writeSection(CONSTRUCTOR_SECTION)) {
Ethan Nicholas68990be2017-07-13 09:36:52 -0400213 const char* msg = "may not be present when constructor is overridden";
214 this->failOnSection(CONSTRUCTOR_CODE_SECTION, msg);
215 this->failOnSection(CONSTRUCTOR_PARAMS_SECTION, msg);
Ethan Nicholas68990be2017-07-13 09:36:52 -0400216 this->failOnSection(INITIALIZERS_SECTION, msg);
217 this->failOnSection(OPTIMIZATION_FLAGS_SECTION, msg);
Robert Phillips1e8501e2018-03-23 15:00:20 -0400218 return;
Ethan Nicholas762466e2017-06-29 10:03:38 -0400219 }
220 this->writef(" %s(", fFullName.c_str());
221 const char* separator = "";
Ethan Nicholas68990be2017-07-13 09:36:52 -0400222 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholasd608c092017-10-26 09:30:08 -0400223 this->writef("%s%s %s", separator, ParameterType(fContext, param->fType,
224 param->fModifiers.fLayout).c_str(),
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700225 String(param->fName).c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400226 separator = ", ";
227 }
228 this->writeSection(CONSTRUCTOR_PARAMS_SECTION, separator);
229 this->writef(")\n"
Ethan Nicholasabff9562017-10-09 10:54:08 -0400230 " : INHERITED(k%s_ClassID", fFullName.c_str());
231 if (!this->writeSection(OPTIMIZATION_FLAGS_SECTION, ", (OptimizationFlags) ")) {
232 this->writef(", kNone_OptimizationFlags");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400233 }
234 this->writef(")");
235 this->writeSection(INITIALIZERS_SECTION, "\n , ");
Ethan Nicholas68990be2017-07-13 09:36:52 -0400236 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700237 String nameString(param->fName);
238 const char* name = nameString.c_str();
Ethan Nicholas762466e2017-06-29 10:03:38 -0400239 if (param->fType.kind() == Type::kSampler_Kind) {
Ethan Nicholas68990be2017-07-13 09:36:52 -0400240 this->writef("\n , %s(std::move(%s)", FieldName(name).c_str(), name);
241 for (const Section* s : fSectionAndParameterHelper.getSections(
242 SAMPLER_PARAMS_SECTION)) {
243 if (s->fArgument == name) {
244 this->writef(", %s", s->fText.c_str());
245 }
246 }
247 this->writef(")");
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400248 } else if (param->fType == *fContext.fFragmentProcessor_Type) {
249 // do nothing
Ethan Nicholas762466e2017-06-29 10:03:38 -0400250 } else {
251 this->writef("\n , %s(%s)", FieldName(name).c_str(), name);
252 }
253 }
Ethan Nicholas929a6812018-08-06 14:56:59 -0400254 const auto transforms = fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION);
255 for (size_t i = 0; i < transforms.size(); ++i) {
256 const Section& s = *transforms[i];
257 String field = CoordTransformName(s.fArgument.c_str(), i);
258 if (s.fArgument.size()) {
259 this->writef("\n , %s(%s, %s.proxy())", field.c_str(), s.fText.c_str(),
260 FieldName(s.fArgument.c_str()).c_str());
261 }
262 else {
263 this->writef("\n , %s(%s)", field.c_str(), s.fText.c_str());
264 }
Ethan Nicholas68990be2017-07-13 09:36:52 -0400265 }
Ethan Nicholas762466e2017-06-29 10:03:38 -0400266 this->writef(" {\n");
267 this->writeSection(CONSTRUCTOR_CODE_SECTION);
Brian Salomonf7dcd762018-07-30 14:48:15 -0400268 int samplerCount = 0;
Ethan Nicholas68990be2017-07-13 09:36:52 -0400269 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholas762466e2017-06-29 10:03:38 -0400270 if (param->fType.kind() == Type::kSampler_Kind) {
Brian Salomonf7dcd762018-07-30 14:48:15 -0400271 ++samplerCount;
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400272 } else if (param->fType == *fContext.fFragmentProcessor_Type) {
273 this->writef(" this->registerChildProcessor(std::move(%s));",
274 String(param->fName).c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400275 }
276 }
Brian Salomonf7dcd762018-07-30 14:48:15 -0400277 if (samplerCount) {
278 this->writef(" this->setTextureSamplerCnt(%d);", samplerCount);
279 }
Ethan Nicholas929a6812018-08-06 14:56:59 -0400280 for (size_t i = 0; i < transforms.size(); ++i) {
281 const Section& s = *transforms[i];
282 String field = CoordTransformName(s.fArgument.c_str(), i);
283 this->writef(" this->addCoordTransform(&%s);\n", field.c_str());
Ethan Nicholas68990be2017-07-13 09:36:52 -0400284 }
Ethan Nicholasabff9562017-10-09 10:54:08 -0400285 this->writef(" }\n");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400286}
287
288void HCodeGenerator::writeFields() {
289 this->writeSection(FIELDS_SECTION);
Ethan Nicholas68990be2017-07-13 09:36:52 -0400290 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400291 if (param->fType == *fContext.fFragmentProcessor_Type) {
292 continue;
293 }
Ethan Nicholasd608c092017-10-26 09:30:08 -0400294 this->writef(" %s %s;\n", FieldType(fContext, param->fType,
295 param->fModifiers.fLayout).c_str(),
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700296 FieldName(String(param->fName).c_str()).c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400297 }
Ethan Nicholas929a6812018-08-06 14:56:59 -0400298 const auto transforms = fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION);
299 for (size_t i = 0; i < transforms.size(); ++i) {
300 const Section& s = *transforms[i];
301 this->writef(" GrCoordTransform %s;\n",
302 CoordTransformName(s.fArgument.c_str(), i).c_str());
Ethan Nicholas68990be2017-07-13 09:36:52 -0400303 }
Ethan Nicholas762466e2017-06-29 10:03:38 -0400304}
305
Ethan Nicholas130fb3f2018-02-01 12:14:34 -0500306String HCodeGenerator::GetHeader(const Program& program, ErrorReporter& errors) {
307 SymbolTable types(&errors);
308 Parser parser(program.fSource->c_str(), program.fSource->length(), types, errors);
309 for (;;) {
310 Token header = parser.nextRawToken();
311 switch (header.fKind) {
312 case Token::WHITESPACE:
313 break;
314 case Token::BLOCK_COMMENT:
315 return String(program.fSource->c_str() + header.fOffset, header.fLength);
316 default:
317 return "";
318 }
319 }
320}
321
Ethan Nicholas762466e2017-06-29 10:03:38 -0400322bool HCodeGenerator::generateCode() {
Ethan Nicholas130fb3f2018-02-01 12:14:34 -0500323 this->writef("%s\n", GetHeader(fProgram, fErrors).c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400324 this->writef(kFragmentProcessorHeader, fFullName.c_str());
325 this->writef("#ifndef %s_DEFINED\n"
Ethan Nicholas9fb036f2017-07-05 16:19:09 -0400326 "#define %s_DEFINED\n",
327 fFullName.c_str(),
328 fFullName.c_str());
Greg Daniel3e8c3452018-04-06 10:37:55 -0400329 this->writef("#include \"SkTypes.h\"\n");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400330 this->writeSection(HEADER_SECTION);
Ethan Nicholas9fb036f2017-07-05 16:19:09 -0400331 this->writef("#include \"GrFragmentProcessor.h\"\n"
Brian Osman1cb41712017-10-19 12:54:52 -0400332 "#include \"GrCoordTransform.h\"\n");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400333 this->writef("class %s : public GrFragmentProcessor {\n"
334 "public:\n",
335 fFullName.c_str());
Ethan Nicholas3c6ae622018-04-24 13:06:09 -0400336 for (const auto& p : fProgram) {
337 if (ProgramElement::kEnum_Kind == p.fKind && !((Enum&) p).fBuiltin) {
338 this->writef("%s\n", p.description().c_str());
Ethan Nicholasaae47c82017-11-10 15:34:03 -0500339 }
340 }
Ethan Nicholase9d172a2017-11-20 12:12:24 -0500341 this->writeSection(CLASS_SECTION);
Ethan Nicholas68990be2017-07-13 09:36:52 -0400342 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
Ethan Nicholasc9472af2017-10-10 16:30:21 -0400343 if (param->fType.kind() == Type::kSampler_Kind ||
344 param->fType.kind() == Type::kOther_Kind) {
Ethan Nicholas762466e2017-06-29 10:03:38 -0400345 continue;
346 }
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700347 String nameString(param->fName);
348 const char* name = nameString.c_str();
Ethan Nicholas9fb036f2017-07-05 16:19:09 -0400349 this->writef(" %s %s() const { return %s; }\n",
Michael Ludwiga4275592018-08-31 10:52:47 -0400350 AccessType(fContext, param->fType, param->fModifiers.fLayout).c_str(), name,
Ethan Nicholasd608c092017-10-26 09:30:08 -0400351 FieldName(name).c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400352 }
353 this->writeMake();
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400354 this->writef(" %s(const %s& src);\n"
Brian Salomonaff329b2017-08-11 09:40:37 -0400355 " std::unique_ptr<GrFragmentProcessor> clone() const override;\n"
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400356 " const char* name() const override { return \"%s\"; }\n"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400357 "private:\n",
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400358 fFullName.c_str(), fFullName.c_str(), fName.c_str());
Ethan Nicholas762466e2017-06-29 10:03:38 -0400359 this->writeConstructor();
360 this->writef(" GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;\n"
361 " void onGetGLSLProcessorKey(const GrShaderCaps&,"
362 "GrProcessorKeyBuilder*) const override;\n"
Brian Salomonf7dcd762018-07-30 14:48:15 -0400363 " bool onIsEqual(const GrFragmentProcessor&) const override;\n");
364 for (const auto& param : fSectionAndParameterHelper.getParameters()) {
365 if (param->fType.kind() == Type::kSampler_Kind) {
366 this->writef(" const TextureSampler& onTextureSampler(int) const override;");
367 break;
368 }
369 }
370 this->writef(" GR_DECLARE_FRAGMENT_PROCESSOR_TEST\n");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400371 this->writeFields();
372 this->writef(" typedef GrFragmentProcessor INHERITED;\n"
Ethan Nicholas9fb036f2017-07-05 16:19:09 -0400373 "};\n");
374 this->writeSection(HEADER_END_SECTION);
Greg Daniel3e8c3452018-04-06 10:37:55 -0400375 this->writef("#endif\n");
Ethan Nicholas762466e2017-06-29 10:03:38 -0400376 return 0 == fErrors.errorCount();
377}
378
379} // namespace