react-native-skia 3.0.4 → 3.0.5

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 (204) hide show
  1. package/android/CMakeLists.txt +0 -2
  2. package/android/cpp/jni/JniPlatformContext.cpp +0 -24
  3. package/android/cpp/jni/include/JniPlatformContext.h +0 -2
  4. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -140
  5. package/android/src/main/java/com/reactnative/skia/PlatformContext.java +0 -5
  6. package/apple/RNSkApplePlatformContext.h +0 -10
  7. package/apple/RNSkApplePlatformContext.mm +0 -182
  8. package/cpp/api/JsiGPUTexture.h +48 -0
  9. package/cpp/api/JsiSkApi.h +1 -16
  10. package/cpp/api/JsiSkImage.h +0 -12
  11. package/cpp/api/JsiSkImageFactory.h +36 -57
  12. package/cpp/api/JsiSkSurface.h +3 -10
  13. package/cpp/api/JsiSkSurfaceFactory.h +13 -18
  14. package/cpp/rnskia/RNDawnContext.h +5 -113
  15. package/cpp/rnskia/RNDawnUtils.h +33 -0
  16. package/cpp/rnskia/RNSkPlatformContext.h +0 -54
  17. package/lib/commonjs/external/reanimated/index.d.ts +0 -1
  18. package/lib/commonjs/external/reanimated/index.js +0 -11
  19. package/lib/commonjs/external/reanimated/index.js.map +1 -1
  20. package/lib/commonjs/mock/index.js +1 -2
  21. package/lib/commonjs/mock/index.js.map +1 -1
  22. package/lib/commonjs/skia/types/GPUTexture.d.ts +11 -0
  23. package/lib/commonjs/skia/types/GPUTexture.js +2 -0
  24. package/lib/commonjs/skia/types/GPUTexture.js.map +1 -0
  25. package/lib/commonjs/skia/types/Image/Image.d.ts +0 -10
  26. package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
  27. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +25 -48
  28. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  29. package/lib/commonjs/skia/types/Skia.d.ts +0 -4
  30. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  31. package/lib/commonjs/skia/types/Surface/Surface.d.ts +3 -14
  32. package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
  33. package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +10 -9
  34. package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
  35. package/lib/commonjs/skia/types/index.d.ts +1 -2
  36. package/lib/commonjs/skia/types/index.js +11 -22
  37. package/lib/commonjs/skia/types/index.js.map +1 -1
  38. package/lib/commonjs/skia/web/JsiSkImage.d.ts +0 -1
  39. package/lib/commonjs/skia/web/JsiSkImage.js +0 -4
  40. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  41. package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +4 -5
  42. package/lib/commonjs/skia/web/JsiSkImageFactory.js +6 -10
  43. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  44. package/lib/commonjs/skia/web/JsiSkSurface.d.ts +0 -1
  45. package/lib/commonjs/skia/web/JsiSkSurface.js +0 -4
  46. package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
  47. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.d.ts +2 -2
  48. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +1 -1
  49. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  50. package/lib/commonjs/skia/web/JsiSkia.js +0 -4
  51. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  52. package/lib/module/external/reanimated/index.d.ts +0 -1
  53. package/lib/module/external/reanimated/index.js +0 -1
  54. package/lib/module/external/reanimated/index.js.map +1 -1
  55. package/lib/module/mock/index.js +1 -2
  56. package/lib/module/mock/index.js.map +1 -1
  57. package/lib/module/skia/types/GPUTexture.d.ts +11 -0
  58. package/lib/module/skia/types/GPUTexture.js +2 -0
  59. package/lib/module/skia/types/GPUTexture.js.map +1 -0
  60. package/lib/module/skia/types/Image/Image.d.ts +0 -10
  61. package/lib/module/skia/types/Image/Image.js.map +1 -1
  62. package/lib/module/skia/types/Image/ImageFactory.d.ts +25 -48
  63. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  64. package/lib/module/skia/types/Skia.d.ts +0 -4
  65. package/lib/module/skia/types/Skia.js.map +1 -1
  66. package/lib/module/skia/types/Surface/Surface.d.ts +3 -14
  67. package/lib/module/skia/types/Surface/Surface.js.map +1 -1
  68. package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +10 -9
  69. package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
  70. package/lib/module/skia/types/index.d.ts +1 -2
  71. package/lib/module/skia/types/index.js +1 -2
  72. package/lib/module/skia/types/index.js.map +1 -1
  73. package/lib/module/skia/web/JsiSkImage.d.ts +0 -1
  74. package/lib/module/skia/web/JsiSkImage.js +0 -4
  75. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  76. package/lib/module/skia/web/JsiSkImageFactory.d.ts +4 -5
  77. package/lib/module/skia/web/JsiSkImageFactory.js +6 -10
  78. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  79. package/lib/module/skia/web/JsiSkSurface.d.ts +0 -1
  80. package/lib/module/skia/web/JsiSkSurface.js +0 -4
  81. package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
  82. package/lib/module/skia/web/JsiSkSurfaceFactory.d.ts +2 -2
  83. package/lib/module/skia/web/JsiSkSurfaceFactory.js +1 -1
  84. package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  85. package/lib/module/skia/web/JsiSkia.js +0 -4
  86. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  87. package/lib/typescript/src/external/reanimated/index.d.ts +0 -1
  88. package/lib/typescript/src/skia/types/GPUTexture.d.ts +11 -0
  89. package/lib/typescript/src/skia/types/Image/Image.d.ts +0 -10
  90. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +25 -48
  91. package/lib/typescript/src/skia/types/Skia.d.ts +0 -4
  92. package/lib/typescript/src/skia/types/Surface/Surface.d.ts +3 -14
  93. package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +10 -9
  94. package/lib/typescript/src/skia/types/index.d.ts +1 -2
  95. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +0 -1
  96. package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +4 -5
  97. package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +0 -1
  98. package/lib/typescript/src/skia/web/JsiSkSurfaceFactory.d.ts +2 -2
  99. package/package.json +1 -1
  100. package/src/external/reanimated/index.ts +0 -1
  101. package/src/mock/index.ts +0 -1
  102. package/src/skia/types/GPUTexture.ts +9 -0
  103. package/src/skia/types/Image/Image.ts +0 -11
  104. package/src/skia/types/Image/ImageFactory.ts +25 -55
  105. package/src/skia/types/Skia.ts +0 -4
  106. package/src/skia/types/Surface/Surface.ts +3 -15
  107. package/src/skia/types/Surface/SurfaceFactory.ts +11 -9
  108. package/src/skia/types/index.ts +1 -2
  109. package/src/skia/web/JsiSkImage.ts +0 -5
  110. package/src/skia/web/JsiSkImageFactory.ts +16 -16
  111. package/src/skia/web/JsiSkSurface.ts +0 -5
  112. package/src/skia/web/JsiSkSurfaceFactory.ts +2 -2
  113. package/src/skia/web/JsiSkia.ts +0 -4
  114. package/android/cpp/rnskia-android/AHardwareBufferUtils.cpp +0 -31
  115. package/android/cpp/rnskia-android/AHardwareBufferUtils.h +0 -13
  116. package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -200
  117. package/android/cpp/rnskia-android/RNSkAndroidVideo.h +0 -44
  118. package/android/src/main/java/com/reactnative/skia/RNSkVideo.java +0 -320
  119. package/apple/RNSkAppleVideo.h +0 -78
  120. package/apple/RNSkAppleVideo.mm +0 -292
  121. package/cpp/api/JsiNativeBuffer.h +0 -56
  122. package/cpp/api/JsiTextureInfo.h +0 -53
  123. package/cpp/api/JsiVideo.h +0 -101
  124. package/cpp/rnskia/RNSkVideo.h +0 -31
  125. package/lib/commonjs/external/reanimated/useVideo.d.ts +0 -21
  126. package/lib/commonjs/external/reanimated/useVideo.js +0 -150
  127. package/lib/commonjs/external/reanimated/useVideo.js.map +0 -1
  128. package/lib/commonjs/external/reanimated/useVideoLoading.d.ts +0 -4
  129. package/lib/commonjs/external/reanimated/useVideoLoading.js +0 -40
  130. package/lib/commonjs/external/reanimated/useVideoLoading.js.map +0 -1
  131. package/lib/commonjs/external/reanimated/useVideoLoading.web.d.ts +0 -4
  132. package/lib/commonjs/external/reanimated/useVideoLoading.web.js +0 -20
  133. package/lib/commonjs/external/reanimated/useVideoLoading.web.js.map +0 -1
  134. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +0 -29
  135. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js +0 -15
  136. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +0 -1
  137. package/lib/commonjs/skia/types/NativeBuffer/index.d.ts +0 -1
  138. package/lib/commonjs/skia/types/NativeBuffer/index.js +0 -17
  139. package/lib/commonjs/skia/types/NativeBuffer/index.js.map +0 -1
  140. package/lib/commonjs/skia/types/Video/Video.d.ts +0 -20
  141. package/lib/commonjs/skia/types/Video/Video.js +0 -6
  142. package/lib/commonjs/skia/types/Video/Video.js.map +0 -1
  143. package/lib/commonjs/skia/types/Video/index.d.ts +0 -1
  144. package/lib/commonjs/skia/types/Video/index.js +0 -17
  145. package/lib/commonjs/skia/types/Video/index.js.map +0 -1
  146. package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.d.ts +0 -9
  147. package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.js +0 -30
  148. package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.js.map +0 -1
  149. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +0 -9
  150. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js +0 -48
  151. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js.map +0 -1
  152. package/lib/commonjs/skia/web/JsiVideo.d.ts +0 -28
  153. package/lib/commonjs/skia/web/JsiVideo.js +0 -96
  154. package/lib/commonjs/skia/web/JsiVideo.js.map +0 -1
  155. package/lib/module/external/reanimated/useVideo.d.ts +0 -21
  156. package/lib/module/external/reanimated/useVideo.js +0 -142
  157. package/lib/module/external/reanimated/useVideo.js.map +0 -1
  158. package/lib/module/external/reanimated/useVideoLoading.d.ts +0 -4
  159. package/lib/module/external/reanimated/useVideoLoading.js +0 -33
  160. package/lib/module/external/reanimated/useVideoLoading.js.map +0 -1
  161. package/lib/module/external/reanimated/useVideoLoading.web.d.ts +0 -4
  162. package/lib/module/external/reanimated/useVideoLoading.web.js +0 -13
  163. package/lib/module/external/reanimated/useVideoLoading.web.js.map +0 -1
  164. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +0 -29
  165. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js +0 -5
  166. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +0 -1
  167. package/lib/module/skia/types/NativeBuffer/index.d.ts +0 -1
  168. package/lib/module/skia/types/NativeBuffer/index.js +0 -2
  169. package/lib/module/skia/types/NativeBuffer/index.js.map +0 -1
  170. package/lib/module/skia/types/Video/Video.d.ts +0 -20
  171. package/lib/module/skia/types/Video/Video.js +0 -2
  172. package/lib/module/skia/types/Video/Video.js.map +0 -1
  173. package/lib/module/skia/types/Video/index.d.ts +0 -1
  174. package/lib/module/skia/types/Video/index.js +0 -2
  175. package/lib/module/skia/types/Video/index.js.map +0 -1
  176. package/lib/module/skia/web/CanvasKitWebGLBufferImpl.d.ts +0 -9
  177. package/lib/module/skia/web/CanvasKitWebGLBufferImpl.js +0 -23
  178. package/lib/module/skia/web/CanvasKitWebGLBufferImpl.js.map +0 -1
  179. package/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +0 -9
  180. package/lib/module/skia/web/JsiSkNativeBufferFactory.js +0 -41
  181. package/lib/module/skia/web/JsiSkNativeBufferFactory.js.map +0 -1
  182. package/lib/module/skia/web/JsiVideo.d.ts +0 -28
  183. package/lib/module/skia/web/JsiVideo.js +0 -88
  184. package/lib/module/skia/web/JsiVideo.js.map +0 -1
  185. package/lib/typescript/src/external/reanimated/useVideo.d.ts +0 -21
  186. package/lib/typescript/src/external/reanimated/useVideoLoading.d.ts +0 -4
  187. package/lib/typescript/src/external/reanimated/useVideoLoading.web.d.ts +0 -4
  188. package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +0 -29
  189. package/lib/typescript/src/skia/types/NativeBuffer/index.d.ts +0 -1
  190. package/lib/typescript/src/skia/types/Video/Video.d.ts +0 -20
  191. package/lib/typescript/src/skia/types/Video/index.d.ts +0 -1
  192. package/lib/typescript/src/skia/web/CanvasKitWebGLBufferImpl.d.ts +0 -9
  193. package/lib/typescript/src/skia/web/JsiSkNativeBufferFactory.d.ts +0 -9
  194. package/lib/typescript/src/skia/web/JsiVideo.d.ts +0 -28
  195. package/src/external/reanimated/useVideo.ts +0 -161
  196. package/src/external/reanimated/useVideoLoading.ts +0 -39
  197. package/src/external/reanimated/useVideoLoading.web.ts +0 -17
  198. package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +0 -52
  199. package/src/skia/types/NativeBuffer/index.ts +0 -1
  200. package/src/skia/types/Video/Video.ts +0 -19
  201. package/src/skia/types/Video/index.ts +0 -1
  202. package/src/skia/web/CanvasKitWebGLBufferImpl.ts +0 -25
  203. package/src/skia/web/JsiSkNativeBufferFactory.ts +0 -51
  204. package/src/skia/web/JsiVideo.ts +0 -113
