@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.
Files changed (118) hide show
  1. package/android/CMakeLists.txt +0 -1
  2. package/android/cpp/jni/JniWebGPUView.cpp +3 -3
  3. package/android/cpp/rnskia-android/OpenGLContext.h +4 -5
  4. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +1 -1
  5. package/apple/MetalContext.h +5 -6
  6. package/apple/MetalWindowContext.mm +3 -4
  7. package/apple/RNSkApplePlatformContext.h +1 -1
  8. package/apple/RNSkApplePlatformContext.mm +4 -3
  9. package/apple/SkiaCVPixelBufferUtils.h +1 -1
  10. package/apple/SkiaCVPixelBufferUtils.mm +31 -30
  11. package/apple/SkiaPlatformContext.mm +2 -2
  12. package/apple/SkiaUIView.mm +1 -1
  13. package/apple/SkiaWebGPUView.mm +8 -4
  14. package/apple/WebGPUMetalView.h +1 -1
  15. package/apple/WebGPUMetalView.mm +1 -1
  16. package/cpp/api/JsiSkColor.h +8 -4
  17. package/cpp/api/JsiSkContourMeasure.h +4 -3
  18. package/cpp/api/JsiSkImage.h +17 -9
  19. package/cpp/api/JsiSkParagraphBuilder.h +14 -1
  20. package/cpp/api/JsiSkPath.h +71 -81
  21. package/cpp/api/JsiSkPathEffectFactory.h +2 -1
  22. package/cpp/api/JsiSkPathFactory.h +48 -52
  23. package/cpp/api/JsiSkShader.h +1 -1
  24. package/cpp/api/JsiSkShaderFactory.h +50 -26
  25. package/cpp/api/JsiSkSurfaceFactory.h +2 -1
  26. package/cpp/api/recorder/Drawings.h +5 -7
  27. package/cpp/api/recorder/Shaders.h +77 -22
  28. package/cpp/jsi2/JSIConverter.h +1 -1
  29. package/cpp/rnskia/RNDawnContext.h +14 -15
  30. package/cpp/rnskia/RNDawnUtils.h +14 -17
  31. package/cpp/rnskia/RNDawnWindowContext.h +1 -1
  32. package/cpp/rnskia/RNSkManager.cpp +5 -4
  33. package/cpp/rnskia/RNSkPlatformContext.h +2 -2
  34. package/cpp/rnwgpu/api/GPU.cpp +21 -0
  35. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +1 -1
  36. package/cpp/rnwgpu/api/GPUCanvasContext.h +2 -2
  37. package/cpp/rnwgpu/api/GPUFeatures.h +0 -9
  38. package/cpp/rnwgpu/api/GPUTexture.h +14 -2
  39. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +3 -4
  40. package/cpp/rnwgpu/api/RNWebGPU.h +1 -1
  41. package/cpp/rnwgpu/api/descriptors/Unions.h +0 -15
  42. package/cpp/skia/include/android/SkImageAndroid.h +7 -2
  43. package/cpp/skia/include/android/vk/AndroidVulkanMemoryAllocator.h +31 -0
  44. package/cpp/skia/include/codec/SkCodec.h +42 -15
  45. package/cpp/skia/include/config/SkUserConfig.h +8 -0
  46. package/cpp/skia/include/core/SkBitmap.h +0 -5
  47. package/cpp/skia/include/core/SkCanvas.h +2 -39
  48. package/cpp/skia/include/core/SkColor.h +12 -0
  49. package/cpp/skia/include/core/SkColorSpace.h +9 -0
  50. package/cpp/skia/include/core/SkContourMeasure.h +1 -5
  51. package/cpp/skia/include/core/SkData.h +8 -0
  52. package/cpp/skia/include/core/SkFont.h +1 -55
  53. package/cpp/skia/include/core/SkFontArguments.h +15 -0
  54. package/cpp/skia/include/core/SkGraphics.h +0 -5
  55. package/cpp/skia/include/core/SkImage.h +0 -4
  56. package/cpp/skia/include/core/SkImageGenerator.h +1 -4
  57. package/cpp/skia/include/core/SkMatrix.h +0 -37
  58. package/cpp/skia/include/core/SkMilestone.h +1 -1
  59. package/cpp/skia/include/core/SkPath.h +11 -911
  60. package/cpp/skia/include/core/SkPathBuilder.h +42 -32
  61. package/cpp/skia/include/core/SkPathEffect.h +0 -9
  62. package/cpp/skia/include/core/SkPathMeasure.h +1 -4
  63. package/cpp/skia/include/core/SkPathUtils.h +0 -10
  64. package/cpp/skia/include/core/SkRect.h +0 -12
  65. package/cpp/skia/include/core/SkRegion.h +1 -6
  66. package/cpp/skia/include/core/SkSerialProcs.h +4 -5
  67. package/cpp/skia/include/core/SkSurfaceProps.h +6 -0
  68. package/cpp/skia/include/core/SkTextBlob.h +0 -22
  69. package/cpp/skia/include/core/SkTypeface.h +14 -32
  70. package/cpp/skia/include/core/SkTypes.h +0 -8
  71. package/cpp/skia/include/docs/SkPDFDocument.h +19 -17
  72. package/cpp/skia/include/effects/SkDashPathEffect.h +0 -6
  73. package/cpp/skia/include/effects/SkGradient.h +206 -0
  74. package/cpp/skia/include/effects/SkHighContrastFilter.h +2 -2
  75. package/cpp/skia/include/gpu/GpuTypes.h +2 -0
  76. package/cpp/skia/include/gpu/ganesh/GrBackendSemaphore.h +5 -35
  77. package/cpp/skia/include/gpu/ganesh/GrBackendSurface.h +7 -106
  78. package/cpp/skia/include/gpu/ganesh/GrContextOptions.h +0 -11
  79. package/cpp/skia/include/gpu/ganesh/GrDirectContext.h +0 -9
  80. package/cpp/skia/include/gpu/ganesh/d3d/GrD3DBackendSemaphore.h +20 -0
  81. package/cpp/skia/include/gpu/ganesh/d3d/GrD3DBackendSurface.h +59 -0
  82. package/cpp/skia/include/gpu/ganesh/d3d/GrD3DDirectContext.h +28 -0
  83. package/cpp/skia/include/gpu/ganesh/gl/GrGLFunctions.h +4 -1
  84. package/cpp/skia/include/gpu/graphite/ContextOptions.h +4 -20
  85. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +32 -46
  86. package/cpp/skia/include/gpu/graphite/Recorder.h +1 -1
  87. package/cpp/skia/include/gpu/graphite/Surface.h +31 -0
  88. package/cpp/skia/include/gpu/graphite/TextureInfo.h +3 -10
  89. package/cpp/skia/include/gpu/graphite/dawn/DawnGraphiteTypes.h +3 -3
  90. package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h +1 -1
  91. package/cpp/skia/include/gpu/graphite/precompile/PrecompileShader.h +6 -6
  92. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +5 -3
  93. package/cpp/skia/include/gpu/graphite/vk/precompile/VulkanPrecompileShader.h +1 -1
  94. package/cpp/skia/include/gpu/vk/VulkanBackendContext.h +1 -1
  95. package/cpp/skia/include/gpu/vk/VulkanPreferredFeatures.h +8 -0
  96. package/cpp/skia/include/private/SkEncodedInfo.h +43 -105
  97. package/cpp/skia/include/private/SkHdrMetadata.h +165 -2
  98. package/cpp/skia/include/private/SkPathRef.h +0 -457
  99. package/cpp/skia/include/private/base/SkFeatures.h +4 -0
  100. package/cpp/skia/include/private/base/SkFloatingPoint.h +1 -2
  101. package/cpp/skia/include/private/base/SkLoadUserConfig.h +2 -1
  102. package/cpp/skia/include/private/base/SkLog.h +68 -0
  103. package/cpp/skia/include/private/base/SkLogPriority.h +35 -0
  104. package/cpp/skia/include/private/base/SkMacros.h +9 -0
  105. package/cpp/skia/include/private/base/SkTArray.h +1 -1
  106. package/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h +10 -24
  107. package/cpp/skia/include/utils/SkEventTracer.h +5 -7
  108. package/cpp/skia/modules/skottie/include/TextShaper.h +0 -7
  109. package/cpp/skia/modules/skparagraph/include/FontCollection.h +6 -20
  110. package/cpp/skia/modules/skparagraph/include/ParagraphBuilder.h +0 -6
  111. package/cpp/skia/modules/skparagraph/include/ParagraphCache.h +4 -19
  112. package/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h +2 -3
  113. package/cpp/skia/modules/skunicode/include/SkUnicode_icu.h +18 -0
  114. package/cpp/skia/modules/skunicode/include/SkUnicode_libgrapheme.h +19 -0
  115. package/cpp/skia/src/base/SkMathPriv.h +27 -132
  116. package/package.json +5 -5
  117. package/cpp/skia/include/effects/SkGradientShader.h +0 -359
  118. 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<SkColor> getColors(jsi::Runtime &runtime, const jsi::Value &value) {
48
- std::vector<SkColor> colors;
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<SkColor> colors = getColors(runtime, arguments[2]);
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
- sk_sp<SkShader> gradient = SkGradientShader::MakeLinear(
101
- pts, colors.data(), !positions.empty() ? positions.data() : nullptr,
102
- static_cast<int>(colorsSize), tileMode, flag, localMatrix);
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<SkColor> colors = getColors(runtime, arguments[2]);
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
- sk_sp<SkShader> gradient = SkGradientShader::MakeRadial(
129
- center, r, colors.data(),
130
- !positions.empty() ? positions.data() : nullptr,
131
- static_cast<int>(colorsSize), tileMode, flag, localMatrix);
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<SkColor> colors = getColors(runtime, arguments[2]);
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
- (count < 8 || arguments[7].isUndefined()) ? 0 : arguments[7].asNumber();
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
- sk_sp<SkShader> gradient = SkGradientShader::MakeSweep(
160
- x, y, colors.data(), !positions.empty() ? positions.data() : nullptr,
161
- static_cast<int>(colorsSize), tileMode, startAngle, endAngle, flag,
162
- localMatrix);
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<SkColor> colors = getColors(runtime, arguments[4]);
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
- sk_sp<SkShader> gradient = SkGradientShader::MakeTwoPointConical(
193
- start, startRadius, end, endRadius, colors.data(),
194
- !positions.empty() ? positions.data() : nullptr,
195
- static_cast<int>(colorsSize), tileMode, flag, localMatrix);
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 = context->makeOffscreenSurface(width, height, useP3ColorSpace);
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
- float precision = stroke.precision.value_or(1.0f);
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::const_pointer_cast<const SkPath>(strokedPath);
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, variables);
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
- auto shader = SkGradientShader::MakeLinear(
254
- pts, props.colors.data(),
255
- props.positions ? props.positions->data() : nullptr,
256
- props.colors.size(), props.mode.value_or(SkTileMode::kClamp),
257
- props.flags.value_or(0), &m3);
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
- auto shader = SkGradientShader::MakeRadial(
297
- props.center, props.radius, props.colors.data(),
298
- props.positions ? props.positions->data() : nullptr,
299
- props.colors.size(), props.mode.value_or(SkTileMode::kClamp),
300
- props.flags.value_or(0), &m3);
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
- auto shader = SkGradientShader::MakeSweep(
342
- props.center.x(), props.center.y(), props.colors.data(),
343
- props.positions ? props.positions->data() : nullptr,
344
- props.colors.size(), props.mode.value_or(SkTileMode::kClamp),
345
- props.start.value_or(0), props.end.value_or(360),
346
- props.flags.value_or(0), &m3);
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
- auto shader = SkGradientShader::MakeTwoPointConical(
391
- props.start, props.startRadius, props.end, props.endRadius,
392
- props.colors.data(),
393
- props.positions ? props.positions->data() : nullptr,
394
- props.colors.size(), props.mode.value_or(SkTileMode::kClamp),
395
- props.flags.value_or(0), &m3);
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
  };
