1 /* 2 * Copyright 2021 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/gpu/ShaderErrorHandler.h" 9 10 #include "include/private/base/SkDebug.h" 11 #include "src/utils/SkShaderUtils.h" 12 13 #include <functional> 14 #include <string> 15 16 namespace skgpu { 17 DefaultShaderErrorHandler()18ShaderErrorHandler* DefaultShaderErrorHandler() { 19 class DefaultShaderErrorHandler : public ShaderErrorHandler { 20 public: 21 void compileError(const char* shader, const char* errors) override { 22 std::string message = SkShaderUtils::BuildShaderErrorMessage(shader, errors); 23 SkShaderUtils::VisitLineByLine(message, [](int, const char* lineText) { 24 SkDebugf("%s\n", lineText); 25 }); 26 SkDEBUGFAILF("Shader compilation failed!\n\n%s", message.c_str()); 27 } 28 }; 29 30 static DefaultShaderErrorHandler gHandler; 31 return &gHandler; 32 } 33 34 } // namespace SkShaderUtils 35