@@ -12,17 +12,6 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
12
12
  example: https://fiddle.skia.org/c/@Surface_getCanvas
13
13
  */
14
14
  getCanvas(): SkCanvas;
15
- /**
16
- * Returns the backend texture of the surface.
17
- * The returned object can be used to create a Skia Image object.
18
- * The returned object is backend specific and should be used with caution.
19
- * It is the caller's responsibility to ensure that the texture is not used after the surface is deleted
20
- * or draw operations are performed on the surface.
21
- * The returned object may be null if the surface does not have a backend texture.
22
- *
23
- * @return backend texture of the surface or null
24
- */
25
- getNativeTextureUnstable(): unknown;
26
15
  /** Returns Image capturing Surface contents. Subsequent drawing to
27
16
  Surface contents are not captured.
28
17
 
@@ -36,9 +25,9 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
36
25
  /**
37
26
  * Make sure any queued draws are sent to the screen or the GPU.
38
27
  * @param sync - When true, block until the GPU has finished executing the
39
- * submitted work. Use this before reading the surface's texture from a native
40
- * consumer on a different command queue (see {@link getNativeTextureUnstable}).
41
- * Defaults to false.
28
+ * submitted work. Use this before a consumer on a different command queue
29
+ * reads the texture this surface draws into (see
30
+ * `Skia.Surface.MakeFromGPUTexture`). Defaults to false.
42
31
  */
