SkSLCPP.h 1.1 KB

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