• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/core/SkTypes.h"
9 #include "include/private/SkSLProgramKind.h"
10 #include "src/sksl/SkSLCompiler.h"
11 #include "src/sksl/SkSLProgramSettings.h"
12 #include "src/sksl/SkSLUtil.h"
13 #include "src/sksl/ir/SkSLProgram.h"
14 #include "tests/Test.h"
15 
16 #include <memory>
17 #include <string>
18 
test(skiatest::Reporter * r,const char * src,SkSL::ProgramKind kind=SkSL::ProgramKind::kFragment)19 static void test(skiatest::Reporter* r,
20                  const char* src,
21                  SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment) {
22     SkSL::Compiler compiler(SkSL::ShaderCapsFactory::Default());
23     SkSL::ProgramSettings settings;
24     std::unique_ptr<SkSL::Program> program = compiler.convertProgram(kind, std::string(src),
25                                                                      settings);
26     if (!program) {
27         SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str());
28         REPORTER_ASSERT(r, program);
29     } else {
30         std::string output;
31         REPORTER_ASSERT(r, compiler.toMetal(*program, &output));
32         REPORTER_ASSERT(r, output != "");
33         //SkDebugf("Metal output:\n\n%s", output.c_str());
34     }
35 }
36 
DEF_TEST(SkSLMetalTestbed,r)37 DEF_TEST(SkSLMetalTestbed, r) {
38     // Add in your SkSL here.
39     test(r,
40          R"__SkSL__(
41              void main() {
42                  sk_FragColor = half4(0);
43              }
44          )__SkSL__");
45 }
46