• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "src/gpu/GrShaderCaps.h"
9 #include "src/sksl/SkSLCompiler.h"
10 
11 #include "fuzz/Fuzz.h"
12 
FuzzSKSL2Metal(sk_sp<SkData> bytes)13 bool FuzzSKSL2Metal(sk_sp<SkData> bytes) {
14     std::unique_ptr<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
15     SkSL::Compiler compiler(caps.get());
16     SkSL::String output;
17     SkSL::Program::Settings settings;
18     std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
19                                                     SkSL::ProgramKind::kFragment,
20                                                     SkSL::String((const char*) bytes->data(),
21                                                                  bytes->size()),
22                                                     settings);
23     if (!program || !compiler.toMetal(*program, &output)) {
24         return false;
25     }
26     return true;
27 }
28 
29 #if defined(SK_BUILD_FOR_LIBFUZZER)
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)30 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
31     if (size > 3000) {
32         return 0;
33     }
34     auto bytes = SkData::MakeWithoutCopy(data, size);
35     FuzzSKSL2Metal(bytes);
36     return 0;
37 }
38 #endif
39