@shopify/react-native-skia 2.1.1 → 2.2.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 (129) hide show
  1. package/android/CMakeLists.txt +1 -1
  2. package/android/cpp/rnskia-android/OpenGLWindowContext.h +1 -1
  3. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +1 -1
  4. package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +1 -1
  5. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +1 -1
  6. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +1 -1
  7. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +6 -0
  8. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerInterface.java +1 -0
  9. package/apple/MetalContext.h +2 -2
  10. package/apple/MetalWindowContext.h +2 -2
  11. package/apple/MetalWindowContext.mm +7 -4
  12. package/apple/RNSkApplePlatformContext.mm +1 -1
  13. package/apple/RNSkAppleView.h +7 -1
  14. package/apple/RNSkMetalCanvasProvider.h +4 -1
  15. package/apple/RNSkMetalCanvasProvider.mm +9 -4
  16. package/apple/SkiaPictureView.mm +4 -0
  17. package/apple/SkiaUIView.h +1 -0
  18. package/apple/SkiaUIView.mm +9 -0
  19. package/cpp/api/JsiSkImage.h +1 -1
  20. package/cpp/api/JsiSkSurface.h +1 -1
  21. package/cpp/api/JsiSkiaContext.h +1 -1
  22. package/cpp/api/recorder/ImageFilters.h +3 -3
  23. package/cpp/api/recorder/Paint.h +4 -0
  24. package/cpp/rnskia/{DawnContext.h → RNDawnContext.h} +3 -3
  25. package/cpp/rnskia/{DawnWindowContext.cpp → RNDawnWindowContext.cpp} +3 -3
  26. package/cpp/rnskia/{DawnWindowContext.h → RNDawnWindowContext.h} +2 -2
  27. package/cpp/rnskia/RNSkJsiViewApi.h +36 -1
  28. package/cpp/rnskia/RNSkPlatformContext.h +1 -1
  29. package/cpp/rnskia/RNSkView.h +10 -0
  30. package/lib/commonjs/dom/types/Drawings.d.ts +1 -1
  31. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  32. package/lib/commonjs/renderer/Canvas.d.ts +12 -4
  33. package/lib/commonjs/renderer/Canvas.js +49 -25
  34. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  35. package/lib/commonjs/renderer/components/ImageFilter.js.map +1 -1
  36. package/lib/commonjs/skia/types/Matrix4.d.ts +4 -0
  37. package/lib/commonjs/skia/types/Matrix4.js +18 -1
  38. package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
  39. package/lib/commonjs/sksg/Container.d.ts +13 -7
  40. package/lib/commonjs/sksg/Container.js +44 -18
  41. package/lib/commonjs/sksg/Container.js.map +1 -1
  42. package/lib/commonjs/sksg/Reconciler.d.ts +3 -2
  43. package/lib/commonjs/sksg/Reconciler.js +2 -2
  44. package/lib/commonjs/sksg/Reconciler.js.map +1 -1
  45. package/lib/commonjs/sksg/Recorder/Player.js +9 -3
  46. package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
  47. package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +2 -2
  48. package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
  49. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
  50. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  51. package/lib/commonjs/views/types.d.ts +1 -0
  52. package/lib/commonjs/views/types.js.map +1 -1
  53. package/lib/module/dom/types/Drawings.d.ts +1 -1
  54. package/lib/module/dom/types/Drawings.js.map +1 -1
  55. package/lib/module/renderer/Canvas.d.ts +12 -4
  56. package/lib/module/renderer/Canvas.js +48 -25
  57. package/lib/module/renderer/Canvas.js.map +1 -1
  58. package/lib/module/renderer/components/ImageFilter.js.map +1 -1
  59. package/lib/module/skia/types/Matrix4.d.ts +4 -0
  60. package/lib/module/skia/types/Matrix4.js +16 -0
  61. package/lib/module/skia/types/Matrix4.js.map +1 -1
  62. package/lib/module/sksg/Container.d.ts +13 -7
  63. package/lib/module/sksg/Container.js +44 -18
  64. package/lib/module/sksg/Container.js.map +1 -1
  65. package/lib/module/sksg/Reconciler.d.ts +3 -2
  66. package/lib/module/sksg/Reconciler.js +2 -2
  67. package/lib/module/sksg/Reconciler.js.map +1 -1
  68. package/lib/module/sksg/Recorder/Player.js +9 -3
  69. package/lib/module/sksg/Recorder/Player.js.map +1 -1
  70. package/lib/module/sksg/Recorder/commands/ImageFilters.js +2 -2
  71. package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
  72. package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
  73. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  74. package/lib/module/views/types.d.ts +1 -0
  75. package/lib/module/views/types.js.map +1 -1
  76. package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +8 -2
  77. package/lib/typescript/lib/commonjs/skia/types/Matrix4.d.ts +1 -0
  78. package/lib/typescript/lib/commonjs/sksg/Container.d.ts +11 -3
  79. package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +7 -4
  80. package/lib/typescript/lib/module/mock/index.d.ts +1 -0
  81. package/lib/typescript/lib/module/renderer/Canvas.d.ts +11 -2
  82. package/lib/typescript/lib/module/skia/types/Matrix4.d.ts +1 -0
  83. package/lib/typescript/lib/module/sksg/Container.d.ts +11 -3
  84. package/lib/typescript/lib/module/sksg/Reconciler.d.ts +7 -4
  85. package/lib/typescript/src/dom/types/Drawings.d.ts +1 -1
  86. package/lib/typescript/src/renderer/Canvas.d.ts +12 -4
  87. package/lib/typescript/src/skia/types/Matrix4.d.ts +4 -0
  88. package/lib/typescript/src/sksg/Container.d.ts +13 -7
  89. package/lib/typescript/src/sksg/Reconciler.d.ts +3 -2
  90. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
  91. package/lib/typescript/src/views/types.d.ts +1 -0
  92. package/libs/android/arm64-v8a/libskia.a +0 -0
  93. package/libs/android/armeabi-v7a/libskia.a +0 -0
  94. package/libs/android/x86/libskia.a +0 -0
  95. package/libs/android/x86_64/libskia.a +0 -0
  96. package/libs/apple/libpathops.xcframework/Info.plist +15 -15
  97. package/libs/apple/libskia.xcframework/Info.plist +11 -11
  98. package/libs/apple/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  99. package/libs/apple/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  100. package/libs/apple/libskia.xcframework/macos-arm64_x86_64/libskia.a +0 -0
  101. package/libs/apple/libskia.xcframework/tvos-arm64_arm64e/libskia.a +0 -0
  102. package/libs/apple/libskia.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  103. package/libs/apple/libskottie.xcframework/Info.plist +16 -16
  104. package/libs/apple/libskparagraph.xcframework/Info.plist +8 -8
  105. package/libs/apple/libsksg.xcframework/Info.plist +6 -6
  106. package/libs/apple/libskshaper.xcframework/Info.plist +10 -10
  107. package/libs/apple/libskunicode_core.xcframework/Info.plist +10 -10
  108. package/libs/apple/libskunicode_libgrapheme.xcframework/Info.plist +14 -14
  109. package/libs/apple/libsvg.xcframework/Info.plist +15 -15
  110. package/package.json +1 -1
  111. package/react-native-skia.podspec +5 -5
  112. package/src/dom/types/Drawings.ts +1 -1
  113. package/src/renderer/Canvas.tsx +53 -30
  114. package/src/renderer/__tests__/FitBox.spec.tsx +556 -4
  115. package/src/renderer/__tests__/e2e/ImageFilter.spec.tsx +4 -4
  116. package/src/renderer/__tests__/e2e/Paint.spec.tsx +18 -0
  117. package/src/renderer/__tests__/e2e/Skottie.spec.tsx +24 -1
  118. package/src/renderer/__tests__/setup.tsx +2 -0
  119. package/src/renderer/components/ImageFilter.tsx +1 -1
  120. package/src/skia/types/Matrix4.ts +16 -0
  121. package/src/sksg/Container.ts +73 -20
  122. package/src/sksg/Reconciler.ts +5 -3
  123. package/src/sksg/Recorder/Player.ts +7 -7
  124. package/src/sksg/Recorder/commands/ImageFilters.ts +3 -6
  125. package/src/specs/SkiaPictureViewNativeComponent.ts +1 -0
  126. package/src/views/types.ts +1 -0
  127. /package/cpp/rnskia/{DawnUtils.h → RNDawnUtils.h} +0 -0
  128. /package/cpp/rnskia/{ImageProvider.h → RNImageProvider.h} +0 -0
  129. /package/cpp/rnskia/{WindowContext.h → RNWindowContext.h} +0 -0
