react-native-skia 2.15.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/CMakeLists.txt +1 -0
- package/android/build.gradle +17 -0
- package/android/cpp/jni/include/JniSkiaBaseView.h +9 -4
- package/android/cpp/jni/include/JniSkiaGraphiteView.h +2 -2
- package/android/cpp/jni/include/JniSkiaPictureView.h +1 -12
- package/cpp/api/recorder/ColorFilters.h +1 -0
- package/cpp/api/recorder/Convertor.h +39 -11
- package/cpp/api/recorder/DataTypes.h +12 -0
- package/cpp/api/recorder/DrawingCtx.h +14 -0
- package/cpp/api/recorder/Drawings.h +5 -0
- package/cpp/api/recorder/PathEffects.h +8 -0
- package/cpp/api/recorder/RNRecorder.h +68 -11
- package/cpp/api/recorder/Shaders.h +3 -0
- package/cpp/dawn/include/dawn/dawn_proc.h +53 -0
- package/cpp/dawn/include/dawn/dawn_proc_table.h +329 -0
- package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +47 -0
- package/cpp/dawn/include/dawn/dawn_version.h +41 -0
- package/cpp/dawn/include/dawn/native/D3D11Backend.h +65 -0
- package/cpp/dawn/include/dawn/native/D3D12Backend.h +104 -0
- package/cpp/dawn/include/dawn/native/D3DBackend.h +56 -0
- package/cpp/dawn/include/dawn/native/DawnNative.h +367 -0
- package/cpp/dawn/include/dawn/native/MetalBackend.h +56 -0
- package/cpp/dawn/include/dawn/native/NullBackend.h +39 -0
- package/cpp/dawn/include/dawn/native/OpenGLBackend.h +89 -0
- package/cpp/dawn/include/dawn/native/VulkanBackend.h +183 -0
- package/cpp/dawn/include/dawn/native/WebGPUBackend.h +49 -0
- package/cpp/dawn/include/dawn/native/dawn_native_export.h +49 -0
- package/cpp/dawn/include/dawn/platform/DawnPlatform.h +211 -0
- package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +49 -0
- package/cpp/dawn/include/dawn/replay/Replay.h +99 -0
- package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +49 -0
- package/cpp/dawn/include/dawn/webgpu_cpp_print.h +2868 -0
- package/cpp/dawn/include/tint/tint.h +91 -0
- package/cpp/dawn/include/webgpu/webgpu.h +5063 -0
- package/cpp/dawn/include/webgpu/webgpu_cpp.h +10401 -0
- package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +57 -0
- package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +163 -0
- package/cpp/dawn/include/webgpu/webgpu_glfw.h +88 -0
- package/cpp/rnskia/RNDawnContext.h +6 -0
- package/cpp/rnskia/RNSkGraphiteProducer.cpp +189 -0
- package/cpp/rnskia/RNSkGraphiteProducer.h +116 -0
- package/cpp/rnskia/RNSkGraphiteView.h +129 -24
- package/cpp/rnskia/RNSkJsiViewApi.h +2 -6
- package/cpp/rnskia/RNSkPictureView.cpp +22 -11
- package/cpp/rnskia/RNSkPictureView.h +24 -11
- package/cpp/rnskia/RNSkThreadPool.h +91 -0
- package/cpp/rnskia/RNSkView.h +18 -0
- package/cpp/skia/src/gpu/graphite/ContextOptionsPriv.h +45 -0
- package/cpp/skia/src/gpu/graphite/ResourceTypes.h +362 -0
- package/cpp/skia/src/gpu/graphite/TextureProxyView.h +105 -0
- package/lib/commonjs/index.d.ts +4 -1
- package/lib/commonjs/index.js +31 -12
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mock/index.js +1 -0
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +10 -1
- package/lib/commonjs/renderer/Canvas.js +37 -10
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/DefaultCanvas.d.ts +8 -0
- package/lib/commonjs/renderer/DefaultCanvas.js +42 -0
- package/lib/commonjs/renderer/DefaultCanvas.js.map +1 -0
- package/lib/commonjs/renderer/GraphiteCanvas.d.ts +22 -0
- package/lib/commonjs/renderer/GraphiteCanvas.js +64 -0
- package/lib/commonjs/renderer/GraphiteCanvas.js.map +1 -0
- package/lib/commonjs/renderer/GraphiteCanvas.web.d.ts +1 -0
- package/lib/commonjs/renderer/GraphiteCanvas.web.js +13 -0
- package/lib/commonjs/renderer/GraphiteCanvas.web.js.map +1 -0
- package/lib/module/index.d.ts +4 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/mock/index.js +1 -0
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +10 -1
- package/lib/module/renderer/Canvas.js +35 -9
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/DefaultCanvas.d.ts +8 -0
- package/lib/module/renderer/DefaultCanvas.js +34 -0
- package/lib/module/renderer/DefaultCanvas.js.map +1 -0
- package/lib/module/renderer/GraphiteCanvas.d.ts +22 -0
- package/lib/module/renderer/GraphiteCanvas.js +57 -0
- package/lib/module/renderer/GraphiteCanvas.js.map +1 -0
- package/lib/module/renderer/GraphiteCanvas.web.d.ts +1 -0
- package/lib/module/renderer/GraphiteCanvas.web.js +4 -0
- package/lib/module/renderer/GraphiteCanvas.web.js.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +10 -1
- package/lib/typescript/src/renderer/DefaultCanvas.d.ts +8 -0
- package/lib/typescript/src/renderer/GraphiteCanvas.d.ts +22 -0
- package/lib/typescript/src/renderer/GraphiteCanvas.web.d.ts +1 -0
- package/libs/.graphite +1 -0
- package/package.json +7 -8
- package/react-native-skia.podspec +18 -1
- package/src/index.ts +4 -1
- package/src/mock/index.ts +1 -0
- package/src/renderer/Canvas.tsx +29 -9
- package/src/renderer/DefaultCanvas.tsx +41 -0
- package/src/renderer/GraphiteCanvas.tsx +61 -0
- package/src/renderer/GraphiteCanvas.web.tsx +3 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright 2023 The Dawn & Tint Authors
|
|
2
|
+
//
|
|
3
|
+
// Redistribution and use in source and binary forms, with or without
|
|
4
|
+
// modification, are permitted provided that the following conditions are met:
|
|
5
|
+
//
|
|
6
|
+
// 1. Redistributions of source code must retain the above copyright notice, this
|
|
7
|
+
// list of conditions and the following disclaimer.
|
|
8
|
+
//
|
|
9
|
+
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
// this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
// and/or other materials provided with the distribution.
|
|
12
|
+
//
|
|
13
|
+
// 3. Neither the name of the copyright holder nor the names of its
|
|
14
|
+
// contributors may be used to endorse or promote products derived from
|
|
15
|
+
// this software without specific prior written permission.
|
|
16
|
+
//
|
|
17
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
18
|
+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
19
|
+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
21
|
+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
22
|
+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
23
|
+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
24
|
+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
25
|
+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
|
|
28
|
+
#ifdef __EMSCRIPTEN__
|
|
29
|
+
#error "Do not include this header. Use the headers provided by Emdawnwebgpu instead."
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
#ifndef WEBGPU_CPP_CHAINED_STRUCT_H_
|
|
33
|
+
#define WEBGPU_CPP_CHAINED_STRUCT_H_
|
|
34
|
+
|
|
35
|
+
#include <cstddef>
|
|
36
|
+
#include <cstdint>
|
|
37
|
+
|
|
38
|
+
// This header file declares the ChainedStruct structures separately from the WebGPU
|
|
39
|
+
// headers so that dependencies can directly extend structures without including the larger header
|
|
40
|
+
// which exposes capabilities that may require correctly set proc tables.
|
|
41
|
+
namespace wgpu {
|
|
42
|
+
|
|
43
|
+
enum class SType : uint32_t;
|
|
44
|
+
|
|
45
|
+
struct ChainedStruct {
|
|
46
|
+
ChainedStruct const * nextInChain = nullptr;
|
|
47
|
+
SType sType = SType(0u);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
struct ChainedStructOut {
|
|
51
|
+
ChainedStructOut * nextInChain = nullptr;
|
|
52
|
+
SType sType = SType(0u);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace wgpu}
|
|
56
|
+
|
|
57
|
+
#endif // WEBGPU_CPP_CHAINED_STRUCT_H_
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// Copyright 2017 The Dawn & Tint Authors
|
|
2
|
+
//
|
|
3
|
+
// Redistribution and use in source and binary forms, with or without
|
|
4
|
+
// modification, are permitted provided that the following conditions are met:
|
|
5
|
+
//
|
|
6
|
+
// 1. Redistributions of source code must retain the above copyright notice, this
|
|
7
|
+
// list of conditions and the following disclaimer.
|
|
8
|
+
//
|
|
9
|
+
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
// this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
// and/or other materials provided with the distribution.
|
|
12
|
+
//
|
|
13
|
+
// 3. Neither the name of the copyright holder nor the names of its
|
|
14
|
+
// contributors may be used to endorse or promote products derived from
|
|
15
|
+
// this software without specific prior written permission.
|
|
16
|
+
//
|
|
17
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
18
|
+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
19
|
+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
21
|
+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
22
|
+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
23
|
+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
24
|
+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
25
|
+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
|
|
28
|
+
#ifndef WEBGPU_ENUM_CLASS_BITMASKS_H_
|
|
29
|
+
#define WEBGPU_ENUM_CLASS_BITMASKS_H_
|
|
30
|
+
|
|
31
|
+
#include <type_traits>
|
|
32
|
+
|
|
33
|
+
// The operators in wgpu:: namespace need be introduced into other namespaces with
|
|
34
|
+
// using-declarations for C++ Argument Dependent Lookup to work.
|
|
35
|
+
#define WGPU_IMPORT_BITMASK_OPERATORS \
|
|
36
|
+
using wgpu::operator|; \
|
|
37
|
+
using wgpu::operator&; \
|
|
38
|
+
using wgpu::operator^; \
|
|
39
|
+
using wgpu::operator~; \
|
|
40
|
+
using wgpu::operator&=; \
|
|
41
|
+
using wgpu::operator|=; \
|
|
42
|
+
using wgpu::operator^=; \
|
|
43
|
+
using wgpu::HasZeroOrOneBits;
|
|
44
|
+
|
|
45
|
+
namespace wgpu {
|
|
46
|
+
|
|
47
|
+
template <typename T>
|
|
48
|
+
struct IsWGPUBitmask {
|
|
49
|
+
static constexpr bool enable = false;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
template <typename T, typename Enable = void>
|
|
53
|
+
struct LowerBitmask {
|
|
54
|
+
static constexpr bool enable = false;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
template <typename T>
|
|
58
|
+
struct LowerBitmask<T, typename std::enable_if<IsWGPUBitmask<T>::enable>::type> {
|
|
59
|
+
static constexpr bool enable = true;
|
|
60
|
+
using type = T;
|
|
61
|
+
constexpr static T Lower(T t) { return t; }
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
template <typename T>
|
|
65
|
+
struct BoolConvertible {
|
|
66
|
+
using Integral = typename std::underlying_type<T>::type;
|
|
67
|
+
|
|
68
|
+
explicit constexpr BoolConvertible(Integral value) : value(value) {}
|
|
69
|
+
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
70
|
+
constexpr operator bool() const { return value != 0; }
|
|
71
|
+
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
72
|
+
constexpr operator T() const { return static_cast<T>(value); }
|
|
73
|
+
|
|
74
|
+
Integral value;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
template <typename T>
|
|
78
|
+
struct LowerBitmask<BoolConvertible<T>> {
|
|
79
|
+
static constexpr bool enable = true;
|
|
80
|
+
using type = T;
|
|
81
|
+
static constexpr type Lower(BoolConvertible<T> t) { return t; }
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
template <
|
|
85
|
+
typename T1,
|
|
86
|
+
typename T2,
|
|
87
|
+
typename = typename std::enable_if<LowerBitmask<T1>::enable && LowerBitmask<T2>::enable>::type>
|
|
88
|
+
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator|(T1 left, T2 right) {
|
|
89
|
+
using T = typename LowerBitmask<T1>::type;
|
|
90
|
+
using Integral = typename std::underlying_type<T>::type;
|
|
91
|
+
return BoolConvertible<T>(static_cast<Integral>(LowerBitmask<T1>::Lower(left)) |
|
|
92
|
+
static_cast<Integral>(LowerBitmask<T2>::Lower(right)));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
template <
|
|
96
|
+
typename T1,
|
|
97
|
+
typename T2,
|
|
98
|
+
typename = typename std::enable_if<LowerBitmask<T1>::enable && LowerBitmask<T2>::enable>::type>
|
|
99
|
+
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator&(T1 left, T2 right) {
|
|
100
|
+
using T = typename LowerBitmask<T1>::type;
|
|
101
|
+
using Integral = typename std::underlying_type<T>::type;
|
|
102
|
+
return BoolConvertible<T>(static_cast<Integral>(LowerBitmask<T1>::Lower(left)) &
|
|
103
|
+
static_cast<Integral>(LowerBitmask<T2>::Lower(right)));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
template <
|
|
107
|
+
typename T1,
|
|
108
|
+
typename T2,
|
|
109
|
+
typename = typename std::enable_if<LowerBitmask<T1>::enable && LowerBitmask<T2>::enable>::type>
|
|
110
|
+
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator^(T1 left, T2 right) {
|
|
111
|
+
using T = typename LowerBitmask<T1>::type;
|
|
112
|
+
using Integral = typename std::underlying_type<T>::type;
|
|
113
|
+
return BoolConvertible<T>(static_cast<Integral>(LowerBitmask<T1>::Lower(left)) ^
|
|
114
|
+
static_cast<Integral>(LowerBitmask<T2>::Lower(right)));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
template <typename T1>
|
|
118
|
+
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator~(T1 t) {
|
|
119
|
+
using T = typename LowerBitmask<T1>::type;
|
|
120
|
+
using Integral = typename std::underlying_type<T>::type;
|
|
121
|
+
return BoolConvertible<T>(
|
|
122
|
+
static_cast<Integral>(~static_cast<Integral>(LowerBitmask<T1>::Lower(t))));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
template <
|
|
126
|
+
typename T,
|
|
127
|
+
typename T2,
|
|
128
|
+
typename = typename std::enable_if<IsWGPUBitmask<T>::enable && LowerBitmask<T2>::enable>::type>
|
|
129
|
+
constexpr T& operator&=(T& l, T2 right) {
|
|
130
|
+
T r = LowerBitmask<T2>::Lower(right);
|
|
131
|
+
l = l & r;
|
|
132
|
+
return l;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
template <
|
|
136
|
+
typename T,
|
|
137
|
+
typename T2,
|
|
138
|
+
typename = typename std::enable_if<IsWGPUBitmask<T>::enable && LowerBitmask<T2>::enable>::type>
|
|
139
|
+
constexpr T& operator|=(T& l, T2 right) {
|
|
140
|
+
T r = LowerBitmask<T2>::Lower(right);
|
|
141
|
+
l = l | r;
|
|
142
|
+
return l;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
template <
|
|
146
|
+
typename T,
|
|
147
|
+
typename T2,
|
|
148
|
+
typename = typename std::enable_if<IsWGPUBitmask<T>::enable && LowerBitmask<T2>::enable>::type>
|
|
149
|
+
constexpr T& operator^=(T& l, T2 right) {
|
|
150
|
+
T r = LowerBitmask<T2>::Lower(right);
|
|
151
|
+
l = l ^ r;
|
|
152
|
+
return l;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
template <typename T>
|
|
156
|
+
constexpr bool HasZeroOrOneBits(T value) {
|
|
157
|
+
using Integral = typename std::underlying_type<T>::type;
|
|
158
|
+
return (static_cast<Integral>(value) & (static_cast<Integral>(value) - 1)) == 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
} // namespace wgpu
|
|
162
|
+
|
|
163
|
+
#endif // WEBGPU_ENUM_CLASS_BITMASKS_H_
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright 2022 The Dawn & Tint Authors
|
|
2
|
+
//
|
|
3
|
+
// Redistribution and use in source and binary forms, with or without
|
|
4
|
+
// modification, are permitted provided that the following conditions are met:
|
|
5
|
+
//
|
|
6
|
+
// 1. Redistributions of source code must retain the above copyright notice, this
|
|
7
|
+
// list of conditions and the following disclaimer.
|
|
8
|
+
//
|
|
9
|
+
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
// this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
// and/or other materials provided with the distribution.
|
|
12
|
+
//
|
|
13
|
+
// 3. Neither the name of the copyright holder nor the names of its
|
|
14
|
+
// contributors may be used to endorse or promote products derived from
|
|
15
|
+
// this software without specific prior written permission.
|
|
16
|
+
//
|
|
17
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
18
|
+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
19
|
+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
21
|
+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
22
|
+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
23
|
+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
24
|
+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
25
|
+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
|
|
28
|
+
#ifndef INCLUDE_WEBGPU_WEBGPU_GLFW_H_
|
|
29
|
+
#define INCLUDE_WEBGPU_WEBGPU_GLFW_H_
|
|
30
|
+
|
|
31
|
+
#ifdef __cplusplus
|
|
32
|
+
#include <memory>
|
|
33
|
+
|
|
34
|
+
#include "webgpu/webgpu_cpp.h"
|
|
35
|
+
#else
|
|
36
|
+
#include "webgpu/webgpu.h"
|
|
37
|
+
#endif
|
|
38
|
+
|
|
39
|
+
#if defined(WGPU_GLFW_SHARED_LIBRARY)
|
|
40
|
+
#if defined(_WIN32)
|
|
41
|
+
#if defined(WGPU_GLFW_IMPLEMENTATION)
|
|
42
|
+
#define WGPU_GLFW_EXPORT __declspec(dllexport)
|
|
43
|
+
#else
|
|
44
|
+
#define WGPU_GLFW_EXPORT __declspec(dllimport)
|
|
45
|
+
#endif
|
|
46
|
+
#else // defined(_WIN32)
|
|
47
|
+
#if defined(WGPU_GLFW_IMPLEMENTATION)
|
|
48
|
+
#define WGPU_GLFW_EXPORT __attribute__((visibility("default")))
|
|
49
|
+
#else
|
|
50
|
+
#define WGPU_GLFW_EXPORT
|
|
51
|
+
#endif
|
|
52
|
+
#endif // defined(_WIN32)
|
|
53
|
+
#else // defined(WGPU_GLFW_SHARED_LIBRARY)
|
|
54
|
+
#define WGPU_GLFW_EXPORT
|
|
55
|
+
#endif // defined(WGPU_GLFW_SHARED_LIBRARY)
|
|
56
|
+
|
|
57
|
+
struct GLFWwindow;
|
|
58
|
+
|
|
59
|
+
#ifdef __cplusplus
|
|
60
|
+
extern "C" {
|
|
61
|
+
#endif
|
|
62
|
+
|
|
63
|
+
WGPU_GLFW_EXPORT WGPUSurface wgpuGlfwCreateSurfaceForWindow(const WGPUInstance instance,
|
|
64
|
+
struct GLFWwindow* window);
|
|
65
|
+
|
|
66
|
+
#ifdef __cplusplus
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
namespace wgpu::glfw {
|
|
70
|
+
|
|
71
|
+
// Does the necessary setup on the GLFWwindow to allow creating a wgpu::Surface with it and
|
|
72
|
+
// calls `instance.CreateSurface` with the correct descriptor for this window.
|
|
73
|
+
// Returns a null wgpu::Surface on failure.
|
|
74
|
+
WGPU_GLFW_EXPORT wgpu::Surface CreateSurfaceForWindow(const wgpu::Instance& instance,
|
|
75
|
+
GLFWwindow* window);
|
|
76
|
+
|
|
77
|
+
// Use for testing only. Does everything that CreateSurfaceForWindow does except the call to
|
|
78
|
+
// CreateSurface. Useful to be able to modify the descriptor for testing, or when trying to
|
|
79
|
+
// avoid using the global proc table.
|
|
80
|
+
// NOLINTNEXTLINE(build/include_what_you_use)
|
|
81
|
+
WGPU_GLFW_EXPORT std::unique_ptr<wgpu::ChainedStruct, void (*)(wgpu::ChainedStruct*)>
|
|
82
|
+
SetupWindowAndGetSurfaceDescriptor(GLFWwindow* window);
|
|
83
|
+
|
|
84
|
+
} // namespace wgpu::glfw
|
|
85
|
+
|
|
86
|
+
#endif
|
|
87
|
+
|
|
88
|
+
#endif // INCLUDE_WEBGPU_WEBGPU_GLFW_H_
|
|
@@ -144,6 +144,11 @@ public:
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
sk_sp<SkImage> MakeImageFromBuffer(void *buffer) {
|
|
147
|
+
#if defined(__ANDROID__) && __ANDROID_API__ < 26
|
|
148
|
+
// AHardwareBuffer is only available from API 26
|
|
149
|
+
(void)buffer;
|
|
150
|
+
return nullptr;
|
|
151
|
+
#else
|
|
147
152
|
#ifdef __APPLE__
|
|
148
153
|
wgpu::SharedTextureMemoryIOSurfaceDescriptor platformDesc;
|
|
149
154
|
auto ioSurface = CVPixelBufferGetIOSurface((CVPixelBufferRef)buffer);
|
|
@@ -213,6 +218,7 @@ public:
|
|
|
213
218
|
return nullptr;
|
|
214
219
|
}
|
|
215
220
|
return nullptr;
|
|
221
|
+
#endif
|
|
216
222
|
}
|
|
217
223
|
|
|
218
224
|
// Create offscreen surface
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Everything that needs a complete Recorder lives here rather than in
|
|
2
|
+
// RNSkGraphiteProducer.h (which the view headers include on their own).
|
|
3
|
+
#if defined(SK_GRAPHITE)
|
|
4
|
+
|
|
5
|
+
#include "RNSkGraphiteProducer.h"
|
|
6
|
+
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <utility>
|
|
9
|
+
|
|
10
|
+
#include "RNSkGraphiteView.h"
|
|
11
|
+
#include "RNSkPictureView.h"
|
|
12
|
+
#include "RNSkThreadPool.h"
|
|
13
|
+
#include "api/recorder/RNRecorder.h"
|
|
14
|
+
#include "utils/RNSkLog.h"
|
|
15
|
+
|
|
16
|
+
#include "include/core/SkCanvas.h"
|
|
17
|
+
#include "include/core/SkPicture.h"
|
|
18
|
+
|
|
19
|
+
namespace RNSkia {
|
|
20
|
+
|
|
21
|
+
RNSkGraphiteProducer::~RNSkGraphiteProducer() = default;
|
|
22
|
+
|
|
23
|
+
void RNSkGraphiteProducer::setTarget(
|
|
24
|
+
std::shared_ptr<RNSkGraphiteTarget> target) {
|
|
25
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
26
|
+
_target = std::move(target);
|
|
27
|
+
_dirty = true;
|
|
28
|
+
kickLocked();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void RNSkGraphiteProducer::setRecorder(std::shared_ptr<Recorder> recorder) {
|
|
32
|
+
sk_sp<SkPicture> picture;
|
|
33
|
+
if (recorder != nullptr && recorder->variables.empty()) {
|
|
34
|
+
picture = recorder->makePicture();
|
|
35
|
+
recorder = nullptr;
|
|
36
|
+
}
|
|
37
|
+
replaceContent(std::move(recorder), std::move(picture), /* dirty= */ true);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
void RNSkGraphiteProducer::setPicture(sk_sp<SkPicture> picture) {
|
|
41
|
+
replaceContent(nullptr, std::move(picture), /* dirty= */ true);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void RNSkGraphiteProducer::clear() {
|
|
45
|
+
replaceContent(nullptr, nullptr, /* dirty= */ false);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
void RNSkGraphiteProducer::replaceContent(std::shared_ptr<Recorder> recorder,
|
|
49
|
+
sk_sp<SkPicture> picture,
|
|
50
|
+
bool dirty) {
|
|
51
|
+
std::shared_ptr<Recorder> retiredRecorder;
|
|
52
|
+
sk_sp<SkPicture> retiredPicture;
|
|
53
|
+
{
|
|
54
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
55
|
+
retiredRecorder = std::exchange(_recorder, std::move(recorder));
|
|
56
|
+
retiredPicture = std::exchange(_picture, std::move(picture));
|
|
57
|
+
_dirty = dirty;
|
|
58
|
+
if (dirty) {
|
|
59
|
+
kickLocked();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Both are released here, outside the lock.
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
bool RNSkGraphiteProducer::hasContent() {
|
|
66
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
67
|
+
return _recorder != nullptr || _picture != nullptr;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
bool RNSkGraphiteProducer::applyUpdates(jsi::Runtime &runtime,
|
|
71
|
+
double recorderId,
|
|
72
|
+
const jsi::Array &values) {
|
|
73
|
+
std::shared_ptr<Recorder> recorder;
|
|
74
|
+
{
|
|
75
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
76
|
+
recorder = _recorder;
|
|
77
|
+
}
|
|
78
|
+
if (recorder == nullptr || recorder->id != recorderId) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
// Outside the lock: a commit replacing the recorder must not wait for the
|
|
82
|
+
// read. Should it land while this runs, the values go into the retired
|
|
83
|
+
// recorder and the commit's own frame draws the new one.
|
|
84
|
+
recorder->readUpdates(runtime, values);
|
|
85
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
86
|
+
_dirty = true;
|
|
87
|
+
kickLocked();
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
bool RNSkGraphiteProducer::requestFrame() {
|
|
92
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
93
|
+
_dirty = true;
|
|
94
|
+
kickLocked();
|
|
95
|
+
return _target != nullptr && (_recorder != nullptr || _picture != nullptr);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
void RNSkGraphiteProducer::onFramePresented() {
|
|
99
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
100
|
+
_presentPending = false;
|
|
101
|
+
if (_dirty) {
|
|
102
|
+
kickLocked();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
void RNSkGraphiteProducer::kickLocked() {
|
|
107
|
+
if (_inFlight || _presentPending || _target == nullptr ||
|
|
108
|
+
(_recorder == nullptr && _picture == nullptr)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
_inFlight = true;
|
|
112
|
+
std::weak_ptr<RNSkGraphiteProducer> weakThis = weak_from_this();
|
|
113
|
+
RNSkThreadPool::getInstance().post([weakThis]() {
|
|
114
|
+
if (auto self = weakThis.lock()) {
|
|
115
|
+
self->produce();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
void RNSkGraphiteProducer::produce() {
|
|
121
|
+
std::shared_ptr<RNSkGraphiteTarget> target;
|
|
122
|
+
std::shared_ptr<Recorder> recorder;
|
|
123
|
+
sk_sp<SkPicture> picture;
|
|
124
|
+
{
|
|
125
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
126
|
+
target = _target;
|
|
127
|
+
recorder = _recorder;
|
|
128
|
+
picture = _picture;
|
|
129
|
+
_dirty = false;
|
|
130
|
+
}
|
|
131
|
+
std::shared_ptr<RNSkGraphiteRecording> recording;
|
|
132
|
+
if (target && (recorder || picture)) {
|
|
133
|
+
SkCanvas *canvas = nullptr;
|
|
134
|
+
try {
|
|
135
|
+
canvas = target->beginRecording();
|
|
136
|
+
} catch (const std::exception &) {
|
|
137
|
+
// No surface and no layout yet: the view asks for a frame once it
|
|
138
|
+
// has a size.
|
|
139
|
+
}
|
|
140
|
+
if (canvas != nullptr) {
|
|
141
|
+
try {
|
|
142
|
+
// The deferred canvas already draws in points.
|
|
143
|
+
drawContent(canvas, recorder.get(), picture, /* pixelDensity= */ 1.0f);
|
|
144
|
+
} catch (const std::exception &e) {
|
|
145
|
+
RNSkLogger::logToConsole(
|
|
146
|
+
"GraphiteCanvas: replaying the scene failed: %s", e.what());
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
recording = target->finishRecording();
|
|
150
|
+
} catch (const std::exception &e) {
|
|
151
|
+
RNSkLogger::logToConsole(
|
|
152
|
+
"GraphiteCanvas: recording the frame failed: %s", e.what());
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
157
|
+
_inFlight = false;
|
|
158
|
+
if (recording != nullptr) {
|
|
159
|
+
// The next job starts when this frame is on screen. Submitted under the
|
|
160
|
+
// lock: a frame presented in between (a redraw replaying the last one)
|
|
161
|
+
// would otherwise clear the flag before the recording is even queued.
|
|
162
|
+
_presentPending = true;
|
|
163
|
+
target->submit(std::move(recording));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// Nothing was recorded: keep the content dirty so that the next request
|
|
167
|
+
// (a surface, a resize) records it. A request that landed while this job
|
|
168
|
+
// ran was only noted as dirty; it starts the next job now.
|
|
169
|
+
const bool requested = _dirty;
|
|
170
|
+
_dirty = true;
|
|
171
|
+
if (requested) {
|
|
172
|
+
kickLocked();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
void RNSkGraphiteProducer::renderInto(SkCanvas *canvas, float pixelDensity) {
|
|
177
|
+
std::shared_ptr<Recorder> recorder;
|
|
178
|
+
sk_sp<SkPicture> picture;
|
|
179
|
+
{
|
|
180
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
181
|
+
recorder = _recorder;
|
|
182
|
+
picture = _picture;
|
|
183
|
+
}
|
|
184
|
+
drawContent(canvas, recorder.get(), picture, pixelDensity);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
} // namespace RNSkia
|
|
188
|
+
|
|
189
|
+
#endif // SK_GRAPHITE
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#if defined(SK_GRAPHITE)
|
|
4
|
+
|
|
5
|
+
#include <memory>
|
|
6
|
+
#include <mutex>
|
|
7
|
+
|
|
8
|
+
#include <jsi/jsi.h>
|
|
9
|
+
|
|
10
|
+
#include "include/core/SkRefCnt.h"
|
|
11
|
+
|
|
12
|
+
class SkCanvas;
|
|
13
|
+
class SkPicture;
|
|
14
|
+
|
|
15
|
+
namespace RNSkia {
|
|
16
|
+
|
|
17
|
+
namespace jsi = facebook::jsi;
|
|
18
|
+
|
|
19
|
+
class Recorder;
|
|
20
|
+
class RNSkGraphiteTarget;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Records the declarative content of a SkiaGraphiteView (a Recorder handed
|
|
24
|
+
* over by <GraphiteCanvas>, or a picture) into Graphite recordings, on the
|
|
25
|
+
* render thread pool.
|
|
26
|
+
*
|
|
27
|
+
* Three threads meet here. The JS thread hands over the content. A Reanimated
|
|
28
|
+
* mapper, on the UI runtime, reads the shared values into the recorder's
|
|
29
|
+
* pending writes: that is the only step that needs a JS runtime, and it never
|
|
30
|
+
* waits for a replay. A pool thread replays the commands (the recorder writes
|
|
31
|
+
* the pending values into them first) into a deferred canvas of the view's
|
|
32
|
+
* target and submits the recording; the main thread presents it on the next
|
|
33
|
+
* vsync.
|
|
34
|
+
*
|
|
35
|
+
* Pacing: a view has at most one job in flight and at most one recording
|
|
36
|
+
* waiting to be presented. Updates that arrive meanwhile only mark the content
|
|
37
|
+
* dirty; the next presented frame starts the next job. A producer that
|
|
38
|
+
* outruns the display therefore records once per vsync, and the queue of the
|
|
39
|
+
* target never grows.
|
|
40
|
+
*/
|
|
41
|
+
class RNSkGraphiteProducer
|
|
42
|
+
: public std::enable_shared_from_this<RNSkGraphiteProducer> {
|
|
43
|
+
public:
|
|
44
|
+
RNSkGraphiteProducer() = default;
|
|
45
|
+
~RNSkGraphiteProducer();
|
|
46
|
+
|
|
47
|
+
/** The target to record into. Main thread. */
|
|
48
|
+
void setTarget(std::shared_ptr<RNSkGraphiteTarget> target);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
Takes ownership of the recorder (or releases it with nullptr). A recording
|
|
52
|
+
without shared values is played once into a picture: nothing will ever
|
|
53
|
+
update it, and drawing a picture is cheaper than replaying commands.
|
|
54
|
+
*/
|
|
55
|
+
void setRecorder(std::shared_ptr<Recorder> recorder);
|
|
56
|
+
|
|
57
|
+
/** Content from the static container: a picture to replay. */
|
|
58
|
+
void setPicture(sk_sp<SkPicture> picture);
|
|
59
|
+
|
|
60
|
+
bool hasContent();
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
Drops the content without scheduling a frame: the host view is being torn
|
|
64
|
+
down.
|
|
65
|
+
*/
|
|
66
|
+
void clear();
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
Reads the shared values on the calling runtime into the recorder and
|
|
70
|
+
schedules a frame. Returns false when there is no recorder to update, or
|
|
71
|
+
another recording than recorderId (a stale mapper).
|
|
72
|
+
*/
|
|
73
|
+
bool applyUpdates(jsi::Runtime &runtime, double recorderId,
|
|
74
|
+
const jsi::Array &values);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
Marks the content dirty and schedules a frame if one can start. Returns
|
|
78
|
+
whether a frame is coming at all: there is content and a target to record
|
|
79
|
+
it into.
|
|
80
|
+
*/
|
|
81
|
+
bool requestFrame();
|
|
82
|
+
|
|
83
|
+
/** The view presented a frame: the next one may start. */
|
|
84
|
+
void onFramePresented();
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
Replays the current content into a canvas, on the calling thread (a
|
|
88
|
+
snapshot). The canvas draws in pixels, this applies the density.
|
|
89
|
+
*/
|
|
90
|
+
void renderInto(SkCanvas *canvas, float pixelDensity);
|
|
91
|
+
|
|
92
|
+
private:
|
|
93
|
+
/**
|
|
94
|
+
Swaps the content under the lock and releases the previous one outside of
|
|
95
|
+
it: the recorder's destructor hands the commands to the main thread, and a
|
|
96
|
+
pool thread still replaying it keeps it alive until it is done. Pending
|
|
97
|
+
writes go away with their recorder.
|
|
98
|
+
*/
|
|
99
|
+
void replaceContent(std::shared_ptr<Recorder> recorder,
|
|
100
|
+
sk_sp<SkPicture> picture, bool dirty);
|
|
101
|
+
void kickLocked();
|
|
102
|
+
void produce();
|
|
103
|
+
|
|
104
|
+
// Content and scheduling state.
|
|
105
|
+
std::mutex _mutex;
|
|
106
|
+
std::shared_ptr<RNSkGraphiteTarget> _target;
|
|
107
|
+
std::shared_ptr<Recorder> _recorder;
|
|
108
|
+
sk_sp<SkPicture> _picture;
|
|
109
|
+
bool _dirty = false;
|
|
110
|
+
bool _inFlight = false;
|
|
111
|
+
bool _presentPending = false;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
} // namespace RNSkia
|
|
115
|
+
|
|
116
|
+
#endif // SK_GRAPHITE
|