1 /* 2 * Copyright 2017 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 SKSL_PIPELINESTAGECODEGENERATOR 9 #define SKSL_PIPELINESTAGECODEGENERATOR 10 11 #include "include/core/SkTypes.h" 12 13 #if defined(SKSL_STANDALONE) || defined(SK_GANESH) || defined(SK_GRAPHITE) 14 15 #include <string> 16 17 namespace SkSL { 18 19 struct Program; 20 class VarDeclaration; 21 22 namespace PipelineStage { 23 class Callbacks { 24 public: 25 virtual ~Callbacks() = default; 26 getMainName()27 virtual std::string getMainName() { return "main"; } getMangledName(const char * name)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; 33 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; 38 39 virtual std::string toLinearSrgb(std::string color) = 0; 40 virtual std::string fromLinearSrgb(std::string color) = 0; 41 }; 42 43 /* 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). 47 * 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. 58 */ 59 void ConvertProgram(const Program& program, 60 const char* sampleCoords, 61 const char* inputColor, 62 const char* destColor, 63 Callbacks* callbacks); 64 } // namespace PipelineStage 65 66 } // namespace SkSL 67 68 #endif 69 70 #endif 71