summaryrefslogtreecommitdiffstats
path: root/gfx/skia/skia/src/sksl/SkSLIntrinsicList.cpp
blob: a582bdff60eeb3050d9208640d563f259cc71616 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 * Copyright 2021 Google LLC.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "src/base/SkStringView.h"
#include "src/sksl/SkSLIntrinsicList.h"

namespace SkSL {

const IntrinsicMap& GetIntrinsicMap() {
    #define SKSL_INTRINSIC(name) {#name, k_##name##_IntrinsicKind},
    static const auto* kAllIntrinsics = new SkTHashMap<std::string_view, IntrinsicKind>{
        SKSL_INTRINSIC_LIST
    };
    #undef SKSL_INTRINSIC

    return *kAllIntrinsics;
}

IntrinsicKind FindIntrinsicKind(std::string_view functionName) {
    if (skstd::starts_with(functionName, '$')) {
        functionName.remove_prefix(1);
    }

    const IntrinsicMap& intrinsicMap = GetIntrinsicMap();
    IntrinsicKind* kind = intrinsicMap.find(functionName);
    return kind ? *kind : kNotIntrinsic;
}

}  // namespace SkSL