Debian Codegraph @

src/sksl/SkSLModuleDataDefault.cpp

raw
1 /*
2 * Copyright 2024 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/core/SkTypes.h"
9 #include "src/sksl/SkSLGraphiteModules.h"
10 #include "src/sksl/SkSLModule.h"
11
12 #include <string>
13
14 // We include minified SkSL module code and pass it directly to the compiler.
15 #if defined(SK_ENABLE_OPTIMIZE_SIZE) || !defined(SK_DEBUG)
16 #include "src/sksl/generated/sksl_compute.minified.sksl"
17 #include "src/sksl/generated/sksl_frag.minified.sksl"
18 #include "src/sksl/generated/sksl_gpu.minified.sksl"
19 #include "src/sksl/generated/sksl_public.minified.sksl"
20 #include "src/sksl/generated/sksl_rt_shader.minified.sksl"
21 #include "src/sksl/generated/sksl_shared.minified.sksl"
22 #include "src/sksl/generated/sksl_vert.minified.sksl"
23 #else
24 #include "src/sksl/generated/sksl_compute.unoptimized.sksl"
25 #include "src/sksl/generated/sksl_frag.unoptimized.sksl"
26 #include "src/sksl/generated/sksl_gpu.unoptimized.sksl"
27 #include "src/sksl/generated/sksl_public.unoptimized.sksl"
28 #include "src/sksl/generated/sksl_rt_shader.unoptimized.sksl"
29 #include "src/sksl/generated/sksl_shared.unoptimized.sksl"
30 #include "src/sksl/generated/sksl_vert.unoptimized.sksl"
31 #endif
32
33 // We don't load the graphite modules by default because we don't want to bloat the Ganesh-only
34 // build with Graphite's modules. These will be filled in during initialization of the
35 // Graphite backend.
36 static const char* sdata_sksl_graphite_frag = "";
37 static const char* sdata_sksl_graphite_vert = "";
38
39 namespace SkSL {
40
41 std::string GetModuleData(ModuleType type, const char* /*filename*/) {
42 #define M(name) case ModuleType::name: return std::string(SKSL_MINIFIED_##name);
43 // Creating a std::string with a nullptr is UB
44 #define G(name) \
45 case ModuleType::name: \
46 if (sdata_##name) { \
47 return std::string(sdata_##name); \
48 } else { \
49 return ""; \
50 }
51
52 switch (type) {
53 M(sksl_shared)
54 M(sksl_compute)
55 M(sksl_frag)
56 M(sksl_gpu)
57 M(sksl_public)
58 M(sksl_rt_shader)
59 M(sksl_vert)
60
61 G(sksl_graphite_frag)
62 G(sksl_graphite_vert)
63 default:
64 SkUNREACHABLE;
65 }
66 #undef M
67 }
68
69 namespace Loader {
70 void SetGraphiteModuleData(const GraphiteModules& modules) {
71 SkASSERTF(sdata_sksl_graphite_frag[0] == '\0', "We should only initialize this once");
72 sdata_sksl_graphite_frag = modules.fFragmentShader;
73 sdata_sksl_graphite_vert = modules.fVertexShader;
74
75 SkASSERT(sdata_sksl_graphite_frag[0] != '\0');
76 SkASSERT(sdata_sksl_graphite_vert[0] != '\0');
77 }
78 } // namespace Loader
79
80 } // namespace SkSL