react-native-skia 3.0.1 → 3.0.3

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 (269) hide show
  1. package/Package.swift +14 -13
  2. package/README.md +19 -2
  3. package/android/CMakeLists.txt +13 -42
  4. package/android/build.gradle +54 -63
  5. package/android/cpp/jni/JniLoad.cpp +2 -4
  6. package/android/cpp/jni/include/JniSkiaView.h +123 -0
  7. package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.cpp → RNSkAndroidCanvasProvider.cpp} +45 -100
  8. package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.h → RNSkAndroidCanvasProvider.h} +24 -22
  9. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -83
  10. package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -8
  11. package/android/src/main/java/com/reactnative/skia/RNSkiaPackage.java +1 -2
  12. package/android/src/main/java/com/reactnative/skia/SkiaSurfaceView.java +1 -3
  13. package/android/src/main/java/com/reactnative/skia/SkiaTextureView.java +1 -17
  14. package/android/src/main/java/com/reactnative/skia/{SkiaBaseView.java → SkiaView.java} +78 -16
  15. package/android/src/main/java/com/reactnative/skia/SkiaViewManager.java +85 -0
  16. package/apple/MetalLayerColorSpace.mm +10 -12
  17. package/apple/RNSkApplePlatformContext.h +12 -14
  18. package/apple/RNSkApplePlatformContext.mm +19 -112
  19. package/apple/RNSkMetalCanvasProvider.h +14 -19
  20. package/apple/RNSkMetalCanvasProvider.mm +39 -70
  21. package/apple/RNSkiaModule.mm +10 -0
  22. package/apple/SkiaView.h +20 -0
  23. package/apple/SkiaView.mm +210 -0
  24. package/cpp/api/JsiSkApi.h +2 -13
  25. package/cpp/api/JsiSkCanvas.h +4 -18
  26. package/cpp/api/JsiSkGraphiteContext.h +1 -5
  27. package/cpp/api/JsiSkGraphiteRecording.h +1 -5
  28. package/cpp/api/JsiSkImage.h +7 -41
  29. package/cpp/api/JsiSkImageFactory.h +0 -14
  30. package/cpp/api/JsiSkSurface.h +2 -16
  31. package/cpp/api/JsiSkSurfaceFactory.h +0 -8
  32. package/cpp/rnskia/RNDawnContext.h +3 -2
  33. package/cpp/rnskia/RNDawnInterop.cpp +0 -4
  34. package/cpp/rnskia/RNDawnUtils.h +12 -1
  35. package/cpp/rnskia/RNDawnWindowContext.cpp +12 -1
  36. package/cpp/rnskia/RNDawnWindowContext.h +19 -7
  37. package/cpp/rnskia/RNMetalLayerColorSpace.h +4 -2
  38. package/cpp/rnskia/RNSkCanvasProvider.h +231 -0
  39. package/cpp/rnskia/RNSkGraphiteProducer.cpp +36 -14
  40. package/cpp/rnskia/RNSkGraphiteProducer.h +23 -8
  41. package/cpp/rnskia/RNSkGraphiteTarget.h +396 -0
  42. package/cpp/rnskia/RNSkJsiViewApi.h +9 -18
  43. package/cpp/rnskia/RNSkPlatformContext.h +17 -15
  44. package/cpp/rnskia/RNSkView.h +362 -246
  45. package/jestSetup.js +1 -3
  46. package/lib/commonjs/Platform/Platform.web.js +1 -1
  47. package/lib/commonjs/Platform/Platform.web.js.map +1 -1
  48. package/lib/commonjs/external/reanimated/interpolators.js +1 -1
  49. package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
  50. package/lib/commonjs/index.d.ts +1 -3
  51. package/lib/commonjs/index.js +3 -12
  52. package/lib/commonjs/index.js.map +1 -1
  53. package/lib/commonjs/mock/index.js +0 -1
  54. package/lib/commonjs/mock/index.js.map +1 -1
  55. package/lib/commonjs/renderer/Canvas.d.ts +15 -12
  56. package/lib/commonjs/renderer/Canvas.js +25 -21
  57. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  58. package/lib/commonjs/skia/types/Graphite.d.ts +3 -3
  59. package/lib/commonjs/skia/types/Graphite.js.map +1 -1
  60. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +2 -2
  61. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  62. package/lib/commonjs/skia/types/Skia.d.ts +1 -2
  63. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  64. package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  65. package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
  66. package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +5 -4
  67. package/lib/commonjs/specs/NativeSkiaModule.web.js +5 -9
  68. package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
  69. package/lib/{typescript/src/specs/SkiaPictureViewNativeComponent.d.ts → commonjs/specs/SkiaViewNativeComponent.d.ts} +0 -3
  70. package/lib/commonjs/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
  71. package/lib/commonjs/specs/SkiaViewNativeComponent.js.map +1 -0
  72. package/lib/commonjs/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  73. package/lib/commonjs/specs/SkiaViewNativeComponent.web.js +27 -0
  74. package/lib/commonjs/specs/SkiaViewNativeComponent.web.js.map +1 -0
  75. package/lib/commonjs/views/SkiaGraphiteView.d.ts +3 -4
  76. package/lib/commonjs/views/SkiaGraphiteView.js +23 -12
  77. package/lib/commonjs/views/SkiaGraphiteView.js.map +1 -1
  78. package/lib/commonjs/views/SkiaPictureView.d.ts +4 -1
  79. package/lib/commonjs/views/SkiaPictureView.js +12 -10
  80. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  81. package/lib/commonjs/views/SkiaView.web.d.ts +12 -0
  82. package/lib/commonjs/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +82 -38
  83. package/lib/commonjs/views/SkiaView.web.js.map +1 -0
  84. package/lib/commonjs/views/SkiaWebRenderer.js +1 -1
  85. package/lib/commonjs/views/SkiaWebRenderer.js.map +1 -1
  86. package/lib/commonjs/views/android.d.ts +6 -0
  87. package/lib/commonjs/views/android.js +17 -0
  88. package/lib/commonjs/views/android.js.map +1 -0
  89. package/lib/commonjs/views/types.d.ts +3 -12
  90. package/lib/commonjs/views/types.js.map +1 -1
  91. package/lib/module/Platform/Platform.web.js +1 -1
  92. package/lib/module/Platform/Platform.web.js.map +1 -1
  93. package/lib/module/external/reanimated/interpolators.js +1 -1
  94. package/lib/module/external/reanimated/interpolators.js.map +1 -1
  95. package/lib/module/index.d.ts +1 -3
  96. package/lib/module/index.js +1 -3
  97. package/lib/module/index.js.map +1 -1
  98. package/lib/module/mock/index.js +0 -1
  99. package/lib/module/mock/index.js.map +1 -1
  100. package/lib/module/renderer/Canvas.d.ts +15 -12
  101. package/lib/module/renderer/Canvas.js +25 -20
  102. package/lib/module/renderer/Canvas.js.map +1 -1
  103. package/lib/module/skia/types/Graphite.d.ts +3 -3
  104. package/lib/module/skia/types/Graphite.js.map +1 -1
  105. package/lib/module/skia/types/Image/ImageFactory.d.ts +2 -2
  106. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  107. package/lib/module/skia/types/Skia.d.ts +1 -2
  108. package/lib/module/skia/types/Skia.js.map +1 -1
  109. package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  110. package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
  111. package/lib/module/specs/NativeSkiaModule.web.d.ts +5 -4
  112. package/lib/module/specs/NativeSkiaModule.web.js +5 -9
  113. package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
  114. package/lib/{commonjs/specs/SkiaPictureViewNativeComponent.d.ts → module/specs/SkiaViewNativeComponent.d.ts} +0 -3
  115. package/lib/module/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
  116. package/lib/module/specs/SkiaViewNativeComponent.js.map +1 -0
  117. package/lib/module/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  118. package/lib/module/specs/SkiaViewNativeComponent.web.js +21 -0
  119. package/lib/module/specs/SkiaViewNativeComponent.web.js.map +1 -0
  120. package/lib/module/views/SkiaGraphiteView.d.ts +3 -4
  121. package/lib/module/views/SkiaGraphiteView.js +23 -12
  122. package/lib/module/views/SkiaGraphiteView.js.map +1 -1
  123. package/lib/module/views/SkiaPictureView.d.ts +4 -1
  124. package/lib/module/views/SkiaPictureView.js +12 -10
  125. package/lib/module/views/SkiaPictureView.js.map +1 -1
  126. package/lib/module/views/SkiaView.web.d.ts +12 -0
  127. package/lib/module/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +80 -36
  128. package/lib/module/views/SkiaView.web.js.map +1 -0
  129. package/lib/module/views/SkiaWebRenderer.js +1 -1
  130. package/lib/module/views/SkiaWebRenderer.js.map +1 -1
  131. package/lib/module/views/android.d.ts +6 -0
  132. package/lib/module/views/android.js +10 -0
  133. package/lib/module/views/android.js.map +1 -0
  134. package/lib/module/views/types.d.ts +3 -12
  135. package/lib/module/views/types.js.map +1 -1
  136. package/lib/typescript/src/index.d.ts +1 -3
  137. package/lib/typescript/src/renderer/Canvas.d.ts +15 -12
  138. package/lib/typescript/src/skia/types/Graphite.d.ts +3 -3
  139. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +2 -2
  140. package/lib/typescript/src/skia/types/Skia.d.ts +1 -2
  141. package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  142. package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +5 -4
  143. package/lib/{module/specs/SkiaPictureViewNativeComponent.d.ts → typescript/src/specs/SkiaViewNativeComponent.d.ts} +0 -3
  144. package/lib/typescript/src/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  145. package/lib/typescript/src/views/SkiaGraphiteView.d.ts +3 -4
  146. package/lib/typescript/src/views/SkiaPictureView.d.ts +4 -1
  147. package/lib/typescript/src/views/SkiaView.web.d.ts +12 -0
  148. package/lib/typescript/src/views/android.d.ts +6 -0
  149. package/lib/typescript/src/views/types.d.ts +3 -12
  150. package/package.json +5 -13
  151. package/react-native-skia.podspec +34 -58
  152. package/src/Platform/Platform.web.tsx +1 -1
  153. package/src/external/reanimated/interpolators.ts +1 -1
  154. package/src/index.ts +1 -3
  155. package/src/mock/index.ts +0 -1
  156. package/src/renderer/Canvas.tsx +24 -28
  157. package/src/skia/types/Graphite.ts +3 -3
  158. package/src/skia/types/Image/ImageFactory.ts +2 -2
  159. package/src/skia/types/Skia.ts +1 -2
  160. package/src/skia/types/Surface/SurfaceFactory.ts +1 -1
  161. package/src/specs/NativeSkiaModule.web.ts +9 -21
  162. package/src/specs/{SkiaPictureViewNativeComponent.ts → SkiaViewNativeComponent.ts} +1 -4
  163. package/src/specs/{SkiaPictureViewNativeComponent.web.ts → SkiaViewNativeComponent.web.ts} +8 -10
  164. package/src/views/SkiaGraphiteView.tsx +27 -16
  165. package/src/views/SkiaPictureView.tsx +11 -10
  166. package/src/views/{SkiaGraphiteView.web.tsx → SkiaView.web.tsx} +100 -53
  167. package/src/views/SkiaWebRenderer.ts +1 -1
  168. package/src/views/android.ts +16 -0
  169. package/src/views/types.ts +3 -14
  170. package/android/cpp/jni/include/JniSkiaBaseView.h +0 -92
  171. package/android/cpp/jni/include/JniSkiaGraphiteView.h +0 -176
  172. package/android/cpp/jni/include/JniSkiaPictureView.h +0 -172
  173. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +0 -245
  174. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.h +0 -33
  175. package/android/cpp/rnskia-android/OpenGLContext.h +0 -248
  176. package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +0 -67
  177. package/android/cpp/rnskia-android/OpenGLWindowContext.h +0 -75
  178. package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -67
  179. package/android/cpp/rnskia-android/gl/Context.h +0 -80
  180. package/android/cpp/rnskia-android/gl/Display.h +0 -123
  181. package/android/cpp/rnskia-android/gl/Error.cpp +0 -45
  182. package/android/cpp/rnskia-android/gl/Error.h +0 -8
  183. package/android/cpp/rnskia-android/gl/Surface.h +0 -43
  184. package/android/src/main/java/com/reactnative/skia/SkiaBaseViewManager.java +0 -65
  185. package/android/src/main/java/com/reactnative/skia/SkiaGraphiteView.java +0 -78
  186. package/android/src/main/java/com/reactnative/skia/SkiaGraphiteViewManager.java +0 -32
  187. package/android/src/main/java/com/reactnative/skia/SkiaPictureView.java +0 -105
  188. package/android/src/main/java/com/reactnative/skia/SkiaPictureViewManager.java +0 -44
  189. package/apple/MetalContext.h +0 -116
  190. package/apple/MetalContext.mm +0 -38
  191. package/apple/MetalWindowContext.h +0 -42
  192. package/apple/MetalWindowContext.mm +0 -95
  193. package/apple/RNSkAppleView.h +0 -49
  194. package/apple/RNSkAppleView.mm +0 -35
  195. package/apple/SkiaCVPixelBufferUtils.h +0 -122
  196. package/apple/SkiaCVPixelBufferUtils.mm +0 -535
  197. package/apple/SkiaGraphiteView.h +0 -26
  198. package/apple/SkiaGraphiteView.mm +0 -180
  199. package/apple/SkiaPictureView.h +0 -7
  200. package/apple/SkiaPictureView.mm +0 -70
  201. package/apple/SkiaUIView.h +0 -31
  202. package/apple/SkiaUIView.mm +0 -164
  203. package/cpp/rnskia/RNSkGraphiteView.h +0 -708
  204. package/cpp/rnskia/RNSkPictureView.cpp +0 -69
  205. package/cpp/rnskia/RNSkPictureView.h +0 -211
  206. package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +0 -1162
  207. package/lib/commonjs/renderer/DefaultCanvas.d.ts +0 -8
  208. package/lib/commonjs/renderer/DefaultCanvas.js +0 -42
  209. package/lib/commonjs/renderer/DefaultCanvas.js.map +0 -1
  210. package/lib/commonjs/renderer/GraphiteCanvas.d.ts +0 -22
  211. package/lib/commonjs/renderer/GraphiteCanvas.js +0 -64
  212. package/lib/commonjs/renderer/GraphiteCanvas.js.map +0 -1
  213. package/lib/commonjs/renderer/GraphiteCanvas.web.d.ts +0 -1
  214. package/lib/commonjs/renderer/GraphiteCanvas.web.js +0 -13
  215. package/lib/commonjs/renderer/GraphiteCanvas.web.js.map +0 -1
  216. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  217. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js +0 -12
  218. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
  219. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  220. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js +0 -28
  221. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
  222. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +0 -1
  223. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  224. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js +0 -29
  225. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
  226. package/lib/commonjs/views/SkiaGraphiteView.web.d.ts +0 -14
  227. package/lib/commonjs/views/SkiaGraphiteView.web.js.map +0 -1
  228. package/lib/commonjs/views/SkiaPictureView.web.d.ts +0 -11
  229. package/lib/commonjs/views/SkiaPictureView.web.js +0 -165
  230. package/lib/commonjs/views/SkiaPictureView.web.js.map +0 -1
  231. package/lib/module/renderer/DefaultCanvas.d.ts +0 -8
  232. package/lib/module/renderer/DefaultCanvas.js +0 -34
  233. package/lib/module/renderer/DefaultCanvas.js.map +0 -1
  234. package/lib/module/renderer/GraphiteCanvas.d.ts +0 -22
  235. package/lib/module/renderer/GraphiteCanvas.js +0 -57
  236. package/lib/module/renderer/GraphiteCanvas.js.map +0 -1
  237. package/lib/module/renderer/GraphiteCanvas.web.d.ts +0 -1
  238. package/lib/module/renderer/GraphiteCanvas.web.js +0 -4
  239. package/lib/module/renderer/GraphiteCanvas.web.js.map +0 -1
  240. package/lib/module/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  241. package/lib/module/specs/SkiaGraphiteViewNativeComponent.js +0 -8
  242. package/lib/module/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
  243. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  244. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js +0 -22
  245. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
  246. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +0 -1
  247. package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  248. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js +0 -23
  249. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
  250. package/lib/module/views/SkiaGraphiteView.web.d.ts +0 -14
  251. package/lib/module/views/SkiaGraphiteView.web.js.map +0 -1
  252. package/lib/module/views/SkiaPictureView.web.d.ts +0 -11
  253. package/lib/module/views/SkiaPictureView.web.js +0 -156
  254. package/lib/module/views/SkiaPictureView.web.js.map +0 -1
  255. package/lib/typescript/src/renderer/DefaultCanvas.d.ts +0 -8
  256. package/lib/typescript/src/renderer/GraphiteCanvas.d.ts +0 -22
  257. package/lib/typescript/src/renderer/GraphiteCanvas.web.d.ts +0 -1
  258. package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  259. package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  260. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  261. package/lib/typescript/src/views/SkiaGraphiteView.web.d.ts +0 -14
  262. package/lib/typescript/src/views/SkiaPictureView.web.d.ts +0 -11
  263. package/libs/.graphite +0 -1
  264. package/src/renderer/DefaultCanvas.tsx +0 -41
  265. package/src/renderer/GraphiteCanvas.tsx +0 -61
  266. package/src/renderer/GraphiteCanvas.web.tsx +0 -3
  267. package/src/specs/SkiaGraphiteViewNativeComponent.ts +0 -17
  268. package/src/specs/SkiaGraphiteViewNativeComponent.web.ts +0 -31
  269. package/src/views/SkiaPictureView.web.tsx +0 -224