@@ -85,7 +85,7 @@ if(SK_GRAPHITE)
85
85
  add_definitions(-DSK_GRAPHITE)
86
86
  set(BACKEND_SOURCES
87
87
  #TODO: is this source needed to be added?
88
- "${PROJECT_SOURCE_DIR}/../cpp/rnskia/DawnWindowContext.cpp"
88
+ "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNDawnWindowContext.cpp"
89
89
  )
90
90
  else()
91
91
  add_definitions(-DSK_GL -DSK_GANESH)
@@ -13,7 +13,7 @@
13
13
  #include <thread>
14
14
  #include <unordered_map>
15
15
 
16
- #include "WindowContext.h"
16
+ #include "RNWindowContext.h"
17
17
  #include "gl/Display.h"
18
18
 
19
19
  #pragma clang diagnostic push
@@ -9,7 +9,7 @@
9
9
  #include <string>
10
10
 
11
11
  #if defined(SK_GRAPHITE)
12
- #include "DawnContext.h"
12
+ #include "RNDawnContext.h"
13
13
  #else
14
14
  #include "OpenGLContext.h"
15
15
  #endif
@@ -8,7 +8,7 @@
8
8
  #include "RNSkLog.h"
9
9
 
10
10
  #if defined(SK_GRAPHITE)
