• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
Float4Float419     Float4(float x, float y, float z, float w)
20     : fX(x)
21     , fY(y)
22     , fZ(z)
23     , fW(w) {}
24 
SkRectFloat425     operator SkRect() const {
26         return SkRect::MakeLTRB(fX, fY, fZ, fW);
27     }
28 
GrColor4fFloat429     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
float2(float xy)46 inline SkPoint float2(float xy) { return SkPoint::Make(xy, xy); }
47 
float2(float x,float y)48 inline SkPoint float2(float x, float y) { return SkPoint::Make(x, y); }
49 
float4(float xyzw)50 inline Float4 float4(float xyzw) { return Float4(xyzw, xyzw, xyzw, xyzw); }
51 
float4(float x,float y,float z,float w)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