OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkSLCompiler.h" | 8 #include "SkSLCompiler.h" |
9 | 9 |
10 #include <fstream> | 10 #include <fstream> |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 void Compiler::writeErrorCount() { | 216 void Compiler::writeErrorCount() { |
217 if (fErrorCount) { | 217 if (fErrorCount) { |
218 fErrorText += to_string(fErrorCount) + " error"; | 218 fErrorText += to_string(fErrorCount) + " error"; |
219 if (fErrorCount > 1) { | 219 if (fErrorCount > 1) { |
220 fErrorText += "s"; | 220 fErrorText += "s"; |
221 } | 221 } |
222 fErrorText += "\n"; | 222 fErrorText += "\n"; |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
226 #include <fstream> | 226 bool Compiler::toSPIRV(Program::Kind kind, const std::string& text, std::ostream
& out) { |
227 bool Compiler::toSPIRV(Program::Kind kind, std::string text, std::ostream& out)
{ | |
228 auto program = this->convertProgram(kind, text); | 227 auto program = this->convertProgram(kind, text); |
229 if (fErrorCount == 0) { | 228 if (fErrorCount == 0) { |
230 SkSL::SPIRVCodeGenerator cg(&fContext); | 229 SkSL::SPIRVCodeGenerator cg(&fContext); |
231 cg.generateCode(*program.get(), out); | 230 cg.generateCode(*program.get(), out); |
232 ASSERT(!out.rdstate()); | 231 ASSERT(!out.rdstate()); |
233 } | 232 } |
234 return fErrorCount == 0; | 233 return fErrorCount == 0; |
235 } | 234 } |
236 | 235 |
237 bool Compiler::toSPIRV(Program::Kind kind, std::string text, std::string* out) { | 236 bool Compiler::toSPIRV(Program::Kind kind, const std::string& text, std::string*
out) { |
238 std::stringstream buffer; | 237 std::stringstream buffer; |
239 bool result = this->toSPIRV(kind, text, buffer); | 238 bool result = this->toSPIRV(kind, text, buffer); |
240 if (result) { | 239 if (result) { |
241 *out = buffer.str(); | 240 *out = buffer.str(); |
242 } | 241 } |
| 242 return result; |
| 243 } |
| 244 |
| 245 bool Compiler::toGLSL(Program::Kind kind, const std::string& text, GLCaps caps, |
| 246 std::ostream& out) { |
| 247 auto program = this->convertProgram(kind, text); |
| 248 if (fErrorCount == 0) { |
| 249 SkSL::GLSLCodeGenerator cg(&fContext, caps); |
| 250 cg.generateCode(*program.get(), out); |
| 251 ASSERT(!out.rdstate()); |
| 252 } |
243 return fErrorCount == 0; | 253 return fErrorCount == 0; |
244 } | 254 } |
245 | 255 |
| 256 bool Compiler::toGLSL(Program::Kind kind, const std::string& text, GLCaps caps, |
| 257 std::string* out) { |
| 258 std::stringstream buffer; |
| 259 bool result = this->toGLSL(kind, text, caps, buffer); |
| 260 if (result) { |
| 261 *out = buffer.str(); |
| 262 } |
| 263 return result; |
| 264 } |
| 265 |
246 } // namespace | 266 } // namespace |
OLD | NEW |