11
- #include "DawnContext.h"
11
+ #include "RNDawnContext.h"
12
12
  #else
13
13
  #include "OpenGLContext.h"
14
14
  #endif
@@ -8,7 +8,7 @@
8
8
  #include "RNSkLog.h"
9
9
 
10
10
  #if defined(SK_GRAPHITE)
11
- #include "DawnContext.h"
11
+ #include "RNDawnContext.h"
12
12
  #else
13
13
  #include "OpenGLContext.h"
14
14
  #endif
@@ -5,7 +5,7 @@
5
5
  #include <memory>
6
6
 
7
7
  #include "RNSkView.h"
8
- #include "WindowContext.h"
8
+ #include "RNWindowContext.h"
9
9
 
10
10
  #include <android/native_window.h>
11
11
 
@@ -5,6 +5,7 @@ import com.facebook.react.viewmanagers.SkiaPictureViewManagerDelegate;
5
5
  import com.facebook.react.viewmanagers.SkiaPictureViewManagerInterface;
6
6
 
7
7
  import androidx.annotation.NonNull;
8
+ import androidx.annotation.Nullable;
8
9
 
9
10
  public class SkiaPictureViewManager extends SkiaBaseViewManager<SkiaPictureView> implements SkiaPictureViewManagerInterface<SkiaPictureView> {
10
11
 
@@ -30,4 +31,9 @@ public class SkiaPictureViewManager extends SkiaBaseViewManager<SkiaPictureView>
30
31
  public SkiaPictureView createViewInstance(@NonNull ThemedReactContext reactContext) {
31
32
  return new SkiaPictureView(reactContext);
32
33
  }
34
+
35
+ @Override
36
+ public void setColorSpace(SkiaPictureView view, @Nullable String value) {
37
+ // nothing to do here at the moment
38
+ }
33
39
  }
@@ -15,4 +15,5 @@ import androidx.annotation.Nullable;
15
15
  public interface SkiaPictureViewManagerInterface<T extends View> {
16
16
  void setDebug(T view, boolean value);
17
17
  void setOpaque(T view, boolean value);
18
+ void setColorSpace(SkiaPictureView view, @Nullable String value);
18
19
  }
@@ -113,10 +113,10 @@ public:
113
113
  }
114
114
 
115
115
  std::unique_ptr<RNSkia::WindowContext> MakeWindow(CALayer *window, int width,
116
- int height) {
116
+ int height, bool useP3ColorSpace = true) {
117
117
  auto device = MetalSharedContext::getInstance().getDevice();
118
118
  return std::make_unique<MetalWindowContext>(
119
- _directContext.get(), device, _commandQueue, window, width, height);
119
+ _directContext.get(), device, _commandQueue, window, width, height, useP3ColorSpace);
120
120
  }
121
121
 
122
122
  GrDirectContext *getDirectContext() { return _directContext.get(); }
@@ -2,7 +2,7 @@
2
2
 
3
3
  #import <MetalKit/MetalKit.h>
4
4
 
5
- #include "WindowContext.h"
5
+ #include "RNWindowContext.h"
6
6
 
7
7
  class SkiaMetalContext;
8
8
 
@@ -10,7 +10,7 @@ class MetalWindowContext : public RNSkia::WindowContext {
10
10
  public:
11
11
  MetalWindowContext(GrDirectContext *directContext, id<MTLDevice> device,
12
12
  id<MTLCommandQueue> commandQueue, CALayer *layer,
13
- int width, int height);
13
+ int width, int height, bool useP3ColorSpace = true);
14
14
  ~MetalWindowContext() = default;
15
15
 
16
16
  sk_sp<SkSurface> getSurface() override;
