2021-01-07 15:57:27 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2021-04-09 19:33:53 +00:00
|
|
|
#include "include/private/SkSLProgramKind.h"
|
2021-02-09 20:22:57 +00:00
|
|
|
#include "include/private/SkTArray.h"
|
2021-03-04 19:30:25 +00:00
|
|
|
#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"
|
2021-05-04 16:22:02 +00:00
|
|
|
#include "include/sksl/DSLWrapper.h"
|
2021-08-13 21:29:51 +00:00
|
|
|
#include "include/sksl/SkSLErrorReporter.h"
|
2021-01-07 15:57:27 +00:00
|
|
|
|
2021-09-07 13:36:08 +00:00
|
|
|
#define SKSL_DSL_PARSER 0
|
2021-07-20 19:23:04 +00:00
|
|
|
|
2021-01-07 15:57:27 +00:00
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
class Compiler;
|
2021-06-15 13:17:05 +00:00
|
|
|
struct Program;
|
2021-05-18 14:12:58 +00:00
|
|
|
struct ProgramSettings;
|
2021-01-07 15:57:27 +00:00
|
|
|
|
|
|
|
namespace dsl {
|
|
|
|
|
2021-02-18 21:06:17 +00:00
|
|
|
// 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;
|
|
|
|
|
2021-01-07 15:57:27 +00:00
|
|
|
/**
|
|
|
|
* Starts DSL output on the current thread using the specified compiler. This must be called
|
2021-01-08 16:42:25 +00:00
|
|
|
* prior to any other DSL functions.
|
2021-01-07 15:57:27 +00:00
|
|
|
*/
|
2021-05-18 14:12:58 +00:00
|
|
|
void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment);
|
|
|
|
|
|
|
|
void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind, const SkSL::ProgramSettings& settings);
|
2021-01-07 15:57:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals the end of DSL output. This must be called sometime between a call to Start() and the
|
|
|
|
* termination of the thread.
|
|
|
|
*/
|
|
|
|
void End();
|
|
|
|
|
2021-06-15 13:17:05 +00:00
|
|
|
/**
|
2021-07-16 13:53:53 +00:00
|
|
|
* 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.
|
2021-06-15 13:17:05 +00:00
|
|
|
*/
|
2021-07-16 13:53:53 +00:00
|
|
|
std::unique_ptr<SkSL::Program> ReleaseProgram(std::unique_ptr<SkSL::String> source = nullptr);
|
2021-06-15 13:17:05 +00:00
|
|
|
|
2021-08-05 18:53:02 +00:00
|
|
|
/**
|
2021-08-13 21:29:51 +00:00
|
|
|
* Returns the ErrorReporter which will be notified of any errors that occur during DSL calls. The
|
|
|
|
* default error reporter aborts on any error.
|
2021-08-05 18:53:02 +00:00
|
|
|
*/
|
2021-08-13 21:29:51 +00:00
|
|
|
ErrorReporter& GetErrorReporter();
|
2021-08-05 18:53:02 +00:00
|
|
|
|
2021-01-26 17:00:25 +00:00
|
|
|
/**
|
2021-08-13 21:29:51 +00:00
|
|
|
* Installs an ErrorReporter which will be notified of any errors that occur during DSL calls.
|
2021-01-26 17:00:25 +00:00
|
|
|
*/
|
2021-08-13 21:29:51 +00:00
|
|
|
void SetErrorReporter(ErrorReporter* errorReporter);
|
2021-01-26 17:00:25 +00:00
|
|
|
|
Broke DSLVar into separate subclasses
Previously, DSLVar represented local, global, and parameter variables.
This splits it into three separate subclasses.
In addition to just being a cleaner API in general, this also addresses
an issue we ran into with the upcoming DSLParser: previously, a global
DSLVar's storage was not set correctly until DeclareGlobal was called,
so an AddToSymbolTable call prior to DeclareGlobal would create the
SkSL variable with the wrong storage, causing spurious errors on
global-only modifiers. But holding off on the AddToSymbolTable tends to
break constructs like "int x = 0, y = x", so improving the API seemed
like the best way to address it.
Now that we have greater type safety around variables, we can
potentially avoid having to call AddToSymbolTable for DSLVar and
DSLGlobalVar altogether, since we know they are both supposed to end up
in the symbol table, but that isn't something I want to change in this
CL.
Change-Id: I5f390a7384ce0af6a2131d84f97fc5e5b318063f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/428576
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2021-07-15 14:35:54 +00:00
|
|
|
DSLGlobalVar sk_FragColor();
|
2021-01-28 15:02:43 +00:00
|
|
|
|
Broke DSLVar into separate subclasses
Previously, DSLVar represented local, global, and parameter variables.
This splits it into three separate subclasses.
In addition to just being a cleaner API in general, this also addresses
an issue we ran into with the upcoming DSLParser: previously, a global
DSLVar's storage was not set correctly until DeclareGlobal was called,
so an AddToSymbolTable call prior to DeclareGlobal would create the
SkSL variable with the wrong storage, causing spurious errors on
global-only modifiers. But holding off on the AddToSymbolTable tends to
break constructs like "int x = 0, y = x", so improving the API seemed
like the best way to address it.
Now that we have greater type safety around variables, we can
potentially avoid having to call AddToSymbolTable for DSLVar and
DSLGlobalVar altogether, since we know they are both supposed to end up
in the symbol table, but that isn't something I want to change in this
CL.
Change-Id: I5f390a7384ce0af6a2131d84f97fc5e5b318063f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/428576
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2021-07-15 14:35:54 +00:00
|
|
|
DSLGlobalVar sk_FragCoord();
|
2021-01-28 15:02:43 +00:00
|
|
|
|
2021-07-09 19:35:23 +00:00
|
|
|
DSLExpression sk_Position();
|
|
|
|
|
2021-09-03 15:10:54 +00:00
|
|
|
/**
|
|
|
|
* #extension <name> : enable
|
|
|
|
*/
|
|
|
|
void AddExtension(skstd::string_view name, PositionInfo pos = PositionInfo::Capture());
|
|
|
|
|
2021-02-05 19:22:32 +00:00
|
|
|
/**
|
|
|
|
* break;
|
|
|
|
*/
|
2021-08-31 11:40:24 +00:00
|
|
|
DSLStatement Break(PositionInfo pos = PositionInfo::Capture());
|
2021-02-05 19:22:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* continue;
|
|
|
|
*/
|
2021-08-31 11:40:24 +00:00
|
|
|
DSLStatement Continue(PositionInfo pos = PositionInfo::Capture());
|
2021-02-05 19:22:32 +00:00
|
|
|
|
2021-09-03 10:33:47 +00:00
|
|
|
/**
|
|
|
|
* Adds a modifiers declaration to the current program.
|
|
|
|
*/
|
|
|
|
void Declare(const DSLModifiers& modifiers, PositionInfo pos = PositionInfo::Capture());
|
|
|
|
|
2021-01-22 20:18:25 +00:00
|
|
|
/**
|
2021-06-15 13:17:05 +00:00
|
|
|
* Creates a local variable declaration statement.
|
2021-01-22 20:18:25 +00:00
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLStatement Declare(DSLVar& var, PositionInfo pos = PositionInfo::Capture());
|
2021-04-30 17:14:24 +00:00
|
|
|
|
2021-07-19 16:55:52 +00:00
|
|
|
/**
|
|
|
|
* Creates a local variable declaration statement containing multiple variables.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLStatement Declare(SkTArray<DSLVar>& vars, PositionInfo pos = PositionInfo::Capture());
|
2021-07-19 16:55:52 +00:00
|
|
|
|
2021-04-30 17:14:24 +00:00
|
|
|
/**
|
|
|
|
* Declares a global variable.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
void Declare(DSLGlobalVar& var, PositionInfo pos = PositionInfo::Capture());
|
2021-01-22 20:18:25 +00:00
|
|
|
|
2021-07-19 16:55:52 +00:00
|
|
|
/**
|
|
|
|
* Declares a set of global variables.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
void Declare(SkTArray<DSLGlobalVar>& vars, PositionInfo pos = PositionInfo::Capture());
|
2021-07-19 16:55:52 +00:00
|
|
|
|
2021-02-09 20:22:57 +00:00
|
|
|
/**
|
|
|
|
* default: statements
|
|
|
|
*/
|
|
|
|
template<class... Statements>
|
|
|
|
DSLCase Default(Statements... statements) {
|
|
|
|
return DSLCase(DSLExpression(), std::move(statements)...);
|
|
|
|
}
|
|
|
|
|
2021-02-05 19:22:32 +00:00
|
|
|
/**
|
|
|
|
* discard;
|
|
|
|
*/
|
2021-09-03 21:00:09 +00:00
|
|
|
DSLStatement Discard(PositionInfo pos = PositionInfo::Capture());
|
2021-02-05 19:22:32 +00:00
|
|
|
|
2021-01-22 20:18:25 +00:00
|
|
|
/**
|
|
|
|
* do stmt; while (test);
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLStatement Do(DSLStatement stmt, DSLExpression test, PositionInfo pos = PositionInfo::Capture());
|
2021-01-22 20:18:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* for (initializer; test; next) stmt;
|
|
|
|
*/
|
|
|
|
DSLStatement For(DSLStatement initializer, DSLExpression test, DSLExpression next,
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLStatement stmt, PositionInfo pos = PositionInfo::Capture());
|
2021-01-22 20:18:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* if (test) ifTrue; [else ifFalse;]
|
|
|
|
*/
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLStatement If(DSLExpression test, DSLStatement ifTrue, DSLStatement ifFalse = DSLStatement(),
|
2021-08-12 15:41:59 +00:00
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-22 20:18:25 +00:00
|
|
|
|
2021-08-05 14:19:11 +00:00
|
|
|
DSLGlobalVar InterfaceBlock(const DSLModifiers& modifiers, skstd::string_view typeName,
|
Broke DSLVar into separate subclasses
Previously, DSLVar represented local, global, and parameter variables.
This splits it into three separate subclasses.
In addition to just being a cleaner API in general, this also addresses
an issue we ran into with the upcoming DSLParser: previously, a global
DSLVar's storage was not set correctly until DeclareGlobal was called,
so an AddToSymbolTable call prior to DeclareGlobal would create the
SkSL variable with the wrong storage, causing spurious errors on
global-only modifiers. But holding off on the AddToSymbolTable tends to
break constructs like "int x = 0, y = x", so improving the API seemed
like the best way to address it.
Now that we have greater type safety around variables, we can
potentially avoid having to call AddToSymbolTable for DSLVar and
DSLGlobalVar altogether, since we know they are both supposed to end up
in the symbol table, but that isn't something I want to change in this
CL.
Change-Id: I5f390a7384ce0af6a2131d84f97fc5e5b318063f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/428576
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2021-07-15 14:35:54 +00:00
|
|
|
SkTArray<DSLField> fields, skstd::string_view varName = "",
|
2021-08-12 15:41:59 +00:00
|
|
|
int arraySize = 0, PositionInfo pos = PositionInfo::Capture());
|
2021-07-08 14:38:43 +00:00
|
|
|
|
2021-01-28 15:02:43 +00:00
|
|
|
/**
|
|
|
|
* return [value];
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLStatement Return(DSLExpression value = DSLExpression(),
|
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-02-26 01:50:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test ? ifTrue : ifFalse
|
|
|
|
*/
|
|
|
|
DSLExpression Select(DSLExpression test, DSLExpression ifTrue, DSLExpression ifFalse,
|
2021-08-12 15:41:59 +00:00
|
|
|
PositionInfo info = PositionInfo::Capture());
|
2021-01-28 15:02:43 +00:00
|
|
|
|
2021-04-30 16:44:00 +00:00
|
|
|
DSLStatement StaticIf(DSLExpression test, DSLStatement ifTrue,
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLStatement ifFalse = DSLStatement(),
|
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-04-30 16:44:00 +00:00
|
|
|
|
2021-09-03 21:00:09 +00:00
|
|
|
DSLPossibleStatement StaticSwitch(DSLExpression value, SkTArray<DSLCase> cases,
|
|
|
|
PositionInfo info = PositionInfo::Capture());
|
2021-04-30 16:44:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 StaticSwitch(std::move(value), std::move(caseArray));
|
|
|
|
}
|
|
|
|
|
2021-09-03 21:00:09 +00:00
|
|
|
DSLPossibleStatement Switch(DSLExpression value, SkTArray<DSLCase> cases,
|
|
|
|
PositionInfo info = PositionInfo::Capture());
|
2021-03-04 19:30:25 +00:00
|
|
|
|
2021-02-09 20:22:57 +00:00
|
|
|
/**
|
|
|
|
* switch (value) { cases }
|
|
|
|
*/
|
|
|
|
template<class... Cases>
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLPossibleStatement Switch(DSLExpression value, Cases... cases) {
|
2021-04-30 16:44:00 +00:00
|
|
|
SkTArray<DSLCase> caseArray;
|
|
|
|
caseArray.reserve_back(sizeof...(cases));
|
|
|
|
(caseArray.push_back(std::move(cases)), ...);
|
|
|
|
return Switch(std::move(value), std::move(caseArray));
|
2021-02-09 20:22:57 +00:00
|
|
|
}
|
|
|
|
|
2021-01-22 20:18:25 +00:00
|
|
|
/**
|
|
|
|
* while (test) stmt;
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLStatement While(DSLExpression test, DSLStatement stmt,
|
|
|
|
PositionInfo info = PositionInfo::Capture());
|
2021-01-07 15:57:27 +00:00
|
|
|
|
2021-02-18 21:06:17 +00:00
|
|
|
/**
|
|
|
|
* expression.xyz1
|
|
|
|
*/
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLExpression Swizzle(DSLExpression base,
|
|
|
|
SkSL::SwizzleComponent::Type a,
|
2021-08-12 15:41:59 +00:00
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 19:31:29 +00:00
|
|
|
|
2021-02-18 21:06:17 +00:00
|
|
|
DSLExpression Swizzle(DSLExpression base,
|
|
|
|
SkSL::SwizzleComponent::Type a,
|
2021-02-26 01:50:32 +00:00
|
|
|
SkSL::SwizzleComponent::Type b,
|
2021-08-12 15:41:59 +00:00
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 19:31:29 +00:00
|
|
|
|
2021-02-18 21:06:17 +00:00
|
|
|
DSLExpression Swizzle(DSLExpression base,
|
|
|
|
SkSL::SwizzleComponent::Type a,
|
|
|
|
SkSL::SwizzleComponent::Type b,
|
2021-02-26 01:50:32 +00:00
|
|
|
SkSL::SwizzleComponent::Type c,
|
2021-08-12 15:41:59 +00:00
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 19:31:29 +00:00
|
|
|
|
2021-02-18 21:06:17 +00:00
|
|
|
DSLExpression Swizzle(DSLExpression base,
|
|
|
|
SkSL::SwizzleComponent::Type a,
|
|
|
|
SkSL::SwizzleComponent::Type b,
|
|
|
|
SkSL::SwizzleComponent::Type c,
|
2021-02-26 01:50:32 +00:00
|
|
|
SkSL::SwizzleComponent::Type d,
|
2021-08-12 15:41:59 +00:00
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 19:31:29 +00:00
|
|
|
|
2021-01-07 15:57:27 +00:00
|
|
|
/**
|
2021-01-26 17:00:25 +00:00
|
|
|
* Returns the absolute value of x. If x is a vector, operates componentwise.
|
2021-01-07 15:57:27 +00:00
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Abs(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if all of the components of boolean vector x are true.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression All(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if any of the components of boolean vector x are true.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Any(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
2021-04-26 13:36:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the arctangent of y over x. Operates componentwise on vectors.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Atan(DSLExpression y_over_x, PositionInfo pos = PositionInfo::Capture());
|
|
|
|
DSLExpression Atan(DSLExpression y, DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-04-26 13:36:07 +00:00
|
|
|
|
2021-01-26 17:00:25 +00:00
|
|
|
/**
|
|
|
|
* Returns x rounded towards positive infinity. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Ceil(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns x clamped to between min and max. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLExpression Clamp(DSLExpression x, DSLExpression min, DSLExpression max,
|
2021-08-12 15:41:59 +00:00
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the cosine of x. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Cos(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the cross product of x and y.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Cross(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns x converted from radians to degrees. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Degrees(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the distance between x and y.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Distance(DSLExpression x, DSLExpression y,
|
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the dot product of x and y.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Dot(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a boolean vector indicating whether components of x are equal to the corresponding
|
|
|
|
* components of y.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Equal(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns e^x. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Exp(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns 2^x. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Exp2(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If dot(i, nref) >= 0, returns n, otherwise returns -n.
|
|
|
|
*/
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLExpression Faceforward(DSLExpression n, DSLExpression i, DSLExpression nref,
|
2021-08-12 15:41:59 +00:00
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns x rounded towards negative infinity. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Floor(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the fractional part of x. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Fract(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a boolean vector indicating whether components of x are greater than the corresponding
|
|
|
|
* components of y.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression GreaterThan(DSLExpression x, DSLExpression y,
|
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a boolean vector indicating whether components of x are greater than or equal to the
|
|
|
|
* corresponding components of y.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression GreaterThanEqual(DSLExpression x, DSLExpression y,
|
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the 1/sqrt(x). If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Inversesqrt(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the inverse of the matrix x.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Inverse(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the length of the vector x.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Length(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a boolean vector indicating whether components of x are less than the corresponding
|
|
|
|
* components of y.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression LessThan(DSLExpression x, DSLExpression y,
|
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a boolean vector indicating whether components of x are less than or equal to the
|
|
|
|
* corresponding components of y.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression LessThanEqual(DSLExpression x, DSLExpression y,
|
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the log base e of x. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Log(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the log base 2 of x. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Log2(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Max(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Min(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLExpression Mix(DSLExpression x, DSLExpression y, DSLExpression a,
|
2021-08-12 15:41:59 +00:00
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Mod(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the vector x normalized to a length of 1.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Normalize(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a boolean vector indicating whether components of x are not equal to the corresponding
|
|
|
|
* components of y.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression NotEqual(DSLExpression x, DSLExpression y,
|
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Pow(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns x converted from degrees to radians. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Radians(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns i reflected from a surface with normal n.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Reflect(DSLExpression i, DSLExpression n, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns i refracted across a surface with normal n and ratio of indices of refraction eta.
|
|
|
|
*/
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLExpression Refract(DSLExpression i, DSLExpression n, DSLExpression eta,
|
2021-08-12 15:41:59 +00:00
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
2021-04-09 19:33:53 +00:00
|
|
|
/**
|
|
|
|
* Samples the child processor at the current coordinates.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Sample(DSLExpression fp, PositionInfo pos = PositionInfo::Capture());
|
2021-04-09 19:33:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements the following functions:
|
|
|
|
* half4 sample(fragmentProcessor fp, float2 coords);
|
|
|
|
* half4 sample(fragmentProcessor fp, half4 input);
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Sample(DSLExpression target, DSLExpression x,
|
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-04-09 19:33:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements the following functions:
|
2021-04-13 13:50:27 +00:00
|
|
|
* half4 sample(fragmentProcessor fp, float2 coords, half4 input);
|
2021-04-09 19:33:53 +00:00
|
|
|
*/
|
|
|
|
DSLExpression Sample(DSLExpression childProcessor, DSLExpression x, DSLExpression y,
|
2021-08-12 15:41:59 +00:00
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-04-09 19:33:53 +00:00
|
|
|
|
2021-01-26 17:00:25 +00:00
|
|
|
/**
|
|
|
|
* Returns x clamped to the range [0, 1]. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Saturate(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns -1, 0, or 1 depending on whether x is negative, zero, or positive, respectively. If x is
|
|
|
|
* a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Sign(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the sine of x. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Sin(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-02-26 01:50:32 +00:00
|
|
|
DSLExpression Smoothstep(DSLExpression edge1, DSLExpression edge2, DSLExpression x,
|
2021-08-12 15:41:59 +00:00
|
|
|
PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the square root of x. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Sqrt(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Step(DSLExpression edge, DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the tangent of x. If x is a vector, operates componentwise.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Tan(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-26 17:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns x converted from premultipled to unpremultiplied alpha.
|
|
|
|
*/
|
2021-08-12 15:41:59 +00:00
|
|
|
DSLExpression Unpremul(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
|
2021-01-07 15:57:27 +00:00
|
|
|
|
|
|
|
} // namespace dsl
|
|
|
|
|
|
|
|
} // namespace SkSL
|
|
|
|
|
|
|
|
#endif
|