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,31 +1,13 @@
1
1
  #import "RNSkMetalCanvasProvider.h"
2
2
 
3
- #import "RNSkLog.h"
4
-
5
- #if defined(SK_GRAPHITE)
6
3
  #import "RNDawnContext.h"
7
- #else
8
- #import "MetalContext.h"
9
- #endif
10
-
11
- #pragma clang diagnostic push
12
- #pragma clang diagnostic ignored "-Wdocumentation"
13
-
14
- #import "include/core/SkCanvas.h"
15
- #import "include/core/SkColorSpace.h"
16
- #import "include/core/SkSurface.h"
17
-
18
- #import <include/gpu/ganesh/GrBackendSurface.h>
19
- #import <include/gpu/ganesh/GrDirectContext.h>
20
- #import <include/gpu/ganesh/SkSurfaceGanesh.h>
4
+ #import "RNSkLog.h"
21
5
 
22
- #pragma clang diagnostic pop
6
+ #include <cmath>
23
7
 
24
8
  RNSkMetalCanvasProvider::RNSkMetalCanvasProvider(
25
- std::function<void()> requestRedraw,
26
- std::shared_ptr<RNSkia::RNSkPlatformContext> context, bool useP3ColorSpace)
27
- : RNSkCanvasProvider(requestRedraw), _context(context),
28
- _useP3ColorSpace(useP3ColorSpace) {
9
+ std::shared_ptr<RNSkia::RNSkPlatformContext> context)
10
+ : _context(std::move(context)) {
29
11
  #pragma clang diagnostic push
30
12
  #pragma clang diagnostic ignored "-Wunguarded-availability-new"
31
13
  _layer = [CAMetalLayer layer];
@@ -61,38 +43,7 @@ static bool appIsBackgrounded() {
61
43
  #endif // !TARGET_OS_OSX
62
44
  }
63
45
 
64
- /**
65
- Render to a canvas
66
- */
67
- bool RNSkMetalCanvasProvider::renderToCanvas(
68
- const std::function<void(SkCanvas *)> &cb) {
69
- if (!_ctx) {
70
- return false;
71
- }
72
-
73
- if ([[NSThread currentThread] isMainThread]) {
74
- if (appIsBackgrounded()) {
75
- // Request a redraw in the next run loop callback
76
- _requestRedraw();
77
- // and don't draw now since it might cause errors in the metal renderer if
78
- // we try to render while in the background. (see above issue)
79
- return false;
80
- }
81
-
82
- auto surface = _ctx->getSurface();
83
- if (!surface) {
84
- return false;
85
- }
86
- auto canvas = surface->getCanvas();
87
- cb(canvas);
88
- _ctx->present();
89
- return true;
90
- }
91
- return false;
92
- };
93
-
94
- #if defined(SK_GRAPHITE)
95
- bool RNSkMetalCanvasProvider::getGraphiteTargetInfo(
46
+ bool RNSkMetalCanvasProvider::getTargetInfo(
96
47
  RNSkia::RNSkGraphiteTargetInfo *info) {
97
48
  std::lock_guard<std::mutex> lock(_targetInfoMutex);
98
49
  if (!_hasTargetInfo) {
@@ -102,49 +53,67 @@ bool RNSkMetalCanvasProvider::getGraphiteTargetInfo(
102
53
  return true;
103
54
  }
104
55
 
56
+ bool RNSkMetalCanvasProvider::getLayoutSize(int *width, int *height) {
57
+ std::lock_guard<std::mutex> lock(_targetInfoMutex);
58
+ if (_layoutWidth <= 0 || _layoutHeight <= 0) {
59
+ return false;
60
+ }
61
+ *width = _layoutWidth;
62
+ *height = _layoutHeight;
63
+ return true;
64
+ }
65
+
105
66
  bool RNSkMetalCanvasProvider::presentRecordings(
106
67
  const std::vector<skgpu::graphite::Recording *> &recordings) {
107
68
  if (!_ctx || ![[NSThread currentThread] isMainThread]) {
108
69
  return false;
109
70
  }
110
71
  if (appIsBackgrounded()) {
111
- _requestRedraw();
72
+ requestRedraw();
112
73
  return false;
113
74
  }
114
75
  return static_cast<RNSkia::DawnWindowContext *>(_ctx.get())
115
76
  ->presentRecordings(recordings);
116
77
  }
117
- #endif
78
+
79
+ bool RNSkMetalCanvasProvider::presentImage(const sk_sp<SkImage> &image) {
80
+ if (!_ctx || ![[NSThread currentThread] isMainThread]) {
81
+ return false;
82
+ }
83
+ if (appIsBackgrounded()) {
84
+ requestRedraw();
85
+ return false;
86
+ }
87
+ return static_cast<RNSkia::DawnWindowContext *>(_ctx.get())
88
+ ->presentImage(image);
89
+ }
118
90
 
119
91
  void RNSkMetalCanvasProvider::setSize(int width, int height) {
120
92
  _layer.frame = CGRectMake(0, 0, width, height);
121
- auto w = width * _context->getPixelDensity();
122
- auto h = height * _context->getPixelDensity();
123
- #if defined(SK_GRAPHITE)
124
- _ctx = RNSkia::DawnContext::getInstance().MakeWindow((__bridge void *)_layer,
125
- w, h, _highBitDepth);
93
+ // The layout is on the pixel grid: round rather than truncate, so that a
94
+ // product like 1169.9999 gives the pixel size the layout means.
95
+ int w = static_cast<int>(std::lround(width * _context->getPixelDensity()));
96
+ int h = static_cast<int>(std::lround(height * _context->getPixelDensity()));
97
+ _ctx = RNSkia::DawnContext::getInstance().MakeWindow(
98
+ (__bridge void *)_layer, w, h, _highBitDepth,
99
+ _context->prefersP3ColorSpace());
126
100
  {
127
101
  auto *window = static_cast<RNSkia::DawnWindowContext *>(_ctx.get());
128
102
  std::lock_guard<std::mutex> lock(_targetInfoMutex);
103
+ _layoutWidth = w;
104
+ _layoutHeight = h;
129
105
  _targetInfo.width = window->getWidth();
130
106
  _targetInfo.height = window->getHeight();
131
107
  _targetInfo.colorType = window->getColorType();
108
+ _targetInfo.useP3ColorSpace = window->usesP3ColorSpace();
132
109
  _targetInfo.textureInfo = window->getTextureInfo();
133
110
  _hasTargetInfo = true;
134
111
  }
135
- #else
136
- _ctx = MetalContext::getInstance().MakeWindow(_layer, w, h, _useP3ColorSpace,
137
- _highBitDepth);
138
- #endif
139
- _requestRedraw();
112
+ requestRedraw();
140
113
  }
141
114
 
142
115
  CALayer *RNSkMetalCanvasProvider::getLayer() { return _layer; }
143
116
 
144
- void RNSkMetalCanvasProvider::setUseP3ColorSpace(bool useP3ColorSpace) {
145
- _useP3ColorSpace = useP3ColorSpace;
146
- }
147
-
148
117
  void RNSkMetalCanvasProvider::setHighBitDepth(bool highBitDepth) {
149
118
  if (_highBitDepth == highBitDepth) {
150
119
  return;
@@ -39,6 +39,16 @@ RCT_EXPORT_MODULE()
39
39
  return YES;
40
40
  }
41
41
 
42
+ - (instancetype)init {
43
+ if (self = [super init]) {
44
+ // Created on the main queue (see requiresMainQueueSetup): the screen is
45
+ // asked for its color gamut here, where UIKit may be used. The platform
46
+ // context is created on the JS thread and only reads the answer.
47
+ RNSkia::RNSkApplePlatformContext::mainScreenSupportsP3();
48
+ }
49
+ return self;
50
+ }
51
+
42
52
  - (void)
43
53
  installJSIBindingsWithRuntime:(facebook::jsi::Runtime &)runtime
44
54
  callInvoker:
@@ -0,0 +1,20 @@
1
+ #pragma once
2
+
3
+ #import <CoreFoundation/CoreFoundation.h>
4
+ #if !TARGET_OS_OSX
5
+ #import <UIKit/UIKit.h>
6
+ #else
7
+ #import <React/RCTUIKit.h>
8
+ #endif // !TARGET_OS_OSX
9
+
10
+ #import <React/RCTViewComponentView.h>
11
+
12
+ /**
13
+ * The Fabric component behind <Canvas>, <SkiaPictureView> and
14
+ * <SkiaGraphiteView>: a CAMetalLayer presenting Graphite recordings on the
15
+ * display link. The frames are recorded by the native render thread pool
16
+ * (declarative content) or by JS (SkiaViewApi.makeGraphiteContext).
17
+ */
18
+ @interface SkiaView : RCTViewComponentView
19
+
20
+ @end
@@ -0,0 +1,210 @@
1
+ #import "SkiaView.h"
2
+
3
+ #import <QuartzCore/CADisplayLink.h>
4
+ #import <QuartzCore/CATransaction.h>
5
+
6
+ #import <React/RCTConversions.h>
7
+ #import <React/RCTConvert.h>
8
+ #import <React/RCTFabricComponentsPlugins.h>
9
+
10
+ #import <react/renderer/components/rnskia/ComponentDescriptors.h>
11
+ #import <react/renderer/components/rnskia/EventEmitters.h>
12
+ #import <react/renderer/components/rnskia/Props.h>
13
+ #import <react/renderer/components/rnskia/RCTComponentViewHelpers.h>
14
+
15
+ #include <memory>
16
+
17
+ #import "RNSkManager.h"
18
+ #import "RNSkMetalCanvasProvider.h"
19
+ #import "RNSkView.h"
20
+ #import "RNSkiaModule.h"
21
+
22
+ using namespace facebook::react;
23
+
24
+ @implementation SkiaView {
25
+ // The native view and the layer it presents into. Both exist while the
26
+ // view is in the hierarchy (see willMoveToSuperview:).
27
+ std::shared_ptr<RNSkia::RNSkView> _view;
28
+ std::shared_ptr<RNSkMetalCanvasProvider> _provider;
29
+ // Owned by the module, which outlives its views (see finalizeUpdates:).
30
+ RNSkia::RNSkManager *_manager;
31
+ size_t _nativeId;
32
+ bool _highBitDepth;
33
+ #if !TARGET_OS_OSX
34
+ CADisplayLink *_displayLink;
35
+ #endif
36
+ }
37
+
38
+ - (instancetype)initWithFrame:(CGRect)frame {
39
+ if (self = [super initWithFrame:frame]) {
40
+ _manager = [RNSkiaModule latestActiveSkManager].get();
41
+ _nativeId = 0;
42
+ _highBitDepth = false;
43
+ static const auto defaultProps = std::make_shared<const SkiaViewProps>();
44
+ _props = defaultProps;
45
+ }
46
+ return self;
47
+ }
48
+
49
+ #pragma mark - Lifecycle
50
+
51
+ // The native view lives while the view is in the hierarchy: it is created
52
+ // when the view gets a superview and torn down when it leaves it, so that a
53
+ // view kept around by a transition does not keep a surface.
54
+ #if !TARGET_OS_OSX
55
+ - (void)willMoveToSuperview:(UIView *)newSuperView {
56
+ [super willMoveToSuperview:newSuperView];
57
+ #else
58
+ - (void)viewWillMoveToSuperview:(NSView *)newSuperView {
59
+ [super viewWillMoveToSuperview:newSuperView];
60
+ #endif // !TARGET_OS_OSX
61
+ if (newSuperView == nullptr || _view != nullptr || _manager == nullptr) {
62
+ return;
63
+ }
64
+ auto context = _manager->getPlatformContext();
65
+ _provider = std::make_shared<RNSkMetalCanvasProvider>(context);
66
+ _view = std::make_shared<RNSkia::RNSkView>(context, _provider);
67
+ [self.layer addSublayer:_provider->getLayer()];
68
+ if (_nativeId != 0) {
69
+ _manager->setSkiaView(_nativeId, _view);
70
+ }
71
+ _provider->setHighBitDepth(_highBitDepth);
72
+ __weak SkiaView *weakSelf = self;
73
+ _view->setFrameScheduler([weakSelf]() { [weakSelf scheduleFrame]; });
74
+ }
75
+
76
+ - (void)removeFromSuperview {
77
+ [self stopDisplayLink];
78
+ if (_view != nullptr) {
79
+ [_provider->getLayer() removeFromSuperlayer];
80
+ if (_nativeId != 0 && _manager != nullptr) {
81
+ _manager->setSkiaView(_nativeId, nullptr);
82
+ }
83
+ _view = nullptr;
84
+ _provider = nullptr;
85
+ }
86
+ [super removeFromSuperview];
87
+ }
88
+
89
+ - (void)dealloc {
90
+ [self stopDisplayLink];
91
+ [self unregisterView];
92
+ }
93
+
94
+ - (void)prepareForRecycle {
95
+ [super prepareForRecycle];
96
+ [self stopDisplayLink];
97
+ [self unregisterView];
98
+ }
99
+
100
+ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask {
101
+ [super finalizeUpdates:updateMask];
102
+ if (updateMask == RNComponentViewUpdateMaskAll) {
103
+ // this flag is only set when the view is inserted and we want to set the
104
+ // manager here since the view could be recycled or the app could be
105
+ // refreshed and we would have a stale manager then
106
+ _manager = [RNSkiaModule latestActiveSkManager].get();
107
+ }
108
+ }
109
+
110
+ - (void)unregisterView {
111
+ if (_manager != nullptr && _nativeId != 0) {
112
+ _manager->unregisterSkiaView(_nativeId);
113
+ }
114
+ }
115
+
116
+ #pragma mark - Frames
117
+
118
+ // Presents on the display link: armed when a recording is submitted, paused
119
+ // again once the queue is empty. macOS has no CADisplayLink on the minimum
120
+ // deployment target, so frames are presented as soon as the main thread gets
121
+ // to them there.
122
+ - (void)scheduleFrame {
123
+ #if !TARGET_OS_OSX
124
+ if (_displayLink == nil) {
125
+ _displayLink = [CADisplayLink displayLinkWithTarget:self
126
+ selector:@selector(onFrame:)];
127
+ [_displayLink addToRunLoop:[NSRunLoop mainRunLoop]
128
+ forMode:NSRunLoopCommonModes];
129
+ }
130
+ _displayLink.paused = NO;
131
+ #else
132
+ if (_view != nullptr) {
133
+ _view->presentFrame();
134
+ }
135
+ #endif
136
+ }
137
+
138
+ #if !TARGET_OS_OSX
139
+ - (void)onFrame:(CADisplayLink *)link {
140
+ if (_view == nullptr || !_view->presentFrame()) {
141
+ link.paused = YES;
142
+ }
143
+ }
144
+ #endif
145
+
146
+ - (void)stopDisplayLink {
147
+ #if !TARGET_OS_OSX
148
+ [_displayLink invalidate];
149
+ _displayLink = nil;
150
+ #endif
151
+ }
152
+
153
+ #pragma mark - Render
154
+
155
+ - (void)drawRect:(CGRect)rect {
156
+ // The OS asked for a draw: present what the view holds right away.
157
+ if (_view != nullptr) {
158
+ _view->redraw();
159
+ }
160
+ }
161
+
162
+ #pragma mark - Layout
163
+
164
+ - (void)layoutSubviews {
165
+ [super layoutSubviews];
166
+ if (_provider != nullptr) {
167
+ [CATransaction begin];
168
+ [CATransaction setDisableActions:YES];
169
+ _provider->setSize(self.bounds.size.width, self.bounds.size.height);
170
+ [CATransaction commit];
171
+ }
172
+ }
173
+
174
+ #pragma mark - Props
175
+
176
+ + (ComponentDescriptorProvider)componentDescriptorProvider {
177
+ return concreteComponentDescriptorProvider<SkiaViewComponentDescriptor>();
178
+ }
179
+
180
+ - (void)updateProps:(const Props::Shared &)props
181
+ oldProps:(const Props::Shared &)oldProps {
182
+ const auto &newProps = *std::static_pointer_cast<const SkiaViewProps>(props);
183
+ [super updateProps:props oldProps:oldProps];
184
+ int nativeId =
185
+ [[RCTConvert NSString:RCTNSStringFromString(newProps.nativeId)] intValue];
186
+ [self bindNativeId:nativeId];
187
+ [self setHighBitDepth:newProps.highBitDepth];
188
+ // opaque, androidSurfaceType and androidZOrderOnTop select the backing view
189
+ // on Android; a CAMetalLayer composites like any other layer.
190
+ }
191
+
192
+ // Not setNativeId:, which is the setter of RCTViewComponentView's nativeId
193
+ // (the string Fabric assigns from the nativeID prop).
194
+ - (void)bindNativeId:(size_t)nativeId {
195
+ _nativeId = nativeId;
196
+ if (_view != nullptr) {
197
+ _manager->registerSkiaView(nativeId, _view);
198
+ }
199
+ }
200
+
201
+ - (void)setHighBitDepth:(bool)highBitDepth {
202
+ _highBitDepth = highBitDepth;
203
+ if (_provider != nullptr) {
204
+ _provider->setHighBitDepth(highBitDepth);
205
+ }
206
+ }
207
+
208
+ @end
209
+
210
+ Class<RCTComponentViewProtocol> SkiaViewCls(void) { return SkiaView.class; }
@@ -6,9 +6,7 @@
6
6
 
7
7
  #include "JsiSkNativeObjects.h"
8
8
 
9
- #ifdef SK_GRAPHITE
10
9
  #include "rnskia/RNDawnContext.h"
11
- #endif
12
10
 
13
11
  #include "JsiNativeBuffer.h"
14
12
  #include "JsiSkAnimatedImage.h"
@@ -167,19 +165,12 @@ public:
167
165
  return JsiSkColor::createCtor()(runtime, thisValue, arguments, count);
168
166
  }
169
167
  JSI_HOST_FUNCTION(getNativeDevice) {
170
- #ifdef SK_GRAPHITE
171
168
  // Raw WGPUDevice pointer of the Graphite device, as a BigInt. Consumed by
172
169
  // react-native-webgpu's importDevice(), which AddRefs it; the pointer
173
170
  // stays owned by DawnContext and is valid for the process lifetime.
174
171
  auto &dawnContext = DawnContext::getInstance();
175
172
  return jsi::BigInt::fromUint64(
176
- runtime,
177
- reinterpret_cast<uint64_t>(dawnContext.getWGPUDevice().Get()));
178
- #else
179
- throw jsi::JSError(runtime,
180
- "getNativeDevice() is only available with the Graphite "
181
- "backend. Rebuild with SK_GRAPHITE enabled.");
182
- #endif
173
+ runtime, reinterpret_cast<uint64_t>(dawnContext.getWGPUDevice().Get()));
183
174
  }
184
175
 
185
176
  JSI_HOST_FUNCTION(Recorder) {
@@ -191,9 +182,7 @@ public:
191
182
  // property access returns a fresh JS wrapper around the shared factory
192
183
  // instance.
193
184
  std::shared_ptr<JsiSkSVGFactory> getSVGFactory() { return _svgFactory; }
194
- std::shared_ptr<JsiSkImageFactory> getImageFactory() {
195
- return _imageFactory;
196
- }
185
+ std::shared_ptr<JsiSkImageFactory> getImageFactory() { return _imageFactory; }
197
186
  std::shared_ptr<JsiSkAnimatedImageFactory> getAnimatedImageFactory() {
198
187
  return _animatedImageFactory;
199
188
  }
@@ -24,9 +24,7 @@
24
24
 
25
25
  #include "utils/RNSkTypedArray.h"
26
26
 
27
- #if defined(SK_GRAPHITE)
28
27
  #include "rnskia/RNDawnContext.h"
29
- #endif
30
28
 
31
29
  #include <jsi/jsi.h>
32
30
 
@@ -42,10 +40,6 @@
42
40
  #include "include/core/SkSurface.h"
43
41
  #include "include/core/SkTypeface.h"
44
42
 
45
- #if !defined(SK_GRAPHITE)
46
- #include "include/gpu/ganesh/GrDirectContext.h"
47
- #endif
48
-
49
43
  #pragma clang diagnostic pop
50
44
 
51
45
  namespace RNSkia {
@@ -56,9 +50,7 @@ class JsiSkCanvas : public JsiSkNativeObject<JsiSkCanvas> {
56
50
  public:
57
51
  static constexpr const char *CLASS_NAME = "Canvas";
58
52
 
59
- void drawPaint(std::shared_ptr<SkPaint> paint) {
60
- _canvas->drawPaint(*paint);
61
- }
53
+ void drawPaint(std::shared_ptr<SkPaint> paint) { _canvas->drawPaint(*paint); }
62
54
 
63
55
  void drawLine(double x1, double y1, double x2, double y2,
64
56
  std::shared_ptr<SkPaint> paint) {
@@ -355,8 +347,7 @@ public:
355
347
 
356
348
  void clipPath(std::shared_ptr<SkPathBuilder> path, double op,
357
349
  bool doAntiAlias) {
358
- _canvas->clipPath(path->snapshot(), static_cast<SkClipOp>(op),
359
- doAntiAlias);
350
+ _canvas->clipPath(path->snapshot(), static_cast<SkClipOp>(op), doAntiAlias);
360
351
  }
361
352
 
362
353
  void clipRect(std::shared_ptr<SkRect> rect, double op, bool doAntiAlias) {
@@ -410,9 +401,7 @@ public:
410
401
 
411
402
  void concat(std::shared_ptr<SkMatrix> matrix) { _canvas->concat(*matrix); }
412
403
 
413
- void drawPicture(sk_sp<SkPicture> picture) {
414
- _canvas->drawPicture(picture);
415
- }
404
+ void drawPicture(sk_sp<SkPicture> picture) { _canvas->drawPicture(picture); }
416
405
 
417
406
  JSI_HOST_FUNCTION(drawAtlas) {
418
407
  auto atlas = JsiSkImage::fromValue(runtime, arguments[0]);
@@ -518,7 +507,6 @@ public:
518
507
  .getArrayBuffer(runtime);
519
508
  auto bfrPtr = reinterpret_cast<void *>(buffer.data(runtime));
520
509
 
521
- #if defined(SK_GRAPHITE)
522
510
  // Graphite records draws lazily and offers no synchronous GPU readback. If
523
511
  // this canvas belongs to a surface, snap & submit its recording, snapshot
524
512
  // it to a CPU raster image and read from that (mirroring
@@ -540,7 +528,6 @@ public:
540
528
  }
541
529
  return dest;
542
530
  }
543
- #endif
544
531
 
545
532
  if (!_canvas->readPixels(*info, bfrPtr, bytesPerRow, srcX, srcY)) {
546
533
  return jsi::Value::null();
@@ -599,8 +586,7 @@ public:
599
586
  installMethod(runtime, prototype, "drawColor", &JsiSkCanvas::drawColor);
600
587
  installMethod(runtime, prototype, "clear", &JsiSkCanvas::clear);
601
588
  installMethod(runtime, prototype, "concat", &JsiSkCanvas::concat);
602
- installMethod(runtime, prototype, "drawPicture",
603
- &JsiSkCanvas::drawPicture);
589
+ installMethod(runtime, prototype, "drawPicture", &JsiSkCanvas::drawPicture);
604
590
  installHostMethod(runtime, prototype, "drawAtlas", &JsiSkCanvas::drawAtlas);
605
591
  installHostMethod(runtime, prototype, "readPixels",
606
592
  &JsiSkCanvas::readPixels);
@@ -1,7 +1,5 @@
1
1
  #pragma once
2
2
 
3
- #if defined(SK_GRAPHITE)
4
-
5
3
  #include <memory>
6
4
  #include <utility>
7
5
 
@@ -10,7 +8,7 @@
10
8
  #include "JsiSkCanvas.h"
11
9
  #include "JsiSkGraphiteRecording.h"
12
10
  #include "JsiSkNativeObjects.h"
13
- #include "rnskia/RNSkGraphiteView.h"
11
+ #include "rnskia/RNSkGraphiteTarget.h"
14
12
 
15
13
  namespace RNSkia {
16
14
 
@@ -78,5 +76,3 @@ private:
78
76
  };
79
77
 
80
78
  } // namespace RNSkia
81
-
82
- #endif // SK_GRAPHITE
@@ -1,14 +1,12 @@
1
1
  #pragma once
2
2
 
3
- #if defined(SK_GRAPHITE)
4
-
5
3
  #include <memory>
6
4
  #include <utility>
7
5
 
8
6
  #include <jsi/jsi.h>
9
7
 
10
8
  #include "JsiSkNativeObjects.h"
11
- #include "rnskia/RNSkGraphiteView.h"
9
+ #include "rnskia/RNSkGraphiteTarget.h"
12
10
 
13
11
  namespace RNSkia {
14
12
 
@@ -40,5 +38,3 @@ public:
40
38
  };
41
39
 
42
40
  } // namespace RNSkia
43
-
44
- #endif // SK_GRAPHITE
@@ -17,12 +17,8 @@
17
17
  #include "JsiTextureInfo.h"
18
18
  #include "utils/RNSkTypedArray.h"
19
19
 
20
- #if defined(SK_GRAPHITE)
21
20
  #include "include/gpu/graphite/Context.h"
22
21
  #include "rnskia/RNDawnContext.h"
23
- #else
24
- #include "include/gpu/ganesh/GrDirectContext.h"
25
- #endif
26
22
 
27
23
  #pragma clang diagnostic push
28
24
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -187,18 +183,7 @@ public:
187
183
  ? static_cast<SkEncodedImageFormat>(*formatParam)
188
184
  : SkEncodedImageFormat::kPNG;
189
185
  auto quality = qualityParam.has_value() ? *qualityParam : 100.0;
190
- auto image = getObject();
191
- #if defined(SK_GRAPHITE)
192
- image = DawnContext::getInstance().MakeRasterImage(image);
193
- #else
194
- if (image->isTextureBacked()) {
195
- auto grContext = getContext()->getDirectContext();
196
- image = image->makeRasterImage(grContext);
197
- if (!image) {
198
- return nullptr;
199
- }
200
- }
201
- #endif
186
+ auto image = DawnContext::getInstance().MakeRasterImage(getObject());
202
187
  sk_sp<SkData> data;
203
188
 
204
189
  if (format == SkEncodedImageFormat::kJPEG) {
@@ -236,10 +221,10 @@ public:
236
221
  count >= 1 && !arguments[0].isUndefined() && !arguments[0].isNull()
237
222
  ? JsiOptional<double>(arguments[0].asNumber())
238
223
  : JsiOptional<double>();
239
- JsiOptional<double> quality = count >= 2 && arguments[1].isNumber()
240
- ? JsiOptional<double>(
241
- arguments[1].asNumber())
242
- : JsiOptional<double>();
224
+ JsiOptional<double> quality =
225
+ count >= 2 && arguments[1].isNumber()
226
+ ? JsiOptional<double>(arguments[1].asNumber())
227
+ : JsiOptional<double>();
243
228
  auto data = encodeImageData(format, quality);
244
229
  if (!data) {
245
230
  return jsi::Value::null();
@@ -310,38 +295,19 @@ public:
310
295
  .getArrayBuffer(runtime);
311
296
  auto bfrPtr = reinterpret_cast<void *>(buffer.data(runtime));
312
297
 
313
- #if defined(SK_GRAPHITE)
314
- // Graphite offers no synchronous GPU readback, so fall back to a CPU raster
315
- // copy of the image (a no-op when the image is already raster) and read the
316
- // pixels from that. This matches the Ganesh behaviour for non-texture and
317
- // texture-backed images alike.
298
+ // Graphite offers no synchronous GPU readback, so read from a CPU raster
299
+ // copy of the image (a no-op when the image is already raster).
318
300
  auto image = DawnContext::getInstance().MakeRasterImage(getObject());
319
301
  if (!image ||
320
302
  !image->readPixels(nullptr, info, bfrPtr, bytesPerRow, srcX, srcY)) {
321
303
  return jsi::Value::null();
322
304
  }
323
- #else
324
- auto grContext = getContext()->getDirectContext();
325
- if (!getObject()->readPixels(grContext, info, bfrPtr, bytesPerRow, srcX,
326
- srcY)) {
327
- return jsi::Value::null();
328
- }
329
- #endif
330
305
  return dest;
331
306
  }
332
307
 
333
308
  std::variant<std::nullptr_t, std::shared_ptr<JsiSkImage>>
334
309
  makeNonTextureImage() {
335
- #if defined(SK_GRAPHITE)
336
310
  auto rasterImage = DawnContext::getInstance().MakeRasterImage(getObject());
337
- #else
338
- auto grContext = getContext()->getDirectContext();
339
- auto image = getObject();
340
- if (!grContext) {
341
- throw std::runtime_error("No GPU context available.");
342
- }
343
- auto rasterImage = image->makeRasterImage(grContext);
344
- #endif
345
311
  if (!rasterImage) {
346
312
  return nullptr;
347
313
  }