@@ -1,180 +0,0 @@
1
- #import "SkiaGraphiteView.h"
2
-
3
- #import <React/RCTConversions.h>
4
- #import <React/RCTConvert.h>
5
- #import <React/RCTFabricComponentsPlugins.h>
6
- #import <React/RCTLog.h>
7
-
8
- #import <react/renderer/components/rnskia/ComponentDescriptors.h>
9
- #import <react/renderer/components/rnskia/EventEmitters.h>
10
- #import <react/renderer/components/rnskia/Props.h>
11
- #import <react/renderer/components/rnskia/RCTComponentViewHelpers.h>
12
-
13
- using namespace facebook::react;
14
-
15
- #if defined(SK_GRAPHITE)
16
-
17
- #import <QuartzCore/CADisplayLink.h>
18
-
19
- #import "RNSkAppleView.h"
20
- #import "RNSkGraphiteView.h"
21
- #import "RNSkPlatformContext.h"
22
- #import "RNSkiaModule.h"
23
-
24
- @implementation SkiaGraphiteView {
25
- #if !TARGET_OS_OSX
26
- CADisplayLink *_displayLink;
27
- #endif
28
- }
29
-
30
- - (instancetype)initWithFrame:(CGRect)frame {
31
- if (self = [super initWithFrame:frame]) {
32
- // Pass SkManager as a raw pointer to avoid circular dependencies
33
- auto skManager = [RNSkiaModule latestActiveSkManager].get();
34
- [self initCommon:skManager
35
- factory:[](std::shared_ptr<RNSkia::RNSkPlatformContext> context) {
36
- return std::make_shared<RNSkAppleView<RNSkia::RNSkGraphiteView>>(
37
- context);
38
- }];
39
- static const auto defaultProps =
40
- std::make_shared<const SkiaGraphiteViewProps>();
41
- _props = defaultProps;
42
- }
43
- return self;
44
- }
45
-
46
- - (std::shared_ptr<RNSkia::RNSkGraphiteView>)graphiteView {
47
- auto impl = [self impl];
48
- if (impl == nullptr) {
49
- return nullptr;
50
- }
51
- return std::static_pointer_cast<RNSkia::RNSkGraphiteView>(
52
- impl->getDrawView());
53
- }
54
-
55
- #pragma mark - Frames
56
-
57
- // Presents on the display link: armed when a recording is submitted, paused
58
- // again once the queue is empty. macOS has no CADisplayLink on the minimum
59
- // deployment target, so frames are presented as soon as the main thread gets
60
- // to them there.
61
- - (void)scheduleFrame {
62
- #if !TARGET_OS_OSX
63
- if (_displayLink == nil) {
64
- _displayLink = [CADisplayLink displayLinkWithTarget:self
65
- selector:@selector(onFrame:)];
66
- [_displayLink addToRunLoop:[NSRunLoop mainRunLoop]
67
- forMode:NSRunLoopCommonModes];
68
- }
69
- _displayLink.paused = NO;
70
- #else
71
- auto view = [self graphiteView];
72
- if (view) {
73
- view->presentFrame();
74
- }
75
- #endif
76
- }
77
-
78
- #if !TARGET_OS_OSX
79
- - (void)onFrame:(CADisplayLink *)link {
80
- auto view = [self graphiteView];
81
- if (view == nullptr || !view->presentFrame()) {
82
- link.paused = YES;
83
- }
84
- }
85
-
86
- - (void)stopDisplayLink {
87
- [_displayLink invalidate];
88
- _displayLink = nil;
89
- }
90
- #endif
91
-
92
- #pragma mark - Lifecycle
93
-
94
- #if !TARGET_OS_OSX
95
- - (void)willMoveToSuperview:(UIView *)newSuperView {
96
- [super willMoveToSuperview:newSuperView];
97
- #else
98
- - (void)viewWillMoveToSuperview:(NSView *)newSuperView {
99
- [super viewWillMoveToSuperview:newSuperView];
100
- #endif // !TARGET_OS_OSX
101
- if (newSuperView != nullptr) {
102
- if (auto view = [self graphiteView]) {
103
- __weak SkiaGraphiteView *weakSelf = self;
104
- view->setFrameScheduler([weakSelf]() { [weakSelf scheduleFrame]; });
105
- }
106
- }
107
- }
108
-
109
- - (void)removeFromSuperview {
110
- #if !TARGET_OS_OSX
111
- [self stopDisplayLink];
112
- #endif
113
- [super removeFromSuperview];
114
- }
115
-
116
- - (void)prepareForRecycle {
117
- #if !TARGET_OS_OSX
118
- [self stopDisplayLink];
119
- #endif
120
- [super prepareForRecycle];
121
- }
122
-
123
- - (void)dealloc {
124
- #if !TARGET_OS_OSX
125
- [self stopDisplayLink];
126
- #endif
127
- }
128
-
129
- #pragma mark - RCTComponentViewProtocol
130
-
131
- + (ComponentDescriptorProvider)componentDescriptorProvider {
132
- return concreteComponentDescriptorProvider<
133
- SkiaGraphiteViewComponentDescriptor>();
134
- }
135
-
136
- - (void)updateProps:(const Props::Shared &)props
137
- oldProps:(const Props::Shared &)oldProps {
138
- const auto &newProps =
139
- *std::static_pointer_cast<const SkiaGraphiteViewProps>(props);
140
- [super updateProps:props oldProps:oldProps];
141
- int nativeId =
142
- [[RCTConvert NSString:RCTNSStringFromString(newProps.nativeId)] intValue];
143
- [self setNativeId:nativeId];
144
- [self setDebugMode:newProps.debug];
145
- [self setOpaque:newProps.opaque];
146
- [self setHighBitDepth:newProps.highBitDepth];
147
- }
148
-
149
- @end
150
-
151
- #else // SK_GRAPHITE
152
-
153
- @implementation SkiaGraphiteView
154
-
155
- - (instancetype)initWithFrame:(CGRect)frame {
156
- if (self = [super initWithFrame:frame]) {
157
- static dispatch_once_t once;
158
- dispatch_once(&once, ^{
159
- RCTLogError(@"SkiaGraphiteView requires the Graphite backend. Rebuild "
160
- @"with SK_GRAPHITE enabled; the view renders nothing.");
161
- });
162
- static const auto defaultProps =
163
- std::make_shared<const SkiaGraphiteViewProps>();
164
- _props = defaultProps;
165
- }
166
- return self;
167
- }
168
-
169
- + (ComponentDescriptorProvider)componentDescriptorProvider {
170
- return concreteComponentDescriptorProvider<
171
- SkiaGraphiteViewComponentDescriptor>();
172
- }
173
-
174
- @end
175
-
176
- #endif // SK_GRAPHITE
177
-
178
- Class<RCTComponentViewProtocol> SkiaGraphiteViewCls(void) {
179
- return SkiaGraphiteView.class;
180
- }
@@ -1,7 +0,0 @@
1
- #pragma once
2
-
3
- #import "SkiaUIView.h"
4
-
5
- @interface SkiaPictureView : SkiaUIView
6
-
7
- @end
@@ -1,70 +0,0 @@
1
- #import "SkiaPictureView.h"
2
-
3
- #import "RNSkAppleView.h"
4
- #import "RNSkPictureView.h"
5
- #import "RNSkPlatformContext.h"
6
-
7
- #import "RNSkiaModule.h"
8
- #import "SkiaUIView.h"
9
-
10
- #import <React/RCTConversions.h>
11
- #import <React/RCTConvert.h>
12
- #import <React/RCTFabricComponentsPlugins.h>
13
-
14
- #import <react/renderer/components/rnskia/ComponentDescriptors.h>
15
- #import <react/renderer/components/rnskia/EventEmitters.h>
16
- #import <react/renderer/components/rnskia/Props.h>
17
- #import <react/renderer/components/rnskia/RCTComponentViewHelpers.h>
18
-
19
- using namespace facebook::react;
20
-
21
- @implementation SkiaPictureView
22
-
23
- - (instancetype)initWithFrame:(CGRect)frame {
24
- if (self = [super initWithFrame:frame]) {
25
- // Pass SkManager as a raw pointer to avoid circular dependencies
26
- auto skManager = [RNSkiaModule latestActiveSkManager].get();
27
- [self initCommon:skManager
28
- factory:[](std::shared_ptr<RNSkia::RNSkPlatformContext> context) {
29
- return std::make_shared<RNSkAppleView<RNSkia::RNSkPictureView>>(
30
- context);
31
- }];
32
- static const auto defaultProps =
33
- std::make_shared<const SkiaPictureViewProps>();
34
- _props = defaultProps;
35
- }
36
- return self;
37
- }
38
-
39
- #pragma mark - RCTComponentViewProtocol
40
-
41
- + (ComponentDescriptorProvider)componentDescriptorProvider {
42
- return concreteComponentDescriptorProvider<
43
- SkiaPictureViewComponentDescriptor>();
44
- }
45
-
46
- - (void)updateProps:(const Props::Shared &)props
47
- oldProps:(const Props::Shared &)oldProps {
48
- const auto &newProps =
49
- *std::static_pointer_cast<const SkiaPictureViewProps>(props);
50
- [super updateProps:props oldProps:oldProps];
51
- int nativeId =
52
- [[RCTConvert NSString:RCTNSStringFromString(newProps.nativeId)] intValue];
53
- [self setNativeId:nativeId];
54
- [self setDebugMode:newProps.debug];
55
- [self setOpaque:newProps.opaque];
56
- [self setHighBitDepth:newProps.highBitDepth];
57
- if (newProps.colorSpace == "" || newProps.colorSpace == "srgb") {
58
- bool useP3 = false;
59
- [self setUseP3ColorSpace:useP3];
60
- } else if (newProps.colorSpace == "p3") {
61
- bool useP3 = true;
62
- [self setUseP3ColorSpace:useP3];
63
- }
64
- }
65
-
66
- @end
67
-
68
- Class<RCTComponentViewProtocol> SkiaPictureViewCls(void) {
69
- return SkiaPictureView.class;
70
- }
@@ -1,31 +0,0 @@
1
- #pragma once
2
-
3
- #import <memory>
4
- #import <string>
5
-
6
- #import <CoreFoundation/CoreFoundation.h>
7
- #if !TARGET_OS_OSX
8
- #import <UIKit/UIKit.h>
9
- #else
10
- #import <React/RCTUIKit.h>
11
- #endif // !TARGET_OS_OSX
12
-
13
- #import <React/RCTViewComponentView.h>
14
-
15
- #import "RNSkAppleView.h"
16
- #import "RNSkManager.h"
17
-
18
- @interface SkiaUIView : RCTViewComponentView
19
-
20
- - (void)initCommon:(RNSkia::RNSkManager *)manager
21
- factory:(std::function<std::shared_ptr<RNSkBaseAppleView>(
22
- std::shared_ptr<RNSkia::RNSkPlatformContext>)>)factory;
23
- - (std::shared_ptr<RNSkBaseAppleView>)impl;
24
-
25
- - (void)setDebugMode:(bool)debugMode;
26
- - (void)setOpaque:(bool)opaque;
27
- - (void)setNativeId:(size_t)nativeId;
28
- - (void)setUseP3ColorSpace:(bool)useP3ColorSpace;
29
- - (void)setHighBitDepth:(bool)highBitDepth;
30
-
31
- @end
@@ -1,164 +0,0 @@
1
- #import <QuartzCore/CATransaction.h>
2
-
3
- #import "RNSkiaModule.h"
4
- #import "SkiaUIView.h"
5
-
6
- #include <utility>
7
- #include <vector>
8
-
9
- #import "RNSkManager.h"
10
-
11
- @implementation SkiaUIView {
12
- std::shared_ptr<RNSkBaseAppleView> _impl;
13
- RNSkia::RNSkManager *_manager;
14
- std::function<std::shared_ptr<RNSkBaseAppleView>(
15
- std::shared_ptr<RNSkia::RNSkPlatformContext>)>
16
- _factory;
17
- bool _debugMode;
18
- bool _opaque;
19
- bool _useP3ColorSpace;
20
- bool _highBitDepth;
21
- size_t _nativeId;
22
- }
23
-
24
- #pragma mark Initialization and destruction
25
-
26
- - (void)initCommon:(RNSkia::RNSkManager *)manager
27
- factory:(std::function<std::shared_ptr<RNSkBaseAppleView>(
28
- std::shared_ptr<RNSkia::RNSkPlatformContext>)>)factory {
29
- _manager = manager;
30
- _nativeId = 0;
31
- _debugMode = false;
32
- _factory = factory;
33
- }
34
-
35
- #pragma mark Lifecycle
36
-
37
- #if !TARGET_OS_OSX
38
- - (void)willMoveToSuperview:(UIView *)newSuperView {
39
- #else
40
- - (void)viewWillMoveToSuperview:(NSView *)newSuperView {
41
- #endif // !TARGET_OS_OSX
42
- if (newSuperView != nullptr) {
43
- // Create implementation view when the parent view is set
44
- if (_impl == nullptr && _manager != nullptr) {
45
- _impl = _factory(_manager->getPlatformContext());
46
- if (_impl == nullptr) {
47
- throw std::runtime_error(
48
- "Expected Skia view implementation, got nullptr.");
49
- }
50
- [self.layer addSublayer:_impl->getLayer()];
51
- if (_nativeId != 0) {
52
- _manager->setSkiaView(_nativeId, _impl->getDrawView());
53
- }
54
- _impl->getDrawView()->setShowDebugOverlays(_debugMode);
55
- _impl->setUseP3ColorSpace(_useP3ColorSpace);
56
- _impl->setHighBitDepth(_highBitDepth);
57
- }
58
- }
59
- }
60
-
61
- - (void)removeFromSuperview {
62
- // Cleanup when removed from view hierarchy
63
- if (_impl != nullptr) {
64
- [_impl->getLayer() removeFromSuperlayer];
65
-
66
- if (_nativeId != 0 && _manager != nullptr) {
67
- _manager->setSkiaView(_nativeId, nullptr);
68
- }
69
-
70
- _impl = nullptr;
71
- }
72
-
73
- [super removeFromSuperview];
74
- }
75
-
76
- - (void)dealloc {
77
- [self unregisterView];
78
- }
79
-
80
- - (void)prepareForRecycle {
81
- [super prepareForRecycle];
82
- [self unregisterView];
83
- }
84
-
85
- - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask {
86
- [super finalizeUpdates:updateMask];
87
- if (updateMask == RNComponentViewUpdateMaskAll) {
88
- // this flag is only set when the view is inserted and we want to set the
89
- // manager here since the view could be recycled or the app could be
90
- // refreshed and we would have a stale manager then
91
- _manager = [RNSkiaModule latestActiveSkManager].get();
92
- }
93
- }
94
-
95
- - (void)unregisterView {
96
- if (_manager != nullptr && _nativeId != 0) {
97
- _manager->unregisterSkiaView(_nativeId);
98
- }
99
- }
100
-
101
- #pragma Render
102
-
103
- - (void)drawRect:(CGRect)rect {
104
- // We override drawRect to ensure we to direct rendering when the
105
- // underlying OS view needs to render:
106
- if (_impl != nullptr) {
107
- _impl->getDrawView()->redraw();
108
- }
109
- }
110
-
111
- #pragma mark Layout
112
-
113
- - (void)layoutSubviews {
114
- [super layoutSubviews];
115
- if (_impl != nullptr) {
116
- [CATransaction begin];
117
- [CATransaction setDisableActions:YES];
118
- _impl->setSize(self.bounds.size.width, self.bounds.size.height);
119
- [CATransaction commit];
120
- }
121
- }
122
-
123
- #pragma mark Properties
124
-
125
- - (void)setDebugMode:(bool)debugMode {
126
- _debugMode = debugMode;
127
- if (_impl != nullptr) {
128
- _impl->getDrawView()->setShowDebugOverlays(debugMode);
129
- }
130
- }
131
-
132
- - (void)setOpaque:(bool)opaque {
133
- _opaque = opaque;
134
- }
135
-
136
- - (void)setNativeId:(size_t)nativeId {
137
- _nativeId = nativeId;
138
-
139
- if (_impl != nullptr) {
140
- _manager->registerSkiaView(nativeId, _impl->getDrawView());
141
- }
142
- }
143
-
144
- - (void)setUseP3ColorSpace:(bool)useP3ColorSpace {
145
- _useP3ColorSpace = useP3ColorSpace;
146
- if (_impl != nullptr) {
147
- _impl->setUseP3ColorSpace(_useP3ColorSpace);
148
- }
149
- }
150
-
151
- - (void)setHighBitDepth:(bool)highBitDepth {
152
- _highBitDepth = highBitDepth;
153
- if (_impl != nullptr) {
154
- _impl->setHighBitDepth(_highBitDepth);
155
- }
156
- }
157
-
158
- #pragma mark External API
159
-
160
- - (std::shared_ptr<RNSkBaseAppleView>)impl {
161
- return _impl;
162
- }
163
-
164
- @end