SkColorFilterPriv.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright 2019 Google LLC
  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 SkColorFilterPriv_DEFINED
  8. #define SkColorFilterPriv_DEFINED
  9. #ifdef SK_SUPPORT_GPU
  10. #include "include/core/SkColorFilter.h"
  11. #include "include/core/SkString.h"
  12. using SkRuntimeColorFilterFn = void(*)(float[4], const void*);
  13. class SK_API SkRuntimeColorFilterFactory {
  14. public:
  15. /**
  16. * Creates a factory which creates runtime color filters. The SkSL must define a 'main' function
  17. * with the signature 'void main(inout half4 color)'. The SkSL will be used when rendering in
  18. * GPU mode, with the 'color' parameter providing the current value on input and receiving the
  19. * new color value on exit. In software mode, the cpuFunc will be called with the current color
  20. * and a pointer to the 'inputs' bytes. cpuFunc may be left null, in which case only GPU
  21. * rendering is supported.
  22. */
  23. SkRuntimeColorFilterFactory(SkString sksl, SkRuntimeColorFilterFn cpuFunc = nullptr);
  24. /**
  25. * Creates a color filter instance with the specified inputs. In GPU rendering, the inputs are
  26. * used to populate the values of 'in' variables. For instance, given the color filter:
  27. * in uniform float x;
  28. * in uniform float y;
  29. * void main(inout half4 color) {
  30. * ...
  31. * }
  32. * The values of the x and y inputs come from the 'inputs' SkData, which are laid out as a
  33. * struct with two float elements. If there are no inputs, the 'inputs' parameter may be null.
  34. *
  35. * In CPU rendering, a pointer to the input bytes is passed as the second parameter to
  36. * 'cpuFunc'.
  37. */
  38. sk_sp<SkColorFilter> make(sk_sp<SkData> inputs);
  39. private:
  40. int fIndex;
  41. SkString fSkSL;
  42. SkRuntimeColorFilterFn fCpuFunc;
  43. };
  44. #endif // SK_SUPPORT_GPU
  45. #endif // SkColorFilterPriv_DEFINED