/* * Copyright 2018 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef GrSkSLFP_DEFINED #define GrSkSLFP_DEFINED #include "include/core/SkRefCnt.h" #include "include/effects/SkRuntimeEffect.h" #include "include/gpu/GrContextOptions.h" #include "src/gpu/GrFragmentProcessor.h" #include class GrShaderCaps; class SkData; class SkRuntimeEffect; class GrSkSLFP : public GrFragmentProcessor { public: /** * Creates a new fragment processor from an SkRuntimeEffect and a data blob containing values * for all of the 'uniform' variables in the SkSL source. The layout of the uniforms blob is * dictated by the SkRuntimeEffect. */ static std::unique_ptr Make(sk_sp effect, const char* name, sk_sp uniforms); const char* name() const override; void addChild(std::unique_ptr child); std::unique_ptr clone() const override; private: GrSkSLFP(sk_sp effect, const char* name, sk_sp uniforms); GrSkSLFP(const GrSkSLFP& other); std::unique_ptr onMakeProgramImpl() const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; bool onIsEqual(const GrFragmentProcessor&) const override; SkPMColor4f constantOutputForConstantInput(const SkPMColor4f&) const override; sk_sp fEffect; const char* fName; sk_sp fUniforms; GR_DECLARE_FRAGMENT_PROCESSOR_TEST using INHERITED = GrFragmentProcessor; friend class GrGLSLSkSLFP; friend class GrSkSLFPFactory; }; class GrRuntimeFPBuilder : public SkRuntimeEffectBuilder> { public: ~GrRuntimeFPBuilder(); // NOTE: We use a static variable as a cache. CODE and MAKE must remain template parameters. template static GrRuntimeFPBuilder Make() { static const SkRuntimeEffect::Result gResult = MAKE(SkString(CODE)); #ifdef SK_DEBUG if (!gResult.effect) { SK_ABORT("Code failed: %s", gResult.errorText.c_str()); } #endif return GrRuntimeFPBuilder(gResult.effect); } std::unique_ptr makeFP(); private: explicit GrRuntimeFPBuilder(sk_sp); GrRuntimeFPBuilder(GrRuntimeFPBuilder&& that) = default; using INHERITED = SkRuntimeEffectBuilder>; }; #endif