FuzzSKSL2GLSL.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. #include "src/gpu/GrShaderCaps.h"
  8. #include "src/sksl/SkSLCompiler.h"
  9. #include "fuzz/Fuzz.h"
  10. bool FuzzSKSL2GLSL(sk_sp<SkData> bytes) {
  11. SkSL::Compiler compiler;
  12. SkSL::String output;
  13. SkSL::Program::Settings settings;
  14. sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
  15. settings.fCaps = caps.get();
  16. std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
  17. SkSL::Program::kFragment_Kind,
  18. SkSL::String((const char*) bytes->data(),
  19. bytes->size()),
  20. settings);
  21. if (!program || !compiler.toGLSL(*program, &output)) {
  22. return false;
  23. }
  24. return true;
  25. }
  26. #if defined(IS_FUZZING_WITH_LIBFUZZER)
  27. extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  28. auto bytes = SkData::MakeWithoutCopy(data, size);
  29. FuzzSKSL2GLSL(bytes);
  30. return 0;
  31. }
  32. #endif