@@ -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
- bool outOfBound) {
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
- bool useP3ColorSpace = false) {
166
+ bool useP3ColorSpace = false) {
168
167
  sk_sp<SkColorSpace> colorSpace =
169
- useP3ColorSpace
170
- ? SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
171
- SkNamedGamut::kDisplayP3)
172
- : nullptr;
173
- SkImageInfo info = SkImageInfo::Make(
174
- width, height, DawnUtils::PreferedColorType, kPremul_SkAlphaType,
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 ImplicitDeviceSynchronization,
193
- // so it won't contend with the primary rendering device's mutex.
194
- // Safe for concurrent GPU work (e.g. ML inference) alongside Skia rendering.
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
- // Note: SharedFenceMTLSharedEvent intentionally NOT enabled — it causes
204
- // EndAccess to encode fence signals that crash with "uncommitted encoder".
205
- // IOSurface data is already written by the camera before we read it.
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
 
@@ -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
- static_cast<int>(message.length), message.data);
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
- wgpu::StringView message) {
119
- SkDebugf("Device error: %.*s\n",
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
- "Device lost: %.*s",
130
- static_cast<int>(message.length), message.data);
127
+ RNSkia::RNSkLogger::logToConsole("Device lost: %.*s",
128
+ static_cast<int>(message.length),
129
+ message.data);
131
130
  }
