react-native-skia 3.0.1 → 3.0.2

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 (260) hide show
  1. package/Package.swift +14 -13
  2. package/android/CMakeLists.txt +13 -42
  3. package/android/build.gradle +54 -63
  4. package/android/cpp/jni/JniLoad.cpp +2 -4
  5. package/android/cpp/jni/include/JniSkiaView.h +123 -0
  6. package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.cpp → RNSkAndroidCanvasProvider.cpp} +45 -100
  7. package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.h → RNSkAndroidCanvasProvider.h} +24 -22
  8. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -83
  9. package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -8
  10. package/android/src/main/java/com/reactnative/skia/RNSkiaPackage.java +1 -2
  11. package/android/src/main/java/com/reactnative/skia/SkiaSurfaceView.java +1 -3
  12. package/android/src/main/java/com/reactnative/skia/SkiaTextureView.java +1 -17
  13. package/android/src/main/java/com/reactnative/skia/{SkiaBaseView.java → SkiaView.java} +78 -16
  14. package/android/src/main/java/com/reactnative/skia/SkiaViewManager.java +85 -0
  15. package/apple/MetalLayerColorSpace.mm +0 -4
  16. package/apple/RNSkApplePlatformContext.h +0 -14
  17. package/apple/RNSkApplePlatformContext.mm +2 -112
  18. package/apple/RNSkMetalCanvasProvider.h +14 -19
  19. package/apple/RNSkMetalCanvasProvider.mm +35 -68
  20. package/apple/SkiaView.h +20 -0
  21. package/apple/SkiaView.mm +210 -0
  22. package/cpp/api/JsiSkApi.h +2 -13
  23. package/cpp/api/JsiSkCanvas.h +4 -18
  24. package/cpp/api/JsiSkGraphiteContext.h +1 -5
  25. package/cpp/api/JsiSkGraphiteRecording.h +1 -5
  26. package/cpp/api/JsiSkImage.h +7 -41
  27. package/cpp/api/JsiSkImageFactory.h +0 -14
  28. package/cpp/api/JsiSkSurface.h +2 -16
  29. package/cpp/api/JsiSkSurfaceFactory.h +0 -8
  30. package/cpp/rnskia/RNDawnInterop.cpp +0 -4
  31. package/cpp/rnskia/RNDawnUtils.h +0 -1
  32. package/cpp/rnskia/RNDawnWindowContext.cpp +10 -0
  33. package/cpp/rnskia/RNDawnWindowContext.h +4 -0
  34. package/cpp/rnskia/RNSkCanvasProvider.h +221 -0
  35. package/cpp/rnskia/RNSkGraphiteProducer.cpp +36 -14
  36. package/cpp/rnskia/RNSkGraphiteProducer.h +23 -8
  37. package/cpp/rnskia/RNSkGraphiteTarget.h +383 -0
  38. package/cpp/rnskia/RNSkJsiViewApi.h +9 -18
  39. package/cpp/rnskia/RNSkPlatformContext.h +9 -15
  40. package/cpp/rnskia/RNSkView.h +340 -245
  41. package/jestSetup.js +1 -3
  42. package/lib/commonjs/Platform/Platform.web.js +1 -1
  43. package/lib/commonjs/Platform/Platform.web.js.map +1 -1
  44. package/lib/commonjs/index.d.ts +1 -3
  45. package/lib/commonjs/index.js +3 -12
  46. package/lib/commonjs/index.js.map +1 -1
  47. package/lib/commonjs/mock/index.js +0 -1
  48. package/lib/commonjs/mock/index.js.map +1 -1
  49. package/lib/commonjs/renderer/Canvas.d.ts +15 -12
  50. package/lib/commonjs/renderer/Canvas.js +24 -20
  51. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  52. package/lib/commonjs/skia/types/Graphite.d.ts +3 -3
  53. package/lib/commonjs/skia/types/Graphite.js.map +1 -1
  54. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +2 -2
  55. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  56. package/lib/commonjs/skia/types/Skia.d.ts +1 -2
  57. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  58. package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  59. package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
  60. package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +5 -4
  61. package/lib/commonjs/specs/NativeSkiaModule.web.js +5 -9
  62. package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
  63. package/lib/{typescript/src/specs/SkiaPictureViewNativeComponent.d.ts → commonjs/specs/SkiaViewNativeComponent.d.ts} +0 -3
  64. package/lib/commonjs/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
  65. package/lib/commonjs/specs/SkiaViewNativeComponent.js.map +1 -0
  66. package/lib/commonjs/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  67. package/lib/commonjs/specs/SkiaViewNativeComponent.web.js +27 -0
  68. package/lib/commonjs/specs/SkiaViewNativeComponent.web.js.map +1 -0
  69. package/lib/commonjs/views/SkiaGraphiteView.d.ts +3 -4
  70. package/lib/commonjs/views/SkiaGraphiteView.js +23 -12
  71. package/lib/commonjs/views/SkiaGraphiteView.js.map +1 -1
  72. package/lib/commonjs/views/SkiaPictureView.d.ts +4 -1
  73. package/lib/commonjs/views/SkiaPictureView.js +12 -10
  74. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  75. package/lib/commonjs/views/SkiaView.web.d.ts +12 -0
  76. package/lib/commonjs/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +82 -38
  77. package/lib/commonjs/views/SkiaView.web.js.map +1 -0
  78. package/lib/commonjs/views/SkiaWebRenderer.js +1 -1
  79. package/lib/commonjs/views/SkiaWebRenderer.js.map +1 -1
  80. package/lib/commonjs/views/android.d.ts +6 -0
  81. package/lib/commonjs/views/android.js +17 -0
  82. package/lib/commonjs/views/android.js.map +1 -0
  83. package/lib/commonjs/views/types.d.ts +3 -12
  84. package/lib/commonjs/views/types.js.map +1 -1
  85. package/lib/module/Platform/Platform.web.js +1 -1
  86. package/lib/module/Platform/Platform.web.js.map +1 -1
  87. package/lib/module/index.d.ts +1 -3
  88. package/lib/module/index.js +1 -3
  89. package/lib/module/index.js.map +1 -1
  90. package/lib/module/mock/index.js +0 -1
  91. package/lib/module/mock/index.js.map +1 -1
  92. package/lib/module/renderer/Canvas.d.ts +15 -12
  93. package/lib/module/renderer/Canvas.js +24 -19
  94. package/lib/module/renderer/Canvas.js.map +1 -1
  95. package/lib/module/skia/types/Graphite.d.ts +3 -3
  96. package/lib/module/skia/types/Graphite.js.map +1 -1
  97. package/lib/module/skia/types/Image/ImageFactory.d.ts +2 -2
  98. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  99. package/lib/module/skia/types/Skia.d.ts +1 -2
  100. package/lib/module/skia/types/Skia.js.map +1 -1
  101. package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  102. package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
  103. package/lib/module/specs/NativeSkiaModule.web.d.ts +5 -4
  104. package/lib/module/specs/NativeSkiaModule.web.js +5 -9
  105. package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
  106. package/lib/{commonjs/specs/SkiaPictureViewNativeComponent.d.ts → module/specs/SkiaViewNativeComponent.d.ts} +0 -3
  107. package/lib/module/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
  108. package/lib/module/specs/SkiaViewNativeComponent.js.map +1 -0
  109. package/lib/module/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  110. package/lib/module/specs/SkiaViewNativeComponent.web.js +21 -0
  111. package/lib/module/specs/SkiaViewNativeComponent.web.js.map +1 -0
  112. package/lib/module/views/SkiaGraphiteView.d.ts +3 -4
  113. package/lib/module/views/SkiaGraphiteView.js +23 -12
  114. package/lib/module/views/SkiaGraphiteView.js.map +1 -1
  115. package/lib/module/views/SkiaPictureView.d.ts +4 -1
  116. package/lib/module/views/SkiaPictureView.js +12 -10
  117. package/lib/module/views/SkiaPictureView.js.map +1 -1
  118. package/lib/module/views/SkiaView.web.d.ts +12 -0
  119. package/lib/module/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +80 -36
  120. package/lib/module/views/SkiaView.web.js.map +1 -0
  121. package/lib/module/views/SkiaWebRenderer.js +1 -1
  122. package/lib/module/views/SkiaWebRenderer.js.map +1 -1
  123. package/lib/module/views/android.d.ts +6 -0
  124. package/lib/module/views/android.js +10 -0
  125. package/lib/module/views/android.js.map +1 -0
  126. package/lib/module/views/types.d.ts +3 -12
  127. package/lib/module/views/types.js.map +1 -1
  128. package/lib/typescript/src/index.d.ts +1 -3
  129. package/lib/typescript/src/renderer/Canvas.d.ts +15 -12
  130. package/lib/typescript/src/skia/types/Graphite.d.ts +3 -3
  131. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +2 -2
  132. package/lib/typescript/src/skia/types/Skia.d.ts +1 -2
  133. package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  134. package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +5 -4
  135. package/lib/{module/specs/SkiaPictureViewNativeComponent.d.ts → typescript/src/specs/SkiaViewNativeComponent.d.ts} +0 -3
  136. package/lib/typescript/src/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  137. package/lib/typescript/src/views/SkiaGraphiteView.d.ts +3 -4
  138. package/lib/typescript/src/views/SkiaPictureView.d.ts +4 -1
  139. package/lib/typescript/src/views/SkiaView.web.d.ts +12 -0
  140. package/lib/typescript/src/views/android.d.ts +6 -0
  141. package/lib/typescript/src/views/types.d.ts +3 -12
  142. package/package.json +5 -13
  143. package/react-native-skia.podspec +34 -58
  144. package/src/Platform/Platform.web.tsx +1 -1
  145. package/src/index.ts +1 -3
  146. package/src/mock/index.ts +0 -1
  147. package/src/renderer/Canvas.tsx +23 -27
  148. package/src/skia/types/Graphite.ts +3 -3
  149. package/src/skia/types/Image/ImageFactory.ts +2 -2
  150. package/src/skia/types/Skia.ts +1 -2
  151. package/src/skia/types/Surface/SurfaceFactory.ts +1 -1
  152. package/src/specs/NativeSkiaModule.web.ts +9 -21
  153. package/src/specs/{SkiaPictureViewNativeComponent.ts → SkiaViewNativeComponent.ts} +1 -4
  154. package/src/specs/{SkiaPictureViewNativeComponent.web.ts → SkiaViewNativeComponent.web.ts} +8 -10
  155. package/src/views/SkiaGraphiteView.tsx +27 -16
  156. package/src/views/SkiaPictureView.tsx +11 -10
  157. package/src/views/{SkiaGraphiteView.web.tsx → SkiaView.web.tsx} +100 -53
  158. package/src/views/SkiaWebRenderer.ts +1 -1
  159. package/src/views/android.ts +16 -0
  160. package/src/views/types.ts +3 -14
  161. package/android/cpp/jni/include/JniSkiaBaseView.h +0 -92
  162. package/android/cpp/jni/include/JniSkiaGraphiteView.h +0 -176
  163. package/android/cpp/jni/include/JniSkiaPictureView.h +0 -172
  164. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +0 -245
  165. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.h +0 -33
  166. package/android/cpp/rnskia-android/OpenGLContext.h +0 -248
  167. package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +0 -67
  168. package/android/cpp/rnskia-android/OpenGLWindowContext.h +0 -75
  169. package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -67
  170. package/android/cpp/rnskia-android/gl/Context.h +0 -80
  171. package/android/cpp/rnskia-android/gl/Display.h +0 -123
  172. package/android/cpp/rnskia-android/gl/Error.cpp +0 -45
  173. package/android/cpp/rnskia-android/gl/Error.h +0 -8
  174. package/android/cpp/rnskia-android/gl/Surface.h +0 -43
  175. package/android/src/main/java/com/reactnative/skia/SkiaBaseViewManager.java +0 -65
  176. package/android/src/main/java/com/reactnative/skia/SkiaGraphiteView.java +0 -78
  177. package/android/src/main/java/com/reactnative/skia/SkiaGraphiteViewManager.java +0 -32
  178. package/android/src/main/java/com/reactnative/skia/SkiaPictureView.java +0 -105
  179. package/android/src/main/java/com/reactnative/skia/SkiaPictureViewManager.java +0 -44
  180. package/apple/MetalContext.h +0 -116
  181. package/apple/MetalContext.mm +0 -38
  182. package/apple/MetalWindowContext.h +0 -42
  183. package/apple/MetalWindowContext.mm +0 -95
  184. package/apple/RNSkAppleView.h +0 -49
  185. package/apple/RNSkAppleView.mm +0 -35
  186. package/apple/SkiaCVPixelBufferUtils.h +0 -122
  187. package/apple/SkiaCVPixelBufferUtils.mm +0 -535
  188. package/apple/SkiaGraphiteView.h +0 -26
  189. package/apple/SkiaGraphiteView.mm +0 -180
  190. package/apple/SkiaPictureView.h +0 -7
  191. package/apple/SkiaPictureView.mm +0 -70
  192. package/apple/SkiaUIView.h +0 -31
  193. package/apple/SkiaUIView.mm +0 -164
  194. package/cpp/rnskia/RNSkGraphiteView.h +0 -708
  195. package/cpp/rnskia/RNSkPictureView.cpp +0 -69
  196. package/cpp/rnskia/RNSkPictureView.h +0 -211
  197. package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +0 -1162
  198. package/lib/commonjs/renderer/DefaultCanvas.d.ts +0 -8
  199. package/lib/commonjs/renderer/DefaultCanvas.js +0 -42
  200. package/lib/commonjs/renderer/DefaultCanvas.js.map +0 -1
  201. package/lib/commonjs/renderer/GraphiteCanvas.d.ts +0 -22
  202. package/lib/commonjs/renderer/GraphiteCanvas.js +0 -64
  203. package/lib/commonjs/renderer/GraphiteCanvas.js.map +0 -1
  204. package/lib/commonjs/renderer/GraphiteCanvas.web.d.ts +0 -1
  205. package/lib/commonjs/renderer/GraphiteCanvas.web.js +0 -13
  206. package/lib/commonjs/renderer/GraphiteCanvas.web.js.map +0 -1
  207. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  208. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js +0 -12
  209. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
  210. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  211. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js +0 -28
  212. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
  213. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +0 -1
  214. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  215. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js +0 -29
  216. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
  217. package/lib/commonjs/views/SkiaGraphiteView.web.d.ts +0 -14
  218. package/lib/commonjs/views/SkiaGraphiteView.web.js.map +0 -1
  219. package/lib/commonjs/views/SkiaPictureView.web.d.ts +0 -11
  220. package/lib/commonjs/views/SkiaPictureView.web.js +0 -165
  221. package/lib/commonjs/views/SkiaPictureView.web.js.map +0 -1
  222. package/lib/module/renderer/DefaultCanvas.d.ts +0 -8
  223. package/lib/module/renderer/DefaultCanvas.js +0 -34
  224. package/lib/module/renderer/DefaultCanvas.js.map +0 -1
  225. package/lib/module/renderer/GraphiteCanvas.d.ts +0 -22
  226. package/lib/module/renderer/GraphiteCanvas.js +0 -57
  227. package/lib/module/renderer/GraphiteCanvas.js.map +0 -1
  228. package/lib/module/renderer/GraphiteCanvas.web.d.ts +0 -1
  229. package/lib/module/renderer/GraphiteCanvas.web.js +0 -4
  230. package/lib/module/renderer/GraphiteCanvas.web.js.map +0 -1
  231. package/lib/module/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  232. package/lib/module/specs/SkiaGraphiteViewNativeComponent.js +0 -8
  233. package/lib/module/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
  234. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  235. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js +0 -22
  236. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
  237. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +0 -1
  238. package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  239. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js +0 -23
  240. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
  241. package/lib/module/views/SkiaGraphiteView.web.d.ts +0 -14
  242. package/lib/module/views/SkiaGraphiteView.web.js.map +0 -1
  243. package/lib/module/views/SkiaPictureView.web.d.ts +0 -11
  244. package/lib/module/views/SkiaPictureView.web.js +0 -156
  245. package/lib/module/views/SkiaPictureView.web.js.map +0 -1
  246. package/lib/typescript/src/renderer/DefaultCanvas.d.ts +0 -8
  247. package/lib/typescript/src/renderer/GraphiteCanvas.d.ts +0 -22
  248. package/lib/typescript/src/renderer/GraphiteCanvas.web.d.ts +0 -1
  249. package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  250. package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  251. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  252. package/lib/typescript/src/views/SkiaGraphiteView.web.d.ts +0 -14
  253. package/lib/typescript/src/views/SkiaPictureView.web.d.ts +0 -11
  254. package/libs/.graphite +0 -1
  255. package/src/renderer/DefaultCanvas.tsx +0 -41
  256. package/src/renderer/GraphiteCanvas.tsx +0 -61
  257. package/src/renderer/GraphiteCanvas.web.tsx +0 -3
  258. package/src/specs/SkiaGraphiteViewNativeComponent.ts +0 -17
  259. package/src/specs/SkiaGraphiteViewNativeComponent.web.ts +0 -31
  260. package/src/views/SkiaPictureView.web.tsx +0 -224