43
32
  flush(sync?: boolean): void;
44
33
  /**
@@ -1,3 +1,4 @@
1
+ import type { GPUTextureHandle } from "../GPUTexture";
1
2
  import type { SkSurface } from "./Surface";
2
3
  export declare const ColorSpace: {
3
4
  readonly SRGB: "srgb";
@@ -25,18 +26,18 @@ export interface SurfaceFactory {
25
26
  MakeOffscreen: (width: number, height: number, opts?: SurfaceOptions) => SkSurface | null;
26
27
  /**
27
28
  * Creates a GPU backed surface that draws directly into a WebGPU texture
28
- * (zero-copy). The texture must be created on Skia's device
29
- * (importDevice(Skia.getNativeDevice())) with RENDER_ATTACHMENT usage; add
30
- * TEXTURE_BINDING to sample what Skia drew from WebGPU after each flush().
31
- * The surface holds its own reference to the texture and keeps it alive
32
- * for its lifetime, so the caller may release the GPUTexture once the
33
- * surface exists. Calling destroy() on the GPUTexture still invalidates
34
- * the surface.
29
+ * (zero-copy). The texture must be created with React Native WebGPU on
30
+ * the shared device (importDevice(Skia.getNativeDevice())) with the
31
+ * RENDER_ATTACHMENT usage; add TEXTURE_BINDING to sample what Skia drew
32
+ * from WebGPU after each flush(). The surface holds its own reference to
33
+ * the texture and keeps it alive for its lifetime, so the caller may
34
+ * release the GPUTexture once the surface exists. Calling destroy() on the
35
+ * GPUTexture still invalidates the surface.
35
36
  *
36
37
  * Native only.
37
38
  *
38
- * @param pointer - The WGPUTexture pointer (texture.nativePointer)
39
+ * @param texture - The GPUTexture (see {@link GPUTextureHandle})
39
40
  * @returns An SkSurface rendering into the texture, or throws if the texture is invalid
40
41
  */