@@ -6,7 +6,8 @@
6
6
  MetalWindowContext::MetalWindowContext(GrDirectContext *directContext,
7
7
  id<MTLDevice> device,
8
8
  id<MTLCommandQueue> commandQueue,
9
- CALayer *layer, int width, int height)
9
+ CALayer *layer, int width, int height,
10
+ bool useP3ColorSpace)
10
11
  : _directContext(directContext), _commandQueue(commandQueue) {
11
12
  #pragma clang diagnostic push
12
13
  #pragma clang diagnostic ignored "-Wunguarded-availability-new"
@@ -24,9 +25,11 @@ MetalWindowContext::MetalWindowContext(GrDirectContext *directContext,
24
25
  _layer.contentsGravity = kCAGravityBottomLeft;
25
26
  _layer.drawableSize = CGSizeMake(width, height);
26
27
  BOOL supportsWideColor = NO;
27
- if (@available(iOS 10.0, *)) {
28
- supportsWideColor =
29
- [UIScreen mainScreen].traitCollection.displayGamut == UIDisplayGamutP3;
28
+ if (useP3ColorSpace) {
29
+ if (@available(iOS 10.0, *)) {
30
+ supportsWideColor =
31
+ [UIScreen mainScreen].traitCollection.displayGamut == UIDisplayGamutP3;
32
+ }
30
33
  }
31
34
  if (supportsWideColor) {
32
35
  CGColorSpaceRef colorSpace =
@@ -7,7 +7,7 @@
7
7
  #include <utility>
8
8
 
9
9
  #if defined(SK_GRAPHITE)
10
- #include "DawnContext.h"
10
+ #include "RNDawnContext.h"
11
11
  #else
12
12
  #include "MetalContext.h"
13
13
  #endif
@@ -10,6 +10,7 @@ class RNSkBaseAppleView {
10
10
  public:
11
11
  virtual CALayer *getLayer() = 0;
12
12
  virtual void setSize(int width, int height) = 0;
13
+ virtual void setUseP3ColorSpace(bool useP3ColorSpace) = 0;
13
14
  virtual std::shared_ptr<RNSkia::RNSkView> getDrawView() = 0;
14
15
  };
15
16
 
@@ -18,7 +19,7 @@ public:
18
19
  RNSkAppleView(std::shared_ptr<RNSkia::RNSkPlatformContext> context)
19
20
  : T(context,
20
21
  std::make_shared<RNSkMetalCanvasProvider>(
21
- std::bind(&RNSkia::RNSkView::requestRedraw, this), context)) {}
22
+ std::bind(&RNSkia::RNSkView::requestRedraw, this), context, true)) {}
22
23
 
23
24
  CALayer *getLayer() override {
24
25
  return std::static_pointer_cast<RNSkMetalCanvasProvider>(
@@ -31,6 +32,11 @@ public:
31
32
  ->setSize(width, height);
32
33
  }
33
34
 
35
+ void setUseP3ColorSpace(bool useP3ColorSpace) override {
36
+ std::static_pointer_cast<RNSkMetalCanvasProvider>(this->getCanvasProvider())
37
+ ->setUseP3ColorSpace(useP3ColorSpace);
38
+ }
39
+
34
40
  std::shared_ptr<RNSkia::RNSkView> getDrawView() override {
35
41
  return this->shared_from_this();
36
42
  }
@@ -16,7 +16,8 @@
16
16
  class RNSkMetalCanvasProvider : public RNSkia::RNSkCanvasProvider {
17
17
  public:
18
18
  RNSkMetalCanvasProvider(std::function<void()> requestRedraw,
19
- std::shared_ptr<RNSkia::RNSkPlatformContext> context);
19
+ std::shared_ptr<RNSkia::RNSkPlatformContext> context,
20
+ bool useP3ColorSpace = true);
20
21
 
21
22
  ~RNSkMetalCanvasProvider();
22
23
 
@@ -26,6 +27,7 @@ public:
26
27
  bool renderToCanvas(const std::function<void(SkCanvas *)> &cb) override;
27
28
 
28
29
  void setSize(int width, int height);
30
+ void setUseP3ColorSpace(bool useP3ColorSpace);
29
31
  CALayer *getLayer();
30
32
 
31
33
  private:
@@ -35,4 +37,5 @@ private:
35
37
  #pragma clang diagnostic ignored "-Wunguarded-availability-new"
36
38
  CAMetalLayer *_layer;
37
39
  #pragma clang diagnostic pop
40
+ bool _useP3ColorSpace = true;
38
41
  };
@@ -3,7 +3,7 @@
3
3
  #import "RNSkLog.h"
4
4
 
5
5
  #if defined(SK_GRAPHITE)
6
- #import "DawnContext.h"
6
+ #import "RNDawnContext.h"
7
7
  #else
8
8
  #import "MetalContext.h"
9
9
  #endif
@@ -23,8 +23,9 @@
23
23
 
24
24
  RNSkMetalCanvasProvider::RNSkMetalCanvasProvider(
25
25
  std::function<void()> requestRedraw,
26
- std::shared_ptr<RNSkia::RNSkPlatformContext> context)
27
- : RNSkCanvasProvider(requestRedraw), _context(context) {
26
+ std::shared_ptr<RNSkia::RNSkPlatformContext> context,
27
+ bool useP3ColorSpace)
28
+ : RNSkCanvasProvider(requestRedraw), _context(context), _useP3ColorSpace(useP3ColorSpace) {
28
29
  #pragma clang diagnostic push
29
30
  #pragma clang diagnostic ignored "-Wunguarded-availability-new"
30
31
  _layer = [CAMetalLayer layer];
@@ -100,9 +101,13 @@ void RNSkMetalCanvasProvider::setSize(int width, int height) {
100
101
  _ctx = RNSkia::DawnContext::getInstance().MakeWindow((__bridge void *)_layer,
101
102
  w, h);
102
103
  #else
103
- _ctx = MetalContext::getInstance().MakeWindow(_layer, w, h);
104
+ _ctx = MetalContext::getInstance().MakeWindow(_layer, w, h, _useP3ColorSpace);
104
105
  #endif
105
106
  _requestRedraw();
106
107
  }
107
108
 
108
109
  CALayer *RNSkMetalCanvasProvider::getLayer() { return _layer; }
110
+
111
+ void RNSkMetalCanvasProvider::setUseP3ColorSpace(bool useP3ColorSpace) {
112
+ _useP3ColorSpace = useP3ColorSpace;
113
+ }
@@ -55,6 +55,10 @@ using namespace facebook::react;
55
55
  [self setNativeId:nativeId];
56
56
  [self setDebugMode:newProps.debug];
57
57
  [self setOpaque:newProps.opaque];
58
+ if (newProps.colorSpace == "" || newProps.colorSpace == "srgb") {
59
+ bool useP3 = false;
60
+ [self setUseP3ColorSpace:useP3];
61
+ }
58
62
  }
59
63
 
60
64
  @end
@@ -41,5 +41,6 @@
41
41
  - (void)setDebugMode:(bool)debugMode;
42
42
  - (void)setOpaque:(bool)opaque;
43
43
  - (void)setNativeId:(size_t)nativeId;
44
+ - (void)setUseP3ColorSpace:(bool)useP3ColorSpace;
44
45
 
45
46
  @end
@@ -16,6 +16,7 @@
16
16
  _factory;
17
17
  bool _debugMode;
18
18
  bool _opaque;
19
+ bool _useP3ColorSpace;
19
20
  size_t _nativeId;
20
21
  }
21
22
 
@@ -73,6 +74,7 @@
73
74
  _manager->setSkiaView(_nativeId, _impl->getDrawView());
74
75
  }