@@ -1,105 +0,0 @@
1
- package com.reactnative.skia;
2
-
3
- import android.content.Context;
4
- import android.graphics.Bitmap;
5
- import android.graphics.Canvas;
6
- import android.graphics.Paint;
7
- import android.graphics.PorterDuff;
8
- import android.graphics.SurfaceTexture;
9
- import android.view.Surface;
10
-
11
- import com.facebook.jni.HybridData;
12
- import com.facebook.jni.annotations.DoNotStrip;
13
- import com.facebook.react.bridge.ReactContext;
14
-
15
- public class SkiaPictureView extends SkiaBaseView {
16
- @DoNotStrip
17
- private HybridData mHybridData;
18
- private Paint paint = new Paint();
19
-
20
- private boolean androidWarmup = false;
21
-
22
- public SkiaPictureView(Context context) {
23
- super(context);
24
- RNSkiaModule skiaModule = ((ReactContext) context).getNativeModule(RNSkiaModule.class);
25
- mHybridData = initHybrid(skiaModule.getSkiaManager());
26
- }
27
-
28
- public void setAndroidWarmup(boolean androidWarmup) {
29
- this.androidWarmup = androidWarmup;
30
- setWillNotDraw(!androidWarmup);
31
- }
32
-
33
- @Override
34
- protected void finalize() throws Throwable {
35
- super.finalize();
36
- mHybridData.resetNative();
37
- }
38
-
39
- @Override
40
- protected void onDraw(Canvas canvas) {
41
- super.onDraw(canvas);
42
-
43
- // Skip the warming up feature if it is disabled or already cleared.
44
- if (!androidWarmup) {
45
- return;
46
- }
47
-
48
- // Get the view dimensions
49
- int width = getWidth();
50
- int height = getHeight();
51
-
52
- if (width > 0 && height > 0) {
53
- // Get the bitmap data from native
54
- int[] pixels = getBitmap(width, height);
55
-
56
- if (pixels != null && pixels.length == width * height) {
57
- // Create bitmap from pixels
58
- Bitmap bitmap = Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
59
-
60
- // Draw the bitmap on the canvas
61
- paint.setFilterBitmap(true);
62
- canvas.drawBitmap(bitmap, 0, 0, paint);
63
- // Let GC release the bitmap; recycling immediately breaks hardware-accelerated draws.
64
- }
65
- }
66
- }
67
-
68
- private native HybridData initHybrid(SkiaManager skiaManager);
69
-
70
- protected native void surfaceAvailable(Object surface, int width, int height, boolean isSurface, boolean highBitDepth);
71
-
72
- protected native void surfaceSizeChanged(Object surface, int width, int height, boolean isSurface, boolean highBitDepth);
73
-
74
- protected native void surfaceDestroyed();
75
-
76
- protected native void setBgColor(int color);
77
-
78
- protected native void setDebugMode(boolean show);
79
-
80
- protected native void registerView(int nativeId);
81
-
82
- protected native void unregisterView();
83
-
84
- protected native int[] getBitmap(int width, int height);
85
-
86
- @Override
87
- public void onSurfaceTextureCreated(SurfaceTexture surface, int width, int height) {
88
- super.onSurfaceTextureCreated(surface, width, height);
89
- }
90
-
91
- @Override
92
- public void onSurfaceTextureChanged(SurfaceTexture surface, int width, int height) {
93
- super.onSurfaceTextureChanged(surface, width, height);
94
- }
95
-
96
- @Override
97
- public void onSurfaceCreated(Surface surface, int width, int height) {
98
- super.onSurfaceCreated(surface, width, height);
99
- }
100
-
101
- @Override
102
- public void onSurfaceChanged(Surface surface, int width, int height) {
103
- super.onSurfaceChanged(surface, width, height);
104
- }
105
- }
@@ -1,44 +0,0 @@
1
- package com.reactnative.skia;
2
-
3
- import com.facebook.react.uimanager.ThemedReactContext;
4
- import com.facebook.react.viewmanagers.SkiaPictureViewManagerDelegate;
5
- import com.facebook.react.viewmanagers.SkiaPictureViewManagerInterface;
6
-
7
- import androidx.annotation.NonNull;
8
- import androidx.annotation.Nullable;
9
-
10
- public class SkiaPictureViewManager extends SkiaBaseViewManager<SkiaPictureView> implements SkiaPictureViewManagerInterface<SkiaPictureView> {
11
-
12
-
13
- protected SkiaPictureViewManagerDelegate mDelegate;
14
-
15
- SkiaPictureViewManager() {
16
- mDelegate = new SkiaPictureViewManagerDelegate(this);
17
- }
18
-
19
- protected SkiaPictureViewManagerDelegate getDelegate() {
20
- return mDelegate;
21
- }
22
-
23
- @NonNull
24
- @Override
25
- public String getName() {
26
- return "SkiaPictureView";
27
- }
28
-
29
- @NonNull
30
- @Override
31
- public SkiaPictureView createViewInstance(@NonNull ThemedReactContext reactContext) {
32
- return new SkiaPictureView(reactContext);
33
- }
34
-
35
- @Override
36
- public void setColorSpace(SkiaPictureView view, @Nullable String value) {
37
- // nothing to do here at the moment
38
- }
39
-
40
- @Override
41
- public void setAndroidWarmup(SkiaPictureView view, boolean value) {
42
- view.setAndroidWarmup(value);
43
- }
44
- }
@@ -1,116 +0,0 @@
1
- #pragma once
2
-
3
- #include "MetalWindowContext.h"
4
- #include "SkiaCVPixelBufferUtils.h"
5
-
6
- #include "include/core/SkSurface.h"
7
-
8
- #include "include/core/SkColorSpace.h"
9
- #import <include/gpu/ganesh/GrBackendSurface.h>
10
- #import <include/gpu/ganesh/GrDirectContext.h>
11
- #import <include/gpu/ganesh/SkImageGanesh.h>
12
- #import <include/gpu/ganesh/SkSurfaceGanesh.h>
13
- #import <include/gpu/ganesh/mtl/GrMtlBackendContext.h>
14
- #import <include/gpu/ganesh/mtl/GrMtlBackendSurface.h>
15
- #import <include/gpu/ganesh/mtl/GrMtlDirectContext.h>
16
- #import <include/gpu/ganesh/mtl/SkSurfaceMetal.h>
17
-
18
- struct OffscreenRenderContext {
19
- id<MTLTexture> texture;
20
-
21
- OffscreenRenderContext(id<MTLDevice> device,
22
- sk_sp<GrDirectContext> skiaContext,
23
- id<MTLCommandQueue> commandQueue, int width,
24
- int height) {
25
- // Create a Metal texture descriptor
26
- MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor
27
- texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
28
- width:width
29
- height:height
30
- mipmapped:NO];
31
- textureDescriptor.usage =
32
- MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead;
33
- texture = [device newTextureWithDescriptor:textureDescriptor];
34
- }
35
- };
36
-
37
- class MetalContext {
38
-
39
- public:
40
- MetalContext(const MetalContext &) = delete;
41
- MetalContext &operator=(const MetalContext &) = delete;
42
-
43
- static MetalContext &getInstance() {
44
- static thread_local MetalContext instance;
45
- return instance;
46
- }
47
-
48
- sk_sp<SkSurface> MakeOffscreen(int width, int height,
49
- bool useP3ColorSpace = false) {
50
- auto device = _device;
51
- auto ctx = new OffscreenRenderContext(device, _directContext, _commandQueue,
52
- width, height);
53
-
54
- // Create a GrBackendTexture from the Metal texture
55
- GrMtlTextureInfo info;
56
- info.fTexture.retain((__bridge void *)ctx->texture);
57
- GrBackendTexture backendTexture =
58
- GrBackendTextures::MakeMtl(width, height, skgpu::Mipmapped::kNo, info);
59
-
60
- sk_sp<SkColorSpace> colorSpace =
61
- useP3ColorSpace ? SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
62
- SkNamedGamut::kDisplayP3)
63
- : nullptr;
64
-
65
- // Create a SkSurface from the GrBackendTexture
66
- auto surface = SkSurfaces::WrapBackendTexture(
67
- _directContext.get(), backendTexture, kTopLeft_GrSurfaceOrigin, 0,
68
- kBGRA_8888_SkColorType, colorSpace, nullptr,
69
- [](void *addr) { delete (OffscreenRenderContext *)addr; }, ctx);
70
-
71
- return surface;
72
- }
73
-
74
- sk_sp<SkImage> MakeImageFromBuffer(void *buffer) {
75
- CVPixelBufferRef sampleBuffer = (CVPixelBufferRef)buffer;
76
- SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat format =
77
- SkiaCVPixelBufferUtils::getCVPixelBufferBaseFormat(sampleBuffer);
78
- switch (format) {
79
- case SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat::rgb: {
80
- // CVPixelBuffer is in any RGB format, single-plane
81
- return SkiaCVPixelBufferUtils::RGB::makeSkImageFromCVPixelBuffer(
82
- _device, _directContext.get(), sampleBuffer);
83
- }
84
- case SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat::yuv: {
85
- // CVPixelBuffer is in any YUV format, multi-plane
86
- return SkiaCVPixelBufferUtils::YUV::makeSkImageFromCVPixelBuffer(
87
- _device, _directContext.get(), sampleBuffer);
88
- }
89
- default:
90
- [[unlikely]] {
91
- throw std::runtime_error("Failed to convert NativeBuffer to SkImage - "
92
- "NativeBuffer has unsupported PixelFormat! " +
93
- std::to_string(static_cast<int>(format)));
94
- }
95
- }
96
- }
97
-
98
- std::unique_ptr<RNSkia::WindowContext> MakeWindow(CALayer *window, int width,
99
- int height,
100
- bool useP3ColorSpace = true,
101
- bool highBitDepth = false) {
102
- auto device = _device;
103
- return std::make_unique<MetalWindowContext>(
104
- _directContext.get(), device, _commandQueue, window, width, height,
105
- useP3ColorSpace, highBitDepth);
106
- }
107
-
108
- GrDirectContext *getDirectContext() { return _directContext.get(); }
109
-
110
- private:
111
- id<MTLDevice> _device = nullptr;
112
- id<MTLCommandQueue> _commandQueue = nullptr;
113
- sk_sp<GrDirectContext> _directContext = nullptr;
114
-
115
- MetalContext();
116
- };
@@ -1,38 +0,0 @@
1
- #include "MetalContext.h"
2
-
3
- #include "RNSkLog.h"
4
-
5
- #import <MetalKit/MetalKit.h>
6
-
7
- #pragma clang diagnostic push
8
- #pragma clang diagnostic ignored "-Wdocumentation"
9
-
10
- #import <include/gpu/ganesh/GrBackendSurface.h>
11
- #import <include/gpu/ganesh/SkImageGanesh.h>
12
- #import <include/gpu/ganesh/mtl/GrMtlBackendContext.h>
13
- #import <include/gpu/ganesh/mtl/GrMtlBackendSurface.h>
14
- #import <include/gpu/ganesh/mtl/GrMtlDirectContext.h>
15
- #import <include/gpu/ganesh/mtl/GrMtlTypes.h>
16
- #import <include/gpu/ganesh/mtl/SkSurfaceMetal.h>
17
-
18
- #pragma clang diagnostic pop
19
-
20
- MetalContext::MetalContext() {
21
- _device = MTLCreateSystemDefaultDevice();
22
- if (!_device) {
23
- throw std::runtime_error("Failed to create Metal device");
24
- }
25
-
26
- _commandQueue =
27
- id<MTLCommandQueue>(CFRetain((GrMTLHandle)[_device newCommandQueue]));
28
- GrMtlBackendContext backendContext = {};
29
- backendContext.fDevice.reset((__bridge void *)_device);
30
- backendContext.fQueue.reset((__bridge void *)_commandQueue);
31
- GrContextOptions grContextOptions; // set different options here.
32
-
33
- // Create the Skia Direct Context
34
- _directContext = GrDirectContexts::MakeMetal(backendContext, grContextOptions);
35
- if (_directContext == nullptr) {
36
- RNSkia::RNSkLogger::logToConsole("Couldn't create a Skia Metal Context");
37
- }
38
- }
@@ -1,42 +0,0 @@
1
- #pragma once
2
-
3
- #import <MetalKit/MetalKit.h>
4
-
5
- #include "RNWindowContext.h"
6
-
7
- class SkiaMetalContext;
8
-
9
- class MetalWindowContext : public RNSkia::WindowContext {
10
- public:
11
- MetalWindowContext(GrDirectContext *directContext, id<MTLDevice> device,
12
- id<MTLCommandQueue> commandQueue, CALayer *layer,
13
- int width, int height, bool useP3ColorSpace = true,
14
- bool highBitDepth = false);
15
- ~MetalWindowContext() = default;
16
-
17
- sk_sp<SkSurface> getSurface() override;
18
-
19
- void present() override;
20
-
21
- int getWidth() override {
22
- return _layer.frame.size.width * _layer.contentsScale;
23
- };
24
-
25
- int getHeight() override {
26
- return _layer.frame.size.height * _layer.contentsScale;
27
- };
28
-
29
- void resize(int width, int height) override { _skSurface = nullptr; }
30
-
31
- private:
32
- GrDirectContext *_directContext;
33
- id<MTLCommandQueue> _commandQueue;
34
- sk_sp<SkSurface> _skSurface = nullptr;
35
- #pragma clang diagnostic push
36
- #pragma clang diagnostic ignored "-Wunguarded-availability-new"
37
- CAMetalLayer *_layer;
38
- #pragma clang diagnostic pop
39
- id<CAMetalDrawable> _currentDrawable = nil;
40
- bool _useP3ColorSpace = false;
41
- bool _highBitDepth = false;
42
- };
@@ -1,95 +0,0 @@
1
- #include "MetalWindowContext.h"
2
-
3
- #include "MetalContext.h"
4
- #include "MetalLayerColorSpaceUtils.h"
5
- #include "RNSkLog.h"
6
- #include "include/core/SkColorSpace.h"
7
-
8
- MetalWindowContext::MetalWindowContext(GrDirectContext *directContext,
9
- id<MTLDevice> device,
10
- id<MTLCommandQueue> commandQueue,
11
- CALayer *layer, int width, int height,
12
- bool useP3ColorSpace, bool highBitDepth)
13
- : _directContext(directContext), _commandQueue(commandQueue),
14
- _highBitDepth(highBitDepth) {
15
- #pragma clang diagnostic push
16
- #pragma clang diagnostic ignored "-Wunguarded-availability-new"
17
- _layer = (CAMetalLayer *)layer;
18
- #pragma clang diagnostic pop
19
- _layer.framebufferOnly = NO;
20
- _layer.device = device;
21
- _layer.opaque = false;
22
- #if !TARGET_OS_OSX
23
- _layer.contentsScale = [UIScreen mainScreen].scale;
24
- #else
25
- _layer.contentsScale = [NSScreen mainScreen].backingScaleFactor;
26
- #endif // !TARGET_OS_OSX
27
- _layer.pixelFormat =
28
- _highBitDepth ? MTLPixelFormatRGBA16Float : MTLPixelFormatBGRA8Unorm;
29
- _layer.contentsGravity = kCAGravityBottomLeft;
30
- _layer.drawableSize = CGSizeMake(width, height);
31
- BOOL supportsWideColor = NO;
32
- if (useP3ColorSpace) {
33
- #if !TARGET_OS_OSX
34
- if (@available(iOS 10.0, *)) {
35
- supportsWideColor = [UIScreen mainScreen].traitCollection.displayGamut ==
36
- UIDisplayGamutP3;
37
- }
38
- #else
39
- if (@available(macOS 10.12, *)) {
40
- NSScreen *screen = [NSScreen mainScreen];
41
- NSColorSpace *displayP3 = [NSColorSpace displayP3ColorSpace];
42
- if (screen.colorSpace && displayP3) {
43
- supportsWideColor = [screen.colorSpace isEqual:displayP3];
44
- }
45
- }
46
- #endif // !TARGET_OS_OSX
47
- }
48
- if (supportsWideColor) {
49
- _useP3ColorSpace = true;
50
- }
51
- RNSkia::setCAMetalLayerColorSpace(_layer, _highBitDepth, _useP3ColorSpace);
52
- }
53
-
54
- sk_sp<SkSurface> MetalWindowContext::getSurface() {
55
- if (_skSurface) {
56
- return _skSurface;
57
- }
58
-
59
- // Get the next drawable from the CAMetalLayer
60
- _currentDrawable = [_layer nextDrawable];
61
- if (!_currentDrawable) {
62
- RNSkia::RNSkLogger::logToConsole(
63
- "Could not retrieve drawable from CAMetalLayer");
64
- return nullptr;
65
- }
66
-
67
- // Get the texture from the drawable
68
- GrMtlTextureInfo fbInfo;
69
- fbInfo.fTexture.retain((__bridge void *)_currentDrawable.texture);
70
-
71
- GrBackendRenderTarget backendRT = GrBackendRenderTargets::MakeMtl(
72
- _layer.drawableSize.width, _layer.drawableSize.height, fbInfo);
73
-
74
- sk_sp<SkColorSpace> skColorSpace =
75
- _useP3ColorSpace ? SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
76
- SkNamedGamut::kDisplayP3)
77
- : nullptr;
78
- _skSurface = SkSurfaces::WrapBackendRenderTarget(
79
- _directContext, backendRT, kTopLeft_GrSurfaceOrigin,
80
- _highBitDepth ? kRGBA_F16_SkColorType : kBGRA_8888_SkColorType,
81
- skColorSpace, nullptr);
82
-
83
- return _skSurface;
84
- }
85
-
86
- void MetalWindowContext::present() {
87
- if (auto dContext = GrAsDirectContext(_skSurface->recordingContext())) {
88
- dContext->flushAndSubmit();
89
- }
90
-
91
- id<MTLCommandBuffer> commandBuffer([_commandQueue commandBuffer]);
92
- [commandBuffer presentDrawable:_currentDrawable];
93
- [commandBuffer commit];
94
- _skSurface = nullptr;
95
- }
@@ -1,49 +0,0 @@
1
- #pragma once
2
-
3
- #import <memory>
4
-
5
- #import "RNSkApplePlatformContext.h"
6
- #import "RNSkMetalCanvasProvider.h"
7
- #import "RNSkView.h"
8
-
9
- class RNSkBaseAppleView {
10
- public:
11
- virtual CALayer *getLayer() = 0;
12
- virtual void setSize(int width, int height) = 0;
13
- virtual void setUseP3ColorSpace(bool useP3ColorSpace) = 0;
14
- virtual void setHighBitDepth(bool highBitDepth) = 0;
15
- virtual std::shared_ptr<RNSkia::RNSkView> getDrawView() = 0;
16
- };
17
-
18
- template <class T> class RNSkAppleView : public RNSkBaseAppleView, public T {
19
- public:
20
- RNSkAppleView(std::shared_ptr<RNSkia::RNSkPlatformContext> context)
21
- : T(context, std::make_shared<RNSkMetalCanvasProvider>(
22
- std::bind(&RNSkia::RNSkView::requestRedraw, this),
23
- context, true)) {}
24
-
25
- CALayer *getLayer() override {
26
- return std::static_pointer_cast<RNSkMetalCanvasProvider>(
27
- this->getCanvasProvider())
28
- ->getLayer();
29
- }
30
-
31
- void setSize(int width, int height) override {
32
- std::static_pointer_cast<RNSkMetalCanvasProvider>(this->getCanvasProvider())
33
- ->setSize(width, height);
34
- }
35
-
36
- void setUseP3ColorSpace(bool useP3ColorSpace) override {
37
- std::static_pointer_cast<RNSkMetalCanvasProvider>(this->getCanvasProvider())
38
- ->setUseP3ColorSpace(useP3ColorSpace);
39
- }
40
-
41
- void setHighBitDepth(bool highBitDepth) override {
42
- std::static_pointer_cast<RNSkMetalCanvasProvider>(this->getCanvasProvider())
43
- ->setHighBitDepth(highBitDepth);
44
- }
45
-
46
- std::shared_ptr<RNSkia::RNSkView> getDrawView() override {
47
- return this->shared_from_this();
48
- }
49
- };
@@ -1,35 +0,0 @@
1
- #import <memory>
2
-
3
- #import "RNSkApplePlatformContext.h"
4
- #import "RNSkMetalCanvasProvider.h"
5
- #import "RNSkView.h"
6
-
7
- class RNSkBaseAppleView {
8
- public:
9
- virtual CALayer *getLayer() = 0;
10
- virtual void setSize(int width, int height) = 0;
11
- virtual std::shared_ptr<RNSkia::RNSkView> getDrawView() = 0;
12
- };
13
-
14
- template <class T> class RNSkAppleView : public RNSkBaseAppleView, public T {
15
- public:
16
- RNSkAppleView(std::shared_ptr<RNSkia::RNSkPlatformContext> context)
17
- : T(context,
18
- std::make_shared<RNSkMetalCanvasProvider>(
19
- std::bind(&RNSkia::RNSkView::requestRedraw, this), context)) {}
20
-
21
- CALayer *getLayer() override {
22
- return std::static_pointer_cast<RNSkMetalCanvasProvider>(
23
- this->getCanvasProvider())
24
- ->getLayer();
25
- }
26
-
27
- void setSize(int width, int height) override {
28
- std::static_pointer_cast<RNSkMetalCanvasProvider>(this->getCanvasProvider())
29
- ->setSize(width, height);
30
- }
31
-
32
- std::shared_ptr<RNSkia::RNSkView> getDrawView() override {
33
- return this->shared_from_this();
34
- }
35
- };
@@ -1,122 +0,0 @@
1
- //
2
- // SkiaCVPixelBufferUtils.h
3
- // react-native-skia
4
- //
5
- // Created by Marc Rousavy on 10.04.24.
6
- //
7
-
8
- #pragma once
9
-
10
- #import <vector>
11
-
12
- #import <CoreVideo/CVMetalTextureCache.h>
13
- #import <CoreVideo/CVPixelBuffer.h>
14
- #import <MetalKit/MetalKit.h>
15
-
16
- #pragma clang diagnostic push
17
- #pragma clang diagnostic ignored "-Wdocumentation"
18
- #import "include/core/SkColorSpace.h"
19
- #import "include/core/SkImage.h"
20
- #import "include/gpu/ganesh/GrBackendSurface.h"
21
- #import "include/gpu/ganesh/GrYUVABackendTextures.h"
22
- #pragma clang diagnostic pop
23
-
24
- /**
25
- Holds a Metal Texture.
26
- When the `TextureHolder` is destroyed, the underlying Metal Texture
27
- is marked as invalid and might be overwritten by the Texture Cache,
28
- so make sure to delete the `TextureHolder` only when the `SkImage`
29
- has been deleted.
30
-
31
- For example, use the `releaseProc` parameter in `BorrowImageFromTexture`
32
- to delete the `TextureHolder`.
33
- */
34
- class TextureHolder {
35
- public:
36
- /**
37
- Create a new instance of TextureHolder which holds
38
- the given `CVMetalTextureRef`.
39
-
40
- The given `CVMetalTextureRef` is assumed to already be
41
- retained with `CFRetain`, and will later be manually
42
- released with `CFRelease`.
43
- */
44
- TextureHolder(CVMetalTextureRef texture);
45
- ~TextureHolder();
46
-
47
- /**
48
- Converts this Texture to a Skia GrBackendTexture.
49
- */
50
- GrBackendTexture toGrBackendTexture();
51
-
52
- private:
53
- CVMetalTextureRef _texture;
54
- };
55
-
56
- /**
57
- Same as `TextureHolder`, but for multiple planar textures (e.g. YUVA)
58
- */
59
- class MultiTexturesHolder {
60
- public:
61
- ~MultiTexturesHolder();
62
- void addTexture(TextureHolder *texture);
63
-
64
- private:
65
- std::vector<TextureHolder *> _textures;
66
- };
67
-
68
- class SkiaCVPixelBufferUtils {
69
- public:
70
- enum class CVPixelBufferBaseFormat { rgb, yuv };
71
-
72
- /**
73
- Get the base format (currently only RGB) of the PixelBuffer.
74
- Depending on the base-format, different methods have to be used to create
75
- Skia buffers.
76
- */
77
- static CVPixelBufferBaseFormat
78
- getCVPixelBufferBaseFormat(CVPixelBufferRef pixelBuffer);
79
-
80
- class RGB {
81
- public:
82
- /**
83
- Creates a GPU-backed Skia Texture (SkImage) with the given RGB
84
- CVPixelBuffer.
85
- */
86
- static sk_sp<SkImage>
87
- makeSkImageFromCVPixelBuffer(id<MTLDevice> device, GrDirectContext *context,
88
- CVPixelBufferRef pixelBuffer);
89
-
90
- private:
91
- static SkColorType getCVPixelBufferColorType(CVPixelBufferRef pixelBuffer);
92
- };
93
-
94
- class YUV {
95
- public:
96
- /**
97
- Creates a GPU-backed Skia Texture (SkImage) with the given YUV
98
- CVPixelBuffer.
99
- */
100
- static sk_sp<SkImage>
101
- makeSkImageFromCVPixelBuffer(id<MTLDevice> device, GrDirectContext *context,
102
- CVPixelBufferRef pixelBuffer);
103
-
104
- private:
105
- static SkYUVAInfo::PlaneConfig getPlaneConfig(OSType pixelFormat);
106
- static SkYUVAInfo::Subsampling getSubsampling(OSType pixelFormat);
107
- static SkYUVColorSpace getColorspace(CVPixelBufferRef pixelBuffer);
108
- static bool isFullRangeYUVFormat(OSType pixelFormat);
109
- static bool isTenBitYUVFormat(OSType pixelFormat);
110
- static SkYUVColorSpace getSkYUVColorSpaceFromMatrix(CFStringRef matrix,
111
- OSType pixelFormat);
112
- static SkYUVAInfo getYUVAInfoForCVPixelBuffer(CVPixelBufferRef pixelBuffer);
113
- };
114
-
115
- private:
116
- static CVMetalTextureCacheRef getTextureCache(id<MTLDevice> device);
117
- static TextureHolder *getSkiaTextureForCVPixelBufferPlane(
118
- id<MTLDevice> device, CVPixelBufferRef pixelBuffer, size_t planeIndex);
119
- static MTLPixelFormat
120
- getMTLPixelFormatForCVPixelBufferPlane(CVPixelBufferRef pixelBuffer,
121
- size_t planeIndex);
122
- };