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