/src/skia/src/sksl/SkSLIntrinsicList.cpp
Line | Count | Source |
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 "src/base/SkNoDestructor.h" |
9 | | #include "src/base/SkStringView.h" |
10 | | #include "src/sksl/SkSLIntrinsicList.h" |
11 | | |
12 | | using namespace skia_private; |
13 | | |
14 | | namespace SkSL { |
15 | | |
16 | 35.7k | const IntrinsicMap& GetIntrinsicMap() { |
17 | 3.64M | #define SKSL_INTRINSIC(name) {#name, k_##name##_IntrinsicKind}, |
18 | 35.7k | static const SkNoDestructor<IntrinsicMap> kAllIntrinsics(IntrinsicMap{ |
19 | 35.7k | SKSL_INTRINSIC_LIST |
20 | 35.7k | }); |
21 | 35.7k | #undef SKSL_INTRINSIC |
22 | | |
23 | 35.7k | return *kAllIntrinsics; |
24 | 35.7k | } |
25 | | |
26 | 35.7k | IntrinsicKind FindIntrinsicKind(std::string_view functionName) { |
27 | 35.7k | if (skstd::starts_with(functionName, '$')) { |
28 | 136 | functionName.remove_prefix(1); |
29 | 136 | } |
30 | | |
31 | 35.7k | const IntrinsicMap& intrinsicMap = GetIntrinsicMap(); |
32 | 35.7k | IntrinsicKind* kind = intrinsicMap.find(functionName); |
33 | 35.7k | return kind ? *kind : kNotIntrinsic; |
34 | 35.7k | } |
35 | | |
36 | | } // namespace SkSL |