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