xref: /aosp_15_r20/external/skia/src/utils/SkShaderUtils.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 #ifndef SkShaderUtils_DEFINED
9 #define SkShaderUtils_DEFINED
10 
11 #include "include/private/base/SkDebug.h"
12 
13 #include <cstdint>
14 #include <functional>
15 #include <string>
16 
17 namespace SkSL { enum class ProgramKind : int8_t; }
18 
19 namespace SkShaderUtils {
20 
21 std::string PrettyPrint(const std::string& string);
22 
23 void VisitLineByLine(const std::string& text,
24                      const std::function<void(int lineNumber, const char* lineText)>&);
25 
26 // Prints shaders one line at the time. This ensures they don't get truncated by the adb log.
PrintLineByLine(const std::string & text)27 inline void PrintLineByLine(const std::string& text) {
28     VisitLineByLine(text, [](int lineNumber, const char* lineText) {
29         SkDebugf("%4i\t%s\n", lineNumber, lineText);
30     });
31 }
32 
33 // Combines raw shader and error text into an easier-to-read error message with line numbers.
34 std::string BuildShaderErrorMessage(const char* shader, const char* errors);
35 
36 void PrintShaderBanner(SkSL::ProgramKind programKind);
37 
38 }  // namespace SkShaderUtils
39 
40 #endif
41