• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 #include <cstddef>
14 
15 template <typename T> class SkSpan;
16 
17 namespace SkSL {
18 
19 class FunctionDefinition;
20 struct Program;
21 class SkVMDebugTrace;
22 
23 class SkVMCallbacks {
24 public:
25     virtual ~SkVMCallbacks() = default;
26 
27     virtual skvm::Color sampleShader(int index, skvm::Coord coord) = 0;
28     virtual skvm::Color sampleColorFilter(int index, skvm::Color color) = 0;
29     virtual skvm::Color sampleBlender(int index, skvm::Color src, skvm::Color dst) = 0;
30 
31     virtual skvm::Color toLinearSrgb(skvm::Color color) = 0;
32     virtual skvm::Color fromLinearSrgb(skvm::Color color) = 0;
33 };
34 
35 // Convert 'function' to skvm instructions in 'builder', for use by blends, shaders, & color filters
36 skvm::Color ProgramToSkVM(const Program& program,
37                           const FunctionDefinition& function,
38                           skvm::Builder* builder,
39                           SkVMDebugTrace* debugTrace,
40                           SkSpan<skvm::Val> uniforms,
41                           skvm::Coord device,
42                           skvm::Coord local,
43                           skvm::Color inputColor,
44                           skvm::Color destColor,
45                           SkVMCallbacks* callbacks);
46 
47 struct SkVMSignature {
48     size_t fParameterSlots = 0;
49     size_t fReturnSlots    = 0;
50 };
51 
52 /*
53  * Converts 'function' to skvm instructions in 'builder'. Always adds one arg per value in the
54  * parameter list, then one per value in the return type. For example:
55  *
56  *   float2 fn(float2 a, float b) { ... }
57  *
58  * ... is mapped so that it can be called as:
59  *
60  *   p.eval(N, &a.x, &a.y, &b, &return.x, &return.y);
61  *
62  * The number of parameter and return slots (pointers) is placed in 'outSignature', if provided.
63  * If the program declares any uniforms, 'uniforms' should contain the IDs of each individual value
64  * (eg, one ID per component of a vector).
65  */
66 bool ProgramToSkVM(const Program& program,
67                    const FunctionDefinition& function,
68                    skvm::Builder* b,
69                    SkVMDebugTrace* debugTrace,
70                    SkSpan<skvm::Val> uniforms,
71                    SkVMSignature* outSignature = nullptr);
72 
73 bool testingOnly_ProgramToSkVMShader(const Program& program,
74                                      skvm::Builder* builder,
75                                      SkVMDebugTrace* debugTrace);
76 
77 }  // namespace SkSL
78 
79 #endif
80