41
- MakeFromNativeTexture: (pointer: bigint) => SkSurface;
42
+ MakeFromGPUTexture: (texture: GPUTextureHandle) => SkSurface;
42
43
  }
@@ -29,8 +29,7 @@ export * from "./TextBlob";
29
29
  export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
- export * from "./NativeBuffer";
33
32
  export * from "./Recorder";
34
- export * from "./Video";
35
33
  export * from "./Skottie";
36
34
  export * from "./Graphite";
35
+ export * from "./GPUTexture";
@@ -13,5 +13,4 @@ export declare class JsiSkImage extends HostObject<Image, "Image"> implements Sk
13
13
  encodeToBase64(fmt?: ImageFormat, quality?: number): string;
14
14
  readPixels(srcX?: number, srcY?: number, imageInfo?: ImageInfo): Float32Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | null;
15
15
  makeNonTextureImage(): SkImage;
16
- getNativeTextureUnstable(): unknown;
17
16
  }
@@ -1,5 +1,5 @@
1
1
  import type { CanvasKit } from "canvaskit-wasm";
2
- import type { SkData, ImageInfo, SkImage, NativeBuffer, ImageFactory } from "../types";
2
+ import type { SkData, ImageInfo, SkImage, ImageFactory, GPUTextureHandle } from "../types";
3
3
  import { Host } from "./Host";
4
4
  import { JsiSkImage } from "./JsiSkImage";
5
5
  import type { JsiSkSurface } from "./JsiSkSurface";
@@ -7,10 +7,9 @@ export declare class JsiSkImageFactory extends Host implements ImageFactory {
7
7
  constructor(CanvasKit: CanvasKit);
8
8
  MakeNull(): JsiSkImage;
9
9
  MakeImageFromViewTag(viewTag: number): Promise<SkImage | null>;
10
- MakeImageFromNativeBuffer(buffer: NativeBuffer, surface?: JsiSkSurface, image?: JsiSkImage): JsiSkImage;
10
+ MakeImageFromNativeBuffer(buffer: CanvasImageSource, surface?: JsiSkSurface, image?: JsiSkImage): JsiSkImage;
11
11
  MakeImageFromEncoded(encoded: SkData): JsiSkImage | null;
12
- MakeImageFromNativeTextureUnstable(): SkImage;
13
12
  MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): JsiSkImage | null;
14
- MakeImageFromNativeTexture(_pointer: bigint): SkImage;
15
- MakeNativeTextureFromImage(_image: SkImage): bigint;
13
+ MakeImageFromGPUTexture(_texture: GPUTextureHandle): SkImage;
14
+ MakeGPUTextureFromImage(_image: SkImage): bigint;
16
15
  }
@@ -10,5 +10,4 @@ export declare class JsiSkSurface extends HostObject<Surface, "Surface"> impleme
10
10
  height(): number;
11
11
  getCanvas(): SkCanvas;
12
12
  makeImageSnapshot(bounds?: SkRect, outputImage?: JsiSkImage): SkImage;
13
- getNativeTextureUnstable(): unknown;
14
13
  }
@@ -1,10 +1,10 @@
1
1
  import type { CanvasKit } from "canvaskit-wasm";
2
- import type { SkSurface, SurfaceFactory } from "../types";
2
+ import type { GPUTextureHandle, SkSurface, SurfaceFactory } from "../types";
3
3
  import { Host } from "./Host";
4
4
  import { JsiSkSurface } from "./JsiSkSurface";
