blob: ba4a0a023ba1613f578184acad0c44635e4bfb9e [file] [log] [blame]
Kevin Lubicke9c1ce82019-03-11 11:09:40 -04001/*
2 * Copyright 2019 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 "GrShaderCaps.h"
9#include "SkSLCompiler.h"
10
11#include "../Fuzz.h"
12
13bool FuzzSKSL2GLSL(sk_sp<SkData> bytes) {
14 SkSL::Compiler compiler;
15 SkSL::String output;
16 SkSL::Program::Settings settings;
17 sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
18 settings.fCaps = caps.get();
19 std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
20 SkSL::Program::kFragment_Kind,
21 SkSL::String((const char*) bytes->data()),
22 settings);
23 if (!program || !compiler.toGLSL(*program, &output)) {
24 return false;
25 }
26 return true;
27}
28
29#if defined(IS_FUZZING_WITH_LIBFUZZER)
30extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
31 auto bytes = SkData::MakeWithoutCopy(data, size);
32 FuzzSKSL2GLSL(bytes);
33 return 0;
34}
35#endif