Flutter Engine
The Flutter Engine
SkSLSetting.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
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
9
12#include "src/core/SkTHash.h"
17#include "src/sksl/SkSLUtil.h"
19
20#include <initializer_list>
21
22using namespace skia_private;
23
24namespace SkSL {
25namespace {
26
28
29static const CapsLookupTable& caps_lookup_table() {
30 // Create a lookup table that converts strings into the equivalent ShaderCaps member-pointers.
31 static SkNoDestructor<CapsLookupTable> sCapsLookupTable(CapsLookupTable{
32 CapsLookupTable::Pair("mustDoOpBetweenFloorAndAbs",
34 CapsLookupTable::Pair("mustGuardDivisionEvenAfterExplicitZeroCheck",
36 CapsLookupTable::Pair("atan2ImplementedAsAtanYOverX",
38 CapsLookupTable::Pair("floatIs32Bits",
40 CapsLookupTable::Pair("integerSupport",
42 CapsLookupTable::Pair("builtinDeterminantSupport",
44 CapsLookupTable::Pair("rewriteMatrixVectorMultiply",
46 CapsLookupTable::Pair("PerlinNoiseRoundingFix",
48 });
49 return *sCapsLookupTable;
50}
51
52} // namespace
53
54std::string_view Setting::name() const {
55 for (const auto& [name, capsPtr] : caps_lookup_table()) {
56 if (capsPtr == fCapsPtr) {
57 return name;
58 }
59 }
61}
62
63std::unique_ptr<Expression> Setting::Convert(const Context& context,
65 const std::string_view& name) {
66 SkASSERT(context.fConfig);
67
69 context.fErrors->error(pos, "name 'sk_Caps' is reserved");
70 return nullptr;
71 }
72
73 const CapsPtr* capsPtr = caps_lookup_table().find(name);
74 if (!capsPtr) {
75 context.fErrors->error(pos, "unknown capability flag '" + std::string(name) + "'");
76 return nullptr;
77 }
78
79 return Setting::Make(context, pos, *capsPtr);
80}
81
82std::unique_ptr<Expression> Setting::Make(const Context& context, Position pos, CapsPtr capsPtr) {
84
85 return std::make_unique<Setting>(pos, capsPtr, context.fTypes.fBool.get());
86}
87
88std::unique_ptr<Expression> Setting::toLiteral(const ShaderCaps& caps) const {
89 return Literal::MakeBool(fPosition, caps.*fCapsPtr, &this->type());
90}
91
92} // namespace SkSL
SkPoint pos
#define SkUNREACHABLE
Definition: SkAssert.h:135
#define SkASSERT(cond)
Definition: SkAssert.h:116
const std::unique_ptr< Type > fBool
const BuiltinTypes & fTypes
Definition: SkSLContext.h:30
ErrorReporter * fErrors
Definition: SkSLContext.h:36
ProgramConfig * fConfig
Definition: SkSLContext.h:33
void error(Position position, std::string_view msg)
Position fPosition
Definition: SkSLIRNode.h:109
static std::unique_ptr< Literal > MakeBool(const Context &context, Position pos, bool value)
Definition: SkSLLiteral.h:69
std::unique_ptr< Expression > toLiteral(const ShaderCaps &caps) const
Definition: SkSLSetting.cpp:88
CapsPtr capsPtr() const
Definition: SkSLSetting.h:63
static std::unique_ptr< Expression > Convert(const Context &context, Position pos, const std::string_view &name)
Definition: SkSLSetting.cpp:63
const bool ShaderCaps::* CapsPtr
Definition: SkSLSetting.h:37
static std::unique_ptr< Expression > Make(const Context &context, Position pos, CapsPtr capsPtr)
Definition: SkSLSetting.cpp:82
std::string_view name() const
Definition: SkSLSetting.cpp:54
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
static bool AllowsPrivateIdentifiers(ProgramKind kind)
bool fMustGuardDivisionEvenAfterExplicitZeroCheck
Definition: SkSLUtil.h:123
bool fPerlinNoiseRoundingFix
Definition: SkSLUtil.h:147
bool fIntegerSupport
Definition: SkSLUtil.h:89
bool fRewriteMatrixVectorMultiply
Definition: SkSLUtil.h:140
bool fBuiltinDeterminantSupport
Definition: SkSLUtil.h:107
bool fMustDoOpBetweenFloorAndAbs
Definition: SkSLUtil.h:120
bool fFloatIs32Bits
Definition: SkSLUtil.h:100
bool fAtan2ImplementedAsAtanYOverX
Definition: SkSLUtil.h:116