@shopify/react-native-skia 2.6.0 → 2.6.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 +0 -1
- package/android/cpp/jni/JniWebGPUView.cpp +3 -3
- package/android/cpp/rnskia-android/OpenGLContext.h +4 -5
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +1 -1
- package/apple/MetalContext.h +5 -6
- package/apple/MetalWindowContext.mm +3 -4
- package/apple/RNSkApplePlatformContext.h +1 -1
- package/apple/RNSkApplePlatformContext.mm +4 -3
- package/apple/SkiaCVPixelBufferUtils.h +1 -1
- package/apple/SkiaCVPixelBufferUtils.mm +31 -30
- package/apple/SkiaPlatformContext.mm +2 -2
- package/apple/SkiaUIView.mm +1 -1
- package/apple/SkiaWebGPUView.mm +8 -4
- package/apple/WebGPUMetalView.h +1 -1
- package/apple/WebGPUMetalView.mm +1 -1
- package/cpp/api/JsiSkColor.h +8 -4
- package/cpp/api/JsiSkContourMeasure.h +4 -3
- package/cpp/api/JsiSkImage.h +17 -9
- package/cpp/api/JsiSkParagraphBuilder.h +14 -1
- package/cpp/api/JsiSkPath.h +71 -81
- package/cpp/api/JsiSkPathEffectFactory.h +2 -1
- package/cpp/api/JsiSkPathFactory.h +48 -52
- package/cpp/api/JsiSkShader.h +1 -1
- package/cpp/api/JsiSkShaderFactory.h +50 -26
- package/cpp/api/JsiSkSurfaceFactory.h +2 -1
- package/cpp/api/recorder/Drawings.h +5 -7
- package/cpp/api/recorder/Shaders.h +77 -22
- package/cpp/jsi2/JSIConverter.h +1 -1
- package/cpp/rnskia/RNDawnContext.h +14 -15
- package/cpp/rnskia/RNDawnUtils.h +14 -17
- package/cpp/rnskia/RNDawnWindowContext.h +1 -1
- package/cpp/rnskia/RNSkManager.cpp +5 -4
- package/cpp/rnskia/RNSkPlatformContext.h +2 -2
- package/cpp/rnwgpu/api/GPU.cpp +21 -0
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +1 -1
- package/cpp/rnwgpu/api/GPUCanvasContext.h +2 -2
- package/cpp/rnwgpu/api/GPUFeatures.h +0 -9
- package/cpp/rnwgpu/api/GPUTexture.h +14 -2
- package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +3 -4
- package/cpp/rnwgpu/api/RNWebGPU.h +1 -1
- package/cpp/rnwgpu/api/descriptors/Unions.h +0 -15
- package/cpp/skia/include/android/SkImageAndroid.h +7 -2
- package/cpp/skia/include/android/vk/AndroidVulkanMemoryAllocator.h +31 -0
- package/cpp/skia/include/codec/SkCodec.h +42 -15
- package/cpp/skia/include/config/SkUserConfig.h +8 -0
- package/cpp/skia/include/core/SkBitmap.h +0 -5
- package/cpp/skia/include/core/SkCanvas.h +2 -39
- package/cpp/skia/include/core/SkColor.h +12 -0
- package/cpp/skia/include/core/SkColorSpace.h +9 -0
- package/cpp/skia/include/core/SkContourMeasure.h +1 -5
- package/cpp/skia/include/core/SkData.h +8 -0
- package/cpp/skia/include/core/SkFont.h +1 -55
- package/cpp/skia/include/core/SkFontArguments.h +15 -0
- package/cpp/skia/include/core/SkGraphics.h +0 -5
- package/cpp/skia/include/core/SkImage.h +0 -4
- package/cpp/skia/include/core/SkImageGenerator.h +1 -4
- package/cpp/skia/include/core/SkMatrix.h +0 -37
- package/cpp/skia/include/core/SkMilestone.h +1 -1
- package/cpp/skia/include/core/SkPath.h +11 -911
- package/cpp/skia/include/core/SkPathBuilder.h +42 -32
- package/cpp/skia/include/core/SkPathEffect.h +0 -9
- package/cpp/skia/include/core/SkPathMeasure.h +1 -4
- package/cpp/skia/include/core/SkPathUtils.h +0 -10
- package/cpp/skia/include/core/SkRect.h +0 -12
- package/cpp/skia/include/core/SkRegion.h +1 -6
- package/cpp/skia/include/core/SkSerialProcs.h +4 -5
- package/cpp/skia/include/core/SkSurfaceProps.h +6 -0
- package/cpp/skia/include/core/SkTextBlob.h +0 -22
- package/cpp/skia/include/core/SkTypeface.h +14 -32
- package/cpp/skia/include/core/SkTypes.h +0 -8
- package/cpp/skia/include/docs/SkPDFDocument.h +19 -17
- package/cpp/skia/include/effects/SkDashPathEffect.h +0 -6
- package/cpp/skia/include/effects/SkGradient.h +206 -0
- package/cpp/skia/include/effects/SkHighContrastFilter.h +2 -2
- package/cpp/skia/include/gpu/GpuTypes.h +2 -0
- package/cpp/skia/include/gpu/ganesh/GrBackendSemaphore.h +5 -35
- package/cpp/skia/include/gpu/ganesh/GrBackendSurface.h +7 -106
- package/cpp/skia/include/gpu/ganesh/GrContextOptions.h +0 -11
- package/cpp/skia/include/gpu/ganesh/GrDirectContext.h +0 -9
- package/cpp/skia/include/gpu/ganesh/d3d/GrD3DBackendSemaphore.h +20 -0
- package/cpp/skia/include/gpu/ganesh/d3d/GrD3DBackendSurface.h +59 -0
- package/cpp/skia/include/gpu/ganesh/d3d/GrD3DDirectContext.h +28 -0
- package/cpp/skia/include/gpu/ganesh/gl/GrGLFunctions.h +4 -1
- package/cpp/skia/include/gpu/graphite/ContextOptions.h +4 -20
- package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +32 -46
- package/cpp/skia/include/gpu/graphite/Recorder.h +1 -1
- package/cpp/skia/include/gpu/graphite/Surface.h +31 -0
- package/cpp/skia/include/gpu/graphite/TextureInfo.h +3 -10
- package/cpp/skia/include/gpu/graphite/dawn/DawnGraphiteTypes.h +3 -3
- package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h +1 -1
- package/cpp/skia/include/gpu/graphite/precompile/PrecompileShader.h +6 -6
- package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +5 -3
- package/cpp/skia/include/gpu/graphite/vk/precompile/VulkanPrecompileShader.h +1 -1
- package/cpp/skia/include/gpu/vk/VulkanBackendContext.h +1 -1
- package/cpp/skia/include/gpu/vk/VulkanPreferredFeatures.h +8 -0
- package/cpp/skia/include/private/SkEncodedInfo.h +43 -105
- package/cpp/skia/include/private/SkHdrMetadata.h +165 -2
- package/cpp/skia/include/private/SkPathRef.h +0 -457
- package/cpp/skia/include/private/base/SkFeatures.h +4 -0
- package/cpp/skia/include/private/base/SkFloatingPoint.h +1 -2
- package/cpp/skia/include/private/base/SkLoadUserConfig.h +2 -1
- package/cpp/skia/include/private/base/SkLog.h +68 -0
- package/cpp/skia/include/private/base/SkLogPriority.h +35 -0
- package/cpp/skia/include/private/base/SkMacros.h +9 -0
- package/cpp/skia/include/private/base/SkTArray.h +1 -1
- package/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h +10 -24
- package/cpp/skia/include/utils/SkEventTracer.h +5 -7
- package/cpp/skia/modules/skottie/include/TextShaper.h +0 -7
- package/cpp/skia/modules/skparagraph/include/FontCollection.h +6 -20
- package/cpp/skia/modules/skparagraph/include/ParagraphBuilder.h +0 -6
- package/cpp/skia/modules/skparagraph/include/ParagraphCache.h +4 -19
- package/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h +2 -3
- package/cpp/skia/modules/skunicode/include/SkUnicode_icu.h +18 -0
- package/cpp/skia/modules/skunicode/include/SkUnicode_libgrapheme.h +19 -0
- package/cpp/skia/src/base/SkMathPriv.h +27 -132
- package/package.json +5 -5
- package/cpp/skia/include/effects/SkGradientShader.h +0 -359
- package/cpp/skia/include/gpu/graphite/LogPriority.h +0 -36
|
@@ -44,8 +44,9 @@ SkTileMode getTileMode(const jsi::Value *values, int i, size_t size) {
|
|
|
44
44
|
return static_cast<SkTileMode>(values[i].asNumber());
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
std::vector<
|
|
48
|
-
|
|
47
|
+
std::vector<SkColor4f> getColors(jsi::Runtime &runtime,
|
|
48
|
+
const jsi::Value &value) {
|
|
49
|
+
std::vector<SkColor4f> colors;
|
|
49
50
|
if (!value.isNull()) {
|
|
50
51
|
auto jsiColors = value.asObject(runtime).asArray(runtime);
|
|
51
52
|
auto size = jsiColors.size(runtime);
|
|
@@ -53,7 +54,7 @@ std::vector<SkColor> getColors(jsi::Runtime &runtime, const jsi::Value &value) {
|
|
|
53
54
|
for (int i = 0; i < size; i++) {
|
|
54
55
|
SkColor color =
|
|
55
56
|
JsiSkColor::fromValue(runtime, jsiColors.getValueAtIndex(runtime, i));
|
|
56
|
-
colors.push_back(color);
|
|
57
|
+
colors.push_back(SkColor4f::FromColor(color));
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
return colors;
|
|
@@ -83,7 +84,7 @@ public:
|
|
|
83
84
|
*JsiSkPoint::fromValue(runtime, arguments[1].asObject(runtime)).get();
|
|
84
85
|
SkPoint pts[] = {p1, p2};
|
|
85
86
|
|
|
86
|
-
std::vector<
|
|
87
|
+
std::vector<SkColor4f> colors = getColors(runtime, arguments[2]);
|
|
87
88
|
auto colorsSize = colors.size();
|
|
88
89
|
if (colorsSize < 2) {
|
|
89
90
|
throw std::invalid_argument("colors must have at least 2 colors");
|
|
@@ -97,9 +98,15 @@ public:
|
|
|
97
98
|
auto flag = getFlag(arguments, 6, count);
|
|
98
99
|
auto localMatrix = getLocalMatrix(runtime, arguments, 5, count);
|
|
99
100
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
SkGradient::Colors gradColors(
|
|
102
|
+
SkSpan(colors),
|
|
103
|
+
!positions.empty()
|
|
104
|
+
? SkSpan<const float>(positions.data(), positions.size())
|
|
105
|
+
: SkSpan<const float>(),
|
|
106
|
+
tileMode);
|
|
107
|
+
SkGradient grad(gradColors, SkGradient::Interpolation::FromFlags(flag));
|
|
108
|
+
sk_sp<SkShader> gradient =
|
|
109
|
+
SkShaders::LinearGradient(pts, grad, localMatrix);
|
|
103
110
|
auto shader =
|
|
104
111
|
std::make_shared<JsiSkShader>(getContext(), std::move(gradient));
|
|
105
112
|
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shader,
|
|
@@ -111,7 +118,7 @@ public:
|
|
|
111
118
|
*JsiSkPoint::fromValue(runtime, arguments[0].asObject(runtime)).get();
|
|
112
119
|
auto r = arguments[1].asNumber();
|
|
113
120
|
|
|
114
|
-
std::vector<
|
|
121
|
+
std::vector<SkColor4f> colors = getColors(runtime, arguments[2]);
|
|
115
122
|
auto colorsSize = colors.size();
|
|
116
123
|
if (colorsSize < 2) {
|
|
117
124
|
throw std::invalid_argument("colors must have at least 2 colors");
|
|
@@ -125,10 +132,15 @@ public:
|
|
|
125
132
|
auto flag = getFlag(arguments, 6, count);
|
|
126
133
|
auto localMatrix = getLocalMatrix(runtime, arguments, 5, count);
|
|
127
134
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
!positions.empty()
|
|
131
|
-
|
|
135
|
+
SkGradient::Colors gradColors(
|
|
136
|
+
SkSpan(colors),
|
|
137
|
+
!positions.empty()
|
|
138
|
+
? SkSpan<const float>(positions.data(), positions.size())
|
|
139
|
+
: SkSpan<const float>(),
|
|
140
|
+
tileMode);
|
|
141
|
+
SkGradient grad(gradColors, SkGradient::Interpolation::FromFlags(flag));
|
|
142
|
+
sk_sp<SkShader> gradient =
|
|
143
|
+
SkShaders::RadialGradient(center, r, grad, localMatrix);
|
|
132
144
|
auto shader =
|
|
133
145
|
std::make_shared<JsiSkShader>(getContext(), std::move(gradient));
|
|
134
146
|
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shader,
|
|
@@ -138,7 +150,7 @@ public:
|
|
|
138
150
|
JSI_HOST_FUNCTION(MakeSweepGradient) {
|
|
139
151
|
auto x = arguments[0].asNumber();
|
|
140
152
|
auto y = arguments[1].asNumber();
|
|
141
|
-
std::vector<
|
|
153
|
+
std::vector<SkColor4f> colors = getColors(runtime, arguments[2]);
|
|
142
154
|
auto colorsSize = colors.size();
|
|
143
155
|
if (colorsSize < 2) {
|
|
144
156
|
throw std::invalid_argument("colors must have at least 2 colors");
|
|
@@ -151,15 +163,22 @@ public:
|
|
|
151
163
|
auto tileMode = getTileMode(arguments, 4, count);
|
|
152
164
|
auto localMatrix = getLocalMatrix(runtime, arguments, 5, count);
|
|
153
165
|
auto flag = getFlag(arguments, 6, count);
|
|
154
|
-
auto startAngle =
|
|
155
|
-
|
|
166
|
+
auto startAngle = (count < 8 || arguments[7].isUndefined())
|
|
167
|
+
? 0.0f
|
|
168
|
+
: static_cast<float>(arguments[7].asNumber());
|
|
156
169
|
auto endAngle = (count < 9 || arguments[8].isUndefined())
|
|
157
|
-
? 360
|
|
158
|
-
: arguments[8].asNumber();
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
170
|
+
? 360.0f
|
|
171
|
+
: static_cast<float>(arguments[8].asNumber());
|
|
172
|
+
|
|
173
|
+
SkGradient::Colors gradColors(
|
|
174
|
+
SkSpan(colors),
|
|
175
|
+
!positions.empty()
|
|
176
|
+
? SkSpan<const float>(positions.data(), positions.size())
|
|
177
|
+
: SkSpan<const float>(),
|
|
178
|
+
tileMode);
|
|
179
|
+
SkGradient grad(gradColors, SkGradient::Interpolation::FromFlags(flag));
|
|
180
|
+
sk_sp<SkShader> gradient = SkShaders::SweepGradient(
|
|
181
|
+
SkPoint::Make(x, y), startAngle, endAngle, grad, localMatrix);
|
|
163
182
|
auto shader =
|
|
164
183
|
std::make_shared<JsiSkShader>(getContext(), std::move(gradient));
|
|
165
184
|
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shader,
|
|
@@ -175,7 +194,7 @@ public:
|
|
|
175
194
|
*JsiSkPoint::fromValue(runtime, arguments[2].asObject(runtime)).get();
|
|
176
195
|
auto endRadius = arguments[3].asNumber();
|
|
177
196
|
|
|
178
|
-
std::vector<
|
|
197
|
+
std::vector<SkColor4f> colors = getColors(runtime, arguments[4]);
|
|
179
198
|
auto colorsSize = colors.size();
|
|
180
199
|
if (colorsSize < 2) {
|
|
181
200
|
throw std::invalid_argument("colors must have at least 2 colors");
|
|
@@ -189,10 +208,15 @@ public:
|
|
|
189
208
|
auto localMatrix = getLocalMatrix(runtime, arguments, 7, count);
|
|
190
209
|
auto flag = getFlag(arguments, 8, count);
|
|
191
210
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
!positions.empty()
|
|
195
|
-
|
|
211
|
+
SkGradient::Colors gradColors(
|
|
212
|
+
SkSpan(colors),
|
|
213
|
+
!positions.empty()
|
|
214
|
+
? SkSpan<const float>(positions.data(), positions.size())
|
|
215
|
+
: SkSpan<const float>(),
|
|
216
|
+
tileMode);
|
|
217
|
+
SkGradient grad(gradColors, SkGradient::Interpolation::FromFlags(flag));
|
|
218
|
+
sk_sp<SkShader> gradient = SkShaders::TwoPointConicalGradient(
|
|
219
|
+
start, startRadius, end, endRadius, grad, localMatrix);
|
|
196
220
|
|
|
197
221
|
auto shader =
|
|
198
222
|
std::make_shared<JsiSkShader>(getContext(), std::move(gradient));
|
|
@@ -51,7 +51,8 @@ public:
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
auto context = getContext();
|
|
54
|
-
auto surface =
|
|
54
|
+
auto surface =
|
|
55
|
+
context->makeOffscreenSurface(width, height, useP3ColorSpace);
|
|
55
56
|
if (surface == nullptr) {
|
|
56
57
|
return jsi::Value::null();
|
|
57
58
|
}
|
|
@@ -166,14 +166,11 @@ public:
|
|
|
166
166
|
strokePaint.setStrokeMiter(stroke.miter_limit.value());
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
auto strokedPath = std::make_shared<SkPath>();
|
|
172
|
-
if (!skpathutils::FillPathWithPaint(*p, strokePaint, strokedPath.get(),
|
|
173
|
-
nullptr, precision)) {
|
|
169
|
+
SkPathBuilder resultBuilder;
|
|
170
|
+
if (!skpathutils::FillPathWithPaint(*p, strokePaint, &resultBuilder)) {
|
|
174
171
|
throw std::runtime_error("Failed to apply stroke to path");
|
|
175
172
|
}
|
|
176
|
-
pathToUse = std::
|
|
173
|
+
pathToUse = std::make_shared<const SkPath>(resultBuilder.snapshot());
|
|
177
174
|
} else {
|
|
178
175
|
pathToUse = std::const_pointer_cast<const SkPath>(p);
|
|
179
176
|
}
|
|
@@ -939,7 +936,8 @@ public:
|
|
|
939
936
|
convertProperty(runtime, object, "sprites", props.sprites, variables);
|
|
940
937
|
convertProperty(runtime, object, "transforms", props.transforms, variables);
|
|
941
938
|
convertProperty(runtime, object, "colors", props.colors, variables);
|
|
942
|
-
convertProperty(runtime, object, "colorBlendMode", props.blendMode,
|
|
939
|
+
convertProperty(runtime, object, "colorBlendMode", props.blendMode,
|
|
940
|
+
variables);
|
|
943
941
|
convertProperty(runtime, object, "sampling", props.sampling, variables);
|
|
944
942
|
}
|
|
945
943
|
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#include <variant>
|
|
6
6
|
|
|
7
7
|
#include <include/core/SkSamplingOptions.h>
|
|
8
|
+
#include <include/effects/SkGradient.h>
|
|
8
9
|
|
|
9
10
|
#include "Command.h"
|
|
10
11
|
#include "Convertor.h"
|
|
@@ -250,11 +251,24 @@ public:
|
|
|
250
251
|
|
|
251
252
|
SkMatrix m3 = processTransform(props.matrix, props.transform, props.origin);
|
|
252
253
|
const SkPoint pts[2] = {props.start, props.end};
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
254
|
+
|
|
255
|
+
// Convert SkColor to SkColor4f
|
|
256
|
+
std::vector<SkColor4f> colors4f;
|
|
257
|
+
colors4f.reserve(props.colors.size());
|
|
258
|
+
for (const auto &c : props.colors) {
|
|
259
|
+
colors4f.push_back(SkColor4f::FromColor(c));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
auto tileMode = props.mode.value_or(SkTileMode::kClamp);
|
|
263
|
+
SkGradient::Colors gradColors(
|
|
264
|
+
SkSpan(colors4f),
|
|
265
|
+
props.positions ? SkSpan<const float>(props.positions->data(),
|
|
266
|
+
props.positions->size())
|
|
267
|
+
: SkSpan<const float>(),
|
|
268
|
+
tileMode);
|
|
269
|
+
SkGradient grad(gradColors, SkGradient::Interpolation::FromFlags(
|
|
270
|
+
props.flags.value_or(0)));
|
|
271
|
+
auto shader = SkShaders::LinearGradient(pts, grad, &m3);
|
|
258
272
|
ctx->shaders.push_back(shader);
|
|
259
273
|
}
|
|
260
274
|
};
|
|
@@ -293,11 +307,25 @@ public:
|
|
|
293
307
|
}
|
|
294
308
|
|
|
295
309
|
SkMatrix m3 = processTransform(props.matrix, props.transform, props.origin);
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
310
|
+
|
|
311
|
+
// Convert SkColor to SkColor4f
|
|
312
|
+
std::vector<SkColor4f> colors4f;
|
|
313
|
+
colors4f.reserve(props.colors.size());
|
|
314
|
+
for (const auto &c : props.colors) {
|
|
315
|
+
colors4f.push_back(SkColor4f::FromColor(c));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
auto tileMode = props.mode.value_or(SkTileMode::kClamp);
|
|
319
|
+
SkGradient::Colors gradColors(
|
|
320
|
+
SkSpan(colors4f),
|
|
321
|
+
props.positions ? SkSpan<const float>(props.positions->data(),
|
|
322
|
+
props.positions->size())
|
|
323
|
+
: SkSpan<const float>(),
|
|
324
|
+
tileMode);
|
|
325
|
+
SkGradient grad(gradColors, SkGradient::Interpolation::FromFlags(
|
|
326
|
+
props.flags.value_or(0)));
|
|
327
|
+
auto shader =
|
|
328
|
+
SkShaders::RadialGradient(props.center, props.radius, grad, &m3);
|
|
301
329
|
ctx->shaders.push_back(shader);
|
|
302
330
|
}
|
|
303
331
|
};
|
|
@@ -338,12 +366,26 @@ public:
|
|
|
338
366
|
}
|
|
339
367
|
|
|
340
368
|
SkMatrix m3 = processTransform(props.matrix, props.transform, props.origin);
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
369
|
+
|
|
370
|
+
// Convert SkColor to SkColor4f
|
|
371
|
+
std::vector<SkColor4f> colors4f;
|
|
372
|
+
colors4f.reserve(props.colors.size());
|
|
373
|
+
for (const auto &c : props.colors) {
|
|
374
|
+
colors4f.push_back(SkColor4f::FromColor(c));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
auto tileMode = props.mode.value_or(SkTileMode::kClamp);
|
|
378
|
+
SkGradient::Colors gradColors(
|
|
379
|
+
SkSpan(colors4f),
|
|
380
|
+
props.positions ? SkSpan<const float>(props.positions->data(),
|
|
381
|
+
props.positions->size())
|
|
382
|
+
: SkSpan<const float>(),
|
|
383
|
+
tileMode);
|
|
384
|
+
SkGradient grad(gradColors, SkGradient::Interpolation::FromFlags(
|
|
385
|
+
props.flags.value_or(0)));
|
|
386
|
+
auto shader =
|
|
387
|
+
SkShaders::SweepGradient(props.center, props.start.value_or(0),
|
|
388
|
+
props.end.value_or(360), grad, &m3);
|
|
347
389
|
ctx->shaders.push_back(shader);
|
|
348
390
|
}
|
|
349
391
|
};
|
|
@@ -387,12 +429,25 @@ public:
|
|
|
387
429
|
}
|
|
388
430
|
|
|
389
431
|
SkMatrix m3 = processTransform(props.matrix, props.transform, props.origin);
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
432
|
+
|
|
433
|
+
// Convert SkColor to SkColor4f
|
|
434
|
+
std::vector<SkColor4f> colors4f;
|
|
435
|
+
colors4f.reserve(props.colors.size());
|
|
436
|
+
for (const auto &c : props.colors) {
|
|
437
|
+
colors4f.push_back(SkColor4f::FromColor(c));
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
auto tileMode = props.mode.value_or(SkTileMode::kClamp);
|
|
441
|
+
SkGradient::Colors gradColors(
|
|
442
|
+
SkSpan(colors4f),
|
|
443
|
+
props.positions ? SkSpan<const float>(props.positions->data(),
|
|
444
|
+
props.positions->size())
|
|
445
|
+
: SkSpan<const float>(),
|
|
446
|
+
tileMode);
|
|
447
|
+
SkGradient grad(gradColors, SkGradient::Interpolation::FromFlags(
|
|
448
|
+
props.flags.value_or(0)));
|
|
449
|
+
auto shader = SkShaders::TwoPointConicalGradient(
|
|
450
|
+
props.start, props.startRadius, props.end, props.endRadius, grad, &m3);
|
|
396
451
|
ctx->shaders.push_back(shader);
|
|
397
452
|
}
|
|
398
453
|
};
|
package/cpp/jsi2/JSIConverter.h
CHANGED
|
@@ -241,7 +241,7 @@ template <> struct JSIConverter<rnwgpu::async::AsyncTaskHandle> {
|
|
|
241
241
|
// jsi::Function <> Function
|
|
242
242
|
template <> struct JSIConverter<jsi::Function> {
|
|
243
243
|
static jsi::Function fromJSI(jsi::Runtime &runtime, const jsi::Value &arg,
|
|
244
|
-
|
|
244
|
+
bool outOfBound) {
|
|
245
245
|
return arg.asObject(runtime).asFunction(runtime);
|
|
246
246
|
}
|
|
247
247
|
static jsi::Value toJSI(jsi::Runtime &runtime, jsi::Function &&arg) {
|
|
@@ -114,7 +114,6 @@ public:
|
|
|
114
114
|
wgpu::SharedTextureMemoryAHardwareBufferDescriptor platformDesc;
|
|
115
115
|
auto ahb = (AHardwareBuffer *)buffer;
|
|
116
116
|
platformDesc.handle = ahb;
|
|
117
|
-
platformDesc.useExternalFormat = true;
|
|
118
117
|
AHardwareBuffer_Desc adesc;
|
|
119
118
|
AHardwareBuffer_describe(ahb, &adesc);
|
|
120
119
|
int width = adesc.width;
|
|
@@ -164,15 +163,14 @@ public:
|
|
|
164
163
|
|
|
165
164
|
// Create offscreen surface
|
|
166
165
|
sk_sp<SkSurface> MakeOffscreen(int width, int height,
|
|
167
|
-
|
|
166
|
+
bool useP3ColorSpace = false) {
|
|
168
167
|
sk_sp<SkColorSpace> colorSpace =
|
|
169
|
-
useP3ColorSpace
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
colorSpace);
|
|
168
|
+
useP3ColorSpace ? SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
|
|
169
|
+
SkNamedGamut::kDisplayP3)
|
|
170
|
+
: nullptr;
|
|
171
|
+
SkImageInfo info =
|
|
172
|
+
SkImageInfo::Make(width, height, DawnUtils::PreferedColorType,
|
|
173
|
+
kPremul_SkAlphaType, colorSpace);
|
|
176
174
|
sk_sp<SkSurface> surface = SkSurfaces::RenderTarget(getRecorder(), info);
|
|
177
175
|
|
|
178
176
|
if (!surface) {
|
|
@@ -189,9 +187,10 @@ public:
|
|
|
189
187
|
wgpu::Device getWGPUDevice() { return backendContext.fDevice; }
|
|
190
188
|
|
|
191
189
|
// Create a secondary Dawn device from the same adapter.
|
|
192
|
-
// Has its own command queue and does NOT enable
|
|
193
|
-
// so it won't contend with the primary
|
|
194
|
-
// Safe for concurrent GPU work (e.g. ML inference)
|
|
190
|
+
// Has its own command queue and does NOT enable
|
|
191
|
+
// ImplicitDeviceSynchronization, so it won't contend with the primary
|
|
192
|
+
// rendering device's mutex. Safe for concurrent GPU work (e.g. ML inference)
|
|
193
|
+
// alongside Skia rendering.
|
|
195
194
|
wgpu::Device createSecondaryDevice() {
|
|
196
195
|
auto adapter = DawnUtils::getMatchedAdapter(instance.get());
|
|
197
196
|
|
|
@@ -200,9 +199,9 @@ public:
|
|
|
200
199
|
#ifdef __APPLE__
|
|
201
200
|
wgpu::FeatureName::SharedTextureMemoryIOSurface,
|
|
202
201
|
wgpu::FeatureName::DawnMultiPlanarFormats,
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
// Note: SharedFenceMTLSharedEvent intentionally NOT enabled — it causes
|
|
203
|
+
// EndAccess to encode fence signals that crash with "uncommitted encoder".
|
|
204
|
+
// IOSurface data is already written by the camera before we read it.
|
|
206
205
|
#endif
|
|
207
206
|
};
|
|
208
207
|
|
package/cpp/rnskia/RNDawnUtils.h
CHANGED
|
@@ -109,15 +109,14 @@ requestDevice(dawn::native::Adapter &nativeAdapter,
|
|
|
109
109
|
[](const wgpu::Device &, wgpu::DeviceLostReason reason,
|
|
110
110
|
wgpu::StringView message) {
|
|
111
111
|
if (reason != wgpu::DeviceLostReason::Destroyed) {
|
|
112
|
-
SK_ABORT("Device lost: %.*s\n",
|
|
113
|
-
|
|
112
|
+
SK_ABORT("Device lost: %.*s\n", static_cast<int>(message.length),
|
|
113
|
+
message.data);
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
116
|
desc.SetUncapturedErrorCallback(
|
|
117
|
-
[](const wgpu::Device &, wgpu::ErrorType,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
static_cast<int>(message.length), message.data);
|
|
117
|
+
[](const wgpu::Device &, wgpu::ErrorType, wgpu::StringView message) {
|
|
118
|
+
SkDebugf("Device error: %.*s\n", static_cast<int>(message.length),
|
|
119
|
+
message.data);
|
|
121
120
|
});
|
|
122
121
|
} else {
|
|
123
122
|
desc.SetDeviceLostCallback(
|
|
@@ -125,18 +124,16 @@ requestDevice(dawn::native::Adapter &nativeAdapter,
|
|
|
125
124
|
[](const wgpu::Device &, wgpu::DeviceLostReason reason,
|
|
126
125
|
wgpu::StringView message) {
|
|
127
126
|
if (reason != wgpu::DeviceLostReason::Destroyed) {
|
|
128
|
-
RNSkia::RNSkLogger::logToConsole(
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
RNSkia::RNSkLogger::logToConsole("Device lost: %.*s",
|
|
128
|
+
static_cast<int>(message.length),
|
|
129
|
+
message.data);
|
|
131
130
|
}
|
|
132
131
|
});
|
|
133
|
-
desc.SetUncapturedErrorCallback(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
static_cast<int>(message.length), message.data);
|
|
139
|
-
});
|
|
132
|
+
desc.SetUncapturedErrorCallback([](const wgpu::Device &, wgpu::ErrorType,
|
|
133
|
+
wgpu::StringView message) {
|
|
134
|
+
RNSkia::RNSkLogger::logToConsole(
|
|
135
|
+
"Device error: %.*s", static_cast<int>(message.length), message.data);
|
|
136
|
+
});
|
|
140
137
|
}
|
|
141
138
|
|
|
142
139
|
return wgpu::Device::Acquire(nativeAdapter.CreateDevice(&desc));
|
|
@@ -201,7 +198,7 @@ createDawnBackendContext(dawn::native::Instance *instance) {
|
|
|
201
198
|
wgpu::FeatureName::BufferMapExtendedUsages,
|
|
202
199
|
wgpu::FeatureName::TextureCompressionETC2,
|
|
203
200
|
wgpu::FeatureName::TextureCompressionBC,
|
|
204
|
-
wgpu::FeatureName::
|
|
201
|
+
wgpu::FeatureName::BGRA8UnormStorage,
|
|
205
202
|
wgpu::FeatureName::DawnLoadResolveTexture,
|
|
206
203
|
wgpu::FeatureName::DawnPartialLoadResolveTexture,
|
|
207
204
|
wgpu::FeatureName::TimestampQuery,
|
|
@@ -38,7 +38,7 @@ public:
|
|
|
38
38
|
return nullptr;
|
|
39
39
|
}
|
|
40
40
|
skgpu::graphite::DawnTextureInfo info(
|
|
41
|
-
|
|
41
|
+
skgpu::graphite::SampleCount::k1, skgpu::Mipmapped::kNo,
|
|
42
42
|
DawnUtils::PreferredTextureFormat, texture.GetUsage(),
|
|
43
43
|
wgpu::TextureAspect::All);
|
|
44
44
|
auto backendTex = skgpu::graphite::BackendTextures::MakeDawn(texture.Get());
|
|
@@ -106,13 +106,14 @@ void RNSkManager::installBindings() {
|
|
|
106
106
|
rnwgpu::GPUMapMode::create(*_jsRuntime));
|
|
107
107
|
_jsRuntime->global().setProperty(*_jsRuntime, "GPUShaderStage",
|
|
108
108
|
rnwgpu::GPUShaderStage::create(*_jsRuntime));
|
|
109
|
-
_jsRuntime->global().setProperty(
|
|
110
|
-
|
|
109
|
+
_jsRuntime->global().setProperty(
|
|
110
|
+
*_jsRuntime, "GPUTextureUsage",
|
|
111
|
+
rnwgpu::GPUTextureUsage::create(*_jsRuntime));
|
|
111
112
|
|
|
112
113
|
// Install RNWebGPU global object for WebGPU Canvas support
|
|
113
114
|
auto rnWebGPU = std::make_shared<rnwgpu::RNWebGPU>(gpu, nullptr);
|
|
114
|
-
_jsRuntime->global().setProperty(
|
|
115
|
-
|
|
115
|
+
_jsRuntime->global().setProperty(
|
|
116
|
+
*_jsRuntime, "RNWebGPU", rnwgpu::RNWebGPU::create(*_jsRuntime, rnWebGPU));
|
|
116
117
|
#endif
|
|
117
118
|
}
|
|
118
119
|
} // namespace RNSkia
|
|
@@ -93,8 +93,8 @@ public:
|
|
|
93
93
|
* @param useP3ColorSpace If true, surface will use Display P3 color space
|
|
94
94
|
* @return sk_sp<SkSurface>
|
|
95
95
|
*/
|
|
96
|
-
virtual sk_sp<SkSurface>
|
|
97
|
-
|
|
96
|
+
virtual sk_sp<SkSurface>
|
|
97
|
+
makeOffscreenSurface(int width, int height, bool useP3ColorSpace = false) = 0;
|
|
98
98
|
|
|
99
99
|
virtual std::shared_ptr<WindowContext>
|
|
100
100
|
makeContextFromNativeSurface(void *surface, int width, int height) = 0;
|
package/cpp/rnwgpu/api/GPU.cpp
CHANGED
|
@@ -124,6 +124,27 @@ std::unordered_set<std::string> GPU::getWgslLanguageFeatures() {
|
|
|
124
124
|
case wgpu::WGSLLanguageFeatureName::ChromiumPrint:
|
|
125
125
|
name = "chromium_print";
|
|
126
126
|
break;
|
|
127
|
+
case wgpu::WGSLLanguageFeatureName::TextureAndSamplerLet:
|
|
128
|
+
name = "texture_and_sampler_let";
|
|
129
|
+
break;
|
|
130
|
+
case wgpu::WGSLLanguageFeatureName::SubgroupUniformity:
|
|
131
|
+
name = "subgroup_uniformity";
|
|
132
|
+
break;
|
|
133
|
+
case wgpu::WGSLLanguageFeatureName::TextureFormatsTier1:
|
|
134
|
+
name = "texture_formats_tier1";
|
|
135
|
+
break;
|
|
136
|
+
case wgpu::WGSLLanguageFeatureName::BufferView:
|
|
137
|
+
name = "buffer_view";
|
|
138
|
+
break;
|
|
139
|
+
case wgpu::WGSLLanguageFeatureName::FilteringParameters:
|
|
140
|
+
name = "filtering_parameters";
|
|
141
|
+
break;
|
|
142
|
+
case wgpu::WGSLLanguageFeatureName::SwizzleAssignment:
|
|
143
|
+
name = "swizzle_assignment";
|
|
144
|
+
break;
|
|
145
|
+
case wgpu::WGSLLanguageFeatureName::LinearIndexing:
|
|
146
|
+
name = "linear_indexing";
|
|
147
|
+
break;
|
|
127
148
|
}
|
|
128
149
|
result.insert(name);
|
|
129
150
|
}
|
|
@@ -47,7 +47,7 @@ std::shared_ptr<GPUTexture> GPUCanvasContext::getCurrentTexture() {
|
|
|
47
47
|
_surfaceInfo->reconfigure(width, height);
|
|
48
48
|
}
|
|
49
49
|
auto texture = _surfaceInfo->getCurrentTexture();
|
|
50
|
-
return std::make_shared<GPUTexture>(texture, "");
|
|
50
|
+
return std::make_shared<GPUTexture>(texture, "", false);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
void GPUCanvasContext::present() {
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
#include "jsi2/NativeObject.h"
|
|
12
12
|
|
|
13
|
-
#include "rnwgpu/Canvas.h"
|
|
14
13
|
#include "GPU.h"
|
|
15
|
-
#include "descriptors/GPUCanvasConfiguration.h"
|
|
16
14
|
#include "GPUTexture.h"
|
|
15
|
+
#include "descriptors/GPUCanvasConfiguration.h"
|
|
16
|
+
#include "rnwgpu/Canvas.h"
|
|
17
17
|
#include "rnwgpu/SurfaceRegistry.h"
|
|
18
18
|
|
|
19
19
|
namespace rnwgpu {
|
|
@@ -89,9 +89,6 @@ static void convertEnumToJSUnion(wgpu::FeatureName inEnum,
|
|
|
89
89
|
case wgpu::FeatureName::Unorm16TextureFormats:
|
|
90
90
|
*outUnion = "unorm16-texture-formats";
|
|
91
91
|
break;
|
|
92
|
-
case wgpu::FeatureName::Snorm16TextureFormats:
|
|
93
|
-
*outUnion = "snorm16-texture-formats";
|
|
94
|
-
break;
|
|
95
92
|
case wgpu::FeatureName::MultiPlanarFormatExtendedUsages:
|
|
96
93
|
*outUnion = "multi-planar-format-extended-usages";
|
|
97
94
|
break;
|
|
@@ -122,18 +119,12 @@ static void convertEnumToJSUnion(wgpu::FeatureName inEnum,
|
|
|
122
119
|
case wgpu::FeatureName::AdapterPropertiesVk:
|
|
123
120
|
*outUnion = "adapter-properties-vk";
|
|
124
121
|
break;
|
|
125
|
-
case wgpu::FeatureName::R8UnormStorage:
|
|
126
|
-
*outUnion = "r8unorm-storage";
|
|
127
|
-
break;
|
|
128
122
|
case wgpu::FeatureName::DawnFormatCapabilities:
|
|
129
123
|
*outUnion = "format-capabilities";
|
|
130
124
|
break;
|
|
131
125
|
case wgpu::FeatureName::DawnDrmFormatCapabilities:
|
|
132
126
|
*outUnion = "drm-format-capabilities";
|
|
133
127
|
break;
|
|
134
|
-
case wgpu::FeatureName::Norm16TextureFormats:
|
|
135
|
-
*outUnion = "norm16-texture-formats";
|
|
136
|
-
break;
|
|
137
128
|
case wgpu::FeatureName::MultiPlanarFormatNv16:
|
|
138
129
|
*outUnion = "multi-planar-format-nv16";
|
|
139
130
|
break;
|
|
@@ -21,8 +21,10 @@ class GPUTexture : public NativeObject<GPUTexture> {
|
|
|
21
21
|
public:
|
|
22
22
|
static constexpr const char *CLASS_NAME = "GPUTexture";
|
|
23
23
|
|
|
24
|
-
explicit GPUTexture(wgpu::Texture instance, std::string label
|
|
25
|
-
|
|
24
|
+
explicit GPUTexture(wgpu::Texture instance, std::string label,
|
|
25
|
+
bool reportsMemoryPressure = true)
|
|
26
|
+
: NativeObject(CLASS_NAME), _instance(instance), _label(label),
|
|
27
|
+
_reportsMemoryPressure(reportsMemoryPressure) {}
|
|
26
28
|
|
|
27
29
|
public:
|
|
28
30
|
std::string getBrand() { return CLASS_NAME; }
|
|
@@ -68,6 +70,9 @@ public:
|
|
|
68
70
|
inline const wgpu::Texture get() { return _instance; }
|
|
69
71
|
|
|
70
72
|
size_t getMemoryPressure() override {
|
|
73
|
+
if (!_reportsMemoryPressure) {
|
|
74
|
+
return sizeof(GPUTexture);
|
|
75
|
+
}
|
|
71
76
|
// Calculate approximate memory usage based on texture properties
|
|
72
77
|
uint32_t width = getWidth();
|
|
73
78
|
uint32_t height = getHeight();
|
|
@@ -85,6 +90,7 @@ public:
|
|
|
85
90
|
case wgpu::TextureFormat::R8Snorm:
|
|
86
91
|
case wgpu::TextureFormat::R8Uint:
|
|
87
92
|
case wgpu::TextureFormat::R8Sint:
|
|
93
|
+
case wgpu::TextureFormat::Stencil8:
|
|
88
94
|
bytesPerPixel = 1;
|
|
89
95
|
break;
|
|
90
96
|
case wgpu::TextureFormat::R16Uint:
|
|
@@ -94,6 +100,7 @@ public:
|
|
|
94
100
|
case wgpu::TextureFormat::RG8Snorm:
|
|
95
101
|
case wgpu::TextureFormat::RG8Uint:
|
|
96
102
|
case wgpu::TextureFormat::RG8Sint:
|
|
103
|
+
case wgpu::TextureFormat::Depth16Unorm:
|
|
97
104
|
bytesPerPixel = 2;
|
|
98
105
|
break;
|
|
99
106
|
case wgpu::TextureFormat::RGBA8Unorm:
|
|
@@ -110,6 +117,9 @@ public:
|
|
|
110
117
|
case wgpu::TextureFormat::RG16Uint:
|
|
111
118
|
case wgpu::TextureFormat::RG16Sint:
|
|
112
119
|
case wgpu::TextureFormat::RG16Float:
|
|
120
|
+
case wgpu::TextureFormat::Depth24Plus:
|
|
121
|
+
case wgpu::TextureFormat::Depth24PlusStencil8:
|
|
122
|
+
case wgpu::TextureFormat::Depth32Float:
|
|
113
123
|
bytesPerPixel = 4;
|
|
114
124
|
break;
|
|
115
125
|
case wgpu::TextureFormat::RG32Float:
|
|
@@ -118,6 +128,7 @@ public:
|
|
|
118
128
|
case wgpu::TextureFormat::RGBA16Uint:
|
|
119
129
|
case wgpu::TextureFormat::RGBA16Sint:
|
|
120
130
|
case wgpu::TextureFormat::RGBA16Float:
|
|
131
|
+
case wgpu::TextureFormat::Depth32FloatStencil8:
|
|
121
132
|
bytesPerPixel = 8;
|
|
122
133
|
break;
|
|
123
134
|
case wgpu::TextureFormat::RGBA32Float:
|
|
@@ -145,6 +156,7 @@ public:
|
|
|
145
156
|
private:
|
|
146
157
|
wgpu::Texture _instance;
|
|
147
158
|
std::string _label;
|
|
159
|
+
bool _reportsMemoryPressure = true;
|
|
148
160
|
};
|
|
149
161
|
|
|
150
162
|
} // namespace rnwgpu
|
|
@@ -15,10 +15,9 @@ namespace rnwgpu {
|
|
|
15
15
|
|
|
16
16
|
namespace jsi = facebook::jsi;
|
|
17
17
|
|
|
18
|
-
using GPUErrorVariant =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
std::shared_ptr<GPUInternalError>>;
|
|
18
|
+
using GPUErrorVariant = std::variant<std::shared_ptr<GPUValidationError>,
|
|
19
|
+
std::shared_ptr<GPUOutOfMemoryError>,
|
|
20
|
+
std::shared_ptr<GPUInternalError>>;
|
|
22
21
|
|
|
23
22
|
class GPUUncapturedErrorEvent : public NativeObject<GPUUncapturedErrorEvent> {
|
|
24
23
|
public:
|