| 1 | /* |
|---|---|
| 2 | * Copyright 2018 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 | |
| 8 | #ifndef GrSkSLFP_DEFINED |
| 9 | #define GrSkSLFP_DEFINED |
| 10 | |
| 11 | #include "include/core/SkRefCnt.h" |
| 12 | #include "include/gpu/GrContextOptions.h" |
| 13 | #include "src/gpu/GrCaps.h" |
| 14 | #include "src/gpu/GrFragmentProcessor.h" |
| 15 | #include "src/sksl/SkSLCompiler.h" |
| 16 | #include "src/sksl/SkSLPipelineStageCodeGenerator.h" |
| 17 | #include <atomic> |
| 18 | |
| 19 | #if GR_TEST_UTILS |
| 20 | #define GR_FP_SRC_STRING const char* |
| 21 | #else |
| 22 | #define GR_FP_SRC_STRING static const char* |
| 23 | #endif |
| 24 | |
| 25 | class GrContext_Base; |
| 26 | class GrShaderCaps; |
| 27 | class SkData; |
| 28 | class SkRuntimeEffect; |
| 29 | |
| 30 | class GrSkSLFP : public GrFragmentProcessor { |
| 31 | public: |
| 32 | /** |
| 33 | * Creates a new fragment processor from an SkRuntimeEffect and a data blob containing values |
| 34 | * for all of the 'uniform' variables in the SkSL source. The layout of the uniforms blob is |
| 35 | * dictated by the SkRuntimeEffect. |
| 36 | */ |
| 37 | static std::unique_ptr<GrSkSLFP> Make(GrContext_Base* context, |
| 38 | sk_sp<SkRuntimeEffect> effect, |
| 39 | const char* name, |
| 40 | sk_sp<SkData> uniforms); |
| 41 | |
| 42 | const char* name() const override; |
| 43 | |
| 44 | void addChild(std::unique_ptr<GrFragmentProcessor> child); |
| 45 | |
| 46 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
| 47 | |
| 48 | private: |
| 49 | using ShaderErrorHandler = GrContextOptions::ShaderErrorHandler; |
| 50 | |
| 51 | GrSkSLFP(sk_sp<const GrShaderCaps> shaderCaps, ShaderErrorHandler* shaderErrorHandler, |
| 52 | sk_sp<SkRuntimeEffect> effect, const char* name, sk_sp<SkData> uniforms); |
| 53 | |
| 54 | GrSkSLFP(const GrSkSLFP& other); |
| 55 | |
| 56 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 57 | |
| 58 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
| 59 | |
| 60 | bool onIsEqual(const GrFragmentProcessor&) const override; |
| 61 | |
| 62 | sk_sp<const GrShaderCaps> fShaderCaps; |
| 63 | ShaderErrorHandler* fShaderErrorHandler; |
| 64 | |
| 65 | sk_sp<SkRuntimeEffect> fEffect; |
| 66 | const char* fName; |
| 67 | sk_sp<SkData> fUniforms; |
| 68 | |
| 69 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
| 70 | |
| 71 | typedef GrFragmentProcessor INHERITED; |
| 72 | |
| 73 | friend class GrGLSLSkSLFP; |
| 74 | |
| 75 | friend class GrSkSLFPFactory; |
| 76 | }; |
| 77 | |
| 78 | #endif |
| 79 |