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 operator GrColor4f() const { 30 return GrColor4f(fX, fY, fZ, fW); 31 } 32 33 private: 34 float fX; 35 float fY; 36 float fZ; 37 float fW; 38 }; 39 40 // macros to make sk_Caps.<cap name> work from C++ code 41 #define sk_Caps (*args.fShaderCaps) 42 43 #define floatIs32Bits floatIs32Bits() 44 45 // functions to make GLSL constructors work from C++ code 46 inline SkPoint float2(float xy) { return SkPoint::Make(xy, xy); } 47 48 inline SkPoint float2(float x, float y) { return SkPoint::Make(x, y); } 49 50 inline Float4 float4(float xyzw) { return Float4(xyzw, xyzw, xyzw, xyzw); } 51 52 inline Float4 float4(float x, float y, float z, float w) { return Float4(x, y, z, w); } 53 54 #define half2 float2 55 56 #define half3 float3 57 58 #define half4 float4 59 60 #endif 61