5
5
  export declare class JsiSkSurfaceFactory extends Host implements SurfaceFactory {
6
6
  constructor(CanvasKit: CanvasKit);
7
7
  Make(width: number, height: number): JsiSkSurface;
8
8
  MakeOffscreen(width: number, height: number): JsiSkSurface | null;
9
- MakeFromNativeTexture(_pointer: bigint): SkSurface;
9
+ MakeFromGPUTexture(_texture: GPUTextureHandle): SkSurface;
10
10
  }
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "setup-skia-web": "scripts/setup-canvaskit.js"
9
9
  },
10
10
  "title": "React Native Skia",
11
- "version": "3.0.4",
11
+ "version": "3.0.5",
12
12
  "description": "High-performance React Native Graphics using Skia",
13
13
  "main": "lib/module/index.js",
14
14
  "react-native": "src/index.ts",
@@ -3,4 +3,3 @@ export * from "./renderHelpers";
3
3
  export * from "./interpolators";
4
4
  export * from "./textures";
5
5
  export * from "./buffers";
6
- export * from "./useVideo";
package/src/mock/index.ts CHANGED
@@ -67,6 +67,5 @@ export const Mock = (CanvasKit: CanvasKit) => {
67
67
  useTypeface: () => null,
68
68
  useImage: () => null,
69
69
  useSVG: () => null,
70
- useVideo: () => null,
71
70
  };
72
71
  };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * A WebGPU texture, as accepted by `Skia.Image.MakeImageFromGPUTexture` and
3
+ * `Skia.Surface.MakeFromGPUTexture`: a `GPUTexture` created with React Native
4
+ * WebGPU on the shared device, whose `nativePointer` (a non-spec extension)
5
+ * holds the `WGPUTexture` handle. The handle itself, as a `BigInt`, is
6
+ * accepted too for libraries that export textures without React Native
7
+ * WebGPU.
8
+ */
9
+ export type GPUTextureHandle = { readonly nativePointer: bigint } | bigint;
@@ -62,17 +62,6 @@ export interface SkImage extends SkJSIInstance<"Image"> {
62
62
  */
63
63
  getImageInfo(): ImageInfo;
64
64
 
65
- /**
66
- * Returns the backend texture of the image.
67
- * The returned object can be used to create a Skia Image object.
68
- * The returned object is backend specific and should be used with caution.
69
- * It is the caller's responsibility to ensure that the texture is not used after the image is deleted.
70
- * The returned object may be null if the image does not have a backend texture.
71
- *
72
- * @return backend texture of the image or null
73
- */
74
- getNativeTextureUnstable(): unknown;
75
-
76
65
  /**
77
66
  * Returns this image as a shader with the specified tiling. It will use cubic sampling.
78
67
  * @param tx - tile mode in the x direction.
@@ -1,5 +1,5 @@
1
1
  import type { SkData } from "../Data";
2
- import type { NativeBuffer } from "../NativeBuffer";
2
+ import type { GPUTextureHandle } from "../GPUTexture";
3
3
 
4
4
  import type { ColorType } from "./ColorType";
5
5
  import type { SkImage } from "./Image";
@@ -35,45 +35,17 @@ export interface ImageFactory {
35
35
  MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
36
36
 
37
37
  /**
38
- * Return an Image backed by a given native buffer.
39
- * The native buffer must be a valid owning reference.
38
+ * Web only. Creates an image from a `CanvasImageSource`: an
39
+ * `HTMLVideoElement`, an `ImageBitmap`, a canvas, an `HTMLImageElement`...
40
40
  *
41
- * For instance, this API is used by
42
- * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
43
- * to render a Skia Camera preview.
41
+ * On native platforms, camera and video frames are rendered into a texture
42
+ * of the shared device by React Native WebGPU
43
+ * (`queue.copyExternalImageToTexture()`), and the texture is wrapped with
44
+ * {@link MakeImageFromGPUTexture}. Calling this method there throws.
44
45
  *
45
- * - On Android; This is an `AHardwareBuffer*`
46
- * - On iOS, this is a `CVPixelBufferRef`
47
- * @param nativeBuffer A strong `uintptr_t` pointer to the native buffer
48
- * @throws Throws an error if the Image could not be created, for example when the given
49
- * native buffer is invalid.
46
+ * @param source The image source
50
47
  */
51
- MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;
52
-
53
- /**
54
- *
55
- * Return an Image backed by a given native texture.
56
- *
57
- * The native texture must be a valid owning reference.
58
- *
59
- * This API might be used to integrate with other libraries using gpu textures,
60
- * or to transfer images between different threads.
61
- *
62
- * @param texture A native texture handle
63
- * @param width The width of the texture
64
- * @param height The height of the texture
65
- * @param mipmapped Whether the texture is mipmapped
66
- * @throws Throws an error if the Image could not be created, for example when the given native texture is invalid.
67
- *
68
- * @returns Returns a valid SkImage, if the texture is invalid, an error is thrown.
69
- */
70
- MakeImageFromNativeTextureUnstable: (
71
- texture: unknown,
72
- width: number,
73
- height: number,
74
- mipmapped?: boolean,
75
- outputImage?: SkImage
76
- ) => SkImage;
48
+ MakeImageFromNativeBuffer: (source: CanvasImageSource) => SkImage;
77
49
 
78
50
  /**
79
51
  * Returns an image that will be a screenshot of the view represented by
@@ -96,33 +68,31 @@ export interface ImageFactory {
96
68
  MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): SkImage | null;
97
69
 
98
70
  /**
99
- * Creates an SkImage from a WebGPU texture.
100
- * This allows using textures rendered by WebGPU in Skia drawings. The
101
- * texture crosses the package boundary as a raw pointer: pass
102
- * `texture.nativePointer` from a react-native-webgpu GPUTexture created on
103
- * the shared device (importDevice(Skia.getNativeDevice())). The native side
104
- * takes its own reference, so the handle stays valid even if the JS
105
- * GPUTexture is garbage collected — but do not call texture.destroy()
106
- * while the image is in use: destroy() releases the underlying GPU
107
- * resource regardless of reference counts.
71
+ * Creates an SkImage from a WebGPU texture, without copying it.
72
+ * The texture must be created with React Native WebGPU on the shared
73
+ * device (importDevice(Skia.getNativeDevice())) with the TEXTURE_BINDING
74
+ * usage. The image takes its own reference to the texture, so it stays
75
+ * valid even if the JS GPUTexture is garbage collected; do not call
76
+ * texture.destroy() while the image is in use, as destroy() releases the
77
+ * GPU resource regardless of references.
108
78
  *
109
79
  * Native only.
110
80
  *
111
- * @param pointer - The WGPUTexture pointer (texture.nativePointer)
112
- * @returns An SkImage wrapping the texture, or throws if the texture is invalid
81
+ * @param texture - The GPUTexture (see {@link GPUTextureHandle})
82
+ * @returns An SkImage sampling the texture, or throws if the texture is invalid
113
83
  */
114
- MakeImageFromNativeTexture(pointer: bigint): SkImage;
84
+ MakeImageFromGPUTexture(texture: GPUTextureHandle): SkImage;
115
85
 
116
86
  /**
117
- * Creates a WebGPU texture from an SkImage.
118
- * This allows using Skia images in WebGPU rendering pipelines. The
119
- * returned pointer carries one reference and must be adopted exactly once
120
- * with react-native-webgpu's adoptTexture(), which owns it from then on.
87
+ * Draws an SkImage into a new WebGPU texture on the shared device.
88
+ * The returned pointer carries one reference and must be adopted exactly
89
+ * once with React Native WebGPU's adoptTexture(), which builds the
90
+ * GPUTexture and owns the reference from then on.
121
91
  *
122
92
  * Native only.
123
93
  *
124
- * @param image - An SkImage to convert to a texture
94
+ * @param image - The SkImage to draw into the texture
125
95
  * @returns A WGPUTexture pointer for adoptTexture(), or throws on failure
126
96
  */
127
- MakeNativeTextureFromImage(image: SkImage): bigint;
97
+ MakeGPUTextureFromImage(image: SkImage): bigint;
128
98
  }
