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 
10 #include "tests/Test.h"
11 
test(skiatest::Reporter * r,const GrShaderCaps & caps,const char * src,SkSL::ProgramKind kind=SkSL::ProgramKind::kFragment)12 static void test(skiatest::Reporter* r,
13                  const GrShaderCaps& caps,
14                  const char* src,
15                  SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment) {
16     SkSL::Compiler compiler(&caps);
17     SkSL::Program::Settings settings;
18     SkSL::String output;
19     std::unique_ptr<SkSL::Program> program = compiler.convertProgram(kind, SkSL::String(src),
20                                                                      settings);
21     if (!program) {
22         SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str());
23         REPORTER_ASSERT(r, program);
24     } else {
25         REPORTER_ASSERT(r, compiler.toMetal(*program, &output));
26         REPORTER_ASSERT(r, output != "");
27         //SkDebugf("Metal output:\n\n%s", output.c_str());
28     }
29 }
30 
DEF_TEST(SkSLMetalTestbed,r)31 DEF_TEST(SkSLMetalTestbed, r) {
32     // Add in your SkSL here.
33     test(r,
34          *SkSL::ShaderCapsFactory::Default(),
35          R"__SkSL__(
36              void main() {
37                  sk_FragColor = half4(0);
38              }
39          )__SkSL__");
40 }
41