8#ifndef GrSkSLFP_DEFINED
9#define GrSkSLFP_DEFINED
34namespace skgpu {
class KeyBuilder; }
46 template <
typename U>
struct add_a_UNIFORM_TYPE_specialization_for {};
47 static constexpr add_a_UNIFORM_TYPE_specialization_for<T>
value = {};
49#define UNIFORM_TYPE(E, ...) \
50 template <> struct GrFPUniformType<__VA_ARGS__> { \
51 static constexpr SkRuntimeEffect::Uniform::Type value = SkRuntimeEffect::Uniform::Type::E; \
53 template <> struct GrFPUniformType<SkSpan<__VA_ARGS__>> { \
54 static constexpr SkRuntimeEffect::Uniform::Type value = SkRuntimeEffect::Uniform::Type::E; \
57UNIFORM_TYPE(
kFloat,
float);
58UNIFORM_TYPE(kFloat2,
SkV2);
60UNIFORM_TYPE(kFloat4,
SkRect);
61UNIFORM_TYPE(kFloat4,
SkV4);
63UNIFORM_TYPE(kFloat4x4,
SkM44);
64UNIFORM_TYPE(kInt,
int);
82 return {condition,
value};
91 return {condition,
value};
95 std::unique_ptr<GrFragmentProcessor>
child;
98 return {std::move(child)};
105 kAll = kCompatibleWithCoverageAsAlpha | kPreservesOpaqueInput,
125 std::unique_ptr<GrFragmentProcessor> inputFP,
126 std::unique_ptr<GrFragmentProcessor> destColorFP,
128 SkSpan<std::unique_ptr<GrFragmentProcessor>> childFPs);
158 template <
typename... Args>
161 std::unique_ptr<GrFragmentProcessor> inputFP,
165 checkArgs(effect->fUniforms.begin(),
166 effect->fUniforms.end(),
167 effect->fChildren.begin(),
168 effect->fChildren.end(),
169 std::forward<Args>(
args)...);
174 SkASSERT(!effect->usesColorTransform());
176 size_t uniformPayloadSize = UniformPayloadSize(effect);
179 fp->appendArgs(
fp->uniformData(),
fp->specialized(), std::forward<Args>(
args)...);
181 fp->setInput(std::move(inputFP));
186 const char*
name()
const override {
return fName; }
187 std::unique_ptr<GrFragmentProcessor>
clone()
const override;
197 void addChild(std::unique_ptr<GrFragmentProcessor> child,
bool mergeOptFlags);
198 void setInput(std::unique_ptr<GrFragmentProcessor> input);
199 void setDestColorFP(std::unique_ptr<GrFragmentProcessor> destColorFP);
200 void addColorTransformChildren(
SkColorSpace* dstColorSpace);
202 std::unique_ptr<ProgramImpl> onMakeProgramImpl()
const override;
210 size_t uniformCount()
const {
return fEffect->
uniforms().size(); }
218 const uint8_t* uniformData()
const {
return reinterpret_cast<const uint8_t*
>(
this + 1); }
219 uint8_t* uniformData() {
return reinterpret_cast< uint8_t*
>(
this + 1); }
223 const Specialized* specialized()
const {
224 return reinterpret_cast<const Specialized*
>(this->uniformData() + fUniformSize);
226 Specialized* specialized() {
227 return reinterpret_cast<Specialized*
>(this->uniformData() + fUniformSize);
232 void appendArgs(uint8_t* uniformDataPtr, Specialized* specializedPtr) {
235 template <
typename... Args>
236 void appendArgs(uint8_t* uniformDataPtr,
237 Specialized* specializedPtr,
239 std::unique_ptr<GrFragmentProcessor>&& child,
240 Args&&... remainder) {
243 this->addChild(std::move(child),
true);
244 this->appendArgs(uniformDataPtr, specializedPtr, std::forward<Args>(remainder)...);
247 template <
typename... Args>
248 void appendArgs(uint8_t* uniformDataPtr,
249 Specialized* specializedPtr,
251 GrIgnoreOptFlags&& child,
252 Args&&... remainder) {
255 this->addChild(std::move(child.child),
false);
256 this->appendArgs(uniformDataPtr, specializedPtr, std::forward<Args>(remainder)...);
258 template <
typename T,
typename... Args>
259 void appendArgs(uint8_t* uniformDataPtr,
260 Specialized* specializedPtr,
262 const GrSpecializedUniform<T>& val,
263 Args&&... remainder) {
269 if (val.specialize) {
273 uniformDataPtr, specializedPtr,
name, val.value, std::forward<Args>(remainder)...);
275 template <
typename T,
typename... Args>
276 void appendArgs(uint8_t* uniformDataPtr,
277 Specialized* specializedPtr,
279 const GrOptionalUniform<T>& val,
280 Args&&... remainder) {
284 memcpy(uniformDataPtr, &val.value,
sizeof(val.value));
285 uniformDataPtr +=
sizeof(val.value);
289 this->appendArgs(uniformDataPtr, specializedPtr, std::forward<Args>(remainder)...);
291 template <
typename T,
typename... Args>
292 void appendArgs(uint8_t* uniformDataPtr,
293 Specialized* specializedPtr,
296 Args&&... remainder) {
302 this->appendArgs(uniformDataPtr, specializedPtr, std::forward<Args>(remainder)...);
304 template <
typename T,
typename... Args>
305 void appendArgs(uint8_t* uniformDataPtr,
306 Specialized* specializedPtr,
309 Args&&... remainder) {
312 memcpy(uniformDataPtr, &val,
sizeof(val));
313 uniformDataPtr +=
sizeof(val);
315 this->appendArgs(uniformDataPtr, specializedPtr, std::forward<Args>(remainder)...);
319 using child_iterator = std::vector<SkRuntimeEffect::Child>::const_iterator;
320 using uniform_iterator = std::vector<SkRuntimeEffect::Uniform>::const_iterator;
323 static void checkArgs(uniform_iterator uIter,
324 uniform_iterator uEnd,
325 child_iterator cIter,
326 child_iterator cEnd) {
328 "Expected more uniforms, starting with '%.*s'",
329 (
int)uIter->name.size(), uIter->name.data());
330 SkASSERTF(cIter == cEnd,
"Expected more children, starting with '%.*s'",
331 (
int)cIter->name.size(), cIter->name.data());
333 static void checkOneChild(child_iterator cIter, child_iterator cEnd,
const char*
name) {
334 SkASSERTF(cIter != cEnd,
"Too many children, wasn't expecting '%s'",
name);
336 "Expected child '%.*s', got '%s' instead",
337 (
int)cIter->name.size(), cIter->name.data(),
name);
339 template <
typename... Args>
340 static void checkArgs(uniform_iterator uIter,
341 uniform_iterator uEnd,
342 child_iterator cIter,
345 std::unique_ptr<GrFragmentProcessor>&& child,
346 Args&&... remainder) {
350 checkOneChild(cIter, cEnd,
name);
351 checkArgs(uIter, uEnd, ++cIter, cEnd, std::forward<Args>(remainder)...);
353 template <
typename... Args>
354 static void checkArgs(uniform_iterator uIter,
355 uniform_iterator uEnd,
356 child_iterator cIter,
359 GrIgnoreOptFlags&& child,
360 Args&&... remainder) {
364 checkOneChild(cIter, cEnd,
name);
365 checkArgs(uIter, uEnd, ++cIter, cEnd, std::forward<Args>(remainder)...);
367 template <
typename T,
typename... Args>
368 static void checkArgs(uniform_iterator uIter,
369 uniform_iterator uEnd,
370 child_iterator cIter,
373 const GrSpecializedUniform<T>& val,
374 Args&&... remainder) {
376 checkArgs(uIter, uEnd, cIter, cEnd,
name, val.value, std::forward<Args>(remainder)...);
378 template <
typename T,
typename... Args>
379 static void checkArgs(uniform_iterator uIter,
380 uniform_iterator uEnd,
381 child_iterator cIter,
384 const GrOptionalUniform<T>& val,
385 Args&&... remainder) {
387 checkArgs(uIter, uEnd, cIter, cEnd,
name, val.value, std::forward<Args>(remainder)...);
389 checkArgs(uIter, uEnd, cIter, cEnd, std::forward<Args>(remainder)...);
392 template <
typename T>
393 static void checkOneUniform(uniform_iterator uIter,
394 uniform_iterator uEnd,
398 SkASSERTF(uIter != uEnd,
"Too many uniforms, wasn't expecting '%s'",
name);
400 "Expected uniform '%.*s', got '%s' instead",
401 (
int)uIter->name.size(), uIter->name.data(),
name);
402 SkASSERTF(uIter->sizeInBytes() == valSize,
403 "Expected uniform '%s' to be %zu bytes, got %zu instead",
404 name, uIter->sizeInBytes(), valSize);
406 "Wrong type for uniform '%s'",
409 template <
typename T,
typename... Args>
410 static void checkArgs(uniform_iterator uIter,
411 uniform_iterator uEnd,
412 child_iterator cIter,
416 Args&&... remainder) {
418 checkArgs(++uIter, uEnd, cIter, cEnd, std::forward<Args>(remainder)...);
420 template <
typename T,
typename... Args>
421 static void checkArgs(uniform_iterator uIter,
422 uniform_iterator uEnd,
423 child_iterator cIter,
427 Args&&... remainder) {
428 checkOneUniform(uIter, uEnd,
name, &val,
sizeof(val));
429 checkArgs(++uIter, uEnd, cIter, cEnd, std::forward<Args>(remainder)...);
435 uint32_t fUniformSize;
436 int fInputChildIndex = -1;
437 int fDestColorChildIndex = -1;
438 int fToLinearSrgbChildIndex = -1;
439 int fFromLinearSrgbChildIndex = -1;
#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
#define GR_MAKE_BITFIELD_CLASS_OPS(X)
#define SkASSERTF(cond, fmt,...)
#define INHERITED(method,...)
sk_sp< T > sk_ref_sp(T *obj)
GrFragmentProcessor(ClassID classID, OptimizationFlags optimizationFlags)
@ kNone_OptimizationFlags
@ kPreservesOpaqueInput_OptimizationFlag
@ kCompatibleWithCoverageAsAlpha_OptimizationFlag
std::unique_ptr< GrFragmentProcessor > clone() const override
static GrSpecializedUniform< T > SpecializeIf(bool condition, const T &value)
static std::unique_ptr< GrSkSLFP > MakeWithData(sk_sp< SkRuntimeEffect > effect, const char *name, sk_sp< SkColorSpace > dstColorSpace, std::unique_ptr< GrFragmentProcessor > inputFP, std::unique_ptr< GrFragmentProcessor > destColorFP, const sk_sp< const SkData > &uniforms, SkSpan< std::unique_ptr< GrFragmentProcessor > > childFPs)
static GrIgnoreOptFlags IgnoreOptFlags(std::unique_ptr< GrFragmentProcessor > child)
const char * name() const override
static std::unique_ptr< GrSkSLFP > Make(const SkRuntimeEffect *effect, const char *name, std::unique_ptr< GrFragmentProcessor > inputFP, OptFlags optFlags, Args &&... args)
friend class GrSkSLFPFactory
static GrSpecializedUniform< T > Specialize(const T &value)
static GrOptionalUniform< T > When(bool condition, const T &value)
size_t uniformSize() const
SkSpan< const Uniform > uniforms() const
constexpr T * data() const
constexpr size_t size_bytes() const
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
std::unique_ptr< GrFragmentProcessor > child