@@ -30,8 +30,6 @@ import type { Color, SkColor } from "./Color";
30
30
  import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
31
31
  import type { AnimatedImageFactory } from "./AnimatedImage";
32
32
  import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
33
- import type { Video } from "./Video";
34
- import type { NativeBufferFactory } from "./NativeBuffer";
35
33
  import type { JsiRecorder } from "./Recorder";
36
34
  import type { SkottieFactory } from "./Skottie";
37
35
 
@@ -100,8 +98,6 @@ export interface Skia {
100
98
  Surface: SurfaceFactory;
101
99
  ParagraphBuilder: ParagraphBuilderFactory;
102
100
  Skottie: SkottieFactory;
103
- Video: (url: string) => Promise<Video> | Video;
104
- NativeBuffer: NativeBufferFactory;
105
101
  Recorder(): JsiRecorder;
106
102
  /**
107
103
  * Raw WGPUDevice pointer of Skia's Graphite device, as a BigInt. Pass it to
@@ -14,18 +14,6 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
14
14
  */
15
15
  getCanvas(): SkCanvas;
16
16
 
17
- /**
18
- * Returns the backend texture of the surface.
19
- * The returned object can be used to create a Skia Image object.
20
- * The returned object is backend specific and should be used with caution.
21
- * It is the caller's responsibility to ensure that the texture is not used after the surface is deleted
22
- * or draw operations are performed on the surface.
23
- * The returned object may be null if the surface does not have a backend texture.
24
- *
25
- * @return backend texture of the surface or null
26
- */
27
- getNativeTextureUnstable(): unknown;
28
-
29
17
  /** Returns Image capturing Surface contents. Subsequent drawing to
30
18
  Surface contents are not captured.
31
19
 
@@ -40,9 +28,9 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
40
28
  /**
41
29
  * Make sure any queued draws are sent to the screen or the GPU.
42
30
  * @param sync - When true, block until the GPU has finished executing the
43
- * submitted work. Use this before reading the surface's texture from a native
44
- * consumer on a different command queue (see {@link getNativeTextureUnstable}).
45
- * Defaults to false.
31
+ * submitted work. Use this before a consumer on a different command queue
32
+ * reads the texture this surface draws into (see
33
+ * `Skia.Surface.MakeFromGPUTexture`). Defaults to false.
46
34
  */
47
35
  flush(sync?: boolean): void;
48
36
 
@@ -1,3 +1,5 @@
1
+ import type { GPUTextureHandle } from "../GPUTexture";
2
+
1
3
  import type { SkSurface } from "./Surface";
2
4
 
3
5
  export const ColorSpace = {
@@ -35,18 +37,18 @@ export interface SurfaceFactory {
35
37
 
36
38
  /**
37
39
  * Creates a GPU backed surface that draws directly into a WebGPU texture
38
- * (zero-copy). The texture must be created on Skia's device
39
- * (importDevice(Skia.getNativeDevice())) with RENDER_ATTACHMENT usage; add
40
- * TEXTURE_BINDING to sample what Skia drew from WebGPU after each flush().
41
- * The surface holds its own reference to the texture and keeps it alive
42
- * for its lifetime, so the caller may release the GPUTexture once the
43
- * surface exists. Calling destroy() on the GPUTexture still invalidates
44
- * the surface.
40
+ * (zero-copy). The texture must be created with React Native WebGPU on
41
+ * the shared device (importDevice(Skia.getNativeDevice())) with the
42
+ * RENDER_ATTACHMENT usage; add TEXTURE_BINDING to sample what Skia drew
43
+ * from WebGPU after each flush(). The surface holds its own reference to
44
+ * the texture and keeps it alive for its lifetime, so the caller may
45
+ * release the GPUTexture once the surface exists. Calling destroy() on the
46
+ * GPUTexture still invalidates the surface.
45
47
  *
46
48
  * Native only.
47
49
  *
48
- * @param pointer - The WGPUTexture pointer (texture.nativePointer)
50
+ * @param texture - The GPUTexture (see {@link GPUTextureHandle})
49
51
  * @returns An SkSurface rendering into the texture, or throws if the texture is invalid
50
52
  */
51
- MakeFromNativeTexture: (pointer: bigint) => SkSurface;
53
+ MakeFromGPUTexture: (texture: GPUTextureHandle) => SkSurface;
52
54
  }
@@ -29,8 +29,7 @@ export * from "./TextBlob";
29
29
  export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
- export * from "./NativeBuffer";
33
32
  export * from "./Recorder";
34
- export * from "./Video";
35
33
  export * from "./Skottie";
36
34
  export * from "./Graphite";
35
+ export * from "./GPUTexture";
@@ -173,9 +173,4 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
173
173
  }
174
174
  return new JsiSkImage(this.CanvasKit, img);
175
175
  }
