2 * Copyright 2017 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SKSL_PIPELINESTAGECODEGENERATOR
9 #define SKSL_PIPELINESTAGECODEGENERATOR
11 #include "include/core/SkTypes.h"
13 #if defined(SKSL_STANDALONE) || SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED)
22 namespace PipelineStage {
25 virtual ~Callbacks() = default;
27 virtual std::string getMainName() { return "main"; }
28 virtual std::string getMangledName(const char* name) { return name; }
29 virtual void defineFunction(const char* declaration, const char* body, bool isMain) = 0;
30 virtual void declareFunction(const char* declaration) = 0;
31 virtual void defineStruct(const char* definition) = 0;
32 virtual void declareGlobal(const char* declaration) = 0;
34 virtual std::string declareUniform(const VarDeclaration*) = 0;
35 virtual std::string sampleShader(int index, std::string coords) = 0;
36 virtual std::string sampleColorFilter(int index, std::string color) = 0;
37 virtual std::string sampleBlender(int index, std::string src, std::string dst) = 0;
39 virtual std::string toLinearSrgb(std::string color) = 0;
40 virtual std::string fromLinearSrgb(std::string color) = 0;
44 * Processes 'program' for use in a GrFragmentProcessor, or other context that wants SkSL-like
45 * code as input. To support fragment processor usage, there are callbacks that allow elements
46 * to be declared programmatically and to rename those elements (mangling to avoid collisions).
48 * - Any reference to the main coords builtin variable will be replaced with 'sampleCoords'.
49 * - Any reference to the input color builtin variable will be replaced with 'inputColor'.
50 * - Any reference to the dest color builtin variable will be replaced with 'destColor'.
51 * Dest-color is used in blend programs.
52 * - Each uniform variable declaration triggers a call to 'declareUniform', which should emit
53 * the declaration, and return the (possibly different) name to use for the variable.
54 * - Each function definition triggers a call to 'defineFunction', which should emit the
55 * definition, and return the (possibly different) name to use for calls to that function.
56 * - Each invocation of sample() triggers a call to 'sampleChild', which should return the full
57 * text of the call expression.
59 void ConvertProgram(const Program& program,
60 const char* sampleCoords,
61 const char* inputColor,
62 const char* destColor,
63 Callbacks* callbacks);
64 } // namespace PipelineStage