132
131
  });
133
- desc.SetUncapturedErrorCallback(
134
- [](const wgpu::Device &, wgpu::ErrorType,
135
- wgpu::StringView message) {
136
- RNSkia::RNSkLogger::logToConsole(
137
- "Device error: %.*s",
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::R8UnormStorage,
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
- /*sampleCount=*/1, skgpu::Mipmapped::kNo,
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(*_jsRuntime, "GPUTextureUsage",
110
- rnwgpu::GPUTextureUsage::create(*_jsRuntime));
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(*_jsRuntime, "RNWebGPU",
115
- rnwgpu::RNWebGPU::create(*_jsRuntime, rnWebGPU));
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> makeOffscreenSurface(int width, int height,
97
- bool useP3ColorSpace = false) = 0;
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;
@@ -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
- : NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
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
- std::variant<std::shared_ptr<GPUValidationError>,
20
- std::shared_ptr<GPUOutOfMemoryError>,
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:
@@ -5,9 +5,9 @@
5
5
 
6
6
  #include "jsi2/NativeObject.h"
7
7
 
8
- #include "rnwgpu/Canvas.h"
9
8
  #include "GPU.h"
10
9
  #include "GPUCanvasContext.h"
10
+ #include "rnwgpu/Canvas.h"
11
11
  #include "rnwgpu/PlatformContext.h"
12
12
 
13
13
  namespace rnwgpu {