176
-
177
- getNativeTextureUnstable(): unknown {
178
- console.warn("getBackendTexture is not implemented on Web");
179
- return null;
180
- }
181
176
  }
@@ -1,19 +1,27 @@
1
1
  import type { CanvasKit, Image } from "canvaskit-wasm";
2
2
 
3
- import { CanvasKitWebGLBuffer, isNativeBufferWeb } from "../types";
4
3
  import type {
5
4
  SkData,
6
5
  ImageInfo,
7
6
  SkImage,
8
- NativeBuffer,
9
7
  ImageFactory,
8
+ GPUTextureHandle,
10
9
  } from "../types";
11
10
 
12
11
  import { Host, getEnum, throwNotImplementedOnRNWeb } from "./Host";
13
12
  import { JsiSkImage } from "./JsiSkImage";
14
13
  import { JsiSkData } from "./JsiSkData";
15
14
  import type { JsiSkSurface } from "./JsiSkSurface";
16
- import type { CanvasKitWebGLBufferImpl } from "./CanvasKitWebGLBufferImpl";
15
+
16
+ // The video element of a playing video, an ImageBitmap, a canvas...
17
+ const isCanvasImageSource = (buffer: unknown): buffer is CanvasImageSource =>
18
+ buffer instanceof HTMLVideoElement ||
19
+ buffer instanceof HTMLCanvasElement ||
20
+ buffer instanceof ImageBitmap ||
21
+ buffer instanceof OffscreenCanvas ||
22
+ (typeof VideoFrame !== "undefined" && buffer instanceof VideoFrame) ||
23
+ buffer instanceof HTMLImageElement ||
24
+ buffer instanceof SVGImageElement;
17
25
 
