blob: 55033b675787d59a5574b82fa672a5da67689ebf [file] [log] [blame]
Ethan Nicholas95046142021-01-07 10:57:27 -05001/*
2 * Copyright 2020 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SKSL_DSL_CORE
9#define SKSL_DSL_CORE
10
Ethan Nicholasee49efc2021-04-09 15:33:53 -040011#include "include/private/SkSLProgramKind.h"
Ethan Nicholascfefec02021-02-09 15:22:57 -050012#include "include/private/SkTArray.h"
Ethan Nicholasdaed2592021-03-04 14:30:25 -050013#include "include/sksl/DSLBlock.h"
14#include "include/sksl/DSLCase.h"
Ethan Nicholasdaed2592021-03-04 14:30:25 -050015#include "include/sksl/DSLExpression.h"
16#include "include/sksl/DSLFunction.h"
17#include "include/sksl/DSLStatement.h"
18#include "include/sksl/DSLType.h"
19#include "include/sksl/DSLVar.h"
Ethan Nicholasa1a0b922021-05-04 12:22:02 -040020#include "include/sksl/DSLWrapper.h"
Ethan Nicholas4a5e22a2021-08-13 17:29:51 -040021#include "include/sksl/SkSLErrorReporter.h"
Ethan Nicholas95046142021-01-07 10:57:27 -050022
Ethan Nicholas22800582021-09-16 10:42:24 -040023#define SKSL_DSL_PARSER 1
Ethan Nicholasdd2fdea2021-07-20 15:23:04 -040024
Ethan Nicholas95046142021-01-07 10:57:27 -050025namespace SkSL {
26
27class Compiler;
Ethan Nicholas4f3e6a22021-06-15 09:17:05 -040028struct Program;
Ethan Nicholas55a63af2021-05-18 10:12:58 -040029struct ProgramSettings;
Ethan Nicholas95046142021-01-07 10:57:27 -050030
31namespace dsl {
32
John Stiles9b7ad1b2021-02-18 16:06:17 -050033// When users import the DSL namespace via `using namespace SkSL::dsl`, we want the SwizzleComponent
34// Type enum to come into scope as well, so `Swizzle(var, X, Y, ONE)` can work as expected.
35// `namespace SkSL::SwizzleComponent` contains only an `enum Type`; this `using namespace` directive
36// shouldn't pollute the SkSL::dsl namespace with anything else.
37using namespace SkSL::SwizzleComponent;
38
Ethan Nicholas95046142021-01-07 10:57:27 -050039/**
Ethan Nicholas95046142021-01-07 10:57:27 -050040 * Starts DSL output on the current thread using the specified compiler. This must be called
Ethan Nicholasb3d4e742021-01-08 11:42:25 -050041 * prior to any other DSL functions.
Ethan Nicholas95046142021-01-07 10:57:27 -050042 */
Ethan Nicholas55a63af2021-05-18 10:12:58 -040043void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment);
44
45void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind, const SkSL::ProgramSettings& settings);
Ethan Nicholas95046142021-01-07 10:57:27 -050046
47/**
48 * Signals the end of DSL output. This must be called sometime between a call to Start() and the
49 * termination of the thread.
50 */
51void End();
52
Ethan Nicholasd6b6f3e2021-01-22 15:18:25 -050053/**
Ethan Nicholasb18c1e22021-07-16 09:53:53 -040054 * Returns all global elements (functions and global variables) as a self-contained Program. The
55 * optional source string is retained as the program's source. DSL programs do not normally have
56 * sources, but when a DSL program is produced from parsed program text (as in DSLParser), it may be
57 * important to retain it so that any skstd::string_views derived from it remain valid.
Ethan Nicholas4f3e6a22021-06-15 09:17:05 -040058 */
Ethan Nicholasb18c1e22021-07-16 09:53:53 -040059std::unique_ptr<SkSL::Program> ReleaseProgram(std::unique_ptr<SkSL::String> source = nullptr);
Ethan Nicholas4f3e6a22021-06-15 09:17:05 -040060
61/**
Ethan Nicholas4a5e22a2021-08-13 17:29:51 -040062 * Returns the ErrorReporter which will be notified of any errors that occur during DSL calls. The
63 * default error reporter aborts on any error.
Ethan Nicholas65e368b2021-08-05 14:53:02 -040064 */
Ethan Nicholas4a5e22a2021-08-13 17:29:51 -040065ErrorReporter& GetErrorReporter();
Ethan Nicholas65e368b2021-08-05 14:53:02 -040066
67/**
Ethan Nicholas4a5e22a2021-08-13 17:29:51 -040068 * Installs an ErrorReporter which will be notified of any errors that occur during DSL calls.
Ethan Nicholas30e93d52021-01-26 12:00:25 -050069 */
Ethan Nicholas4a5e22a2021-08-13 17:29:51 -040070void SetErrorReporter(ErrorReporter* errorReporter);
Ethan Nicholas30e93d52021-01-26 12:00:25 -050071
Ethan Nicholasa2d22b22021-07-15 10:35:54 -040072DSLGlobalVar sk_FragColor();
Ethan Nicholas1ff76092021-01-28 10:02:43 -050073
Ethan Nicholasa2d22b22021-07-15 10:35:54 -040074DSLGlobalVar sk_FragCoord();
Ethan Nicholas1ff76092021-01-28 10:02:43 -050075
Ethan Nicholasebc9fad2021-07-09 15:35:23 -040076DSLExpression sk_Position();
77
Ethan Nicholas30e93d52021-01-26 12:00:25 -050078/**
Ethan Nicholas642215e2021-09-03 11:10:54 -040079 * #extension <name> : enable
80 */
81void AddExtension(skstd::string_view name, PositionInfo pos = PositionInfo::Capture());
82
83/**
Ethan Nicholasdaceb792021-02-05 14:22:32 -050084 * break;
85 */
Ethan Nicholas6f20b8d2021-08-31 07:40:24 -040086DSLStatement Break(PositionInfo pos = PositionInfo::Capture());
Ethan Nicholasdaceb792021-02-05 14:22:32 -050087
88/**
89 * continue;
90 */
Ethan Nicholas6f20b8d2021-08-31 07:40:24 -040091DSLStatement Continue(PositionInfo pos = PositionInfo::Capture());
Ethan Nicholasdaceb792021-02-05 14:22:32 -050092
93/**
Ethan Nicholas678ec712021-09-03 06:33:47 -040094 * Adds a modifiers declaration to the current program.
95 */
96void Declare(const DSLModifiers& modifiers, PositionInfo pos = PositionInfo::Capture());
97
98/**
Ethan Nicholas4f3e6a22021-06-15 09:17:05 -040099 * Creates a local variable declaration statement.
Ethan Nicholasd6b6f3e2021-01-22 15:18:25 -0500100 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400101DSLStatement Declare(DSLVar& var, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholasd6b6f3e2021-01-22 15:18:25 -0500102
103/**
Ethan Nicholasda729782021-07-19 12:55:52 -0400104 * Creates a local variable declaration statement containing multiple variables.
105 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400106DSLStatement Declare(SkTArray<DSLVar>& vars, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholasda729782021-07-19 12:55:52 -0400107
108/**
Ethan Nicholase9c2c5a2021-04-30 13:14:24 -0400109 * Declares a global variable.
110 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400111void Declare(DSLGlobalVar& var, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholase9c2c5a2021-04-30 13:14:24 -0400112
113/**
Ethan Nicholasda729782021-07-19 12:55:52 -0400114 * Declares a set of global variables.
115 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400116void Declare(SkTArray<DSLGlobalVar>& vars, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholasda729782021-07-19 12:55:52 -0400117
118/**
Ethan Nicholascfefec02021-02-09 15:22:57 -0500119 * default: statements
120 */
121template<class... Statements>
122DSLCase Default(Statements... statements) {
123 return DSLCase(DSLExpression(), std::move(statements)...);
124}
125
126/**
Ethan Nicholasdaceb792021-02-05 14:22:32 -0500127 * discard;
128 */
Ethan Nicholas360db872021-09-03 17:00:09 -0400129DSLStatement Discard(PositionInfo pos = PositionInfo::Capture());
Ethan Nicholasdaceb792021-02-05 14:22:32 -0500130
131/**
Ethan Nicholasd6b6f3e2021-01-22 15:18:25 -0500132 * do stmt; while (test);
133 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400134DSLStatement Do(DSLStatement stmt, DSLExpression test, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholasd6b6f3e2021-01-22 15:18:25 -0500135
136/**
137 * for (initializer; test; next) stmt;
138 */
139DSLStatement For(DSLStatement initializer, DSLExpression test, DSLExpression next,
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400140 DSLStatement stmt, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholasd6b6f3e2021-01-22 15:18:25 -0500141
142/**
143 * if (test) ifTrue; [else ifFalse;]
144 */
Ethan Nicholas34c7e112021-02-25 20:50:32 -0500145DSLStatement If(DSLExpression test, DSLStatement ifTrue, DSLStatement ifFalse = DSLStatement(),
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400146 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholasd6b6f3e2021-01-22 15:18:25 -0500147
John Stilese53c7212021-08-05 10:19:11 -0400148DSLGlobalVar InterfaceBlock(const DSLModifiers& modifiers, skstd::string_view typeName,
Ethan Nicholasa2d22b22021-07-15 10:35:54 -0400149 SkTArray<DSLField> fields, skstd::string_view varName = "",
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400150 int arraySize = 0, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholase6ed3c22021-07-08 10:38:43 -0400151
Ethan Nicholasd6b6f3e2021-01-22 15:18:25 -0500152/**
Ethan Nicholas1ff76092021-01-28 10:02:43 -0500153 * return [value];
154 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400155DSLStatement Return(DSLExpression value = DSLExpression(),
156 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas34c7e112021-02-25 20:50:32 -0500157
158/**
159 * test ? ifTrue : ifFalse
160 */
161DSLExpression Select(DSLExpression test, DSLExpression ifTrue, DSLExpression ifFalse,
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400162 PositionInfo info = PositionInfo::Capture());
Ethan Nicholas1ff76092021-01-28 10:02:43 -0500163
Ethan Nicholas8a6537d2021-04-30 12:44:00 -0400164DSLStatement StaticIf(DSLExpression test, DSLStatement ifTrue,
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400165 DSLStatement ifFalse = DSLStatement(),
166 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas8a6537d2021-04-30 12:44:00 -0400167
Ethan Nicholas360db872021-09-03 17:00:09 -0400168DSLPossibleStatement StaticSwitch(DSLExpression value, SkTArray<DSLCase> cases,
169 PositionInfo info = PositionInfo::Capture());
Ethan Nicholas8a6537d2021-04-30 12:44:00 -0400170
171/**
172 * @switch (value) { cases }
173 */
174template<class... Cases>
175DSLPossibleStatement StaticSwitch(DSLExpression value, Cases... cases) {
176 SkTArray<DSLCase> caseArray;
177 caseArray.reserve_back(sizeof...(cases));
178 (caseArray.push_back(std::move(cases)), ...);
179 return StaticSwitch(std::move(value), std::move(caseArray));
180}
181
Ethan Nicholas360db872021-09-03 17:00:09 -0400182DSLPossibleStatement Switch(DSLExpression value, SkTArray<DSLCase> cases,
183 PositionInfo info = PositionInfo::Capture());
Ethan Nicholasdaed2592021-03-04 14:30:25 -0500184
Ethan Nicholas1ff76092021-01-28 10:02:43 -0500185/**
Ethan Nicholascfefec02021-02-09 15:22:57 -0500186 * switch (value) { cases }
187 */
188template<class... Cases>
Ethan Nicholas34c7e112021-02-25 20:50:32 -0500189DSLPossibleStatement Switch(DSLExpression value, Cases... cases) {
Ethan Nicholas8a6537d2021-04-30 12:44:00 -0400190 SkTArray<DSLCase> caseArray;
191 caseArray.reserve_back(sizeof...(cases));
192 (caseArray.push_back(std::move(cases)), ...);
193 return Switch(std::move(value), std::move(caseArray));
Ethan Nicholascfefec02021-02-09 15:22:57 -0500194}
195
196/**
Ethan Nicholasd6b6f3e2021-01-22 15:18:25 -0500197 * while (test) stmt;
198 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400199DSLStatement While(DSLExpression test, DSLStatement stmt,
200 PositionInfo info = PositionInfo::Capture());
Ethan Nicholas95046142021-01-07 10:57:27 -0500201
John Stiles9b7ad1b2021-02-18 16:06:17 -0500202/**
203 * expression.xyz1
204 */
John Stiles9b7ad1b2021-02-18 16:06:17 -0500205DSLExpression Swizzle(DSLExpression base,
206 SkSL::SwizzleComponent::Type a,
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400207 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas68c77d42021-01-26 14:31:29 -0500208
John Stiles9b7ad1b2021-02-18 16:06:17 -0500209DSLExpression Swizzle(DSLExpression base,
210 SkSL::SwizzleComponent::Type a,
211 SkSL::SwizzleComponent::Type b,
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400212 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas68c77d42021-01-26 14:31:29 -0500213
John Stiles9b7ad1b2021-02-18 16:06:17 -0500214DSLExpression Swizzle(DSLExpression base,
215 SkSL::SwizzleComponent::Type a,
216 SkSL::SwizzleComponent::Type b,
217 SkSL::SwizzleComponent::Type c,
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400218 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas34c7e112021-02-25 20:50:32 -0500219
220DSLExpression Swizzle(DSLExpression base,
221 SkSL::SwizzleComponent::Type a,
222 SkSL::SwizzleComponent::Type b,
223 SkSL::SwizzleComponent::Type c,
224 SkSL::SwizzleComponent::Type d,
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400225 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas68c77d42021-01-26 14:31:29 -0500226
Ethan Nicholas95046142021-01-07 10:57:27 -0500227/**
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500228 * Returns the absolute value of x. If x is a vector, operates componentwise.
Ethan Nicholas95046142021-01-07 10:57:27 -0500229 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400230DSLExpression Abs(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500231
232/**
233 * Returns true if all of the components of boolean vector x are true.
234 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400235DSLExpression All(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500236
237/**
238 * Returns true if any of the components of boolean vector x are true.
239 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400240DSLExpression Any(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500241
242/**
John Stilese3fa7452021-04-26 09:36:07 -0400243 * Returns the arctangent of y over x. Operates componentwise on vectors.
244 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400245DSLExpression Atan(DSLExpression y_over_x, PositionInfo pos = PositionInfo::Capture());
246DSLExpression Atan(DSLExpression y, DSLExpression x, PositionInfo pos = PositionInfo::Capture());
John Stilese3fa7452021-04-26 09:36:07 -0400247
248/**
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500249 * Returns x rounded towards positive infinity. If x is a vector, operates componentwise.
250 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400251DSLExpression Ceil(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500252
253/**
254 * Returns x clamped to between min and max. If x is a vector, operates componentwise.
255 */
Ethan Nicholas34c7e112021-02-25 20:50:32 -0500256DSLExpression Clamp(DSLExpression x, DSLExpression min, DSLExpression max,
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400257 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500258
259/**
260 * Returns the cosine of x. If x is a vector, operates componentwise.
261 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400262DSLExpression Cos(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500263
264/**
265 * Returns the cross product of x and y.
266 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400267DSLExpression Cross(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500268
269/**
270 * Returns x converted from radians to degrees. If x is a vector, operates componentwise.
271 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400272DSLExpression Degrees(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500273
274/**
275 * Returns the distance between x and y.
276 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400277DSLExpression Distance(DSLExpression x, DSLExpression y,
278 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500279
280/**
281 * Returns the dot product of x and y.
282 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400283DSLExpression Dot(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500284
285/**
286 * Returns a boolean vector indicating whether components of x are equal to the corresponding
287 * components of y.
288 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400289DSLExpression Equal(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500290
291/**
292 * Returns e^x. If x is a vector, operates componentwise.
293 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400294DSLExpression Exp(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500295
296/**
297 * Returns 2^x. If x is a vector, operates componentwise.
298 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400299DSLExpression Exp2(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500300
301/**
302 * If dot(i, nref) >= 0, returns n, otherwise returns -n.
303 */
Ethan Nicholas34c7e112021-02-25 20:50:32 -0500304DSLExpression Faceforward(DSLExpression n, DSLExpression i, DSLExpression nref,
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400305 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500306
307/**
308 * Returns x rounded towards negative infinity. If x is a vector, operates componentwise.
309 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400310DSLExpression Floor(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500311
312/**
313 * Returns the fractional part of x. If x is a vector, operates componentwise.
314 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400315DSLExpression Fract(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500316
317/**
318 * Returns a boolean vector indicating whether components of x are greater than the corresponding
319 * components of y.
320 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400321DSLExpression GreaterThan(DSLExpression x, DSLExpression y,
322 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500323
324/**
325 * Returns a boolean vector indicating whether components of x are greater than or equal to the
326 * corresponding components of y.
327 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400328DSLExpression GreaterThanEqual(DSLExpression x, DSLExpression y,
329 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500330
331/**
332 * Returns the 1/sqrt(x). If x is a vector, operates componentwise.
333 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400334DSLExpression Inversesqrt(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500335
336/**
337 * Returns the inverse of the matrix x.
338 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400339DSLExpression Inverse(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500340
341/**
342 * Returns the length of the vector x.
343 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400344DSLExpression Length(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500345
346/**
347 * Returns a boolean vector indicating whether components of x are less than the corresponding
348 * components of y.
349 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400350DSLExpression LessThan(DSLExpression x, DSLExpression y,
351 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500352
353/**
354 * Returns a boolean vector indicating whether components of x are less than or equal to the
355 * corresponding components of y.
356 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400357DSLExpression LessThanEqual(DSLExpression x, DSLExpression y,
358 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500359
360/**
361 * Returns the log base e of x. If x is a vector, operates componentwise.
362 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400363DSLExpression Log(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500364
365/**
366 * Returns the log base 2 of x. If x is a vector, operates componentwise.
367 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400368DSLExpression Log2(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500369
370/**
371 * Returns the larger (closer to positive infinity) of x and y. If x is a vector, operates
372 * componentwise. y may be either a vector of the same dimensions as x, or a scalar.
373 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400374DSLExpression Max(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500375
376/**
377 * Returns the smaller (closer to negative infinity) of x and y. If x is a vector, operates
378 * componentwise. y may be either a vector of the same dimensions as x, or a scalar.
379 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400380DSLExpression Min(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500381
382/**
383 * Returns a linear intepolation between x and y at position a, where a=0 results in x and a=1
384 * results in y. If x and y are vectors, operates componentwise. a may be either a vector of the
385 * same dimensions as x and y, or a scalar.
386 */
Ethan Nicholas34c7e112021-02-25 20:50:32 -0500387DSLExpression Mix(DSLExpression x, DSLExpression y, DSLExpression a,
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400388 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500389
390/**
391 * Returns x modulo y. If x is a vector, operates componentwise. y may be either a vector of the
392 * same dimensions as x, or a scalar.
393 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400394DSLExpression Mod(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500395
396/**
397 * Returns the vector x normalized to a length of 1.
398 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400399DSLExpression Normalize(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500400
401/**
402 * Returns a boolean vector indicating whether components of x are not equal to the corresponding
403 * components of y.
404 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400405DSLExpression NotEqual(DSLExpression x, DSLExpression y,
406 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500407
408/**
409 * Returns x raised to the power y. If x is a vector, operates componentwise. y may be either a
410 * vector of the same dimensions as x, or a scalar.
411 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400412DSLExpression Pow(DSLExpression x, DSLExpression y, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500413
414/**
415 * Returns x converted from degrees to radians. If x is a vector, operates componentwise.
416 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400417DSLExpression Radians(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500418
419/**
420 * Returns i reflected from a surface with normal n.
421 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400422DSLExpression Reflect(DSLExpression i, DSLExpression n, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500423
424/**
425 * Returns i refracted across a surface with normal n and ratio of indices of refraction eta.
426 */
Ethan Nicholas34c7e112021-02-25 20:50:32 -0500427DSLExpression Refract(DSLExpression i, DSLExpression n, DSLExpression eta,
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400428 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500429
430/**
John Stiles25339532021-09-08 17:50:09 -0400431 * Returns x, rounded to the nearest integer. If x is a vector, operates componentwise.
432 */
433DSLExpression Round(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
434
435/**
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500436 * Returns x clamped to the range [0, 1]. If x is a vector, operates componentwise.
437 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400438DSLExpression Saturate(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500439
440/**
441 * Returns -1, 0, or 1 depending on whether x is negative, zero, or positive, respectively. If x is
442 * a vector, operates componentwise.
443 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400444DSLExpression Sign(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500445
446/**
447 * Returns the sine of x. If x is a vector, operates componentwise.
448 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400449DSLExpression Sin(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500450
451/**
452 * Returns a smooth interpolation between 0 (at x=edge1) and 1 (at x=edge2). If x is a vector,
453 * operates componentwise. edge1 and edge2 may either be both vectors of the same dimensions as x or
454 * scalars.
455 */
Ethan Nicholas34c7e112021-02-25 20:50:32 -0500456DSLExpression Smoothstep(DSLExpression edge1, DSLExpression edge2, DSLExpression x,
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400457 PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500458
459/**
460 * Returns the square root of x. If x is a vector, operates componentwise.
461 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400462DSLExpression Sqrt(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500463
464/**
465 * Returns 0 if x < edge or 1 if x >= edge. If x is a vector, operates componentwise. edge may be
466 * either a vector of the same dimensions as x, or a scalar.
467 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400468DSLExpression Step(DSLExpression edge, DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500469
470/**
471 * Returns the tangent of x. If x is a vector, operates componentwise.
472 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400473DSLExpression Tan(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas30e93d52021-01-26 12:00:25 -0500474
475/**
476 * Returns x converted from premultipled to unpremultiplied alpha.
477 */
Ethan Nicholasa2fd01c2021-08-12 11:41:59 -0400478DSLExpression Unpremul(DSLExpression x, PositionInfo pos = PositionInfo::Capture());
Ethan Nicholas95046142021-01-07 10:57:27 -0500479
480} // namespace dsl
481
482} // namespace SkSL
483
484#endif