75
76
  _impl->getDrawView()->setShowDebugOverlays(_debugMode);
77
+ _impl->setUseP3ColorSpace(_useP3ColorSpace);
76
78
  }
77
79
  }
78
80
  }
@@ -163,6 +165,13 @@
163
165
  }
164
166
  }
165
167
 
168
+ - (void)setUseP3ColorSpace:(bool)useP3ColorSpace {
169
+ _useP3ColorSpace = useP3ColorSpace;
170
+ if (_impl != nullptr) {
171
+ _impl->setUseP3ColorSpace(_useP3ColorSpace);
172
+ }
173
+ }
174
+
166
175
  #pragma mark External API
167
176
 
168
177
  - (std::shared_ptr<RNSkBaseAppleView>)impl {
@@ -14,7 +14,7 @@
14
14
  #include "RNSkTypedArray.h"
15
15
 
16
16
  #if defined(SK_GRAPHITE)
17
- #include "DawnContext.h"
17
+ #include "RNDawnContext.h"
18
18
  #include "include/gpu/graphite/Context.h"
19
19
  #endif
20
20
 
@@ -12,7 +12,7 @@
12
12
  #include "JsiSkImage.h"
13
13
 
14
14
  #if defined(SK_GRAPHITE)
15
- #include "DawnContext.h"
15
+ #include "RNDawnContext.h"
16
16
  #endif
17
17
 
18
18
  #pragma clang diagnostic push
@@ -14,7 +14,7 @@
14
14
  #include "JsiSkRect.h"
15
15
  #include "JsiSkTypeface.h"
16
16
 
17
- #include "WindowContext.h"
17
+ #include "RNWindowContext.h"
18
18
 
19
19
  #pragma clang diagnostic push
20
20
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -290,7 +290,7 @@ public:
290
290
  };
291
291
 
292
292
  struct ImageFilterCmdProps {
293
- sk_sp<SkImageFilter> imageFilter;
293
+ sk_sp<SkImageFilter> filter;
294
294
  };
295
295
 
296
296
  class ImageFilterCmd : public Command {
@@ -301,11 +301,11 @@ public:
301
301
  ImageFilterCmd(jsi::Runtime &runtime, const jsi::Object &object,
302
302
  Variables &variables)
303
303
  : Command(CommandType::PushImageFilter, "skImageFilter") {
304
- convertProperty(runtime, object, "imageFilter", props.imageFilter, variables);
304
+ convertProperty(runtime, object, "filter", props.filter, variables);
305
305
  }
306
306
 
307
307
  void pushImageFilter(DrawingCtx *ctx) {
308
- ctx->imageFilters.push_back(props.imageFilter);
308
+ ctx->imageFilters.push_back(props.filter);
309
309
  }
310
310
  };
311
311
 
@@ -152,6 +152,10 @@ public:
152
152
  return;
153
153
  }
154
154
  ctx->savePaint();
155
+ if (standalone) {
156
+ SkPaint freshPaint;
157
+ ctx->pushPaint(freshPaint);
158
+ }
155
159
  auto &paint = ctx->getPaint();