18
26
  export class JsiSkImageFactory extends Host implements ImageFactory {
19
27
  constructor(CanvasKit: CanvasKit) {
@@ -32,12 +40,12 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
32
40
  }
33
41
 
34
42
  MakeImageFromNativeBuffer(
35
- buffer: NativeBuffer,
43
+ buffer: CanvasImageSource,
36
44
  surface?: JsiSkSurface,
37
45
  image?: JsiSkImage
38
46
  ) {
39
- if (!isNativeBufferWeb(buffer)) {
40
- throw new Error("Invalid NativeBuffer");
47
+ if (!isCanvasImageSource(buffer)) {
48
+ throw new Error("MakeImageFromNativeBuffer expects a CanvasImageSource");
41
49
  }
42
50
  if (!surface) {
43
51
  let img: Image;
@@ -47,10 +55,6 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
47
55
  buffer instanceof ImageBitmap
48
56
  ) {
49
57
  img = this.CanvasKit.MakeLazyImageFromTextureSource(buffer);
50
- } else if (buffer instanceof CanvasKitWebGLBuffer) {
51
- img = (
52
- buffer as CanvasKitWebGLBuffer as CanvasKitWebGLBufferImpl
53
- ).toImage();
54
58
  } else {
55
59
  img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);
56
60
  }
@@ -79,10 +83,6 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
79
83
  return new JsiSkImage(this.CanvasKit, image);
80
84
  }
81
85
 
82
- MakeImageFromNativeTextureUnstable() {
83
- return throwNotImplementedOnRNWeb<SkImage>();
84
- }
85
-
86
86
  MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number) {
87
87
  // see toSkImageInfo() from canvaskit
88
88
  const image = this.CanvasKit.MakeImage(
@@ -102,11 +102,11 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
102
102
  return new JsiSkImage(this.CanvasKit, image);
103
103
  }
104
104
 
105
- MakeImageFromNativeTexture(_pointer: bigint): SkImage {
105
+ MakeImageFromGPUTexture(_texture: GPUTextureHandle): SkImage {
106
106
  return throwNotImplementedOnRNWeb<SkImage>();
107
107
  }
108
108
 
109
- MakeNativeTextureFromImage(_image: SkImage): bigint {
109
+ MakeGPUTextureFromImage(_image: SkImage): bigint {
110
110
  return throwNotImplementedOnRNWeb<bigint>();
111
111
  }
112
112
  }
@@ -47,9 +47,4 @@ export class JsiSkSurface
47
47
  }
48
48
  return new JsiSkImage(this.CanvasKit, image);
49
49
  }
50
-
51
- getNativeTextureUnstable(): unknown {
52
- console.warn("getBackendTexture is not implemented on Web");
53
- return null;
54
- }
55
50
  }
@@ -1,6 +1,6 @@
1
1
  import type { CanvasKit, Surface } from "canvaskit-wasm";
2
2
 
3
- import type { SkSurface, SurfaceFactory } from "../types";
3
+ import type { GPUTextureHandle, SkSurface, SurfaceFactory } from "../types";
4
4
 
5
5
  import { Host, throwNotImplementedOnRNWeb } from "./Host";
6
6
  import { JsiSkSurface } from "./JsiSkSurface";
@@ -39,7 +39,7 @@ export class JsiSkSurfaceFactory extends Host implements SurfaceFactory {
39
39
  return new JsiSkSurface(this.CanvasKit, surface);
40
40
  }
41
41
 
42
- MakeFromNativeTexture(_pointer: bigint): SkSurface {
42
+ MakeFromGPUTexture(_texture: GPUTextureHandle): SkSurface {
43
43
  return throwNotImplementedOnRNWeb<SkSurface>();
44
44
  }
45
45
  }
@@ -43,8 +43,6 @@ import { JsiSkTypefaceFontProviderFactory } from "./JsiSkTypefaceFontProviderFac
43
43
  import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
44
44
  import { JsiSkAnimatedImageFactory } from "./JsiSkAnimatedImageFactory";
45
45
  import { JsiSkParagraphBuilderFactory } from "./JsiSkParagraphBuilderFactory";
46
- import { JsiSkNativeBufferFactory } from "./JsiSkNativeBufferFactory";
47
- import { createVideo } from "./JsiVideo";
48
46
  import { throwNotImplementedOnRNWeb } from "./Host";
49
47
  import { JsiSkottieFactory } from "./JsiSkottieFactory";
50
48
 
@@ -133,9 +131,7 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
133
131
  TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),
134
132
  FontMgr: new JsiSkFontMgrFactory(CanvasKit),
135
133
  ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),
136
- NativeBuffer: new JsiSkNativeBufferFactory(CanvasKit),
137
134
  Skottie: new JsiSkottieFactory(CanvasKit),
138
- Video: createVideo.bind(null, CanvasKit),
139
135
  Recorder: () => {
140
136
  return throwNotImplementedOnRNWeb<JsiRecorder>();
141
137
  },
@@ -1,31 +0,0 @@
1
- #if __ANDROID_API__ >= 26
2
-
3
- #include "AHardwareBufferUtils.h"
4
- #include <android/hardware_buffer.h>
5
-
6
- namespace RNSkia {
7
-
8
- uint32_t GetBufferFormatFromSkColorType(SkColorType bufferFormat) {
9
- switch (bufferFormat) {
10
- case kRGBA_8888_SkColorType:
11
- return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
12
- case kRGB_888x_SkColorType:
13
- return AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM;
14
- case kRGBA_F16_SkColorType:
15
- return AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT;
16
- case kRGB_565_SkColorType:
17
- return AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM;
18
- case kRGBA_1010102_SkColorType:
19
- return AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM;
20
- #if __ANDROID_API__ >= 33
21
- case kAlpha_8_SkColorType:
22
- return AHARDWAREBUFFER_FORMAT_R8_UNORM;
23
- #endif
24
- default:
25
- return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
26
- }
27
- }
28
-
29
- } // namespace RNSkia
30
-
31
- #endif
@@ -1,13 +0,0 @@
1
- #pragma once
2
-
3
- #include "include/core/SkColorType.h"
4
-
5
- #if __ANDROID_API__ >= 26
6
-
7
- namespace RNSkia {
8
-
9
- uint32_t GetBufferFormatFromSkColorType(SkColorType bufferFormat);
10
-
11
- } // namespace RNSkia
12
-
13
- #endif