blob: 060c29c0ceae36ff78de2694fdb4ba71cd388364 [file] [log] [blame]
John Stilesdb62d082020-09-23 14:08:40 -04001/*
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
Brian Osmand7e76592020-11-02 12:26:22 -050012static void test(skiatest::Reporter* r,
13 const GrShaderCaps& caps,
14 const char* src,
John Stilesdbd4e6f2021-02-16 13:29:15 -050015 SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment) {
Brian Osmand7e76592020-11-02 12:26:22 -050016 SkSL::Compiler compiler(&caps);
17 SkSL::Program::Settings settings;
John Stilesdb62d082020-09-23 14:08:40 -040018 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 {
John Stilesdb62d082020-09-23 14:08:40 -040025 REPORTER_ASSERT(r, compiler.toGLSL(*program, &output));
26 REPORTER_ASSERT(r, output != "");
John Stiles978674a2020-09-23 15:24:51 -040027 //SkDebugf("GLSL output:\n\n%s", output.c_str());
John Stilesdb62d082020-09-23 14:08:40 -040028 }
29}
30
John Stilesdb62d082020-09-23 14:08:40 -040031DEF_TEST(SkSLGLSLTestbed, 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}