1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2019 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#ifndef SKSL_DEFINES
9cb93a386Sopenharmony_ci#define SKSL_DEFINES
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include <cstdint>
12cb93a386Sopenharmony_ci
13cb93a386Sopenharmony_ci#include "include/core/SkTypes.h"
14cb93a386Sopenharmony_ci#include "include/private/SkTArray.h"
15cb93a386Sopenharmony_ci
16cb93a386Sopenharmony_ciusing SKSL_INT = int64_t;
17cb93a386Sopenharmony_ciusing SKSL_FLOAT = float;
18cb93a386Sopenharmony_ci
19cb93a386Sopenharmony_cinamespace SkSL {
20cb93a386Sopenharmony_ci
21cb93a386Sopenharmony_ciclass Expression;
22cb93a386Sopenharmony_ciclass Statement;
23cb93a386Sopenharmony_ci
24cb93a386Sopenharmony_ciusing ComponentArray = SkSTArray<4, int8_t>; // for Swizzles
25cb93a386Sopenharmony_ciusing ExpressionArray = SkSTArray<2, std::unique_ptr<Expression>>;
26cb93a386Sopenharmony_ciusing StatementArray = SkSTArray<2, std::unique_ptr<Statement>>;
27cb93a386Sopenharmony_ci
28cb93a386Sopenharmony_ci// Functions larger than this (measured in IR nodes) will not be inlined. This growth factor
29cb93a386Sopenharmony_ci// accounts for the number of calls being inlined--i.e., a function called five times (that is, with
30cb93a386Sopenharmony_ci// five inlining opportunities) would be considered 5x larger than if it were called once. This
31cb93a386Sopenharmony_ci// default threshold value is arbitrary, but tends to work well in practice.
32cb93a386Sopenharmony_cistatic constexpr int kDefaultInlineThreshold = 50;
33cb93a386Sopenharmony_ci
34cb93a386Sopenharmony_ci// A hard upper limit on the number of variable slots allowed in a function/global scope.
35cb93a386Sopenharmony_ci// This is an arbitrary limit, but is needed to prevent code generation from taking unbounded
36cb93a386Sopenharmony_ci// amounts of time or space.
37cb93a386Sopenharmony_cistatic constexpr int kVariableSlotLimit = 100000;
38cb93a386Sopenharmony_ci
39cb93a386Sopenharmony_ci// The SwizzleComponent namespace is used both by the SkSL::Swizzle expression, and the DSL swizzle.
40cb93a386Sopenharmony_ci// This namespace is injected into SkSL::dsl so that `using namespace SkSL::dsl` enables DSL code
41cb93a386Sopenharmony_ci// like `Swizzle(var, X, Y, ONE)` to compile without any extra qualifications.
42cb93a386Sopenharmony_cinamespace SwizzleComponent {
43cb93a386Sopenharmony_ci
44cb93a386Sopenharmony_cienum Type : int8_t {
45cb93a386Sopenharmony_ci    X  =  0,  Y =  1,  Z =  2,  W =  3,
46cb93a386Sopenharmony_ci    R  =  4,  G =  5,  B =  6,  A =  7,
47cb93a386Sopenharmony_ci    S  =  8,  T =  9,  P = 10,  Q = 11,
48cb93a386Sopenharmony_ci    UL = 12, UT = 13, UR = 14, UB = 15,
49cb93a386Sopenharmony_ci    ZERO,
50cb93a386Sopenharmony_ci    ONE
51cb93a386Sopenharmony_ci};
52cb93a386Sopenharmony_ci
53cb93a386Sopenharmony_ci}  // namespace SwizzleComponent
54cb93a386Sopenharmony_ci}  // namespace SkSL
55cb93a386Sopenharmony_ci
56cb93a386Sopenharmony_ci#endif
57