Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / sksl / tracing / SkVMDebugTrace.h
1 /*
2  * Copyright 2021 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 SKVMDEBUGTRACE
9 #define SKVMDEBUGTRACE
10
11 #include "include/sksl/SkSLDebugTrace.h"
12
13 #include "include/core/SkPoint.h"
14 #include "src/core/SkVM.h"
15 #include "src/sksl/ir/SkSLType.h"
16
17 #include <memory>
18 #include <stdint.h>
19 #include <string>
20 #include <vector>
21
22 class SkStream;
23 class SkWStream;
24
25 namespace SkSL {
26
27 struct SkVMSlotInfo {
28     /** The full name of this variable (without component): (e.g. `myArray[3].myStruct.myVector`) */
29     std::string             name;
30     /** The dimensions of this variable: 1x1 is a scalar, Nx1 is a vector, NxM is a matrix. */
31     uint8_t                 columns = 1, rows = 1;
32     /** Which component of the variable is this slot? (e.g. `vec4.z` is component 2) */
33     uint8_t                 componentIndex = 0;
34     /** Complex types (arrays/structs) can be tracked as a "group" of adjacent slots. */
35     int                     groupIndex = 0;
36     /** What kind of numbers belong in this slot? */
37     SkSL::Type::NumberKind  numberKind = SkSL::Type::NumberKind::kNonnumeric;
38     /** Where is this variable located in the program? */
39     int                     line;
40     /** If this slot holds a function's return value, its FunctionInfo index; if not, -1. */
41     int                     fnReturnValue;
42 };
43
44 struct SkVMFunctionInfo {
45     /** Full function declaration: `float myFunction(half4 color)`) */
46     std::string             name;
47 };
48
49 struct SkVMTraceInfo {
50     enum class Op {
51         kLine,  /** data: line number, (unused) */
52         kVar,   /** data: slot, value */
53         kEnter, /** data: function index, (unused) */
54         kExit,  /** data: function index, (unused) */
55         kScope, /** data: scope delta, (unused) */
56     };
57     Op op;
58     int32_t data[2];
59 };
60
61 class SkVMDebugTrace : public DebugTrace {
62 public:
63     /**
64      * Sets the device-coordinate pixel to trace. If it's not set, the point at (0, 0) will be used.
65      */
66     void setTraceCoord(const SkIPoint& coord);
67
68     /** Attaches the SkSL source to be debugged. */
69     void setSource(std::string source);
70
71     /** Serializes a debug trace to JSON which can be parsed by our debugger. */
72     bool readTrace(SkStream* r);
73     void writeTrace(SkWStream* w) const override;
74
75     /** Generates a human-readable dump of the debug trace. */
76     void dump(SkWStream* o) const override;
77
78     /** Returns a slot's component as a variable-name suffix, e.g. ".x" or "[2][2]". */
79     std::string getSlotComponentSuffix(int slotIndex) const;
80
81     /** Bit-casts a slot's value, then converts to text, e.g. "3.14" or "true" or "12345". */
82     std::string getSlotValue(int slotIndex, int32_t value) const;
83
84     /** Bit-casts a value for a given slot into a double, honoring the slot's NumberKind. */
85     double interpretValueBits(int slotIndex, int32_t valueBits) const;
86
87     /** Converts a numeric value into text, based on the slot's NumberKind. */
88     std::string slotValueToString(int slotIndex, double value) const;
89
90     /** The device-coordinate pixel to trace (controlled by setTraceCoord) */
91     SkIPoint fTraceCoord = {};
92
93     /** A 1:1 mapping of slot numbers to debug information. */
94     std::vector<SkVMSlotInfo> fSlotInfo;
95     std::vector<SkVMFunctionInfo> fFuncInfo;
96
97     /** The SkSL debug trace. */
98     std::vector<SkVMTraceInfo> fTraceInfo;
99
100     /** The SkSL code, split line-by-line. */
101     std::vector<std::string> fSource;
102
103     /**
104      * A trace hook which populates fTraceInfo during SkVM program evaluation. This will be created
105      * automatically by the SkSLVMCodeGenerator.
106      */
107     std::unique_ptr<skvm::TraceHook> fTraceHook;
108 };
109
110 }  // namespace SkSL
111
112 #endif