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