156
160
  if (props.opacity.has_value()) {
157
161
  if (standalone) {
@@ -3,9 +3,9 @@
3
3
  #include <memory>
4
4
  #include <mutex>
5
5
 
6
- #include "DawnUtils.h"
7
- #include "DawnWindowContext.h"
8
- #include "ImageProvider.h"
6
+ #include "RNDawnWindowContext.h"
7
+ #include "RNImageProvider.h"
8
+ #include "RNDawnUtils.h"
9
9
 
10
10
  #include "include/core/SkData.h"
11
11
  #include "include/gpu/graphite/BackendTexture.h"
@@ -1,6 +1,6 @@
1
- #include "DawnWindowContext.h"
1
+ #include "RNDawnWindowContext.h"
2
2
 
3
- #include "DawnContext.h"
3
+ #include "RNDawnContext.h"
4
4
 
5
5
  namespace RNSkia {
6
6
 
@@ -16,4 +16,4 @@ void DawnWindowContext::present() {
16
16
  _surface.Present();
17
17
  }
18
18
 
19
- } // namespace RNSkia
19
+ } // namespace RNSkia
@@ -1,7 +1,7 @@
1
1
  #pragma once
2
2
 
3
- #include "DawnUtils.h"
4
- #include "WindowContext.h"
3
+ #include "RNDawnUtils.h"
4
+ #include "RNWindowContext.h"
5
5
 
6
6
  #include "dawn/native/MetalBackend.h"
7
7
  #include "webgpu/webgpu_cpp.h"
@@ -232,10 +232,45 @@ public:
232
232
  });
233
233
  }
234
234
 
235
+ JSI_HOST_FUNCTION(size) {
236
+ if (count != 1) {
237
+ _platformContext->raiseError(
238
+ std::string("size: Expected 1 argument, got " +
239
+ std::to_string(count) + "."));
240
+ return jsi::Value::undefined();
241
+ }
242
+
243
+ if (!arguments[0].isNumber()) {
244
+ _platformContext->raiseError(
245
+ "size: First argument must be a number");
246
+ return jsi::Value::undefined();
247
+ }
248
+
249
+ // find Skia View
250
+ int nativeId = arguments[0].asNumber();
251
+ std::shared_ptr<RNSkView> view = ViewRegistry::getInstance().withViewInfo(
252
+ nativeId,
253
+ [](std::shared_ptr<RNSkViewInfo> info) { return info->view; });
254
+ if (view != nullptr) {
255
+ auto pixelDensity = _platformContext->getPixelDensity();
256
+ auto sizeObj = jsi::Object(runtime);
257
+ sizeObj.setProperty(runtime, "width", view->getScaledWidth() / pixelDensity);
258
+ sizeObj.setProperty(runtime, "height", view->getScaledHeight() / pixelDensity);
259
+ return sizeObj;
260
+ }
261
+
262
+ // Return default size if view not found
263
+ auto sizeObj = jsi::Object(runtime);
264
+ sizeObj.setProperty(runtime, "width", 0);
265
+ sizeObj.setProperty(runtime, "height", 0);
266
+ return sizeObj;
267
+ }
268
+
235
269
  JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkJsiViewApi, setJsiProperty),
236
270
  JSI_EXPORT_FUNC(RNSkJsiViewApi, requestRedraw),
237
271
  JSI_EXPORT_FUNC(RNSkJsiViewApi, makeImageSnapshotAsync),
238
- JSI_EXPORT_FUNC(RNSkJsiViewApi, makeImageSnapshot))
272
+ JSI_EXPORT_FUNC(RNSkJsiViewApi, makeImageSnapshot),
273
+ JSI_EXPORT_FUNC(RNSkJsiViewApi, size))
239
274
 
240
275
  /**
241
276
  * Constructor
@@ -10,7 +10,7 @@
10
10
  #include <utility>
11
11
 
12
12
  #include "RNSkVideo.h"
13
- #include "WindowContext.h"
13
+ #include "RNWindowContext.h"
14
14
 
15
15
  #pragma clang diagnostic push
16
16
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -203,6 +203,16 @@ public:
203
203
 
204
204
  std::shared_ptr<RNSkRenderer> getRenderer() { return _renderer; }
205
205
 
206
+ /**
207
+ Returns the scaled width of the view
208
+ */
209
+ int getScaledWidth() { return _canvasProvider->getScaledWidth(); }
210
+
211
+ /**
212
+ Returns the scaled height of the view
213
+ */
214
+ int getScaledHeight() { return _canvasProvider->getScaledHeight(); }
215
+
206
216
  protected:
