1 /* 2 * Copyright 2017 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_CPP 9 #define SKSL_CPP 10 11 // functions used by CPP programs created by skslc 12 13 #include <cmath> 14 #include "SkPoint.h" 15 16 using std::abs; 17 18 struct Float4 { 19 Float4(float x, float y, float z, float w) 20 : fX(x) 21 , fY(y) 22 , fZ(z) 23 , fW(w) {} 24 25 operator SkRect() const { 26 return SkRect::MakeLTRB(fX, fY, fZ, fW); 27 } 28 29 private: 30 float fX; 31 float fY; 32 float fZ; 33 float fW; 34 }; 35 36 // macros to make sk_Caps.<cap name> work from C++ code 37 #define sk_Caps (*args.fShaderCaps) 38 39 #define floatIs32Bits floatIs32Bits() 40 41 // functions to make GLSL constructors work from C++ code 42 inline SkPoint float2(float xy) { return SkPoint::Make(xy, xy); } 43 44 inline SkPoint float2(float x, float y) { return SkPoint::Make(x, y); } 45 46 inline Float4 float4(float xyzw) { return Float4(xyzw, xyzw, xyzw, xyzw); } 47 48 inline Float4 float4(float x, float y, float z, float w) { return Float4(x, y, z, w); } 49 50 #define half2 float2 51 52 #define half3 float3 53 54 #define half4 float4 55 56 #endif 57