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/private/SkSLString.h" 12 13 #if defined(SKSL_STANDALONE) || SK_SUPPORT_GPU 14 15 namespace SkSL { 16 17 struct Program; 18 class VarDeclaration; 19 20 namespace PipelineStage { 21 class Callbacks { 22 public: 23 virtual ~Callbacks() = default; 24 getMangledName(const char * name)25 virtual String getMangledName(const char* name) { return name; } 26 virtual void defineFunction(const char* declaration, const char* body, bool isMain) = 0; 27 virtual void declareFunction(const char* declaration) = 0; 28 virtual void defineStruct(const char* definition) = 0; 29 virtual void declareGlobal(const char* declaration) = 0; 30 31 virtual String declareUniform(const VarDeclaration*) = 0; 32 virtual String sampleShader(int index, String coords) = 0; 33 virtual String sampleColorFilter(int index, String color) = 0; 34 virtual String sampleBlender(int index, String src, String dst) = 0; 35 }; 36 37 /* 38 * Processes 'program' for use in a GrFragmentProcessor, or other context that wants SkSL-like 39 * code as input. To support fragment processor usage, there are callbacks that allow elements 40 * to be declared programmatically and to rename those elements (mangling to avoid collisions). 41 * 42 * - Any reference to the main coords builtin variable will be replaced with 'sampleCoords'. 43 * - Any reference to the input color builtin variable will be replaced with 'inputColor'. 44 * - Any reference to the dest color builtin variable will be replaced with 'destColor'. 45 * Dest-color is used in blend programs. 46 * - Each uniform variable declaration triggers a call to 'declareUniform', which should emit 47 * the declaration, and return the (possibly different) name to use for the variable. 48 * - Each function definition triggers a call to 'defineFunction', which should emit the 49 * definition, and return the (possibly different) name to use for calls to that function. 50 * - Each invocation of sample() triggers a call to 'sampleChild', which should return the full 51 * text of the call expression. 52 */ 53 void ConvertProgram(const Program& program, 54 const char* sampleCoords, 55 const char* inputColor, 56 const char* destColor, 57 Callbacks* callbacks); 58 } // namespace PipelineStage 59 60 } // namespace SkSL 61 62 #endif 63 64 #endif 65