207
217
  std::shared_ptr<RNSkPlatformContext> getPlatformContext() {
208
218
  return _platformContext;
@@ -116,5 +116,5 @@ export interface BoxShadowProps {
116
116
  inner?: boolean;
117
117
  }
118
118
  export interface ImageFilterProps extends GroupProps {
119
- imageFilter: SkImageFilter;
119
+ filter: SkImageFilter;
120
120
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["Drawings.ts"],"sourcesContent":["import type {\n FillType,\n SkImage,\n StrokeOpts,\n Vector,\n Color,\n SkPoint,\n BlendMode,\n PointMode,\n VertexMode,\n SkFont,\n SkRRect,\n SkTextBlob,\n SkPicture,\n SkSVG,\n SkPaint,\n SkRect,\n SkRSXform,\n SkColor,\n SamplingOptions,\n SkSkottieAnimation,\n SkImageFilter,\n} from \"../../skia/types\";\n\nimport type {\n CircleDef,\n Fit,\n GroupProps,\n PathDef,\n RectDef,\n RRectDef,\n SkEnum,\n} from \"./Common\";\n\nexport interface DrawingNodeProps extends GroupProps {\n paint?: SkPaint;\n}\n\nexport type ImageProps = DrawingNodeProps &\n RectDef & {\n fit?: Fit;\n image: SkImage | null;\n sampling?: SamplingOptions;\n };\n\nexport type CircleProps = CircleDef & DrawingNodeProps;\n\nexport interface PathProps extends DrawingNodeProps {\n path: PathDef;\n start: number;\n end: number;\n stroke?: StrokeOpts;\n fillType?: SkEnum<typeof FillType>;\n}\n\nexport interface LineProps extends DrawingNodeProps {\n p1: Vector;\n p2: Vector;\n}\n\nexport type OvalProps = RectDef & DrawingNodeProps;\n\nexport type RectProps = RectDef & DrawingNodeProps;\n\nexport type RoundedRectProps = RRectDef & DrawingNodeProps;\n\nexport interface AtlasProps extends DrawingNodeProps {\n image: SkImage | null;\n sprites: SkRect[];\n transforms: SkRSXform[];\n colors?: SkColor[];\n sampling?: SamplingOptions;\n}\n\nexport interface CubicBezierHandle {\n pos: Vector;\n c1: Vector;\n c2: Vector;\n}\n\nexport interface PatchProps extends DrawingNodeProps {\n colors?: Color[];\n patch: [\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle\n ];\n texture?: readonly [SkPoint, SkPoint, SkPoint, SkPoint];\n blendMode?: SkEnum<typeof BlendMode>;\n}\n\nexport interface VerticesProps extends DrawingNodeProps {\n colors?: string[];\n vertices: SkPoint[];\n textures?: SkPoint[];\n mode: SkEnum<typeof VertexMode>;\n blendMode?: SkEnum<typeof BlendMode>;\n indices?: number[];\n}\n\nexport interface ImageSVGProps extends DrawingNodeProps {\n svg: SkSVG | null;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n rect?: SkRect;\n}\n\nexport interface SkottieProps extends DrawingNodeProps {\n animation: SkSkottieAnimation;\n frame: number;\n}\n\nexport interface PictureProps extends DrawingNodeProps {\n picture: SkPicture;\n}\n\nexport interface PointsProps extends DrawingNodeProps {\n points: SkPoint[];\n mode: SkEnum<typeof PointMode>;\n}\n\nexport interface DiffRectProps extends DrawingNodeProps {\n inner: SkRRect;\n outer: SkRRect;\n}\n\nexport interface TextProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n x: number;\n y: number;\n}\n\nexport interface TextPathProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n path: PathDef;\n initialOffset: number;\n}\n\nexport interface TextBlobProps extends DrawingNodeProps {\n blob: SkTextBlob;\n x: number;\n y: number;\n}\n\nexport interface Glyph {\n id: number;\n pos: SkPoint;\n}\n\nexport interface GlyphsProps extends DrawingNodeProps {\n font: SkFont | null;\n x: number;\n y: number;\n glyphs: Glyph[];\n}\n\nexport interface BoxProps extends DrawingNodeProps {\n box: SkRRect | SkRect;\n}\n\nexport interface BoxShadowProps {\n dx?: number;\n dy?: number;\n spread?: number;\n blur: number;\n color?: Color;\n inner?: boolean;\n}\n\nexport interface ImageFilterProps extends GroupProps {\n imageFilter: SkImageFilter;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["Drawings.ts"],"sourcesContent":["import type {\n FillType,\n SkImage,\n StrokeOpts,\n Vector,\n Color,\n SkPoint,\n BlendMode,\n PointMode,\n VertexMode,\n SkFont,\n SkRRect,\n SkTextBlob,\n SkPicture,\n SkSVG,\n SkPaint,\n SkRect,\n SkRSXform,\n SkColor,\n SamplingOptions,\n SkSkottieAnimation,\n SkImageFilter,\n} from \"../../skia/types\";\n\nimport type {\n CircleDef,\n Fit,\n GroupProps,\n PathDef,\n RectDef,\n RRectDef,\n SkEnum,\n} from \"./Common\";\n\nexport interface DrawingNodeProps extends GroupProps {\n paint?: SkPaint;\n}\n\nexport type ImageProps = DrawingNodeProps &\n RectDef & {\n fit?: Fit;\n image: SkImage | null;\n sampling?: SamplingOptions;\n };\n\nexport type CircleProps = CircleDef & DrawingNodeProps;\n\nexport interface PathProps extends DrawingNodeProps {\n path: PathDef;\n start: number;\n end: number;\n stroke?: StrokeOpts;\n fillType?: SkEnum<typeof FillType>;\n}\n\nexport interface LineProps extends DrawingNodeProps {\n p1: Vector;\n p2: Vector;\n}\n\nexport type OvalProps = RectDef & DrawingNodeProps;\n\nexport type RectProps = RectDef & DrawingNodeProps;\n\nexport type RoundedRectProps = RRectDef & DrawingNodeProps;\n\nexport interface AtlasProps extends DrawingNodeProps {\n image: SkImage | null;\n sprites: SkRect[];\n transforms: SkRSXform[];\n colors?: SkColor[];\n sampling?: SamplingOptions;\n}\n\nexport interface CubicBezierHandle {\n pos: Vector;\n c1: Vector;\n c2: Vector;\n}\n\nexport interface PatchProps extends DrawingNodeProps {\n colors?: Color[];\n patch: [\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle\n ];\n texture?: readonly [SkPoint, SkPoint, SkPoint, SkPoint];\n blendMode?: SkEnum<typeof BlendMode>;\n}\n\nexport interface VerticesProps extends DrawingNodeProps {\n colors?: string[];\n vertices: SkPoint[];\n textures?: SkPoint[];\n mode: SkEnum<typeof VertexMode>;\n blendMode?: SkEnum<typeof BlendMode>;\n indices?: number[];\n}\n\nexport interface ImageSVGProps extends DrawingNodeProps {\n svg: SkSVG | null;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n rect?: SkRect;\n}\n\nexport interface SkottieProps extends DrawingNodeProps {\n animation: SkSkottieAnimation;\n frame: number;\n}\n\nexport interface PictureProps extends DrawingNodeProps {\n picture: SkPicture;\n}\n\nexport interface PointsProps extends DrawingNodeProps {\n points: SkPoint[];\n mode: SkEnum<typeof PointMode>;\n}\n\nexport interface DiffRectProps extends DrawingNodeProps {\n inner: SkRRect;\n outer: SkRRect;\n}\n\nexport interface TextProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n x: number;\n y: number;\n}\n\nexport interface TextPathProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n path: PathDef;\n initialOffset: number;\n}\n\nexport interface TextBlobProps extends DrawingNodeProps {\n blob: SkTextBlob;\n x: number;\n y: number;\n}\n\nexport interface Glyph {\n id: number;\n pos: SkPoint;\n}\n\nexport interface GlyphsProps extends DrawingNodeProps {\n font: SkFont | null;\n x: number;\n y: number;\n glyphs: Glyph[];\n}\n\nexport interface BoxProps extends DrawingNodeProps {\n box: SkRRect | SkRect;\n}\n\nexport interface BoxShadowProps {\n dx?: number;\n dy?: number;\n spread?: number;\n blur: number;\n color?: Color;\n inner?: boolean;\n}\n\nexport interface ImageFilterProps extends GroupProps {\n filter: SkImageFilter;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,19 +1,27 @@
1
1
  import type { FC } from "react";
2
2
  import React from "react";
3
- import type { ViewProps } from "react-native";
4
- import type { SharedValue } from "react-native-reanimated";
3
+ import type { MeasureInWindowOnSuccessCallback, MeasureOnSuccessCallback, ViewProps } from "react-native";
4
+ import { type SharedValue } from "react-native-reanimated";
5
5
  import type { SkImage, SkRect, SkSize } from "../skia/types";
6
6
  export interface CanvasRef extends FC<CanvasProps> {
7
7
  makeImageSnapshot(rect?: SkRect): SkImage;
8
8
  makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;
9
9
  redraw(): void;
10
10
  getNativeId(): number;
11
+ measure(callback: MeasureOnSuccessCallback): void;
12
+ measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
11
13
  }
12
14
  export declare const useCanvasRef: () => React.RefObject<CanvasRef | null>;
13
- export interface CanvasProps extends ViewProps {
15
+ export declare const useCanvasSize: () => {
16
+ ref: React.RefObject<CanvasRef | null>;
17
+ size: SkSize;
18
+ };
19
+ export declare const isFabric: boolean;
20
+ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
14
21
  debug?: boolean;
15
22
  opaque?: boolean;
16
23
  onSize?: SharedValue<SkSize>;
24
+ colorSpace?: "p3" | "srgb";
17
25
  ref?: React.Ref<CanvasRef>;
18
26
  }
19
- export declare const Canvas: ({ debug, opaque, children, onSize, onLayout: _onLayout, ref, ...viewProps }: CanvasProps) => React.JSX.Element;
27
+ export declare const Canvas: ({ debug, opaque, children, onSize, colorSpace, ref, onLayout, ...viewProps }: CanvasProps) => React.JSX.Element;