Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / sksl / codegen / SkSLVMCodeGenerator.h
1 /*
2  * Copyright 2020 Google LLC
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_VMGENERATOR
9 #define SKSL_VMGENERATOR
10
11 #include "src/core/SkVM.h"
12 #include "src/sksl/ir/SkSLType.h"
13
14 #include <memory>
15 #include <string>
16 #include <vector>
17
18 template <typename T> class SkSpan;
19
20 namespace SkSL {
21
22 class FunctionDefinition;
23 struct Program;
24 class SkVMDebugTrace;
25
26 class SkVMCallbacks {
27 public:
28     virtual ~SkVMCallbacks() = default;
29
30     virtual skvm::Color sampleShader(int index, skvm::Coord coord) = 0;
31     virtual skvm::Color sampleColorFilter(int index, skvm::Color color) = 0;
32     virtual skvm::Color sampleBlender(int index, skvm::Color src, skvm::Color dst) = 0;
33
34     virtual skvm::Color toLinearSrgb(skvm::Color color) = 0;
35     virtual skvm::Color fromLinearSrgb(skvm::Color color) = 0;
36 };
37
38 // Convert 'function' to skvm instructions in 'builder', for use by blends, shaders, & color filters
39 skvm::Color ProgramToSkVM(const Program& program,
40                           const FunctionDefinition& function,
41                           skvm::Builder* builder,
42                           SkVMDebugTrace* debugTrace,
43                           SkSpan<skvm::Val> uniforms,
44                           skvm::Coord device,
45                           skvm::Coord local,
46                           skvm::Color inputColor,
47                           skvm::Color destColor,
48                           SkVMCallbacks* callbacks);
49
50 struct SkVMSignature {
51     size_t fParameterSlots = 0;
52     size_t fReturnSlots    = 0;
53 };
54
55 /*
56  * Converts 'function' to skvm instructions in 'builder'. Always adds one arg per value in the
57  * parameter list, then one per value in the return type. For example:
58  *
59  *   float2 fn(float2 a, float b) { ... }
60  *
61  * ... is mapped so that it can be called as:
62  *
63  *   p.eval(N, &a.x, &a.y, &b, &return.x, &return.y);
64  *
65  * The number of parameter and return slots (pointers) is placed in 'outSignature', if provided.
66  * If the program declares any uniforms, 'uniforms' should contain the IDs of each individual value
67  * (eg, one ID per component of a vector).
68  */
69 bool ProgramToSkVM(const Program& program,
70                    const FunctionDefinition& function,
71                    skvm::Builder* b,
72                    SkVMDebugTrace* debugTrace,
73                    SkSpan<skvm::Val> uniforms,
74                    SkVMSignature* outSignature = nullptr);
75
76 const FunctionDefinition* Program_GetFunction(const Program& program, const char* function);
77
78 struct UniformInfo {
79     struct Uniform {
80         std::string fName;
81         Type::NumberKind fKind;
82         int fColumns;
83         int fRows;
84         int fSlot;
85     };
86     std::vector<Uniform> fUniforms;
87     int fUniformSlotCount = 0;
88 };
89
90 std::unique_ptr<UniformInfo> Program_GetUniformInfo(const Program& program);
91
92 bool testingOnly_ProgramToSkVMShader(const Program& program,
93                                      skvm::Builder* builder,
94                                      SkVMDebugTrace* debugTrace);
95
96 }  // namespace SkSL
97
98 #endif