1 /*
2 * Copyright 2020 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 #include "src/sksl/SkSLCompiler.h"
9 #include "src/sksl/SkSLStringStream.h"
10
11 #include "tests/Test.h"
12
test(skiatest::Reporter * r,const GrShaderCaps & caps,const char * src)13 static void test(skiatest::Reporter* r, const GrShaderCaps& caps, const char* src) {
14 SkSL::Program::Settings settings;
15 settings.fRemoveDeadFunctions = false;
16 SkSL::Compiler compiler(&caps);
17 SkSL::StringStream output;
18 std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
19 SkSL::ProgramKind::kFragmentProcessor,
20 SkSL::String(src),
21 settings);
22 if (!program) {
23 SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str());
24 return;
25 }
26 REPORTER_ASSERT(r, program);
27 bool success = compiler.toH(*program, "Test", output);
28 if (!success) {
29 SkDebugf("Unexpected error generating .h file for %s\n%s",
30 src, compiler.errorText().c_str());
31 }
32 REPORTER_ASSERT(r, success);
33 output.reset();
34 success = compiler.toCPP(*program, "Test", output);
35 if (!success) {
36 SkDebugf("Unexpected error generating .cpp file for %s\n%s",
37 src, compiler.errorText().c_str());
38 }
39 REPORTER_ASSERT(r, success);
40 }
41
DEF_TEST(SkSLFPTestbed,r)42 DEF_TEST(SkSLFPTestbed, r) {
43 test(r,
44 *SkSL::ShaderCapsFactory::Default(),
45 R"__SkSL__(
46 half4 main(float2 coord) {
47 return half4(0);
48 }
49 )__SkSL__");
50 }
51