@shopify/react-native-skia 2.0.0-next.4 → 2.0.0
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/apple/RNSkApplePlatformContext.h +2 -1
- package/apple/RNSkApplePlatformContext.mm +6 -4
- package/apple/RNSkAppleView.h +1 -1
- package/apple/RNSkAppleView.mm +1 -1
- package/apple/SkiaManager.mm +2 -1
- package/apple/SkiaUIView.h +1 -1
- package/cpp/api/JsiSkCanvas.h +29 -25
- package/cpp/api/recorder/Drawings.h +13 -17
- package/cpp/api/recorder/Shaders.h +21 -32
- package/package.json +2 -3
@@ -26,7 +26,8 @@ public:
|
|
26
26
|
#if !TARGET_OS_OSX
|
27
27
|
: RNSkPlatformContext(jsCallInvoker, [[UIScreen mainScreen] scale]) {
|
28
28
|
#else
|
29
|
-
: RNSkPlatformContext(jsCallInvoker,
|
29
|
+
: RNSkPlatformContext(jsCallInvoker,
|
30
|
+
[[NSScreen mainScreen] backingScaleFactor]) {
|
30
31
|
#endif // !TARGET_OS_OSX
|
31
32
|
|
32
33
|
// Create screenshot manager
|
@@ -173,7 +173,8 @@ const TextureInfo RNSkApplePlatformContext::getTexture(sk_sp<SkImage> image) {
|
|
173
173
|
return result;
|
174
174
|
}
|
175
175
|
|
176
|
-
const TextureInfo
|
176
|
+
const TextureInfo
|
177
|
+
RNSkApplePlatformContext::getTexture(sk_sp<SkSurface> surface) {
|
177
178
|
GrBackendTexture texture = SkSurfaces::GetBackendTexture(
|
178
179
|
surface.get(), SkSurfaces::BackendHandleAccess::kFlushRead);
|
179
180
|
TextureInfo result;
|
@@ -195,7 +196,7 @@ RNSkApplePlatformContext::createVideo(const std::string &url) {
|
|
195
196
|
|
196
197
|
std::shared_ptr<WindowContext>
|
197
198
|
RNSkApplePlatformContext::makeContextFromNativeSurface(void *surface, int width,
|
198
|
-
|
199
|
+
int height) {
|
199
200
|
#if defined(SK_GRAPHITE)
|
200
201
|
return DawnContext::getInstance().MakeWindow(surface, width, height);
|
201
202
|
#else
|
@@ -209,7 +210,7 @@ void RNSkApplePlatformContext::raiseError(const std::exception &err) {
|
|
209
210
|
}
|
210
211
|
|
211
212
|
sk_sp<SkSurface> RNSkApplePlatformContext::makeOffscreenSurface(int width,
|
212
|
-
|
213
|
+
int height) {
|
213
214
|
#if defined(SK_GRAPHITE)
|
214
215
|
return DawnContext::getInstance().MakeOffscreen(width, height);
|
215
216
|
#else
|
@@ -217,7 +218,8 @@ sk_sp<SkSurface> RNSkApplePlatformContext::makeOffscreenSurface(int width,
|
|
217
218
|
#endif
|
218
219
|
}
|
219
220
|
|
220
|
-
sk_sp<SkImage>
|
221
|
+
sk_sp<SkImage>
|
222
|
+
RNSkApplePlatformContext::makeImageFromNativeBuffer(void *buffer) {
|
221
223
|
#if defined(SK_GRAPHITE)
|
222
224
|
return DawnContext::getInstance().MakeImageFromBuffer(buffer);
|
223
225
|
#else
|
package/apple/RNSkAppleView.h
CHANGED
package/apple/RNSkAppleView.mm
CHANGED
package/apple/SkiaManager.mm
CHANGED
@@ -41,7 +41,8 @@ static __weak SkiaManager *sharedInstance = nil;
|
|
41
41
|
// Create the RNSkiaManager (cross platform)
|
42
42
|
_skManager = std::make_shared<RNSkia::RNSkManager>(
|
43
43
|
jsRuntime, jsInvoker,
|
44
|
-
std::make_shared<RNSkia::RNSkApplePlatformContext>(bridge,
|
44
|
+
std::make_shared<RNSkia::RNSkApplePlatformContext>(bridge,
|
45
|
+
jsInvoker));
|
45
46
|
}
|
46
47
|
}
|
47
48
|
return self;
|
package/apple/SkiaUIView.h
CHANGED
package/cpp/api/JsiSkCanvas.h
CHANGED
@@ -243,12 +243,12 @@ public:
|
|
243
243
|
|
244
244
|
auto jsiPoints = arguments[1].asObject(runtime).asArray(runtime);
|
245
245
|
auto pointsSize = jsiPoints.size(runtime);
|
246
|
-
|
246
|
+
|
247
247
|
// Check if we have at least one point
|
248
248
|
if (pointsSize == 0) {
|
249
249
|
throw std::invalid_argument("Points array must not be empty");
|
250
250
|
}
|
251
|
-
|
251
|
+
|
252
252
|
points.reserve(pointsSize);
|
253
253
|
|
254
254
|
for (int i = 0; i < pointsSize; i++) {
|
@@ -280,12 +280,13 @@ public:
|
|
280
280
|
|
281
281
|
auto jsiCubics = arguments[0].asObject(runtime).asArray(runtime);
|
282
282
|
auto cubicsSize = jsiCubics.size(runtime);
|
283
|
-
|
283
|
+
|
284
284
|
// Validate cubic points - must be exactly 12 points
|
285
285
|
if (cubicsSize != 12) {
|
286
|
-
throw std::invalid_argument(
|
286
|
+
throw std::invalid_argument(
|
287
|
+
"Cubic points array must contain exactly 12 points");
|
287
288
|
}
|
288
|
-
|
289
|
+
|
289
290
|
cubics.reserve(cubicsSize);
|
290
291
|
for (int i = 0; i < cubicsSize; i++) {
|
291
292
|
std::shared_ptr<SkPoint> point = JsiSkPoint::fromValue(
|
@@ -296,12 +297,13 @@ public:
|
|
296
297
|
if (count >= 2 && !arguments[1].isNull() && !arguments[1].isUndefined()) {
|
297
298
|
auto jsiColors = arguments[1].asObject(runtime).asArray(runtime);
|
298
299
|
auto colorsSize = jsiColors.size(runtime);
|
299
|
-
|
300
|
+
|
300
301
|
// Validate colors array - must be exactly 4 colors
|
301
302
|
if (colorsSize != 4) {
|
302
|
-
throw std::invalid_argument(
|
303
|
+
throw std::invalid_argument(
|
304
|
+
"Colors array must contain exactly 4 colors");
|
303
305
|
}
|
304
|
-
|
306
|
+
|
305
307
|
colors.reserve(colorsSize);
|
306
308
|
for (int i = 0; i < colorsSize; i++) {
|
307
309
|
SkColor color = JsiSkColor::fromValue(
|
@@ -313,12 +315,13 @@ public:
|
|
313
315
|
if (count >= 3 && !arguments[2].isNull() && !arguments[2].isUndefined()) {
|
314
316
|
auto jsiTexs = arguments[2].asObject(runtime).asArray(runtime);
|
315
317
|
auto texsSize = jsiTexs.size(runtime);
|
316
|
-
|
318
|
+
|
317
319
|
// Validate textures array - must be exactly 4 points
|
318
320
|
if (texsSize != 4) {
|
319
|
-
throw std::invalid_argument(
|
321
|
+
throw std::invalid_argument(
|
322
|
+
"Texture coordinates array must contain exactly 4 points");
|
320
323
|
}
|
321
|
-
|
324
|
+
|
322
325
|
texs.reserve(texsSize);
|
323
326
|
for (int i = 0; i < texsSize; i++) {
|
324
327
|
auto point = JsiSkPoint::fromValue(
|
@@ -330,9 +333,8 @@ public:
|
|
330
333
|
auto paint =
|
331
334
|
count >= 4 ? JsiSkPaint::fromValue(runtime, arguments[4]) : nullptr;
|
332
335
|
auto blendMode = static_cast<SkBlendMode>(arguments[3].asNumber());
|
333
|
-
_canvas->drawPatch(cubics.data(), colors.empty() ? nullptr : colors.data(),
|
334
|
-
texs.empty() ? nullptr : texs.data(), blendMode,
|
335
|
-
*paint);
|
336
|
+
_canvas->drawPatch(cubics.data(), colors.empty() ? nullptr : colors.data(),
|
337
|
+
texs.empty() ? nullptr : texs.data(), blendMode, *paint);
|
336
338
|
return jsi::Value::undefined();
|
337
339
|
}
|
338
340
|
|
@@ -389,12 +391,13 @@ public:
|
|
389
391
|
|
390
392
|
std::vector<SkGlyphID> glyphs;
|
391
393
|
int glyphsSize = static_cast<int>(jsiGlyphs.size(runtime));
|
392
|
-
|
394
|
+
|
393
395
|
// Validate that glyphs and positions arrays have the same size
|
394
396
|
if (glyphsSize != pointsSize) {
|
395
|
-
throw std::invalid_argument(
|
397
|
+
throw std::invalid_argument(
|
398
|
+
"Glyphs and positions arrays must have the same length");
|
396
399
|
}
|
397
|
-
|
400
|
+
|
398
401
|
glyphs.reserve(glyphsSize);
|
399
402
|
for (int i = 0; i < glyphsSize; i++) {
|
400
403
|
glyphs.push_back(jsiGlyphs.getValueAtIndex(runtime, i).asNumber());
|
@@ -553,22 +556,24 @@ public:
|
|
553
556
|
runtime, rects.getValueAtIndex(runtime, i).asObject(runtime));
|
554
557
|
skRects.push_back(*rect.get());
|
555
558
|
}
|
556
|
-
|
559
|
+
|
557
560
|
// Validate transforms and rects have the same size
|
558
561
|
if (xformsSize != rectsSize) {
|
559
|
-
throw std::invalid_argument(
|
562
|
+
throw std::invalid_argument(
|
563
|
+
"Transforms and rects arrays must have the same length");
|
560
564
|
}
|
561
565
|
|
562
566
|
std::vector<SkColor> colors;
|
563
567
|
if (count > 5 && !arguments[5].isUndefined()) {
|
564
568
|
auto colorsArray = arguments[5].asObject(runtime).asArray(runtime);
|
565
569
|
int colorsSize = static_cast<int>(colorsArray.size(runtime));
|
566
|
-
|
570
|
+
|
567
571
|
// Validate colors array matches the size of sprites and transforms
|
568
572
|
if (colorsSize != rectsSize) {
|
569
|
-
throw std::invalid_argument(
|
573
|
+
throw std::invalid_argument(
|
574
|
+
"Colors array must have the same length as rects/transforms");
|
570
575
|
}
|
571
|
-
|
576
|
+
|
572
577
|
colors.reserve(colorsSize);
|
573
578
|
for (int i = 0; i < colorsSize; i++) {
|
574
579
|
// Convert from [r,g,b,a] in [0,1] to SkColor
|
@@ -593,9 +598,8 @@ public:
|
|
593
598
|
sampling = SamplingOptionsFromValue(runtime, arguments[6]);
|
594
599
|
}
|
595
600
|
_canvas->drawAtlas(atlas.get(), xforms.data(), skRects.data(),
|
596
|
-
colors.empty() ? nullptr : colors.data(),
|
597
|
-
|
598
|
-
nullptr, paint.get());
|
601
|
+
colors.empty() ? nullptr : colors.data(), skRects.size(),
|
602
|
+
blendMode, sampling, nullptr, paint.get());
|
599
603
|
|
600
604
|
return jsi::Value::undefined();
|
601
605
|
}
|
@@ -639,12 +639,14 @@ public:
|
|
639
639
|
void draw(DrawingCtx *ctx) {
|
640
640
|
// Validate colors array has exactly 4 colors if provided
|
641
641
|
if (props.colors.has_value() && props.colors.value().size() != 4) {
|
642
|
-
throw std::invalid_argument(
|
642
|
+
throw std::invalid_argument(
|
643
|
+
"Colors array for patch must have exactly 4 colors");
|
643
644
|
}
|
644
|
-
|
645
|
+
|
645
646
|
// Validate texture array has exactly 4 points if provided
|
646
647
|
if (props.texture.has_value() && props.texture.value().size() != 4) {
|
647
|
-
throw std::invalid_argument(
|
648
|
+
throw std::invalid_argument(
|
649
|
+
"Texture coordinates array for patch must have exactly 4 points");
|
648
650
|
}
|
649
651
|
|
650
652
|
// Determine default blend mode based on presence of colors
|
@@ -686,15 +688,6 @@ public:
|
|
686
688
|
}
|
687
689
|
|
688
690
|
void draw(DrawingCtx *ctx) {
|
689
|
-
// Validate array sizes
|
690
|
-
if (props.colors.has_value() && props.colors.value().size() != props.vertices.size()) {
|
691
|
-
throw std::invalid_argument("Colors array must have the same size as vertices array");
|
692
|
-
}
|
693
|
-
|
694
|
-
if (props.textures.has_value() && props.textures.value().size() != props.vertices.size()) {
|
695
|
-
throw std::invalid_argument("Textures array must have the same size as vertices array");
|
696
|
-
}
|
697
|
-
|
698
691
|
// Create vertices using MakeCopy
|
699
692
|
auto vertices = SkVertices::MakeCopy(
|
700
693
|
props.mode, static_cast<int>(props.vertices.size()),
|
@@ -930,14 +923,17 @@ public:
|
|
930
923
|
if (props.image) {
|
931
924
|
// Validate transforms and sprites have the same size
|
932
925
|
if (props.transforms.size() != props.sprites.size()) {
|
933
|
-
throw std::invalid_argument(
|
926
|
+
throw std::invalid_argument(
|
927
|
+
"transforms and sprites arrays must have the same length");
|
934
928
|
}
|
935
|
-
|
929
|
+
|
936
930
|
// Validate colors array matches if provided
|
937
|
-
if (props.colors.has_value() &&
|
938
|
-
|
931
|
+
if (props.colors.has_value() &&
|
932
|
+
props.colors.value().size() != props.transforms.size()) {
|
933
|
+
throw std::invalid_argument(
|
934
|
+
"colors array must have the same length as transforms/sprites");
|
939
935
|
}
|
940
|
-
|
936
|
+
|
941
937
|
auto colors =
|
942
938
|
props.colors.has_value() ? props.colors.value().data() : nullptr;
|
943
939
|
auto blendMode = props.blendMode.value_or(SkBlendMode::kDstOver);
|
@@ -239,16 +239,13 @@ public:
|
|
239
239
|
}
|
240
240
|
|
241
241
|
void pushShader(DrawingCtx *ctx) {
|
242
|
-
// Validate colors array has at least 2 colors
|
243
|
-
if (props.colors.size() < 2) {
|
244
|
-
throw std::invalid_argument("Colors array must have at least 2 colors");
|
245
|
-
}
|
246
|
-
|
247
242
|
// Validate positions array matches colors array in size
|
248
|
-
if (props.positions.has_value() &&
|
249
|
-
|
243
|
+
if (props.positions.has_value() &&
|
244
|
+
props.positions.value().size() != props.colors.size()) {
|
245
|
+
throw std::invalid_argument(
|
246
|
+
"Positions array must have the same size as colors array");
|
250
247
|
}
|
251
|
-
|
248
|
+
|
252
249
|
SkMatrix m3 = processTransform(props.matrix, props.transform, props.origin);
|
253
250
|
const SkPoint pts[2] = {props.start, props.end};
|
254
251
|
auto shader = SkGradientShader::MakeLinear(
|
@@ -286,16 +283,13 @@ public:
|
|
286
283
|
}
|
287
284
|
|
288
285
|
void pushShader(DrawingCtx *ctx) {
|
289
|
-
// Validate colors array has at least 2 colors
|
290
|
-
if (props.colors.size() < 2) {
|
291
|
-
throw std::invalid_argument("Colors array must have at least 2 colors");
|
292
|
-
}
|
293
|
-
|
294
286
|
// Validate positions array matches colors array in size
|
295
|
-
if (props.positions.has_value() &&
|
296
|
-
|
287
|
+
if (props.positions.has_value() &&
|
288
|
+
props.positions.value().size() != props.colors.size()) {
|
289
|
+
throw std::invalid_argument(
|
290
|
+
"Positions array must have the same size as colors array");
|
297
291
|
}
|
298
|
-
|
292
|
+
|
299
293
|
SkMatrix m3 = processTransform(props.matrix, props.transform, props.origin);
|
300
294
|
auto shader = SkGradientShader::MakeRadial(
|
301
295
|
props.center, props.radius, props.colors.data(),
|
@@ -334,16 +328,13 @@ public:
|
|
334
328
|
}
|
335
329
|
|
336
330
|
void pushShader(DrawingCtx *ctx) {
|
337
|
-
// Validate colors array has at least 2 colors
|
338
|
-
if (props.colors.size() < 2) {
|
339
|
-
throw std::invalid_argument("Colors array must have at least 2 colors");
|
340
|
-
}
|
341
|
-
|
342
331
|
// Validate positions array matches colors array in size
|
343
|
-
if (props.positions.has_value() &&
|
344
|
-
|
332
|
+
if (props.positions.has_value() &&
|
333
|
+
props.positions.value().size() != props.colors.size()) {
|
334
|
+
throw std::invalid_argument(
|
335
|
+
"Positions array must have the same size as colors array");
|
345
336
|
}
|
346
|
-
|
337
|
+
|
347
338
|
SkMatrix m3 = processTransform(props.matrix, props.transform, props.origin);
|
348
339
|
auto shader = SkGradientShader::MakeSweep(
|
349
340
|
props.center.x(), props.center.y(), props.colors.data(),
|
@@ -385,16 +376,14 @@ public:
|
|
385
376
|
}
|
386
377
|
|
387
378
|
void pushShader(DrawingCtx *ctx) {
|
388
|
-
|
389
|
-
if (props.colors.size() < 2) {
|
390
|
-
throw std::invalid_argument("Colors array must have at least 2 colors");
|
391
|
-
}
|
392
|
-
|
379
|
+
|
393
380
|
// Validate positions array matches colors array in size
|
394
|
-
if (props.positions.has_value() &&
|
395
|
-
|
381
|
+
if (props.positions.has_value() &&
|
382
|
+
props.positions.value().size() != props.colors.size()) {
|
383
|
+
throw std::invalid_argument(
|
384
|
+
"Positions array must have the same size as colors array");
|
396
385
|
}
|
397
|
-
|
386
|
+
|
398
387
|
SkMatrix m3 = processTransform(props.matrix, props.transform, props.origin);
|
399
388
|
auto shader = SkGradientShader::MakeTwoPointConical(
|
400
389
|
props.start, props.startRadius, props.end, props.endRadius,
|
package/package.json
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
"setup-skia-web": "scripts/setup-canvaskit.js"
|
9
9
|
},
|
10
10
|
"title": "React Native Skia",
|
11
|
-
"version": "2.0.0
|
11
|
+
"version": "2.0.0",
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
13
13
|
"main": "lib/module/index.js",
|
14
14
|
"react-native": "src/index.ts",
|
@@ -155,6 +155,5 @@
|
|
155
155
|
}
|
156
156
|
]
|
157
157
|
]
|
158
|
-
}
|
159
|
-
"stableVersion": "0.0.0"
|
158
|
+
}
|
160
159
|
}
|