diff options
Diffstat (limited to '')
-rw-r--r-- | src/deps/skia/include/sksl/BUILD.bazel | 176 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSL.h | 34 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLBlock.h | 67 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLCase.h | 68 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLCore.h | 488 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLExpression.h | 299 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLFunction.h | 116 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLLayout.h | 94 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLModifiers.h | 64 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLRuntimeEffects.h | 32 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLStatement.h | 111 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLSymbols.h | 71 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLType.h | 259 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLVar.h | 310 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/DSLWrapper.h | 77 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/SkSLDebugTrace.h | 28 | ||||
-rw-r--r-- | src/deps/skia/include/sksl/SkSLErrorReporter.h | 115 |
17 files changed, 2409 insertions, 0 deletions
diff --git a/src/deps/skia/include/sksl/BUILD.bazel b/src/deps/skia/include/sksl/BUILD.bazel new file mode 100644 index 000000000..2d20d6d55 --- /dev/null +++ b/src/deps/skia/include/sksl/BUILD.bazel @@ -0,0 +1,176 @@ +load("//bazel:macros.bzl", "generated_cc_atom") + +generated_cc_atom( + name = "DSLBlock_hdr", + hdrs = ["DSLBlock.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":DSLExpression_hdr", + ":DSLStatement_hdr", + "//include/private:SkSLDefines_hdr", + ], +) + +generated_cc_atom( + name = "DSLCase_hdr", + hdrs = ["DSLCase.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":DSLExpression_hdr", + ":DSLStatement_hdr", + "//include/private:SkSLDefines_hdr", + ], +) + +generated_cc_atom( + name = "DSLCore_hdr", + hdrs = ["DSLCore.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":DSLBlock_hdr", + ":DSLCase_hdr", + ":DSLExpression_hdr", + ":DSLFunction_hdr", + ":DSLStatement_hdr", + ":DSLType_hdr", + ":DSLVar_hdr", + ":DSLWrapper_hdr", + ":SkSLErrorReporter_hdr", + "//include/private:SkSLProgramKind_hdr", + "//include/private:SkTArray_hdr", + ], +) + +generated_cc_atom( + name = "DSLExpression_hdr", + hdrs = ["DSLExpression.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":DSLWrapper_hdr", + ":SkSLErrorReporter_hdr", + "//include/core:SkStringView_hdr", + "//include/core:SkTypes_hdr", + "//include/private:SkTArray_hdr", + ], +) + +generated_cc_atom( + name = "DSLFunction_hdr", + hdrs = ["DSLFunction.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":DSLBlock_hdr", + ":DSLExpression_hdr", + ":DSLType_hdr", + ":DSLVar_hdr", + ":DSLWrapper_hdr", + ], +) + +generated_cc_atom( + name = "DSLLayout_hdr", + hdrs = ["DSLLayout.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":SkSLErrorReporter_hdr", + "//include/private:SkSLLayout_hdr", + ], +) + +generated_cc_atom( + name = "DSLModifiers_hdr", + hdrs = ["DSLModifiers.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":DSLLayout_hdr", + "//include/core:SkSpan_hdr", + "//include/private:SkSLModifiers_hdr", + ], +) + +generated_cc_atom( + name = "DSLRuntimeEffects_hdr", + hdrs = ["DSLRuntimeEffects.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":DSL_hdr", + "//include/effects:SkRuntimeEffect_hdr", + ], +) + +generated_cc_atom( + name = "DSLStatement_hdr", + hdrs = ["DSLStatement.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":SkSLErrorReporter_hdr", + "//include/core:SkString_hdr", + "//include/core:SkTypes_hdr", + "//include/private:SkSLStatement_hdr", + ], +) + +generated_cc_atom( + name = "DSLSymbols_hdr", + hdrs = ["DSLSymbols.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":DSLExpression_hdr", + "//include/core:SkStringView_hdr", + "//include/private:SkSLString_hdr", + ], +) + +generated_cc_atom( + name = "DSLType_hdr", + hdrs = ["DSLType.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":DSLExpression_hdr", + ":DSLModifiers_hdr", + "//include/core:SkSpan_hdr", + "//include/private:SkSLString_hdr", + ], +) + +generated_cc_atom( + name = "DSLVar_hdr", + hdrs = ["DSLVar.h"], + visibility = ["//:__subpackages__"], + deps = [ + ":DSLExpression_hdr", + ":DSLModifiers_hdr", + ":DSLType_hdr", + ], +) + +generated_cc_atom( + name = "DSLWrapper_hdr", + hdrs = ["DSLWrapper.h"], + visibility = ["//:__subpackages__"], +) + +generated_cc_atom( + name = "DSL_hdr", + hdrs = ["DSL.h"], + visibility = ["//:__subpackages__"], + deps = [":DSLCore_hdr"], +) + +generated_cc_atom( + name = "SkSLErrorReporter_hdr", + hdrs = ["SkSLErrorReporter.h"], + visibility = ["//:__subpackages__"], + deps = [ + "//include/core:SkStringView_hdr", + "//include/core:SkTypes_hdr", + "//include/private:SkSLString_hdr", + ], +) + +generated_cc_atom( + name = "SkSLDebugTrace_hdr", + hdrs = ["SkSLDebugTrace.h"], + visibility = ["//:__subpackages__"], + deps = ["//include/core:SkRefCnt_hdr"], +) diff --git a/src/deps/skia/include/sksl/DSL.h b/src/deps/skia/include/sksl/DSL.h new file mode 100644 index 000000000..a8c8f5285 --- /dev/null +++ b/src/deps/skia/include/sksl/DSL.h @@ -0,0 +1,34 @@ +/* + * Copyright 2020 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL +#define SKSL_DSL + +#include "include/sksl/DSLCore.h" + +namespace SkSL { + +namespace dsl { + +using Block = DSLBlock; +using Case = DSLCase; +using Expression = DSLExpression; +using Field = DSLField; +using Function = DSLFunction; +using GlobalVar = DSLGlobalVar; +using Layout = DSLLayout; +using Modifiers = DSLModifiers; +using Parameter = DSLParameter; +using Statement = DSLStatement; +using Var = DSLVar; +template<typename T> using Wrapper = DSLWrapper<T>; + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/DSLBlock.h b/src/deps/skia/include/sksl/DSLBlock.h new file mode 100644 index 000000000..3fcbb34c8 --- /dev/null +++ b/src/deps/skia/include/sksl/DSLBlock.h @@ -0,0 +1,67 @@ +/* + * Copyright 2021 Google LLC. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_BLOCK +#define SKSL_DSL_BLOCK + +#include "include/private/SkSLDefines.h" +#include "include/sksl/DSLExpression.h" +#include "include/sksl/DSLStatement.h" + +#include <memory> + +namespace SkSL { + +class Block; +class SymbolTable; + +namespace dsl { + +class DSLBlock { +public: + template<class... Statements> + DSLBlock(Statements... statements) { + fStatements.reserve_back(sizeof...(statements)); + // in C++17, we could just do: + // (fStatements.push_back(DSLStatement(statements.release()).release()), ...); + int unused[] = + {0, + (static_cast<void>(fStatements.push_back(DSLStatement(statements.release()).release())), + 0)...}; + static_cast<void>(unused); + } + + DSLBlock(DSLBlock&& other) = default; + + DSLBlock(SkSL::StatementArray statements, std::shared_ptr<SymbolTable> symbols = nullptr); + + DSLBlock(SkTArray<DSLStatement> statements, std::shared_ptr<SymbolTable> symbols = nullptr); + + ~DSLBlock(); + + DSLBlock& operator=(DSLBlock&& other) { + fStatements = std::move(other.fStatements); + return *this; + } + + void append(DSLStatement stmt); + + std::unique_ptr<SkSL::Block> release(); + +private: + SkSL::StatementArray fStatements; + std::shared_ptr<SkSL::SymbolTable> fSymbols; + + friend class DSLStatement; + friend class DSLFunction; +}; + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/DSLCase.h b/src/deps/skia/include/sksl/DSLCase.h new file mode 100644 index 000000000..5b006e7e2 --- /dev/null +++ b/src/deps/skia/include/sksl/DSLCase.h @@ -0,0 +1,68 @@ +/* + * Copyright 2021 Google LLC. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_CASE +#define SKSL_DSL_CASE + +#include "include/private/SkSLDefines.h" +#include "include/sksl/DSLExpression.h" +#include "include/sksl/DSLStatement.h" + +#include <memory> + +namespace SkSL { + +class Statement; + +namespace dsl { + +class DSLCase { +public: + // An empty expression means 'default:'. + template<class... Statements> + DSLCase(DSLExpression value, Statements... statements) + : fValue(std::move(value)) { + fStatements.reserve_back(sizeof...(statements)); + // in C++17, we could just do: + // (fStatements.push_back(DSLStatement(std::move(statements)).release()), ...); + int unused[] = + {0, + (static_cast<void>(fStatements.push_back(DSLStatement(std::move(statements)).release())), + 0)...}; + static_cast<void>(unused); + } + + DSLCase(DSLExpression value, SkTArray<DSLStatement> statements, + PositionInfo info = PositionInfo::Capture()); + + DSLCase(DSLExpression value, SkSL::StatementArray statements, + PositionInfo info = PositionInfo::Capture()); + + DSLCase(DSLCase&&); + + ~DSLCase(); + + DSLCase& operator=(DSLCase&&); + + void append(DSLStatement stmt); + +private: + DSLExpression fValue; + SkSL::StatementArray fStatements; + PositionInfo fPosition; + + friend class DSLCore; + + template<class... Cases> + friend DSLPossibleStatement Switch(DSLExpression value, Cases... cases); +}; + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/DSLCore.h b/src/deps/skia/include/sksl/DSLCore.h new file mode 100644 index 000000000..5363bda89 --- /dev/null +++ b/src/deps/skia/include/sksl/DSLCore.h @@ -0,0 +1,488 @@ +/* + * Copyright 2020 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_CORE +#define SKSL_DSL_CORE + +#include "include/private/SkSLProgramKind.h" +#include "include/private/SkTArray.h" +#include "include/sksl/DSLBlock.h" +#include "include/sksl/DSLCase.h" +#include "include/sksl/DSLExpression.h" +#include "include/sksl/DSLFunction.h" +#include "include/sksl/DSLStatement.h" +#include "include/sksl/DSLType.h" +#include "include/sksl/DSLVar.h" +#include "include/sksl/DSLWrapper.h" +#include "include/sksl/SkSLErrorReporter.h" + +namespace SkSL { + +class Compiler; +struct Program; +struct ProgramSettings; + +namespace dsl { + +// When users import the DSL namespace via `using namespace SkSL::dsl`, we want the SwizzleComponent +// Type enum to come into scope as well, so `Swizzle(var, X, Y, ONE)` can work as expected. +// `namespace SkSL::SwizzleComponent` contains only an `enum Type`; this `using namespace` directive +// shouldn't pollute the SkSL::dsl namespace with anything else. +using namespace SkSL::SwizzleComponent; + +/** + * Starts DSL output on the current thread using the specified compiler. This must be called + * prior to any other DSL functions. + */ +void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment); + +void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind, const SkSL::ProgramSettings& settings); + +/** + * Signals the end of DSL output. This must be called sometime between a call to Start() and the + * termination of the thread. + */ +void End(); + +/** + * Returns all global elements (functions and global variables) as a self-contained Program. The + * optional source string is retained as the program's source. DSL programs do not normally have + * sources, but when a DSL program is produced from parsed program text (as in DSLParser), it may be + * important to retain it so that any skstd::string_views derived from it remain valid. + */ +std::unique_ptr<SkSL::Program> ReleaseProgram(std::unique_ptr<SkSL::String> source = nullptr); + +/** + * Returns the ErrorReporter which will be notified of any errors that occur during DSL calls. The + * default error reporter aborts on any error. + */ +ErrorReporter& GetErrorReporter(); + +/** + * Installs an ErrorReporter which will be notified of any errors that occur during DSL calls. + */ +void SetErrorReporter(ErrorReporter* errorReporter); + +DSLGlobalVar sk_FragColor(); + +DSLGlobalVar sk_FragCoord(); + +DSLExpression sk_Position(); + +/** + * #extension <name> : enable + */ +void AddExtension(skstd::string_view name, PositionInfo pos = PositionInfo::Capture()); + +/** + * break; + */ +DSLStatement Break(PositionInfo pos = PositionInfo::Capture()); + +/** + * continue; + */ +DSLStatement Continue(PositionInfo pos = PositionInfo::Capture()); + +/** + * Adds a modifiers declaration to the current program. + */ +void Declare(const DSLModifiers& modifiers, PositionInfo pos = PositionInfo::Capture()); + +/** + * Creates a local variable declaration statement. + */ +DSLStatement Declare(DSLVar& var, PositionInfo pos = PositionInfo::Capture()); + +/** + * Creates a local variable declaration statement containing multiple variables. + */ +DSLStatement Declare(SkTArray<DSLVar>& vars, PositionInfo pos = PositionInfo::Capture()); + +/** + * Declares a global variable. + */ +void Declare(DSLGlobalVar& var, PositionInfo pos = PositionInfo::Capture()); + +/** + * Declares a set of global variables. + */ +void Declare(SkTArray<DSLGlobalVar>& vars, PositionInfo pos = PositionInfo::Capture()); + +/** + * default: statements + */ +template<class... Statements> +DSLCase Default(Statements... statements) { + return DSLCase(DSLExpression(), std::move(statements)...); +} + +/** + * discard; + */ +DSLStatement Discard(PositionInfo pos = PositionInfo::Capture()); + +/** + * do stmt; while (test); + */ +DSLStatement Do(DSLStatement stmt, DSLExpression test, PositionInfo pos = PositionInfo::Capture()); + +/** + * for (initializer; test; next) stmt; + */ +DSLStatement For(DSLStatement initializer, DSLExpression test, DSLExpression next, + DSLStatement stmt, PositionInfo pos = PositionInfo::Capture()); + +/** + * if (test) ifTrue; [else ifFalse;] + */ +DSLStatement If(DSLExpression test, DSLStatement ifTrue, DSLStatement ifFalse = DSLStatement(), + PositionInfo pos = PositionInfo::Capture()); + +DSLGlobalVar InterfaceBlock(const DSLModifiers& modifiers, skstd::string_view typeName, + SkTArray<DSLField> fields, skstd::string_view varName = "", + int arraySize = 0, PositionInfo pos = PositionInfo::Capture()); + +/** + * return [value]; + */ +DSLStatement Return(DSLExpression value = DSLExpression(), + PositionInfo pos = PositionInfo::Capture()); + +/** + * test ? ifTrue : ifFalse + */ +DSLExpression Select(DSLExpression test, DSLExpression ifTrue, DSLExpression ifFalse, + PositionInfo info = PositionInfo::Capture()); + +DSLStatement StaticIf(DSLExpression test, DSLStatement ifTrue, + DSLStatement ifFalse = DSLStatement(), + PositionInfo pos = PositionInfo::Capture()); + +// Internal use only +DSLPossibleStatement PossibleStaticSwitch(DSLExpression value, SkTArray<DSLCase> cases); + +DSLStatement StaticSwitch(DSLExpression value, SkTArray<DSLCase> cases, + PositionInfo info = PositionInfo::Capture()); + +/** + * @switch (value) { cases } + */ +template<class... Cases> +DSLPossibleStatement StaticSwitch(DSLExpression value, Cases... cases) { + SkTArray<DSLCase> caseArray; + caseArray.reserve_back(sizeof...(cases)); + (caseArray.push_back(std::move(cases)), ...); + return PossibleStaticSwitch(std::move(value), std::move(caseArray)); +} + +// Internal use only +DSLPossibleStatement PossibleSwitch(DSLExpression value, SkTArray<DSLCase> cases); + +DSLStatement Switch(DSLExpression value, SkTArray<DSLCase> cases, + PositionInfo info = PositionInfo::Capture()); + +/** + * switch (value) { cases } + */ +template<class... Cases> +DSLPossibleStatement Switch(DSLExpression value, Cases... cases) { + SkTArray<DSLCase> caseArray; + caseArray.reserve_back(sizeof...(cases)); + (caseArray.push_back(std::move(cases)), ...); + return PossibleSwitch(std::move(value), std::move(caseArray)); +} + +/** + * while (test) stmt; + */ +DSLStatement While(DSLExpression test, DSLStatement stmt, + PositionInfo info = PositionInfo::Capture()); + +/** + * expression.xyz1 + */ +DSLExpression Swizzle(DSLExpression base, + SkSL::SwizzleComponent::Type a, + PositionInfo pos = PositionInfo::Capture()); + +DSLExpression Swizzle(DSLExpression base, + SkSL::SwizzleComponent::Type a, + SkSL::SwizzleComponent::Type b, + PositionInfo pos = PositionInfo::Capture()); + +DSLExpression Swizzle(DSLExpression base, + SkSL::SwizzleComponent::Type a, + SkSL::SwizzleComponent::Type b, + SkSL::SwizzleComponent::Type c, + PositionInfo pos = PositionInfo::Capture()); + +DSLExpression Swizzle(DSLExpression base, + SkSL::SwizzleComponent::Type a, + SkSL::SwizzleComponent::Type b, + SkSL::SwizzleComponent::Type c, + SkSL::SwizzleComponent::Type d, + PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the absolute value of x. If x is a vector, operates componentwise. + */ +DSLExpression Abs(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns true if all of the components of boolean vector x are true. + */ +DSLExpression All(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns true if any of the components of boolean vector x are true. + */ +DSLExpression Any(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the arctangent of y over x. Operates componentwise on vectors. + */ +DSLExpression Atan(DSLExpression y_over_x, PositionInfo pos = PositionInfo::Capture()); +DSLExpression Atan(DSLExpression y, DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns x rounded towards positive infinity. If x is a vector, operates componentwise. + */ +DSLExpression Ceil(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns x clamped to between min and max. If x is a vector, operates componentwise. + */ +DSLExpression Clamp(DSLExpression x, DSLExpression min, DSLExpression max, + PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the cosine of x. If x is a vector, operates componentwise. + */ +DSLExpression Cos(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the cross product of x and y. + */ +DSLExpression Cross(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns x converted from radians to degrees. If x is a vector, operates componentwise. + */ +DSLExpression Degrees(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the distance between x and y. + */ +DSLExpression Distance(DSLExpression x, DSLExpression y, + PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the dot product of x and y. + */ +DSLExpression Dot(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns a boolean vector indicating whether components of x are equal to the corresponding + * components of y. + */ +DSLExpression Equal(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns e^x. If x is a vector, operates componentwise. + */ +DSLExpression Exp(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns 2^x. If x is a vector, operates componentwise. + */ +DSLExpression Exp2(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * If dot(i, nref) >= 0, returns n, otherwise returns -n. + */ +DSLExpression Faceforward(DSLExpression n, DSLExpression i, DSLExpression nref, + PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns x rounded towards negative infinity. If x is a vector, operates componentwise. + */ +DSLExpression Floor(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the fractional part of x. If x is a vector, operates componentwise. + */ +DSLExpression Fract(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns a boolean vector indicating whether components of x are greater than the corresponding + * components of y. + */ +DSLExpression GreaterThan(DSLExpression x, DSLExpression y, + PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns a boolean vector indicating whether components of x are greater than or equal to the + * corresponding components of y. + */ +DSLExpression GreaterThanEqual(DSLExpression x, DSLExpression y, + PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the 1/sqrt(x). If x is a vector, operates componentwise. + */ +DSLExpression Inversesqrt(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the inverse of the matrix x. + */ +DSLExpression Inverse(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the length of the vector x. + */ +DSLExpression Length(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns a boolean vector indicating whether components of x are less than the corresponding + * components of y. + */ +DSLExpression LessThan(DSLExpression x, DSLExpression y, + PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns a boolean vector indicating whether components of x are less than or equal to the + * corresponding components of y. + */ +DSLExpression LessThanEqual(DSLExpression x, DSLExpression y, + PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the log base e of x. If x is a vector, operates componentwise. + */ +DSLExpression Log(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the log base 2 of x. If x is a vector, operates componentwise. + */ +DSLExpression Log2(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the larger (closer to positive infinity) of x and y. If x is a vector, operates + * componentwise. y may be either a vector of the same dimensions as x, or a scalar. + */ +DSLExpression Max(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the smaller (closer to negative infinity) of x and y. If x is a vector, operates + * componentwise. y may be either a vector of the same dimensions as x, or a scalar. + */ +DSLExpression Min(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns a linear intepolation between x and y at position a, where a=0 results in x and a=1 + * results in y. If x and y are vectors, operates componentwise. a may be either a vector of the + * same dimensions as x and y, or a scalar. + */ +DSLExpression Mix(DSLExpression x, DSLExpression y, DSLExpression a, + PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns x modulo y. If x is a vector, operates componentwise. y may be either a vector of the + * same dimensions as x, or a scalar. + */ +DSLExpression Mod(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the vector x normalized to a length of 1. + */ +DSLExpression Normalize(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns a boolean vector indicating whether components of x are not equal to the corresponding + * components of y. + */ +DSLExpression NotEqual(DSLExpression x, DSLExpression y, + PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns x raised to the power y. If x is a vector, operates componentwise. y may be either a + * vector of the same dimensions as x, or a scalar. + */ +DSLExpression Pow(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns x converted from degrees to radians. If x is a vector, operates componentwise. + */ +DSLExpression Radians(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns i reflected from a surface with normal n. + */ +DSLExpression Reflect(DSLExpression i, DSLExpression n, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns i refracted across a surface with normal n and ratio of indices of refraction eta. + */ +DSLExpression Refract(DSLExpression i, DSLExpression n, DSLExpression eta, + PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns x, rounded to the nearest integer. If x is a vector, operates componentwise. + */ +DSLExpression Round(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns x clamped to the range [0, 1]. If x is a vector, operates componentwise. + */ +DSLExpression Saturate(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns -1, 0, or 1 depending on whether x is negative, zero, or positive, respectively. If x is + * a vector, operates componentwise. + */ +DSLExpression Sign(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the sine of x. If x is a vector, operates componentwise. + */ +DSLExpression Sin(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns a smooth interpolation between 0 (at x=edge1) and 1 (at x=edge2). If x is a vector, + * operates componentwise. edge1 and edge2 may either be both vectors of the same dimensions as x or + * scalars. + */ +DSLExpression Smoothstep(DSLExpression edge1, DSLExpression edge2, DSLExpression x, + PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the square root of x. If x is a vector, operates componentwise. + */ +DSLExpression Sqrt(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns 0 if x < edge or 1 if x >= edge. If x is a vector, operates componentwise. edge may be + * either a vector of the same dimensions as x, or a scalar. + */ +DSLExpression Step(DSLExpression edge, DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns the tangent of x. If x is a vector, operates componentwise. + */ +DSLExpression Tan(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns x converted from premultipled to unpremultiplied alpha. + */ +DSLExpression Unpremul(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/DSLExpression.h b/src/deps/skia/include/sksl/DSLExpression.h new file mode 100644 index 000000000..9ee0f6d20 --- /dev/null +++ b/src/deps/skia/include/sksl/DSLExpression.h @@ -0,0 +1,299 @@ +/* + * Copyright 2020 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_EXPRESSION +#define SKSL_DSL_EXPRESSION + +#include "include/core/SkStringView.h" +#include "include/core/SkTypes.h" +#include "include/private/SkTArray.h" +#include "include/sksl/DSLWrapper.h" +#include "include/sksl/SkSLErrorReporter.h" + +#include <cstdint> +#include <memory> + +#if defined(__has_cpp_attribute) && __has_cpp_attribute(clang::reinitializes) +#define SK_CLANG_REINITIALIZES [[clang::reinitializes]] +#else +#define SK_CLANG_REINITIALIZES +#endif + +namespace SkSL { + +class Expression; +class Type; + +namespace dsl { + +class DSLPossibleExpression; +class DSLStatement; +class DSLType; +class DSLVarBase; + +/** + * Represents an expression such as 'cos(x)' or 'a + b'. + */ +class DSLExpression { +public: + DSLExpression(const DSLExpression&) = delete; + + DSLExpression(DSLExpression&&); + + DSLExpression(); + + /** + * Creates an expression representing a literal float. + */ + DSLExpression(float value, PositionInfo pos = PositionInfo::Capture()); + + /** + * Creates an expression representing a literal float. + */ + DSLExpression(double value, PositionInfo pos = PositionInfo::Capture()) + : DSLExpression((float) value) {} + + /** + * Creates an expression representing a literal int. + */ + DSLExpression(int value, PositionInfo pos = PositionInfo::Capture()); + + /** + * Creates an expression representing a literal int. + */ + DSLExpression(int64_t value, PositionInfo pos = PositionInfo::Capture()); + + /** + * Creates an expression representing a literal uint. + */ + DSLExpression(unsigned int value, PositionInfo pos = PositionInfo::Capture()); + + /** + * Creates an expression representing a literal bool. + */ + DSLExpression(bool value, PositionInfo pos = PositionInfo::Capture()); + + /** + * Creates an expression representing a variable reference. + */ + DSLExpression(DSLVarBase& var, PositionInfo pos = PositionInfo::Capture()); + + DSLExpression(DSLVarBase&& var, PositionInfo pos = PositionInfo::Capture()); + + DSLExpression(DSLPossibleExpression expr, PositionInfo pos = PositionInfo::Capture()); + + explicit DSLExpression(std::unique_ptr<SkSL::Expression> expression); + + static DSLExpression Poison(PositionInfo pos = PositionInfo::Capture()); + + ~DSLExpression(); + + DSLType type(); + + /** + * Overloads the '=' operator to create an SkSL assignment statement. + */ + DSLPossibleExpression operator=(DSLExpression other); + + DSLExpression x(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression y(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression z(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression w(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression r(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression g(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression b(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression a(PositionInfo pos = PositionInfo::Capture()); + + /** + * Creates an SkSL struct field access expression. + */ + DSLExpression field(skstd::string_view name, PositionInfo pos = PositionInfo::Capture()); + + /** + * Creates an SkSL array index expression. + */ + DSLPossibleExpression operator[](DSLExpression index); + + DSLPossibleExpression operator()(SkTArray<DSLWrapper<DSLExpression>> args, + PositionInfo pos = PositionInfo::Capture()); + + DSLPossibleExpression operator()(ExpressionArray args, + PositionInfo pos = PositionInfo::Capture()); + + /** + * Returns true if this object contains an expression. DSLExpressions which were created with + * the empty constructor or which have already been release()ed do not have a value. + * DSLExpressions created with errors are still considered to have a value (but contain poison). + */ + bool hasValue() const { + return fExpression != nullptr; + } + + /** + * Returns true if this object contains an expression which is not poison. + */ + bool isValid() const; + + SK_CLANG_REINITIALIZES void swap(DSLExpression& other); + + /** + * Invalidates this object and returns the SkSL expression it represents. It is an error to call + * this on an invalid DSLExpression. + */ + std::unique_ptr<SkSL::Expression> release(); + +private: + /** + * Calls release if this expression has a value, otherwise returns null. + */ + std::unique_ptr<SkSL::Expression> releaseIfPossible(); + + std::unique_ptr<SkSL::Expression> fExpression; + + friend DSLExpression SampleChild(int index, DSLExpression coords); + + friend class DSLCore; + friend class DSLFunction; + friend class DSLPossibleExpression; + friend class DSLType; + friend class DSLVarBase; + friend class DSLWriter; + template<typename T> friend class DSLWrapper; +}; + +DSLPossibleExpression operator+(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator+(DSLExpression expr); +DSLPossibleExpression operator+=(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator-(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator-(DSLExpression expr); +DSLPossibleExpression operator-=(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator*(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator*=(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator/(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator/=(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator%(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator%=(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator<<(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator<<=(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator>>(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator>>=(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator&&(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator||(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator&(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator&=(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator|(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator|=(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator^(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator^=(DSLExpression left, DSLExpression right); +DSLPossibleExpression LogicalXor(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator,(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator,(DSLPossibleExpression left, DSLExpression right); +DSLPossibleExpression operator,(DSLExpression left, DSLPossibleExpression right); +DSLPossibleExpression operator,(DSLPossibleExpression left, DSLPossibleExpression right); +DSLPossibleExpression operator==(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator!=(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator>(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator<(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator>=(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator<=(DSLExpression left, DSLExpression right); +DSLPossibleExpression operator!(DSLExpression expr); +DSLPossibleExpression operator~(DSLExpression expr); +DSLPossibleExpression operator++(DSLExpression expr); +DSLPossibleExpression operator++(DSLExpression expr, int); +DSLPossibleExpression operator--(DSLExpression expr); +DSLPossibleExpression operator--(DSLExpression expr, int); + +/** + * Represents an Expression which may have failed and/or have pending errors to report. Converting a + * PossibleExpression into an Expression requires PositionInfo so that any pending errors can be + * reported at the correct position. + * + * PossibleExpression is used instead of Expression in situations where it is not possible to + * capture the PositionInfo at the time of Expression construction (notably in operator overloads, + * where we cannot add default parameters). + */ +class DSLPossibleExpression { +public: + DSLPossibleExpression(std::unique_ptr<SkSL::Expression> expression); + + DSLPossibleExpression(DSLPossibleExpression&& other); + + ~DSLPossibleExpression(); + + bool valid() const { + return fExpression != nullptr; + } + + /** + * Reports any pending errors at the specified position. + */ + void reportErrors(PositionInfo pos); + + DSLType type(); + + DSLExpression x(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression y(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression z(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression w(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression r(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression g(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression b(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression a(PositionInfo pos = PositionInfo::Capture()); + + DSLExpression field(skstd::string_view name, PositionInfo pos = PositionInfo::Capture()); + + DSLPossibleExpression operator=(DSLExpression expr); + + DSLPossibleExpression operator=(int expr); + + DSLPossibleExpression operator=(float expr); + + DSLPossibleExpression operator=(double expr); + + DSLPossibleExpression operator[](DSLExpression index); + + DSLPossibleExpression operator()(SkTArray<DSLWrapper<DSLExpression>> args, + PositionInfo pos = PositionInfo::Capture()); + + DSLPossibleExpression operator()(ExpressionArray args, + PositionInfo pos = PositionInfo::Capture()); + + DSLPossibleExpression operator++(); + + DSLPossibleExpression operator++(int); + + DSLPossibleExpression operator--(); + + DSLPossibleExpression operator--(int); + + std::unique_ptr<SkSL::Expression> release(PositionInfo pos = PositionInfo::Capture()); + +private: + std::unique_ptr<SkSL::Expression> fExpression; + + friend class DSLExpression; +}; + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/DSLFunction.h b/src/deps/skia/include/sksl/DSLFunction.h new file mode 100644 index 000000000..aa40bdfb6 --- /dev/null +++ b/src/deps/skia/include/sksl/DSLFunction.h @@ -0,0 +1,116 @@ +/* + * Copyright 2021 Google LLC. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_FUNCTION +#define SKSL_DSL_FUNCTION + +#include "include/sksl/DSLBlock.h" +#include "include/sksl/DSLExpression.h" +#include "include/sksl/DSLType.h" +#include "include/sksl/DSLVar.h" +#include "include/sksl/DSLWrapper.h" + +namespace SkSL { + +class Block; +class FunctionDeclaration; +class Variable; + +namespace dsl { + +class DSLType; + +class DSLFunction { +public: + template<class... Parameters> + DSLFunction(const DSLType& returnType, skstd::string_view name, Parameters&... parameters) + : DSLFunction(DSLModifiers(), returnType, name, parameters...) {} + + template<class... Parameters> + DSLFunction(const DSLModifiers& modifiers, const DSLType& returnType, skstd::string_view name, + Parameters&... parameters) { + SkTArray<DSLParameter*> parameterArray; + parameterArray.reserve_back(sizeof...(parameters)); + + // in C++17, we could just do: + // (parameterArray.push_back(¶meters), ...); + int unused[] = {0, (static_cast<void>(parameterArray.push_back(¶meters)), 0)...}; + static_cast<void>(unused); + // We can't have a default parameter and a template parameter pack at the same time, so + // unfortunately we can't capture position info from this overload. + this->init(modifiers, returnType, name, std::move(parameterArray), PositionInfo()); + } + + DSLFunction(const DSLType& returnType, skstd::string_view name, + SkTArray<DSLParameter*> parameters, PositionInfo pos = PositionInfo::Capture()) { + this->init(DSLModifiers(), returnType, name, std::move(parameters), pos); + } + + DSLFunction(const DSLModifiers& modifiers, const DSLType& returnType, skstd::string_view name, + SkTArray<DSLParameter*> parameters, PositionInfo pos = PositionInfo::Capture()) { + this->init(modifiers, returnType, name, std::move(parameters), pos); + } + + DSLFunction(const SkSL::FunctionDeclaration* decl) + : fDecl(decl) {} + + virtual ~DSLFunction() = default; + + template<class... Stmt> + void define(Stmt... stmts) { + DSLBlock block = DSLBlock(DSLStatement(std::move(stmts))...); + this->define(std::move(block)); + } + + void define(DSLBlock block, PositionInfo pos = PositionInfo::Capture()); + + /** + * Invokes the function with the given arguments. + */ + template<class... Args> + DSLExpression operator()(Args&&... args) { + ExpressionArray argArray; + argArray.reserve_back(sizeof...(args)); + this->collectArgs(argArray, std::forward<Args>(args)...); + return this->call(std::move(argArray)); + } + + /** + * Invokes the function with the given arguments. + */ + DSLExpression call(SkTArray<DSLWrapper<DSLExpression>> args, + PositionInfo pos = PositionInfo::Capture()); + + DSLExpression call(ExpressionArray args, PositionInfo pos = PositionInfo::Capture()); + +private: + void collectArgs(ExpressionArray& args) {} + + template<class... RemainingArgs> + void collectArgs(ExpressionArray& args, DSLVar& var, RemainingArgs&&... remaining) { + args.push_back(DSLExpression(var).release()); + collectArgs(args, std::forward<RemainingArgs>(remaining)...); + } + + template<class... RemainingArgs> + void collectArgs(ExpressionArray& args, DSLExpression expr, RemainingArgs&&... remaining) { + args.push_back(expr.release()); + collectArgs(args, std::forward<RemainingArgs>(remaining)...); + } + + void init(DSLModifiers modifiers, const DSLType& returnType, skstd::string_view name, + SkTArray<DSLParameter*> params, PositionInfo pos); + + const SkSL::FunctionDeclaration* fDecl = nullptr; + SkSL::PositionInfo fPosition; +}; + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/DSLLayout.h b/src/deps/skia/include/sksl/DSLLayout.h new file mode 100644 index 000000000..a0698f77f --- /dev/null +++ b/src/deps/skia/include/sksl/DSLLayout.h @@ -0,0 +1,94 @@ +/* + * Copyright 2021 Google LLC. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_LAYOUT +#define SKSL_DSL_LAYOUT + +#include "include/sksl/DSLLayout.h" + +#include "include/private/SkSLLayout.h" +#include "include/sksl/SkSLErrorReporter.h" + +namespace SkSL { + +namespace dsl { + +class DSLLayout { +public: + DSLLayout() {} + + DSLLayout& originUpperLeft(PositionInfo pos = PositionInfo::Capture()) { + return this->flag(SkSL::Layout::kOriginUpperLeft_Flag, "origin_upper_left", pos); + } + + DSLLayout& pushConstant(PositionInfo pos = PositionInfo::Capture()) { + return this->flag(SkSL::Layout::kPushConstant_Flag, "push_constant", pos); + } + + DSLLayout& blendSupportAllEquations(PositionInfo pos = PositionInfo::Capture()) { + return this->flag(SkSL::Layout::kBlendSupportAllEquations_Flag, + "blend_support_all_equations", pos); + } + + DSLLayout& color(PositionInfo pos = PositionInfo::Capture()) { + return this->flag(SkSL::Layout::kColor_Flag, "color", pos); + } + + DSLLayout& location(int location, PositionInfo pos = PositionInfo::Capture()) { + return this->intValue(&fSkSLLayout.fLocation, location, SkSL::Layout::kLocation_Flag, + "location", pos); + } + + DSLLayout& offset(int offset, PositionInfo pos = PositionInfo::Capture()) { + return this->intValue(&fSkSLLayout.fOffset, offset, SkSL::Layout::kOffset_Flag, "offset", + pos); + } + + DSLLayout& binding(int binding, PositionInfo pos = PositionInfo::Capture()) { + return this->intValue(&fSkSLLayout.fBinding, binding, SkSL::Layout::kBinding_Flag, + "binding", pos); + } + + DSLLayout& index(int index, PositionInfo pos = PositionInfo::Capture()) { + return this->intValue(&fSkSLLayout.fIndex, index, SkSL::Layout::kIndex_Flag, "index", pos); + } + + DSLLayout& set(int set, PositionInfo pos = PositionInfo::Capture()) { + return this->intValue(&fSkSLLayout.fSet, set, SkSL::Layout::kSet_Flag, "set", pos); + } + + DSLLayout& builtin(int builtin, PositionInfo pos = PositionInfo::Capture()) { + return this->intValue(&fSkSLLayout.fBuiltin, builtin, SkSL::Layout::kBuiltin_Flag, + "builtin", pos); + } + + DSLLayout& inputAttachmentIndex(int inputAttachmentIndex, + PositionInfo pos = PositionInfo::Capture()) { + return this->intValue(&fSkSLLayout.fInputAttachmentIndex, inputAttachmentIndex, + SkSL::Layout::kInputAttachmentIndex_Flag, "input_attachment_index", + pos); + } + +private: + explicit DSLLayout(SkSL::Layout skslLayout) + : fSkSLLayout(skslLayout) {} + + DSLLayout& flag(SkSL::Layout::Flag mask, const char* name, PositionInfo pos); + + DSLLayout& intValue(int* target, int value, SkSL::Layout::Flag flag, const char* name, + PositionInfo pos); + + SkSL::Layout fSkSLLayout; + + friend class DSLModifiers; +}; + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/DSLModifiers.h b/src/deps/skia/include/sksl/DSLModifiers.h new file mode 100644 index 000000000..10c6aaafa --- /dev/null +++ b/src/deps/skia/include/sksl/DSLModifiers.h @@ -0,0 +1,64 @@ +/* + * Copyright 2020 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_MODIFIERS +#define SKSL_DSL_MODIFIERS + +#include "include/core/SkSpan.h" +#include "include/private/SkSLModifiers.h" +#include "include/sksl/DSLLayout.h" + +namespace SkSL { + +namespace dsl { + +class DSLField; +class DSLType; + +enum Modifier { + kNo_Modifier = SkSL::Modifiers::kNo_Flag, + kConst_Modifier = SkSL::Modifiers::kConst_Flag, + kIn_Modifier = SkSL::Modifiers::kIn_Flag, + kOut_Modifier = SkSL::Modifiers::kOut_Flag, + kInOut_Modifier = SkSL::Modifiers::kIn_Flag | SkSL::Modifiers::kOut_Flag, + kUniform_Modifier = SkSL::Modifiers::kUniform_Flag, + kFlat_Modifier = SkSL::Modifiers::kFlat_Flag, + kNoPerspective_Modifier = SkSL::Modifiers::kNoPerspective_Flag, +}; + +class DSLModifiers { +public: + DSLModifiers(int flags = 0) + : DSLModifiers(DSLLayout(), flags) {} + + DSLModifiers(DSLLayout layout, int flags = 0) + : fModifiers(layout.fSkSLLayout, flags) {} + + int flags() const { + return fModifiers.fFlags; + } + + DSLLayout layout() const { + return DSLLayout(fModifiers.fLayout); + } + +private: + SkSL::Modifiers fModifiers; + + friend DSLType Struct(skstd::string_view name, SkSpan<DSLField> fields, PositionInfo pos); + friend class DSLCore; + friend class DSLFunction; + friend class DSLType; + friend class DSLVarBase; + friend class DSLWriter; +}; + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/DSLRuntimeEffects.h b/src/deps/skia/include/sksl/DSLRuntimeEffects.h new file mode 100644 index 000000000..3d9b99091 --- /dev/null +++ b/src/deps/skia/include/sksl/DSLRuntimeEffects.h @@ -0,0 +1,32 @@ +/* + * Copyright 2021 Google LLC. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_RUNTIME_EFFECTS +#define SKSL_DSL_RUNTIME_EFFECTS + +#include "include/effects/SkRuntimeEffect.h" +#include "include/sksl/DSL.h" + +namespace SkSL { + +class Compiler; + +namespace dsl { + +#ifndef SKSL_STANDALONE + +void StartRuntimeShader(SkSL::Compiler* compiler); + +sk_sp<SkRuntimeEffect> EndRuntimeShader(SkRuntimeEffect::Options options = {}); + +#endif + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/DSLStatement.h b/src/deps/skia/include/sksl/DSLStatement.h new file mode 100644 index 000000000..976198ca1 --- /dev/null +++ b/src/deps/skia/include/sksl/DSLStatement.h @@ -0,0 +1,111 @@ +/* + * Copyright 2021 Google LLC. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_STATEMENT +#define SKSL_DSL_STATEMENT + +#include "include/core/SkString.h" +#include "include/core/SkTypes.h" +#include "include/private/SkSLStatement.h" +#include "include/sksl/SkSLErrorReporter.h" + +#include <memory> + +class GrGLSLShaderBuilder; + +namespace SkSL { + +class Expression; +class Statement; + +namespace dsl { + +class DSLBlock; +class DSLExpression; +class DSLPossibleExpression; +class DSLPossibleStatement; +class DSLVar; + +class DSLStatement { +public: + DSLStatement(); + + DSLStatement(DSLExpression expr); + + DSLStatement(DSLPossibleExpression expr, PositionInfo pos = PositionInfo::Capture()); + + DSLStatement(DSLPossibleStatement stmt, PositionInfo pos = PositionInfo::Capture()); + + DSLStatement(DSLBlock block); + + DSLStatement(DSLStatement&&) = default; + + DSLStatement(std::unique_ptr<SkSL::Statement> stmt); + + DSLStatement(std::unique_ptr<SkSL::Expression> expr); + + ~DSLStatement(); + + DSLStatement& operator=(DSLStatement&& other) = default; + + bool hasValue() { return fStatement != nullptr; } + + std::unique_ptr<SkSL::Statement> release() { + SkASSERT(this->hasValue()); + return std::move(fStatement); + } + +private: + std::unique_ptr<SkSL::Statement> releaseIfPossible() { + return std::move(fStatement); + } + + std::unique_ptr<SkSL::Statement> fStatement; + + friend class DSLBlock; + friend class DSLCore; + friend class DSLExpression; + friend class DSLPossibleStatement; + friend class DSLWriter; + friend DSLStatement operator,(DSLStatement left, DSLStatement right); +}; + +/** + * Represents a Statement which may have failed and/or have pending errors to report. Converting a + * PossibleStatement into a Statement requires PositionInfo so that any pending errors can be + * reported at the correct position. + * + * PossibleStatement is used instead of Statement in situations where it is not possible to capture + * the PositionInfo at the time of Statement construction. + */ +class DSLPossibleStatement { +public: + DSLPossibleStatement(std::unique_ptr<SkSL::Statement> stmt); + + DSLPossibleStatement(DSLPossibleStatement&& other) = default; + + ~DSLPossibleStatement(); + + bool hasValue() { return fStatement != nullptr; } + + std::unique_ptr<SkSL::Statement> release() { + return DSLStatement(std::move(*this)).release(); + } + +private: + std::unique_ptr<SkSL::Statement> fStatement; + + friend class DSLStatement; +}; + +DSLStatement operator,(DSLStatement left, DSLStatement right); + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/DSLSymbols.h b/src/deps/skia/include/sksl/DSLSymbols.h new file mode 100644 index 000000000..9eebeda7c --- /dev/null +++ b/src/deps/skia/include/sksl/DSLSymbols.h @@ -0,0 +1,71 @@ +/* + * Copyright 2021 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_SYMBOLS +#define SKSL_DSL_SYMBOLS + +#include "include/core/SkStringView.h" +#include "include/private/SkSLString.h" +#include "include/sksl/DSLExpression.h" + +#include <memory> + +namespace SkSL { + +class SymbolTable; + +namespace dsl { + +class DSLVar; + +// This header provides methods for manually managing symbol tables in DSL code. They should not be +// used by normal hand-written DSL code, where we rely on C++ to manage symbols, but are instead +// needed when DSL objects are being constructed programmatically (as in DSLParser). + +/** + * Pushes a new symbol table onto the symbol table stack. + */ +void PushSymbolTable(); + +/** + * Pops the top symbol table from the stack. As symbol tables are shared pointers, this will only + * destroy the symbol table if it was never attached to anything (e.g. passed into a Block + * constructor). + */ +void PopSymbolTable(); + +/** + * Returns the current symbol table. Outside of SkSL itself, this is an opaque pointer, used only + * for passing it to DSL methods that require it. + */ +std::shared_ptr<SymbolTable> CurrentSymbolTable(); + +/** + * Returns an expression referring to the named symbol. + */ +DSLPossibleExpression Symbol(skstd::string_view name, PositionInfo pos = PositionInfo::Capture()); + +/** + * Returns true if the name refers to a type (user or built-in) in the current symbol table. + */ +bool IsType(skstd::string_view name); + +/** + * Returns true if the name refers to a builtin type. + */ +bool IsBuiltinType(skstd::string_view name); + +/** + * Adds a variable to the current symbol table. + */ +void AddToSymbolTable(DSLVarBase& var, PositionInfo pos = PositionInfo::Capture()); + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/DSLType.h b/src/deps/skia/include/sksl/DSLType.h new file mode 100644 index 000000000..4e6150f34 --- /dev/null +++ b/src/deps/skia/include/sksl/DSLType.h @@ -0,0 +1,259 @@ +/* + * Copyright 2020 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_TYPE +#define SKSL_DSL_TYPE + +#include "include/core/SkSpan.h" +#include "include/private/SkSLString.h" +#include "include/sksl/DSLExpression.h" +#include "include/sksl/DSLModifiers.h" + +#include <cstdint> + +namespace SkSL { + +class Type; + +namespace dsl { + +class DSLExpression; +class DSLField; +class DSLVarBase; + +enum TypeConstant : uint8_t { + kBool_Type, + kBool2_Type, + kBool3_Type, + kBool4_Type, + kHalf_Type, + kHalf2_Type, + kHalf3_Type, + kHalf4_Type, + kHalf2x2_Type, + kHalf3x2_Type, + kHalf4x2_Type, + kHalf2x3_Type, + kHalf3x3_Type, + kHalf4x3_Type, + kHalf2x4_Type, + kHalf3x4_Type, + kHalf4x4_Type, + kFloat_Type, + kFloat2_Type, + kFloat3_Type, + kFloat4_Type, + kFragmentProcessor_Type, + kFloat2x2_Type, + kFloat3x2_Type, + kFloat4x2_Type, + kFloat2x3_Type, + kFloat3x3_Type, + kFloat4x3_Type, + kFloat2x4_Type, + kFloat3x4_Type, + kFloat4x4_Type, + kInt_Type, + kInt2_Type, + kInt3_Type, + kInt4_Type, + kShader_Type, + kShort_Type, + kShort2_Type, + kShort3_Type, + kShort4_Type, + kUInt_Type, + kUInt2_Type, + kUInt3_Type, + kUInt4_Type, + kUShort_Type, + kUShort2_Type, + kUShort3_Type, + kUShort4_Type, + kVoid_Type, + kPoison_Type, +}; + +class DSLType { +public: + DSLType(TypeConstant tc) + : fTypeConstant(tc) {} + + DSLType(const SkSL::Type* type); + + DSLType(skstd::string_view name); + + DSLType(skstd::string_view name, + DSLModifiers* modifiers, + PositionInfo pos = PositionInfo::Capture()); + + /** + * Returns true if this type is a bool. + */ + bool isBoolean() const; + + /** + * Returns true if this is a numeric scalar type. + */ + bool isNumber() const; + + /** + * Returns true if this is a floating-point scalar type (float or half). + */ + bool isFloat() const; + + /** + * Returns true if this is a signed scalar type (int or short). + */ + bool isSigned() const; + + /** + * Returns true if this is an unsigned scalar type (uint or ushort). + */ + bool isUnsigned() const; + + /** + * Returns true if this is a signed or unsigned integer. + */ + bool isInteger() const; + + /** + * Returns true if this is a scalar type. + */ + bool isScalar() const; + + /** + * Returns true if this is a vector type. + */ + bool isVector() const; + + /** + * Returns true if this is a matrix type. + */ + bool isMatrix() const; + + /** + * Returns true if this is a array type. + */ + bool isArray() const; + + /** + * Returns true if this is a struct type. + */ + bool isStruct() const; + + /** + * Returns true if this is a Skia object type (shader, colorFilter, blender). + */ + bool isEffectChild() const; + + template<typename... Args> + static DSLPossibleExpression Construct(DSLType type, DSLVarBase& var, Args&&... args) { + DSLExpression argArray[] = {var, args...}; + return Construct(type, SkMakeSpan(argArray)); + } + + template<typename... Args> + static DSLPossibleExpression Construct(DSLType type, DSLExpression expr, Args&&... args) { + DSLExpression argArray[] = {std::move(expr), std::move(args)...}; + return Construct(type, SkMakeSpan(argArray)); + } + + static DSLPossibleExpression Construct(DSLType type, SkSpan<DSLExpression> argArray); + +private: + const SkSL::Type& skslType() const; + + const SkSL::Type* fSkSLType = nullptr; + + TypeConstant fTypeConstant = kPoison_Type; + + friend DSLType Array(const DSLType& base, int count, PositionInfo pos); + friend DSLType Struct(skstd::string_view name, SkSpan<DSLField> fields, PositionInfo pos); + friend class DSLCore; + friend class DSLFunction; + friend class DSLVarBase; + friend class DSLWriter; +}; + +#define TYPE(T) \ + template<typename... Args> \ + DSLExpression T(Args&&... args) { \ + return DSLType::Construct(k ## T ## _Type, std::forward<Args>(args)...); \ + } + +#define VECTOR_TYPE(T) \ + TYPE(T) \ + TYPE(T ## 2) \ + TYPE(T ## 3) \ + TYPE(T ## 4) + +#define MATRIX_TYPE(T) \ + TYPE(T ## 2x2) \ + TYPE(T ## 3x2) \ + TYPE(T ## 4x2) \ + TYPE(T ## 2x3) \ + TYPE(T ## 3x3) \ + TYPE(T ## 4x3) \ + TYPE(T ## 2x4) \ + TYPE(T ## 3x4) \ + TYPE(T ## 4x4) + +VECTOR_TYPE(Bool) +VECTOR_TYPE(Float) +VECTOR_TYPE(Half) +VECTOR_TYPE(Int) +VECTOR_TYPE(UInt) +VECTOR_TYPE(Short) +VECTOR_TYPE(UShort) + +MATRIX_TYPE(Float) +MATRIX_TYPE(Half) + +#undef TYPE +#undef VECTOR_TYPE +#undef MATRIX_TYPE + +DSLType Array(const DSLType& base, int count, PositionInfo pos = PositionInfo::Capture()); + +class DSLField { +public: + DSLField(const DSLType type, skstd::string_view name, + PositionInfo pos = PositionInfo::Capture()) + : DSLField(DSLModifiers(), type, name, pos) {} + + DSLField(const DSLModifiers& modifiers, const DSLType type, skstd::string_view name, + PositionInfo pos = PositionInfo::Capture()) + : fModifiers(modifiers) + , fType(type) + , fName(name) + , fPosition(pos) {} + +private: + DSLModifiers fModifiers; + const DSLType fType; + skstd::string_view fName; + PositionInfo fPosition; + + friend class DSLCore; + friend DSLType Struct(skstd::string_view name, SkSpan<DSLField> fields, PositionInfo pos); +}; + +DSLType Struct(skstd::string_view name, SkSpan<DSLField> fields, + PositionInfo pos = PositionInfo::Capture()); + +template<typename... Field> +DSLType Struct(skstd::string_view name, Field... fields) { + DSLField fieldTypes[] = {std::move(fields)...}; + return Struct(name, SkMakeSpan(fieldTypes), PositionInfo()); +} + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/DSLVar.h b/src/deps/skia/include/sksl/DSLVar.h new file mode 100644 index 000000000..391474c5a --- /dev/null +++ b/src/deps/skia/include/sksl/DSLVar.h @@ -0,0 +1,310 @@ +/* + * Copyright 2020 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_VAR +#define SKSL_DSL_VAR + +#include "include/sksl/DSLExpression.h" +#include "include/sksl/DSLModifiers.h" +#include "include/sksl/DSLType.h" + +namespace SkSL { + +class Expression; +class IRGenerator; +class SPIRVCodeGenerator; +class Variable; +enum class VariableStorage : int8_t; + +namespace dsl { + +class DSLVarBase { +public: + /** + * Creates an empty, unpopulated var. Can be replaced with a real var later via `swap`. + */ + DSLVarBase() : fType(kVoid_Type), fDeclared(true) {} + + /** + * Constructs a new variable with the specified type and name. The name is used (in mangled + * form) in the resulting shader code; it is not otherwise important. Since mangling prevents + * name conflicts and the variable's name is only important when debugging shaders, the name + * parameter is optional. + */ + DSLVarBase(DSLType type, skstd::string_view name, DSLExpression initialValue, PositionInfo pos); + + DSLVarBase(DSLType type, DSLExpression initialValue, PositionInfo pos); + + DSLVarBase(const DSLModifiers& modifiers, DSLType type, skstd::string_view name, + DSLExpression initialValue, PositionInfo pos); + + DSLVarBase(const DSLModifiers& modifiers, DSLType type, DSLExpression initialValue, + PositionInfo pos); + + DSLVarBase(DSLVarBase&&) = default; + + virtual ~DSLVarBase(); + + skstd::string_view name() const { + return fName; + } + + const DSLModifiers& modifiers() const { + return fModifiers; + } + + virtual VariableStorage storage() const = 0; + + DSLExpression x() { + return DSLExpression(*this, PositionInfo()).x(); + } + + DSLExpression y() { + return DSLExpression(*this, PositionInfo()).y(); + } + + DSLExpression z() { + return DSLExpression(*this, PositionInfo()).z(); + } + + DSLExpression w() { + return DSLExpression(*this, PositionInfo()).w(); + } + + DSLExpression r() { + return DSLExpression(*this, PositionInfo()).r(); + } + + DSLExpression g() { + return DSLExpression(*this, PositionInfo()).g(); + } + + DSLExpression b() { + return DSLExpression(*this, PositionInfo()).b(); + } + + DSLExpression a() { + return DSLExpression(*this, PositionInfo()).a(); + } + + DSLExpression field(skstd::string_view name) { + return DSLExpression(*this, PositionInfo()).field(name); + } + + DSLPossibleExpression operator[](DSLExpression&& index); + + DSLPossibleExpression operator++() { + return ++DSLExpression(*this, PositionInfo()); + } + + DSLPossibleExpression operator++(int) { + return DSLExpression(*this, PositionInfo())++; + } + + DSLPossibleExpression operator--() { + return --DSLExpression(*this, PositionInfo()); + } + + DSLPossibleExpression operator--(int) { + return DSLExpression(*this, PositionInfo())--; + } + +protected: + DSLPossibleExpression assign(DSLExpression other); + + void swap(DSLVarBase& other); + + DSLModifiers fModifiers; + // We only need to keep track of the type here so that we can create the SkSL::Variable. For + // predefined variables this field is unnecessary, so we don't bother tracking it and just set + // it to kVoid; in other words, you shouldn't generally be relying on this field to be correct. + // If you need to determine the variable's type, look at DSLWriter::Var(...)->type() instead. + DSLType fType; + int fUniformHandle = -1; + std::unique_ptr<SkSL::Statement> fDeclaration; + const SkSL::Variable* fVar = nullptr; + skstd::string_view fRawName; // for error reporting + skstd::string_view fName; + DSLExpression fInitialValue; + // true if we have attempted to create the SkSL var + bool fInitialized = false; + bool fDeclared = false; + PositionInfo fPosition; + + friend class DSLCore; + friend class DSLExpression; + friend class DSLFunction; + friend class DSLWriter; + friend class ::SkSL::IRGenerator; + friend class ::SkSL::SPIRVCodeGenerator; +}; + +/** + * A local variable. + */ +class DSLVar : public DSLVarBase { +public: + DSLVar() = default; + + DSLVar(DSLType type, skstd::string_view name = "var", + DSLExpression initialValue = DSLExpression(), + PositionInfo pos = PositionInfo::Capture()) + : INHERITED(type, name, std::move(initialValue), pos) {} + + DSLVar(DSLType type, const char* name, DSLExpression initialValue = DSLExpression(), + PositionInfo pos = PositionInfo::Capture()) + : DSLVar(type, skstd::string_view(name), std::move(initialValue), pos) {} + + DSLVar(DSLType type, DSLExpression initialValue, PositionInfo pos = PositionInfo::Capture()) + : INHERITED(type, std::move(initialValue), pos) {} + + DSLVar(const DSLModifiers& modifiers, DSLType type, skstd::string_view name = "var", + DSLExpression initialValue = DSLExpression(), PositionInfo pos = PositionInfo::Capture()) + : INHERITED(modifiers, type, name, std::move(initialValue), pos) {} + + DSLVar(const DSLModifiers& modifiers, DSLType type, const char* name, + DSLExpression initialValue = DSLExpression(), PositionInfo pos = PositionInfo::Capture()) + : DSLVar(modifiers, type, skstd::string_view(name), std::move(initialValue), pos) {} + + DSLVar(DSLVar&&) = default; + + VariableStorage storage() const override; + + void swap(DSLVar& other); + + DSLPossibleExpression operator=(DSLExpression expr); + + DSLPossibleExpression operator=(DSLVar& param) { + return this->operator=(DSLExpression(param)); + } + + template<class Param> + DSLPossibleExpression operator=(Param& param) { + return this->operator=(DSLExpression(param)); + } + +private: + using INHERITED = DSLVarBase; +}; + +/** + * A global variable. + */ +class DSLGlobalVar : public DSLVarBase { +public: + DSLGlobalVar() = default; + + DSLGlobalVar(DSLType type, skstd::string_view name = "var", + DSLExpression initialValue = DSLExpression(), PositionInfo pos = PositionInfo::Capture()) + : INHERITED(type, name, std::move(initialValue), pos) {} + + DSLGlobalVar(DSLType type, const char* name, DSLExpression initialValue = DSLExpression(), + PositionInfo pos = PositionInfo::Capture()) + : DSLGlobalVar(type, skstd::string_view(name), std::move(initialValue), pos) {} + + DSLGlobalVar(DSLType type, DSLExpression initialValue, + PositionInfo pos = PositionInfo::Capture()) + : INHERITED(type, std::move(initialValue), pos) {} + + DSLGlobalVar(const DSLModifiers& modifiers, DSLType type, skstd::string_view name = "var", + DSLExpression initialValue = DSLExpression(), PositionInfo pos = PositionInfo::Capture()) + : INHERITED(modifiers, type, name, std::move(initialValue), pos) {} + + DSLGlobalVar(const DSLModifiers& modifiers, DSLType type, const char* name, + DSLExpression initialValue = DSLExpression(), PositionInfo pos = PositionInfo::Capture()) + : DSLGlobalVar(modifiers, type, skstd::string_view(name), std::move(initialValue), pos) {} + + DSLGlobalVar(const char* name); + + DSLGlobalVar(DSLGlobalVar&&) = default; + + VariableStorage storage() const override; + + void swap(DSLGlobalVar& other); + + DSLPossibleExpression operator=(DSLExpression expr); + + DSLPossibleExpression operator=(DSLGlobalVar& param) { + return this->operator=(DSLExpression(param)); + } + + template<class Param> + DSLPossibleExpression operator=(Param& param) { + return this->operator=(DSLExpression(param)); + } + + /** + * Implements the following method calls: + * half4 shader::eval(float2 coords); + * half4 colorFilter::eval(half4 input); + */ + DSLExpression eval(DSLExpression x, PositionInfo pos = PositionInfo::Capture()); + + /** + * Implements the following method call: + * half4 blender::eval(half4 src, half4 dst); + */ + DSLExpression eval(DSLExpression x, DSLExpression y, + PositionInfo pos = PositionInfo::Capture()); + +private: + DSLExpression eval(ExpressionArray args, PositionInfo pos); + + std::unique_ptr<SkSL::Expression> methodCall(skstd::string_view methodName, PositionInfo pos); + + using INHERITED = DSLVarBase; +}; + +/** + * A function parameter. + */ +class DSLParameter : public DSLVarBase { +public: + DSLParameter() = default; + + DSLParameter(DSLType type, skstd::string_view name = "var", + PositionInfo pos = PositionInfo::Capture()) + : INHERITED(type, name, DSLExpression(), pos) {} + + DSLParameter(DSLType type, const char* name, PositionInfo pos = PositionInfo::Capture()) + : DSLParameter(type, skstd::string_view(name), pos) {} + + DSLParameter(const DSLModifiers& modifiers, DSLType type, skstd::string_view name = "var", + PositionInfo pos = PositionInfo::Capture()) + : INHERITED(modifiers, type, name, DSLExpression(), pos) {} + + DSLParameter(const DSLModifiers& modifiers, DSLType type, const char* name, + PositionInfo pos = PositionInfo::Capture()) + : DSLParameter(modifiers, type, skstd::string_view(name), pos) {} + + DSLParameter(DSLParameter&&) = default; + + VariableStorage storage() const override; + + void swap(DSLParameter& other); + + DSLPossibleExpression operator=(DSLExpression expr); + + DSLPossibleExpression operator=(DSLParameter& param) { + return this->operator=(DSLExpression(param)); + } + + template<class Param> + DSLPossibleExpression operator=(Param& param) { + return this->operator=(DSLExpression(param)); + } + +private: + using INHERITED = DSLVarBase; +}; + +} // namespace dsl + +} // namespace SkSL + + +#endif diff --git a/src/deps/skia/include/sksl/DSLWrapper.h b/src/deps/skia/include/sksl/DSLWrapper.h new file mode 100644 index 000000000..96daa22dd --- /dev/null +++ b/src/deps/skia/include/sksl/DSLWrapper.h @@ -0,0 +1,77 @@ +/* + * Copyright 2021 Google LLC. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DSL_WRAPPER +#define SKSL_DSL_WRAPPER + +#include <memory> + +namespace SkSL { + +namespace dsl { + +/** + * Several of the DSL classes override operator= in a non-standard fashion to allow for expressions + * like "x = 0" to compile into SkSL code. This makes it impossible to directly use these classes in + * C++ containers which expect standard behavior for operator=. + * + * Wrapper<T> contains a T, where T is a DSL class with non-standard operator=, and provides + * standard behavior for operator=, permitting it to be used in standard containers. + */ +template<typename T> +class DSLWrapper { +public: + DSLWrapper(T value) { + fValue.swap(value); + } + + DSLWrapper(const DSLWrapper&) = delete; + + DSLWrapper(DSLWrapper&& other) { + fValue.swap(other.fValue); + } + + T& get() { + return fValue; + } + + T& operator*() { + return fValue; + } + + T* operator->() { + return &fValue; + } + + const T& get() const { + return fValue; + } + + const T& operator*() const { + return fValue; + } + + const T* operator->() const { + return &fValue; + } + + DSLWrapper& operator=(const DSLWrapper&) = delete; + + DSLWrapper& operator=(DSLWrapper&& other) { + fValue.swap(other.fValue); + return *this; + } + +private: + T fValue; +}; + +} // namespace dsl + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/SkSLDebugTrace.h b/src/deps/skia/include/sksl/SkSLDebugTrace.h new file mode 100644 index 000000000..9c5eafbc9 --- /dev/null +++ b/src/deps/skia/include/sksl/SkSLDebugTrace.h @@ -0,0 +1,28 @@ +/* + * Copyright 2021 Google LLC. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_DEBUG_TRACE +#define SKSL_DEBUG_TRACE + +#include "include/core/SkRefCnt.h" + +class SkWStream; + +namespace SkSL { + +class DebugTrace : public SkRefCnt { +public: + /** Serializes a debug trace to JSON which can be parsed by our debugger. */ + virtual void writeTrace(SkWStream* w) const = 0; + + /** Generates a human-readable dump of the debug trace. */ + virtual void dump(SkWStream* o) const = 0; +}; + +} // namespace SkSL + +#endif diff --git a/src/deps/skia/include/sksl/SkSLErrorReporter.h b/src/deps/skia/include/sksl/SkSLErrorReporter.h new file mode 100644 index 000000000..48cc0958e --- /dev/null +++ b/src/deps/skia/include/sksl/SkSLErrorReporter.h @@ -0,0 +1,115 @@ +/* + * Copyright 2021 Google LLC. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_ERROR_REPORTER +#define SKSL_ERROR_REPORTER + +#include "include/core/SkStringView.h" +#include "include/core/SkTypes.h" +#include "include/private/SkSLString.h" + +#include <string> +#include <vector> + +namespace SkSL { + +#ifndef __has_builtin + #define __has_builtin(x) 0 +#endif + +class PositionInfo { +public: + PositionInfo(const char* file = nullptr, int line = -1) + : fFile(file) + , fLine(line) {} + +#if __has_builtin(__builtin_FILE) && __has_builtin(__builtin_LINE) + static PositionInfo Capture(const char* file = __builtin_FILE(), int line = __builtin_LINE()) { + return PositionInfo(file, line); + } +#else + static PositionInfo Capture() { return PositionInfo(); } +#endif // __has_builtin(__builtin_FILE) && __has_builtin(__builtin_LINE) + + const char* file_name() const { + return fFile; + } + + int line() const { + return fLine; + } + +private: + const char* fFile = nullptr; + int32_t fLine = -1; +}; + +/** + * Class which is notified in the event of an error. + */ +class ErrorReporter { +public: + ErrorReporter() {} + + virtual ~ErrorReporter() { + SkASSERT(fPendingErrors.empty()); + } + + void error(skstd::string_view msg, PositionInfo position); + + /** + * Reports an error message at the given line of the source text. Errors reported + * with a line of -1 will be queued until line number information can be determined. + */ + void error(int line, skstd::string_view msg); + + const char* source() const { return fSource; } + + void setSource(const char* source) { fSource = source; } + + void reportPendingErrors(PositionInfo pos) { + for (const String& msg : fPendingErrors) { + this->handleError(msg, pos); + } + fPendingErrors.clear(); + } + + int errorCount() const { + return fErrorCount; + } + + void resetErrorCount() { + fErrorCount = 0; + } + +protected: + /** + * Called when an error is reported. + */ + virtual void handleError(skstd::string_view msg, PositionInfo position) = 0; + +private: + PositionInfo position(int offset) const; + + const char* fSource = nullptr; + std::vector<String> fPendingErrors; + int fErrorCount = 0; +}; + +/** + * Error reporter for tests that need an SkSL context; aborts immediately if an error is reported. + */ +class TestingOnly_AbortErrorReporter : public ErrorReporter { +public: + void handleError(skstd::string_view msg, PositionInfo pos) override { + SK_ABORT("%.*s", (int)msg.length(), msg.data()); + } +}; + +} // namespace SkSL + +#endif |