@shopify/react-native-skia 1.1.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. package/android/CMakeLists.txt +1 -0
  2. package/android/build.gradle +1 -0
  3. package/android/cpp/rnskia-android/AHardwareBufferUtils.cpp +31 -0
  4. package/android/cpp/rnskia-android/AHardwareBufferUtils.h +13 -0
  5. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +75 -0
  6. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp +29 -11
  7. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +1 -2
  8. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +3 -2
  9. package/cpp/api/JsiNativeBuffer.h +43 -0
  10. package/cpp/api/JsiSkApi.h +4 -0
  11. package/cpp/api/JsiSkImage.h +1 -1
  12. package/cpp/api/JsiSkImageFactory.h +15 -1
  13. package/cpp/api/JsiSkSurface.h +9 -1
  14. package/cpp/rnskia/RNSkPlatformContext.h +13 -0
  15. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +6 -0
  16. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +98 -2
  17. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.h +84 -0
  18. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +159 -0
  19. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +5 -0
  20. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +37 -1
  21. package/lib/commonjs/external/reanimated/textures.js +11 -2
  22. package/lib/commonjs/external/reanimated/textures.js.map +1 -1
  23. package/lib/commonjs/external/reanimated/useAnimatedImageValue.d.ts +2 -1
  24. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js +8 -4
  25. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js.map +1 -1
  26. package/lib/commonjs/renderer/Offscreen.d.ts +2 -2
  27. package/lib/commonjs/renderer/Offscreen.js +2 -2
  28. package/lib/commonjs/renderer/Offscreen.js.map +1 -1
  29. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +17 -10
  30. package/lib/commonjs/skia/types/Image/ImageFactory.js +1 -10
  31. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  32. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
  33. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js +13 -0
  34. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -0
  35. package/lib/commonjs/skia/types/NativeBuffer/index.d.ts +1 -0
  36. package/lib/commonjs/skia/types/NativeBuffer/index.js +17 -0
  37. package/lib/commonjs/skia/types/NativeBuffer/index.js.map +1 -0
  38. package/lib/commonjs/skia/types/Skia.d.ts +2 -0
  39. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  40. package/lib/commonjs/skia/types/Surface/Surface.d.ts +8 -0
  41. package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
  42. package/lib/commonjs/skia/types/index.d.ts +1 -0
  43. package/lib/commonjs/skia/types/index.js +11 -0
  44. package/lib/commonjs/skia/types/index.js.map +1 -1
  45. package/lib/commonjs/skia/web/JsiSkImage.d.ts +1 -2
  46. package/lib/commonjs/skia/web/JsiSkImage.js +5 -12
  47. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  48. package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +3 -2
  49. package/lib/commonjs/skia/web/JsiSkImageFactory.js +19 -0
  50. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  51. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
  52. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js +29 -0
  53. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js.map +1 -0
  54. package/lib/commonjs/skia/web/JsiSkSurface.d.ts +3 -2
  55. package/lib/commonjs/skia/web/JsiSkSurface.js +8 -6
  56. package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
  57. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
  58. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +1 -16
  59. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  60. package/lib/commonjs/skia/web/JsiSkia.js +3 -1
  61. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  62. package/lib/module/external/reanimated/textures.js +11 -2
  63. package/lib/module/external/reanimated/textures.js.map +1 -1
  64. package/lib/module/external/reanimated/useAnimatedImageValue.d.ts +2 -1
  65. package/lib/module/external/reanimated/useAnimatedImageValue.js +8 -4
  66. package/lib/module/external/reanimated/useAnimatedImageValue.js.map +1 -1
  67. package/lib/module/renderer/Offscreen.d.ts +2 -2
  68. package/lib/module/renderer/Offscreen.js +2 -2
  69. package/lib/module/renderer/Offscreen.js.map +1 -1
  70. package/lib/module/skia/types/Image/ImageFactory.d.ts +17 -10
  71. package/lib/module/skia/types/Image/ImageFactory.js +1 -10
  72. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  73. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
  74. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js +4 -0
  75. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -0
  76. package/lib/module/skia/types/NativeBuffer/index.d.ts +1 -0
  77. package/lib/module/skia/types/NativeBuffer/index.js +2 -0
  78. package/lib/module/skia/types/NativeBuffer/index.js.map +1 -0
  79. package/lib/module/skia/types/Skia.d.ts +2 -0
  80. package/lib/module/skia/types/Skia.js.map +1 -1
  81. package/lib/module/skia/types/Surface/Surface.d.ts +8 -0
  82. package/lib/module/skia/types/Surface/Surface.js.map +1 -1
  83. package/lib/module/skia/types/index.d.ts +1 -0
  84. package/lib/module/skia/types/index.js +1 -0
  85. package/lib/module/skia/types/index.js.map +1 -1
  86. package/lib/module/skia/web/JsiSkImage.d.ts +1 -2
  87. package/lib/module/skia/web/JsiSkImage.js +5 -12
  88. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  89. package/lib/module/skia/web/JsiSkImageFactory.d.ts +3 -2
  90. package/lib/module/skia/web/JsiSkImageFactory.js +19 -0
  91. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  92. package/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
  93. package/lib/module/skia/web/JsiSkNativeBufferFactory.js +22 -0
  94. package/lib/module/skia/web/JsiSkNativeBufferFactory.js.map +1 -0
  95. package/lib/module/skia/web/JsiSkSurface.d.ts +3 -2
  96. package/lib/module/skia/web/JsiSkSurface.js +8 -6
  97. package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
  98. package/lib/module/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
  99. package/lib/module/skia/web/JsiSkSurfaceFactory.js +1 -16
  100. package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  101. package/lib/module/skia/web/JsiSkia.js +3 -1
  102. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  103. package/lib/typescript/src/external/reanimated/useAnimatedImageValue.d.ts +2 -1
  104. package/lib/typescript/src/renderer/Offscreen.d.ts +2 -2
  105. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +17 -10
  106. package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
  107. package/lib/typescript/src/skia/types/NativeBuffer/index.d.ts +1 -0
  108. package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
  109. package/lib/typescript/src/skia/types/Surface/Surface.d.ts +8 -0
  110. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  111. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +1 -2
  112. package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +3 -2
  113. package/lib/typescript/src/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
  114. package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +3 -2
  115. package/lib/typescript/src/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
  116. package/package.json +1 -1
  117. package/src/external/reanimated/textures.tsx +8 -2
  118. package/src/external/reanimated/useAnimatedImageValue.ts +12 -6
  119. package/src/renderer/Offscreen.tsx +3 -3
  120. package/src/skia/types/Image/ImageFactory.ts +17 -18
  121. package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +38 -0
  122. package/src/skia/types/NativeBuffer/index.ts +1 -0
  123. package/src/skia/types/Skia.ts +2 -1
  124. package/src/skia/types/Surface/Surface.ts +10 -0
  125. package/src/skia/types/index.ts +1 -0
  126. package/src/skia/web/JsiSkImage.ts +5 -22
  127. package/src/skia/web/JsiSkImageFactory.ts +36 -3
  128. package/src/skia/web/JsiSkNativeBufferFactory.ts +35 -0
  129. package/src/skia/web/JsiSkSurface.ts +10 -9
  130. package/src/skia/web/JsiSkSurfaceFactory.ts +3 -19
  131. package/src/skia/web/JsiSkia.ts +2 -0
  132. package/cpp/skia/include/third_party/vulkan/LICENSE +0 -29
  133. package/cpp/skia/modules/skcms/README.chromium +0 -6
  134. package/cpp/skia/readme.txt +0 -1
@@ -0,0 +1,159 @@
1
+ //
2
+ // SkiaCVPixelBufferUtils.mm
3
+ // react-native-skia
4
+ //
5
+ // Created by Marc Rousavy on 10.04.24.
6
+ //
7
+
8
+ #import "SkiaCVPixelBufferUtils.h"
9
+ #import "SkiaMetalSurfaceFactory.h"
10
+
11
+ #pragma clang diagnostic push
12
+ #pragma clang diagnostic ignored "-Wdocumentation"
13
+ #import "include/core/SkColorSpace.h"
14
+ #import <include/gpu/GrBackendSurface.h>
15
+ #pragma clang diagnostic pop
16
+
17
+ #include <TargetConditionals.h>
18
+ #if TARGET_RT_BIG_ENDIAN
19
+ #define FourCC2Str(fourcc) \
20
+ (const char[]) { \
21
+ *((char *)&fourcc), *(((char *)&fourcc) + 1), *(((char *)&fourcc) + 2), \
22
+ *(((char *)&fourcc) + 3), 0 \
23
+ }
24
+ #else
25
+ #define FourCC2Str(fourcc) \
26
+ (const char[]) { \
27
+ *(((char *)&fourcc) + 3), *(((char *)&fourcc) + 2), \
28
+ *(((char *)&fourcc) + 1), *(((char *)&fourcc) + 0), 0 \
29
+ }
30
+ #endif
31
+
32
+ // pragma MARK: TextureHolder
33
+
34
+ TextureHolder::TextureHolder(CVMetalTextureRef texture) : _texture(texture) {}
35
+ TextureHolder::~TextureHolder() { CFRelease(_texture); }
36
+
37
+ GrBackendTexture TextureHolder::toGrBackendTexture() {
38
+ // Unwrap the underlying MTLTexture
39
+ id<MTLTexture> mtlTexture = CVMetalTextureGetTexture(_texture);
40
+ if (mtlTexture == nil) [[unlikely]] {
41
+ throw std::runtime_error(
42
+ "Failed to get MTLTexture from CVMetalTextureRef!");
43
+ }
44
+
45
+ // Wrap MTLTexture in Skia's GrBackendTexture
46
+ GrMtlTextureInfo textureInfo;
47
+ textureInfo.fTexture.retain((__bridge void *)mtlTexture);
48
+ GrBackendTexture texture =
49
+ GrBackendTexture((int)mtlTexture.width, (int)mtlTexture.height,
50
+ skgpu::Mipmapped::kNo, textureInfo);
51
+ return texture;
52
+ }
53
+
54
+ // pragma MARK: Base
55
+
56
+ SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat
57
+ SkiaCVPixelBufferUtils::getCVPixelBufferBaseFormat(
58
+ CVPixelBufferRef pixelBuffer) {
59
+ OSType format = CVPixelBufferGetPixelFormatType(pixelBuffer);
60
+
61
+ switch (format) {
62
+ case kCVPixelFormatType_32BGRA:
63
+ case kCVPixelFormatType_32RGBA:
64
+ return CVPixelBufferBaseFormat::rgb;
65
+ default:
66
+ [[unlikely]] throw std::runtime_error(
67
+ "CVPixelBuffer has unsupported pixel-format! " +
68
+ std::string(FourCC2Str(format)));
69
+ }
70
+ }
71
+
72
+ // pragma MARK: RGB
73
+
74
+ SkColorType SkiaCVPixelBufferUtils::RGB::getCVPixelBufferColorType(
75
+ CVPixelBufferRef pixelBuffer) {
76
+ OSType format = CVPixelBufferGetPixelFormatType(pixelBuffer);
77
+
78
+ switch (format) {
79
+ case kCVPixelFormatType_32BGRA:
80
+ [[likely]] return kBGRA_8888_SkColorType;
81
+ case kCVPixelFormatType_32RGBA:
82
+ return kRGBA_8888_SkColorType;
83
+ // This can be extended with branches for specific RGB formats if new Apple
84
+ // uses new formats.
85
+ default:
86
+ [[unlikely]] throw std::runtime_error(
87
+ "CVPixelBuffer has unknown RGB format! " +
88
+ std::string(FourCC2Str(format)));
89
+ }
90
+ }
91
+
92
+ TextureHolder *SkiaCVPixelBufferUtils::RGB::getSkiaTextureForCVPixelBuffer(
93
+ CVPixelBufferRef pixelBuffer) {
94
+ return getSkiaTextureForCVPixelBufferPlane(pixelBuffer, /* planeIndex */ 0);
95
+ }
96
+
97
+ // pragma MARK: CVPixelBuffer -> Skia Texture
98
+
99
+ TextureHolder *SkiaCVPixelBufferUtils::getSkiaTextureForCVPixelBufferPlane(
100
+ CVPixelBufferRef pixelBuffer, size_t planeIndex) {
101
+ // 1. Get cache
102
+ CVMetalTextureCacheRef textureCache = getTextureCache();
103
+
104
+ // 2. Get MetalTexture from CMSampleBuffer
105
+ size_t width = CVPixelBufferGetWidthOfPlane(pixelBuffer, planeIndex);
106
+ size_t height = CVPixelBufferGetHeightOfPlane(pixelBuffer, planeIndex);
107
+ MTLPixelFormat pixelFormat =
108
+ getMTLPixelFormatForCVPixelBufferPlane(pixelBuffer, planeIndex);
109
+
110
+ CVMetalTextureRef textureHolder;
111
+ CVReturn result = CVMetalTextureCacheCreateTextureFromImage(
112
+ kCFAllocatorDefault, textureCache, pixelBuffer, nil, pixelFormat, width,
113
+ height, planeIndex, &textureHolder);
114
+
115
+ if (result != kCVReturnSuccess) [[unlikely]] {
116
+ throw std::runtime_error(
117
+ "Failed to create Metal Texture from CMSampleBuffer! Result: " +
118
+ std::to_string(result));
119
+ }
120
+
121
+ return new TextureHolder(textureHolder);
122
+ }
123
+
124
+ // pragma MARK: getTextureCache()
125
+
126
+ CVMetalTextureCacheRef SkiaCVPixelBufferUtils::getTextureCache() {
127
+ static CVMetalTextureCacheRef textureCache = nil;
128
+ if (textureCache == nil) {
129
+ // Create a new Texture Cache
130
+ auto result = CVMetalTextureCacheCreate(kCFAllocatorDefault, nil,
131
+ MTLCreateSystemDefaultDevice(), nil,
132
+ &textureCache);
133
+ if (result != kCVReturnSuccess || textureCache == nil) {
134
+ throw std::runtime_error("Failed to create Metal Texture Cache!");
135
+ }
136
+ }
137
+ return textureCache;
138
+ }
139
+
140
+ // pragma MARK: Get CVPixelBuffer MTLPixelFormat
141
+
142
+ MTLPixelFormat SkiaCVPixelBufferUtils::getMTLPixelFormatForCVPixelBufferPlane(
143
+ CVPixelBufferRef pixelBuffer, size_t planeIndex) {
144
+ size_t width = CVPixelBufferGetWidthOfPlane(pixelBuffer, planeIndex);
145
+ size_t bytesPerRow =
146
+ CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, planeIndex);
147
+ double bytesPerPixel = round(static_cast<double>(bytesPerRow) / width);
148
+ if (bytesPerPixel == 1) {
149
+ return MTLPixelFormatR8Unorm;
150
+ } else if (bytesPerPixel == 2) {
151
+ return MTLPixelFormatRG8Unorm;
152
+ } else if (bytesPerPixel == 4) {
153
+ return MTLPixelFormatBGRA8Unorm;
154
+ } else [[unlikely]] {
155
+ throw std::runtime_error("Invalid bytes per row! Expected 1 (R), 2 (RG) or "
156
+ "4 (RGBA), but received " +
157
+ std::to_string(bytesPerPixel));
158
+ }
159
+ }
@@ -4,6 +4,8 @@
4
4
  #pragma clang diagnostic ignored "-Wdocumentation"
5
5
 
6
6
  #import "include/core/SkCanvas.h"
7
+ #import <CoreMedia/CMSampleBuffer.h>
8
+ #import <CoreVideo/CVMetalTextureCache.h>
7
9
  #import <include/gpu/GrDirectContext.h>
8
10
 
9
11
  #pragma clang diagnostic pop
@@ -24,6 +26,9 @@ public:
24
26
  int height);
25
27
  static sk_sp<SkSurface> makeOffscreenSurface(int width, int height);
26
28
 
29
+ static sk_sp<SkImage>
30
+ makeTextureFromCVPixelBuffer(CVPixelBufferRef pixelBuffer);
31
+
27
32
  private:
28
33
  static id<MTLDevice> device;
29
34
  static bool
@@ -1,6 +1,7 @@
1
1
  #import "RNSkLog.h"
2
2
 
3
- #include "SkiaMetalSurfaceFactory.h"
3
+ #import "SkiaCVPixelBufferUtils.h"
4
+ #import "SkiaMetalSurfaceFactory.h"
4
5
 
5
6
  #pragma clang diagnostic push
6
7
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -11,7 +12,9 @@
11
12
 
12
13
  #import <include/gpu/GrBackendSurface.h>
13
14
  #import <include/gpu/GrDirectContext.h>
15
+ #import <include/gpu/ganesh/SkImageGanesh.h>
14
16
  #import <include/gpu/ganesh/SkSurfaceGanesh.h>
17
+ #import <include/gpu/ganesh/mtl/SkSurfaceMetal.h>
15
18
 
16
19
  #pragma clang diagnostic pop
17
20
 
@@ -103,3 +106,36 @@ sk_sp<SkSurface> SkiaMetalSurfaceFactory::makeOffscreenSurface(int width,
103
106
 
104
107
  return surface;
105
108
  }
109
+
110
+ sk_sp<SkImage> SkiaMetalSurfaceFactory::makeTextureFromCVPixelBuffer(
111
+ CVPixelBufferRef pixelBuffer) {
112
+ if (!SkiaMetalSurfaceFactory::createSkiaDirectContextIfNecessary(
113
+ &ThreadContextHolder::ThreadSkiaMetalContext)) [[unlikely]] {
114
+ throw std::runtime_error("Failed to create Skia Context for this Thread!");
115
+ }
116
+ const SkiaMetalContext &context = ThreadContextHolder::ThreadSkiaMetalContext;
117
+
118
+ SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat format =
119
+ SkiaCVPixelBufferUtils::getCVPixelBufferBaseFormat(pixelBuffer);
120
+ switch (format) {
121
+ case SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat::rgb: {
122
+ // CVPixelBuffer is in any RGB format.
123
+ SkColorType colorType =
124
+ SkiaCVPixelBufferUtils::RGB::getCVPixelBufferColorType(pixelBuffer);
125
+ TextureHolder *texture =
126
+ SkiaCVPixelBufferUtils::RGB::getSkiaTextureForCVPixelBuffer(
127
+ pixelBuffer);
128
+ return SkImages::BorrowTextureFrom(
129
+ context.skContext.get(), texture->toGrBackendTexture(),
130
+ kTopLeft_GrSurfaceOrigin, colorType, kOpaque_SkAlphaType, nullptr,
131
+ [](void *texture) { delete (TextureHolder *)texture; },
132
+ (void *)texture);
133
+ }
134
+ default:
135
+ [[unlikely]] {
136
+ throw std::runtime_error("Failed to convert PlatformBuffer to SkImage - "
137
+ "PlatformBuffer has unsupported PixelFormat! " +
138
+ std::to_string(static_cast<int>(format)));
139
+ }
140
+ }
141
+ }
@@ -14,9 +14,18 @@ const createTexture = (texture, picture, size) => {
14
14
  texture.value = (0, _Offscreen.drawAsImageFromPicture)(picture, size);
15
15
  };
16
16
  const useTexture = (element, size) => {
17
+ const {
18
+ width,
19
+ height
20
+ } = size;
17
21
  const picture = (0, _react.useMemo)(() => {
18
- return (0, _Offscreen.drawAsPicture)(element);
19
- }, [element]);
22
+ return (0, _Offscreen.drawAsPicture)(element, {
23
+ x: 0,
24
+ y: 0,
25
+ width,
26
+ height
27
+ });
28
+ }, [element, width, height]);
20
29
  return usePictureAsTexture(picture, size);
21
30
  };
22
31
  exports.useTexture = useTexture;
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_Offscreen","_skia","_moduleWrapper","createTexture","texture","picture","size","value","drawAsImageFromPicture","useTexture","element","useMemo","drawAsPicture","usePictureAsTexture","exports","useTextureAsValue","console","warn","useTextureValueFromPicture","useSharedValue","useEffect","runOnUI","useImageAsTexture","source","image","useImage","width","height","recorder","Skia","PictureRecorder","canvas","beginRecording","x","y","drawImage","finishRecordingAsPicture"],"sources":["textures.tsx"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport type { ReactElement } from \"react\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type {\n DataSourceParam,\n SkImage,\n SkPicture,\n SkSize,\n} from \"../../skia/types\";\nimport {\n drawAsImageFromPicture,\n drawAsPicture,\n} from \"../../renderer/Offscreen\";\nimport { Skia, useImage } from \"../../skia\";\n\nimport { runOnUI, useSharedValue } from \"./moduleWrapper\";\n\nconst createTexture = (\n texture: SharedValue<SkImage | null>,\n picture: SkPicture,\n size: SkSize\n) => {\n \"worklet\";\n texture.value = drawAsImageFromPicture(picture, size);\n};\n\nexport const useTexture = (element: ReactElement, size: SkSize) => {\n const picture = useMemo(() => {\n return drawAsPicture(element);\n }, [element]);\n return usePictureAsTexture(picture, size);\n};\n\nexport const useTextureAsValue = (element: ReactElement, size: SkSize) => {\n console.warn(\"useTextureAsValue has been renamed to use useTexture\");\n return useTexture(element, size);\n};\n\nexport const useTextureValueFromPicture = (\n picture: SkPicture | null,\n size: SkSize\n) => {\n console.warn(\n \"useTextureValueFromPicture has been renamed to use usePictureAsTexture\"\n );\n return usePictureAsTexture(picture, size);\n};\n\nexport const usePictureAsTexture = (\n picture: SkPicture | null,\n size: SkSize\n) => {\n const texture = useSharedValue<SkImage | null>(null);\n useEffect(() => {\n if (picture !== null) {\n runOnUI(createTexture)(texture, picture, size);\n }\n }, [texture, picture, size]);\n return texture;\n};\n\nexport const useImageAsTexture = (source: DataSourceParam) => {\n const image = useImage(source);\n const size = useMemo(() => {\n if (image) {\n return { width: image.width(), height: image.height() };\n }\n return { width: 0, height: 0 };\n }, [image]);\n const picture = useMemo(() => {\n if (image) {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording({\n x: 0,\n y: 0,\n width: size.width,\n height: size.height,\n });\n canvas.drawImage(image, 0, 0);\n return recorder.finishRecordingAsPicture();\n } else {\n return null;\n }\n }, [size, image]);\n return usePictureAsTexture(picture, size);\n};\n"],"mappings":"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"}
1
+ {"version":3,"names":["_react","require","_Offscreen","_skia","_moduleWrapper","createTexture","texture","picture","size","value","drawAsImageFromPicture","useTexture","element","width","height","useMemo","drawAsPicture","x","y","usePictureAsTexture","exports","useTextureAsValue","console","warn","useTextureValueFromPicture","useSharedValue","useEffect","runOnUI","useImageAsTexture","source","image","useImage","recorder","Skia","PictureRecorder","canvas","beginRecording","drawImage","finishRecordingAsPicture"],"sources":["textures.tsx"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport type { ReactElement } from \"react\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type {\n DataSourceParam,\n SkImage,\n SkPicture,\n SkSize,\n} from \"../../skia/types\";\nimport {\n drawAsImageFromPicture,\n drawAsPicture,\n} from \"../../renderer/Offscreen\";\nimport { Skia, useImage } from \"../../skia\";\n\nimport { runOnUI, useSharedValue } from \"./moduleWrapper\";\n\nconst createTexture = (\n texture: SharedValue<SkImage | null>,\n picture: SkPicture,\n size: SkSize\n) => {\n \"worklet\";\n texture.value = drawAsImageFromPicture(picture, size);\n};\n\nexport const useTexture = (element: ReactElement, size: SkSize) => {\n const { width, height } = size;\n const picture = useMemo(() => {\n return drawAsPicture(element, {\n x: 0,\n y: 0,\n width,\n height,\n });\n }, [element, width, height]);\n return usePictureAsTexture(picture, size);\n};\n\nexport const useTextureAsValue = (element: ReactElement, size: SkSize) => {\n console.warn(\"useTextureAsValue has been renamed to use useTexture\");\n return useTexture(element, size);\n};\n\nexport const useTextureValueFromPicture = (\n picture: SkPicture | null,\n size: SkSize\n) => {\n console.warn(\n \"useTextureValueFromPicture has been renamed to use usePictureAsTexture\"\n );\n return usePictureAsTexture(picture, size);\n};\n\nexport const usePictureAsTexture = (\n picture: SkPicture | null,\n size: SkSize\n) => {\n const texture = useSharedValue<SkImage | null>(null);\n useEffect(() => {\n if (picture !== null) {\n runOnUI(createTexture)(texture, picture, size);\n }\n }, [texture, picture, size]);\n return texture;\n};\n\nexport const useImageAsTexture = (source: DataSourceParam) => {\n const image = useImage(source);\n const size = useMemo(() => {\n if (image) {\n return { width: image.width(), height: image.height() };\n }\n return { width: 0, height: 0 };\n }, [image]);\n const picture = useMemo(() => {\n if (image) {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording({\n x: 0,\n y: 0,\n width: size.width,\n height: size.height,\n });\n canvas.drawImage(image, 0, 0);\n return recorder.finishRecordingAsPicture();\n } else {\n return null;\n }\n }, [size, image]);\n return usePictureAsTexture(picture, size);\n};\n"],"mappings":"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"}
@@ -1,2 +1,3 @@
1
+ import { type SharedValue } from "react-native-reanimated";
1
2
  import type { DataSourceParam, SkImage } from "../../skia/types";
2
- export declare const useAnimatedImageValue: (source: DataSourceParam) => import("react-native-reanimated").SharedValue<SkImage | null>;
3
+ export declare const useAnimatedImageValue: (source: DataSourceParam, paused?: SharedValue<boolean>) => SharedValue<SkImage | null>;
@@ -8,10 +8,12 @@ var _react = require("react");
8
8
  var _AnimatedImage = require("../../skia/core/AnimatedImage");
9
9
  var _moduleWrapper = require("./moduleWrapper");
10
10
  const DEFAULT_FRAME_DURATION = 60;
11
- const useAnimatedImageValue = source => {
11
+ const useAnimatedImageValue = (source, paused) => {
12
12
  (0, _moduleWrapper.throwOnMissingReanimated)();
13
+ const defaultPaused = (0, _moduleWrapper.useSharedValue)(false);
14
+ const isPaused = paused !== null && paused !== void 0 ? paused : defaultPaused;
13
15
  const currentFrame = (0, _moduleWrapper.useSharedValue)(null);
14
- const lastTimestamp = (0, _moduleWrapper.useSharedValue)(0);
16
+ const lastTimestamp = (0, _moduleWrapper.useSharedValue)(-1);
15
17
  const animatedImage = (0, _AnimatedImage.useAnimatedImage)(source, err => {
16
18
  console.error(err);
17
19
  throw new Error(`Could not load animated image - got '${err.message}'`);
@@ -22,6 +24,9 @@ const useAnimatedImageValue = source => {
22
24
  currentFrame.value = null;
23
25
  return;
24
26
  }
27
+ if (isPaused.value && lastTimestamp.value !== -1) {
28
+ return;
29
+ }
25
30
  const {
26
31
  timestamp
27
32
  } = frameInfo;
@@ -41,8 +46,7 @@ const useAnimatedImageValue = source => {
41
46
 
42
47
  // Update the last timestamp
43
48
  lastTimestamp.value = timestamp;
44
- // eslint-disable-next-line react-hooks/exhaustive-deps
45
- }, true);
49
+ });
46
50
  (0, _react.useEffect)(() => {
47
51
  return () => {
48
52
  animatedImage === null || animatedImage === void 0 || animatedImage.dispose();
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_AnimatedImage","_moduleWrapper","DEFAULT_FRAME_DURATION","useAnimatedImageValue","source","throwOnMissingReanimated","currentFrame","useSharedValue","lastTimestamp","animatedImage","useAnimatedImage","err","console","error","Error","message","frameDuration","currentFrameDuration","useFrameCallback","frameInfo","value","timestamp","elapsed","decodeNextFrame","dispose","getCurrentFrame","useEffect","exports"],"sources":["useAnimatedImageValue.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport type { FrameInfo } from \"react-native-reanimated\";\n\nimport { useAnimatedImage } from \"../../skia/core/AnimatedImage\";\nimport type { DataSourceParam, SkImage } from \"../../skia/types\";\n\nimport {\n throwOnMissingReanimated,\n useFrameCallback,\n useSharedValue,\n} from \"./moduleWrapper\";\n\nconst DEFAULT_FRAME_DURATION = 60;\n\nexport const useAnimatedImageValue = (source: DataSourceParam) => {\n throwOnMissingReanimated();\n const currentFrame = useSharedValue<null | SkImage>(null);\n const lastTimestamp = useSharedValue(0);\n const animatedImage = useAnimatedImage(\n source,\n (err) => {\n console.error(err);\n throw new Error(`Could not load animated image - got '${err.message}'`);\n },\n false\n );\n const frameDuration =\n animatedImage?.currentFrameDuration() || DEFAULT_FRAME_DURATION;\n\n useFrameCallback((frameInfo: FrameInfo) => {\n if (!animatedImage) {\n currentFrame.value = null;\n return;\n }\n\n const { timestamp } = frameInfo;\n const elapsed = timestamp - lastTimestamp.value;\n\n // Check if it's time to switch frames based on GIF frame duration\n if (elapsed < frameDuration) {\n return;\n }\n\n // Update the current frame\n animatedImage.decodeNextFrame();\n if (currentFrame.value) {\n currentFrame.value.dispose();\n }\n currentFrame.value = animatedImage.getCurrentFrame();\n\n // Update the last timestamp\n lastTimestamp.value = timestamp;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, true);\n useEffect(() => {\n return () => {\n animatedImage?.dispose();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return currentFrame;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AAGA,IAAAE,cAAA,GAAAF,OAAA;AAMA,MAAMG,sBAAsB,GAAG,EAAE;AAE1B,MAAMC,qBAAqB,GAAIC,MAAuB,IAAK;EAChE,IAAAC,uCAAwB,EAAC,CAAC;EAC1B,MAAMC,YAAY,GAAG,IAAAC,6BAAc,EAAiB,IAAI,CAAC;EACzD,MAAMC,aAAa,GAAG,IAAAD,6BAAc,EAAC,CAAC,CAAC;EACvC,MAAME,aAAa,GAAG,IAAAC,+BAAgB,EACpCN,MAAM,EACLO,GAAG,IAAK;IACPC,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC;IAClB,MAAM,IAAIG,KAAK,CAAE,wCAAuCH,GAAG,CAACI,OAAQ,GAAE,CAAC;EACzE,CAAC,EACD,KACF,CAAC;EACD,MAAMC,aAAa,GACjB,CAAAP,aAAa,aAAbA,aAAa,uBAAbA,aAAa,CAAEQ,oBAAoB,CAAC,CAAC,KAAIf,sBAAsB;EAEjE,IAAAgB,+BAAgB,EAAEC,SAAoB,IAAK;IACzC,IAAI,CAACV,aAAa,EAAE;MAClBH,YAAY,CAACc,KAAK,GAAG,IAAI;MACzB;IACF;IAEA,MAAM;MAAEC;IAAU,CAAC,GAAGF,SAAS;IAC/B,MAAMG,OAAO,GAAGD,SAAS,GAAGb,aAAa,CAACY,KAAK;;IAE/C;IACA,IAAIE,OAAO,GAAGN,aAAa,EAAE;MAC3B;IACF;;IAEA;IACAP,aAAa,CAACc,eAAe,CAAC,CAAC;IAC/B,IAAIjB,YAAY,CAACc,KAAK,EAAE;MACtBd,YAAY,CAACc,KAAK,CAACI,OAAO,CAAC,CAAC;IAC9B;IACAlB,YAAY,CAACc,KAAK,GAAGX,aAAa,CAACgB,eAAe,CAAC,CAAC;;IAEpD;IACAjB,aAAa,CAACY,KAAK,GAAGC,SAAS;IAC/B;EACF,CAAC,EAAE,IAAI,CAAC;EACR,IAAAK,gBAAS,EAAC,MAAM;IACd,OAAO,MAAM;MACXjB,aAAa,aAAbA,aAAa,eAAbA,aAAa,CAAEe,OAAO,CAAC,CAAC;IAC1B,CAAC;IACD;EACF,CAAC,EAAE,EAAE,CAAC;EACN,OAAOlB,YAAY;AACrB,CAAC;AAACqB,OAAA,CAAAxB,qBAAA,GAAAA,qBAAA"}
1
+ {"version":3,"names":["_react","require","_AnimatedImage","_moduleWrapper","DEFAULT_FRAME_DURATION","useAnimatedImageValue","source","paused","throwOnMissingReanimated","defaultPaused","useSharedValue","isPaused","currentFrame","lastTimestamp","animatedImage","useAnimatedImage","err","console","error","Error","message","frameDuration","currentFrameDuration","useFrameCallback","frameInfo","value","timestamp","elapsed","decodeNextFrame","dispose","getCurrentFrame","useEffect","exports"],"sources":["useAnimatedImageValue.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { type FrameInfo, type SharedValue } from \"react-native-reanimated\";\n\nimport { useAnimatedImage } from \"../../skia/core/AnimatedImage\";\nimport type { DataSourceParam, SkImage } from \"../../skia/types\";\n\nimport {\n throwOnMissingReanimated,\n useFrameCallback,\n useSharedValue,\n} from \"./moduleWrapper\";\n\nconst DEFAULT_FRAME_DURATION = 60;\n\nexport const useAnimatedImageValue = (\n source: DataSourceParam,\n paused?: SharedValue<boolean>\n) => {\n throwOnMissingReanimated();\n const defaultPaused = useSharedValue(false);\n const isPaused = paused ?? defaultPaused;\n const currentFrame = useSharedValue<null | SkImage>(null);\n const lastTimestamp = useSharedValue(-1);\n const animatedImage = useAnimatedImage(\n source,\n (err) => {\n console.error(err);\n throw new Error(`Could not load animated image - got '${err.message}'`);\n },\n false\n );\n const frameDuration =\n animatedImage?.currentFrameDuration() || DEFAULT_FRAME_DURATION;\n\n useFrameCallback((frameInfo: FrameInfo) => {\n if (!animatedImage) {\n currentFrame.value = null;\n return;\n }\n if (isPaused.value && lastTimestamp.value !== -1) {\n return;\n }\n const { timestamp } = frameInfo;\n const elapsed = timestamp - lastTimestamp.value;\n\n // Check if it's time to switch frames based on GIF frame duration\n if (elapsed < frameDuration) {\n return;\n }\n\n // Update the current frame\n animatedImage.decodeNextFrame();\n if (currentFrame.value) {\n currentFrame.value.dispose();\n }\n currentFrame.value = animatedImage.getCurrentFrame();\n\n // Update the last timestamp\n lastTimestamp.value = timestamp;\n });\n useEffect(() => {\n return () => {\n animatedImage?.dispose();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return currentFrame;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AAGA,IAAAE,cAAA,GAAAF,OAAA;AAMA,MAAMG,sBAAsB,GAAG,EAAE;AAE1B,MAAMC,qBAAqB,GAAGA,CACnCC,MAAuB,EACvBC,MAA6B,KAC1B;EACH,IAAAC,uCAAwB,EAAC,CAAC;EAC1B,MAAMC,aAAa,GAAG,IAAAC,6BAAc,EAAC,KAAK,CAAC;EAC3C,MAAMC,QAAQ,GAAGJ,MAAM,aAANA,MAAM,cAANA,MAAM,GAAIE,aAAa;EACxC,MAAMG,YAAY,GAAG,IAAAF,6BAAc,EAAiB,IAAI,CAAC;EACzD,MAAMG,aAAa,GAAG,IAAAH,6BAAc,EAAC,CAAC,CAAC,CAAC;EACxC,MAAMI,aAAa,GAAG,IAAAC,+BAAgB,EACpCT,MAAM,EACLU,GAAG,IAAK;IACPC,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC;IAClB,MAAM,IAAIG,KAAK,CAAE,wCAAuCH,GAAG,CAACI,OAAQ,GAAE,CAAC;EACzE,CAAC,EACD,KACF,CAAC;EACD,MAAMC,aAAa,GACjB,CAAAP,aAAa,aAAbA,aAAa,uBAAbA,aAAa,CAAEQ,oBAAoB,CAAC,CAAC,KAAIlB,sBAAsB;EAEjE,IAAAmB,+BAAgB,EAAEC,SAAoB,IAAK;IACzC,IAAI,CAACV,aAAa,EAAE;MAClBF,YAAY,CAACa,KAAK,GAAG,IAAI;MACzB;IACF;IACA,IAAId,QAAQ,CAACc,KAAK,IAAIZ,aAAa,CAACY,KAAK,KAAK,CAAC,CAAC,EAAE;MAChD;IACF;IACA,MAAM;MAAEC;IAAU,CAAC,GAAGF,SAAS;IAC/B,MAAMG,OAAO,GAAGD,SAAS,GAAGb,aAAa,CAACY,KAAK;;IAE/C;IACA,IAAIE,OAAO,GAAGN,aAAa,EAAE;MAC3B;IACF;;IAEA;IACAP,aAAa,CAACc,eAAe,CAAC,CAAC;IAC/B,IAAIhB,YAAY,CAACa,KAAK,EAAE;MACtBb,YAAY,CAACa,KAAK,CAACI,OAAO,CAAC,CAAC;IAC9B;IACAjB,YAAY,CAACa,KAAK,GAAGX,aAAa,CAACgB,eAAe,CAAC,CAAC;;IAEpD;IACAjB,aAAa,CAACY,KAAK,GAAGC,SAAS;EACjC,CAAC,CAAC;EACF,IAAAK,gBAAS,EAAC,MAAM;IACd,OAAO,MAAM;MACXjB,aAAa,aAAbA,aAAa,eAAbA,aAAa,CAAEe,OAAO,CAAC,CAAC;IAC1B,CAAC;IACD;EACF,CAAC,EAAE,EAAE,CAAC;EACN,OAAOjB,YAAY;AACrB,CAAC;AAACoB,OAAA,CAAA3B,qBAAA,GAAAA,qBAAA"}
@@ -1,6 +1,6 @@
1
1
  import type { ReactElement } from "react";
2
- import type { SkPicture, SkSize } from "../skia/types";
2
+ import type { SkPicture, SkRect, SkSize } from "../skia/types";
3
3
  export declare const isOnMainThread: () => boolean;
4
- export declare const drawAsPicture: (element: ReactElement) => SkPicture;
4
+ export declare const drawAsPicture: (element: ReactElement, bounds?: SkRect) => SkPicture;
5
5
  export declare const drawAsImage: (element: ReactElement, size: SkSize) => import("../skia").SkImage;
6
6
  export declare const drawAsImageFromPicture: (picture: SkPicture, size: SkSize) => import("../skia").SkImage;
@@ -15,9 +15,9 @@ const isOnMainThread = () => {
15
15
  return typeof _WORKLET !== "undefined" && _WORKLET === true || _Platform.Platform.OS === "web";
16
16
  };
17
17
  exports.isOnMainThread = isOnMainThread;
18
- const drawAsPicture = element => {
18
+ const drawAsPicture = (element, bounds) => {
19
19
  const recorder = _skia.Skia.PictureRecorder();
20
- const canvas = recorder.beginRecording();
20
+ const canvas = recorder.beginRecording(bounds);
21
21
  const root = new _Reconciler.SkiaRoot(_skia.Skia, false);
22
22
  root.render(element);
23
23
  const ctx = new _types.JsiDrawingContext(_skia.Skia, canvas);
@@ -1 +1 @@
1
- {"version":3,"names":["_types","require","_skia","_Platform","_Reconciler","isOnMainThread","_WORKLET","Platform","OS","exports","drawAsPicture","element","recorder","Skia","PictureRecorder","canvas","beginRecording","root","SkiaRoot","render","ctx","JsiDrawingContext","dom","picture","finishRecordingAsPicture","unmount","drawAsImage","size","drawAsImageFromPicture","pd","surface","Surface","MakeOffscreen","width","height","getCanvas","scale","drawPicture","flush","image","makeImageSnapshot","makeNonTextureImage"],"sources":["Offscreen.tsx"],"sourcesContent":["import type { ReactElement } from \"react\";\n\nimport { JsiDrawingContext } from \"../dom/types\";\nimport type { SkPicture, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\n\nimport { SkiaRoot } from \"./Reconciler\";\n\n// We call it main thread because on web main is JS thread\nexport const isOnMainThread = () => {\n \"worklet\";\n return (\n (typeof _WORKLET !== \"undefined\" && _WORKLET === true) ||\n Platform.OS === \"web\"\n );\n};\n\nexport const drawAsPicture = (element: ReactElement) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording();\n const root = new SkiaRoot(Skia, false);\n root.render(element);\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.dom.render(ctx);\n const picture = recorder.finishRecordingAsPicture();\n root.unmount();\n return picture;\n};\n\nexport const drawAsImage = (element: ReactElement, size: SkSize) => {\n return drawAsImageFromPicture(drawAsPicture(element), size);\n};\n\n// TODO: We're not sure yet why PixelRatio is not needed here.\nconst pd = 1;\nexport const drawAsImageFromPicture = (picture: SkPicture, size: SkSize) => {\n \"worklet\";\n const surface = Skia.Surface.MakeOffscreen(\n size.width * pd,\n size.height * pd\n )!;\n const canvas = surface.getCanvas();\n canvas.scale(pd, pd);\n canvas.drawPicture(picture);\n surface.flush();\n const image = surface.makeImageSnapshot();\n // If we are not on the main thread or if we are on Web, we need to make the image non-texture.\n if (!isOnMainThread() || Platform.OS === \"web\") {\n return image.makeNonTextureImage();\n } else {\n return image;\n }\n};\n"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAEA;AACO,MAAMI,cAAc,GAAGA,CAAA,KAAM;EAClC,SAAS;;EACT,OACG,OAAOC,QAAQ,KAAK,WAAW,IAAIA,QAAQ,KAAK,IAAI,IACrDC,kBAAQ,CAACC,EAAE,KAAK,KAAK;AAEzB,CAAC;AAACC,OAAA,CAAAJ,cAAA,GAAAA,cAAA;AAEK,MAAMK,aAAa,GAAIC,OAAqB,IAAK;EACtD,MAAMC,QAAQ,GAAGC,UAAI,CAACC,eAAe,CAAC,CAAC;EACvC,MAAMC,MAAM,GAAGH,QAAQ,CAACI,cAAc,CAAC,CAAC;EACxC,MAAMC,IAAI,GAAG,IAAIC,oBAAQ,CAACL,UAAI,EAAE,KAAK,CAAC;EACtCI,IAAI,CAACE,MAAM,CAACR,OAAO,CAAC;EACpB,MAAMS,GAAG,GAAG,IAAIC,wBAAiB,CAACR,UAAI,EAAEE,MAAM,CAAC;EAC/CE,IAAI,CAACK,GAAG,CAACH,MAAM,CAACC,GAAG,CAAC;EACpB,MAAMG,OAAO,GAAGX,QAAQ,CAACY,wBAAwB,CAAC,CAAC;EACnDP,IAAI,CAACQ,OAAO,CAAC,CAAC;EACd,OAAOF,OAAO;AAChB,CAAC;AAACd,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAEK,MAAMgB,WAAW,GAAGA,CAACf,OAAqB,EAAEgB,IAAY,KAAK;EAClE,OAAOC,sBAAsB,CAAClB,aAAa,CAACC,OAAO,CAAC,EAAEgB,IAAI,CAAC;AAC7D,CAAC;;AAED;AAAAlB,OAAA,CAAAiB,WAAA,GAAAA,WAAA;AACA,MAAMG,EAAE,GAAG,CAAC;AACL,MAAMD,sBAAsB,GAAGA,CAACL,OAAkB,EAAEI,IAAY,KAAK;EAC1E,SAAS;;EACT,MAAMG,OAAO,GAAGjB,UAAI,CAACkB,OAAO,CAACC,aAAa,CACxCL,IAAI,CAACM,KAAK,GAAGJ,EAAE,EACfF,IAAI,CAACO,MAAM,GAAGL,EAChB,CAAE;EACF,MAAMd,MAAM,GAAGe,OAAO,CAACK,SAAS,CAAC,CAAC;EAClCpB,MAAM,CAACqB,KAAK,CAACP,EAAE,EAAEA,EAAE,CAAC;EACpBd,MAAM,CAACsB,WAAW,CAACd,OAAO,CAAC;EAC3BO,OAAO,CAACQ,KAAK,CAAC,CAAC;EACf,MAAMC,KAAK,GAAGT,OAAO,CAACU,iBAAiB,CAAC,CAAC;EACzC;EACA,IAAI,CAACnC,cAAc,CAAC,CAAC,IAAIE,kBAAQ,CAACC,EAAE,KAAK,KAAK,EAAE;IAC9C,OAAO+B,KAAK,CAACE,mBAAmB,CAAC,CAAC;EACpC,CAAC,MAAM;IACL,OAAOF,KAAK;EACd;AACF,CAAC;AAAC9B,OAAA,CAAAmB,sBAAA,GAAAA,sBAAA"}
1
+ {"version":3,"names":["_types","require","_skia","_Platform","_Reconciler","isOnMainThread","_WORKLET","Platform","OS","exports","drawAsPicture","element","bounds","recorder","Skia","PictureRecorder","canvas","beginRecording","root","SkiaRoot","render","ctx","JsiDrawingContext","dom","picture","finishRecordingAsPicture","unmount","drawAsImage","size","drawAsImageFromPicture","pd","surface","Surface","MakeOffscreen","width","height","getCanvas","scale","drawPicture","flush","image","makeImageSnapshot","makeNonTextureImage"],"sources":["Offscreen.tsx"],"sourcesContent":["import type { ReactElement } from \"react\";\n\nimport { JsiDrawingContext } from \"../dom/types\";\nimport type { SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\n\nimport { SkiaRoot } from \"./Reconciler\";\n\n// We call it main thread because on web main is JS thread\nexport const isOnMainThread = () => {\n \"worklet\";\n return (\n (typeof _WORKLET !== \"undefined\" && _WORKLET === true) ||\n Platform.OS === \"web\"\n );\n};\n\nexport const drawAsPicture = (element: ReactElement, bounds?: SkRect) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(bounds);\n const root = new SkiaRoot(Skia, false);\n root.render(element);\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.dom.render(ctx);\n const picture = recorder.finishRecordingAsPicture();\n root.unmount();\n return picture;\n};\n\nexport const drawAsImage = (element: ReactElement, size: SkSize) => {\n return drawAsImageFromPicture(drawAsPicture(element), size);\n};\n\n// TODO: We're not sure yet why PixelRatio is not needed here.\nconst pd = 1;\nexport const drawAsImageFromPicture = (picture: SkPicture, size: SkSize) => {\n \"worklet\";\n const surface = Skia.Surface.MakeOffscreen(\n size.width * pd,\n size.height * pd\n )!;\n const canvas = surface.getCanvas();\n canvas.scale(pd, pd);\n canvas.drawPicture(picture);\n surface.flush();\n const image = surface.makeImageSnapshot();\n // If we are not on the main thread or if we are on Web, we need to make the image non-texture.\n if (!isOnMainThread() || Platform.OS === \"web\") {\n return image.makeNonTextureImage();\n } else {\n return image;\n }\n};\n"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAEA;AACO,MAAMI,cAAc,GAAGA,CAAA,KAAM;EAClC,SAAS;;EACT,OACG,OAAOC,QAAQ,KAAK,WAAW,IAAIA,QAAQ,KAAK,IAAI,IACrDC,kBAAQ,CAACC,EAAE,KAAK,KAAK;AAEzB,CAAC;AAACC,OAAA,CAAAJ,cAAA,GAAAA,cAAA;AAEK,MAAMK,aAAa,GAAGA,CAACC,OAAqB,EAAEC,MAAe,KAAK;EACvE,MAAMC,QAAQ,GAAGC,UAAI,CAACC,eAAe,CAAC,CAAC;EACvC,MAAMC,MAAM,GAAGH,QAAQ,CAACI,cAAc,CAACL,MAAM,CAAC;EAC9C,MAAMM,IAAI,GAAG,IAAIC,oBAAQ,CAACL,UAAI,EAAE,KAAK,CAAC;EACtCI,IAAI,CAACE,MAAM,CAACT,OAAO,CAAC;EACpB,MAAMU,GAAG,GAAG,IAAIC,wBAAiB,CAACR,UAAI,EAAEE,MAAM,CAAC;EAC/CE,IAAI,CAACK,GAAG,CAACH,MAAM,CAACC,GAAG,CAAC;EACpB,MAAMG,OAAO,GAAGX,QAAQ,CAACY,wBAAwB,CAAC,CAAC;EACnDP,IAAI,CAACQ,OAAO,CAAC,CAAC;EACd,OAAOF,OAAO;AAChB,CAAC;AAACf,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAEK,MAAMiB,WAAW,GAAGA,CAAChB,OAAqB,EAAEiB,IAAY,KAAK;EAClE,OAAOC,sBAAsB,CAACnB,aAAa,CAACC,OAAO,CAAC,EAAEiB,IAAI,CAAC;AAC7D,CAAC;;AAED;AAAAnB,OAAA,CAAAkB,WAAA,GAAAA,WAAA;AACA,MAAMG,EAAE,GAAG,CAAC;AACL,MAAMD,sBAAsB,GAAGA,CAACL,OAAkB,EAAEI,IAAY,KAAK;EAC1E,SAAS;;EACT,MAAMG,OAAO,GAAGjB,UAAI,CAACkB,OAAO,CAACC,aAAa,CACxCL,IAAI,CAACM,KAAK,GAAGJ,EAAE,EACfF,IAAI,CAACO,MAAM,GAAGL,EAChB,CAAE;EACF,MAAMd,MAAM,GAAGe,OAAO,CAACK,SAAS,CAAC,CAAC;EAClCpB,MAAM,CAACqB,KAAK,CAACP,EAAE,EAAEA,EAAE,CAAC;EACpBd,MAAM,CAACsB,WAAW,CAACd,OAAO,CAAC;EAC3BO,OAAO,CAACQ,KAAK,CAAC,CAAC;EACf,MAAMC,KAAK,GAAGT,OAAO,CAACU,iBAAiB,CAAC,CAAC;EACzC;EACA,IAAI,CAACpC,cAAc,CAAC,CAAC,IAAIE,kBAAQ,CAACC,EAAE,KAAK,KAAK,EAAE;IAC9C,OAAOgC,KAAK,CAACE,mBAAmB,CAAC,CAAC;EACpC,CAAC,MAAM;IACL,OAAOF,KAAK;EACd;AACF,CAAC;AAAC/B,OAAA,CAAAoB,sBAAA,GAAAA,sBAAA"}
@@ -1,4 +1,5 @@
1
1
  import type { SkData } from "../Data";
2
+ import type { NativeBuffer } from "../NativeBuffer";
2
3
  import type { SkImage } from "./Image";
3
4
  export declare enum AlphaType {
4
5
  Unknown = 0,
@@ -23,16 +24,7 @@ export declare enum ColorType {
23
24
  Gray_8 = 13,
24
25
  RGBA_F16Norm = 14,
25
26
  RGBA_F16 = 15,
26
- RGBA_F32 = 16,
27
- R8G8_unorm = 17,
28
- A16_float = 18,
29
- R16G16_float = 19,
30
- A16_unorm = 20,
31
- R16G16_unorm = 21,
32
- R16G16B16A16_unorm = 22,
33
- SRGBA_8888 = 23,
34
- R8_unorm = 24,
35
- N32_SkColorType = 25
27
+ RGBA_F32 = 16
36
28
  }
37
29
  export interface ImageInfo {
38
30
  alphaType: AlphaType;
@@ -52,6 +44,21 @@ export interface ImageFactory {
52
44
  * image, nullptr is returned.
53
45
  */
54
46
  MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
47
+ /**
48
+ * Return an Image backed by a given native buffer.
49
+ * The platform buffer must be a valid owning reference.
50
+ *
51
+ * For instance, this API is used by
52
+ * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
53
+ * to render a Skia Camera preview.
54
+ *
55
+ * - On Android; This is an `AHardwareBuffer*`
56
+ * - On iOS, this is a `CVPixelBufferRef`
57
+ * @param nativeBuffer A strong `uintptr_t` pointer to the native platform buffer
58
+ * @throws Throws an error if the Image could not be created, for example when the given
59
+ * platform buffer is invalid.
60
+ */
61
+ MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;
55
62
  /**
56
63
  * Returns an image that will be a screenshot of the view represented by
57
64
  * the view tag
@@ -29,15 +29,6 @@ let ColorType = exports.ColorType = /*#__PURE__*/function (ColorType) {
29
29
  ColorType[ColorType["RGBA_F16Norm"] = 14] = "RGBA_F16Norm";
30
30
  ColorType[ColorType["RGBA_F16"] = 15] = "RGBA_F16";
31
31
  ColorType[ColorType["RGBA_F32"] = 16] = "RGBA_F32";
32
- ColorType[ColorType["R8G8_unorm"] = 17] = "R8G8_unorm";
33
- ColorType[ColorType["A16_float"] = 18] = "A16_float";
34
- ColorType[ColorType["R16G16_float"] = 19] = "R16G16_float";
35
- ColorType[ColorType["A16_unorm"] = 20] = "A16_unorm";
36
- ColorType[ColorType["R16G16_unorm"] = 21] = "R16G16_unorm";
37
- ColorType[ColorType["R16G16B16A16_unorm"] = 22] = "R16G16B16A16_unorm";
38
- ColorType[ColorType["SRGBA_8888"] = 23] = "SRGBA_8888";
39
- ColorType[ColorType["R8_unorm"] = 24] = "R8_unorm";
40
- ColorType[ColorType["N32_SkColorType"] = 25] = "N32_SkColorType";
41
32
  return ColorType;
42
- }({}); // either BGRA_8888 or RGBA_8888 based on the platform
33
+ }({}); // pixel using C float for red, green, blue, alpha; in 128-bit word
43
34
  //# sourceMappingURL=ImageFactory.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["AlphaType","exports","ColorType"],"sources":["ImageFactory.ts"],"sourcesContent":["import type { SkData } from \"../Data\";\n\nimport type { SkImage } from \"./Image\";\n\nexport enum AlphaType {\n Unknown,\n Opaque,\n Premul,\n Unpremul,\n}\n\nexport enum ColorType {\n Unknown, // uninitialized\n Alpha_8, // pixel with alpha in 8-bit byte\n RGB_565, // pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word\n ARGB_4444, // pixel with 4 bits for alpha, red, green, blue; in 16-bit word\n RGBA_8888, // pixel with 8 bits for red, green, blue, alpha; in 32-bit word\n RGB_888x, // pixel with 8 bits each for red, green, blue; in 32-bit word\n BGRA_8888, // pixel with 8 bits for blue, green, red, alpha; in 32-bit word\n RGBA_1010102, // 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word\n BGRA_1010102, // 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word\n RGB_101010x, // pixel with 10 bits each for red, green, blue; in 32-bit word\n BGR_101010x, // pixel with 10 bits each for blue, green, red; in 32-bit word\n BGR_101010x_XR, // pixel with 10 bits each for blue, green, red; in 32-bit word, extended range\n RGBA_10x6, // pixel with 10 used bits (most significant) followed by 6 unused\n Gray_8, // pixel with grayscale level in 8-bit byte\n RGBA_F16Norm, // pixel with half floats in [0,1] for red, green, blue, alpha; in 64-bit word\n RGBA_F16, // pixel with half floats for red, green, blue, alpha; in 64-bit word\n RGBA_F32, // pixel using C float for red, green, blue, alpha; in 128-bit word\n\n // The following 6 colortypes are just for reading from - not for rendering to\n R8G8_unorm, // pixel with a uint8_t for red and green\n\n A16_float, // pixel with a half float for alpha\n R16G16_float, // pixel with a half float for red and green\n\n A16_unorm, // pixel with a little endian uint16_t for alpha\n R16G16_unorm, // pixel with a little endian uint16_t for red and green\n R16G16B16A16_unorm, // pixel with a little endian uint16_t for red, green, blue, and alpha\n\n SRGBA_8888,\n R8_unorm,\n\n // The `kN32_SkColorType` is platform dependent in the original enum,\n // and TypeScript doesn't support conditional compilation natively.\n // You might need to handle it differently based on your use case.\n N32_SkColorType, // either BGRA_8888 or RGBA_8888 based on the platform\n}\n\nexport interface ImageInfo {\n alphaType: AlphaType;\n // TODO: add support for color space\n // colorSpace: ColorSpace;\n colorType: ColorType;\n height: number;\n width: number;\n}\n\nexport interface ImageFactory {\n /**\n * Return an Image backed by the encoded data, but attempt to defer decoding until the image\n * is actually used/drawn. This deferral allows the system to cache the result, either on the\n * CPU or on the GPU, depending on where the image is drawn.\n * This decoding uses the codecs that have been compiled into CanvasKit. If the bytes are\n * invalid (or an unrecognized codec), null will be returned. See Image.h for more details.\n * @param data - Data object with bytes of data\n * @returns If the encoded format is not supported, or subset is outside of the bounds of the decoded\n * image, nullptr is returned.\n */\n MakeImageFromEncoded: (encoded: SkData) => SkImage | null;\n\n /**\n * Returns an image that will be a screenshot of the view represented by\n * the view tag\n * @param viewTag - The tag of the view to make an image from.\n * @returns Returns a valid SkImage, if the view tag is invalid, nullptr is returned.\n */\n MakeImageFromViewTag: (viewTag: number) => Promise<SkImage | null>;\n\n /**\n * Returns an image with the given pixel data and format.\n * Note that we will always make a copy of the pixel data, because of inconsistencies in\n * behavior between GPU and CPU (i.e. the pixel data will be turned into a GPU texture and\n * not modifiable after creation).\n *\n * @param info\n * @param data - bytes representing the pixel data.\n * @param bytesPerRow\n */\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): SkImage | null;\n}\n"],"mappings":";;;;;;IAIYA,SAAS,GAAAC,OAAA,CAAAD,SAAA,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA;AAAA,IAOTE,SAAS,GAAAD,OAAA,CAAAC,SAAA,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA,OAmCF"}
1
+ {"version":3,"names":["AlphaType","exports","ColorType"],"sources":["ImageFactory.ts"],"sourcesContent":["import type { SkData } from \"../Data\";\nimport type { NativeBuffer } from \"../NativeBuffer\";\n\nimport type { SkImage } from \"./Image\";\n\nexport enum AlphaType {\n Unknown,\n Opaque,\n Premul,\n Unpremul,\n}\n\nexport enum ColorType {\n Unknown, // uninitialized\n Alpha_8, // pixel with alpha in 8-bit byte\n RGB_565, // pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word\n ARGB_4444, // pixel with 4 bits for alpha, red, green, blue; in 16-bit word\n RGBA_8888, // pixel with 8 bits for red, green, blue, alpha; in 32-bit word\n RGB_888x, // pixel with 8 bits each for red, green, blue; in 32-bit word\n BGRA_8888, // pixel with 8 bits for blue, green, red, alpha; in 32-bit word\n RGBA_1010102, // 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word\n BGRA_1010102, // 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word\n RGB_101010x, // pixel with 10 bits each for red, green, blue; in 32-bit word\n BGR_101010x, // pixel with 10 bits each for blue, green, red; in 32-bit word\n BGR_101010x_XR, // pixel with 10 bits each for blue, green, red; in 32-bit word, extended range\n RGBA_10x6, // pixel with 10 used bits (most significant) followed by 6 unused\n Gray_8, // pixel with grayscale level in 8-bit byte\n RGBA_F16Norm, // pixel with half floats in [0,1] for red, green, blue, alpha; in 64-bit word\n RGBA_F16, // pixel with half floats for red, green, blue, alpha; in 64-bit word\n RGBA_F32, // pixel using C float for red, green, blue, alpha; in 128-bit word\n}\n\nexport interface ImageInfo {\n alphaType: AlphaType;\n // TODO: add support for color space\n // colorSpace: ColorSpace;\n colorType: ColorType;\n height: number;\n width: number;\n}\n\nexport interface ImageFactory {\n /**\n * Return an Image backed by the encoded data, but attempt to defer decoding until the image\n * is actually used/drawn. This deferral allows the system to cache the result, either on the\n * CPU or on the GPU, depending on where the image is drawn.\n * This decoding uses the codecs that have been compiled into CanvasKit. If the bytes are\n * invalid (or an unrecognized codec), null will be returned. See Image.h for more details.\n * @param data - Data object with bytes of data\n * @returns If the encoded format is not supported, or subset is outside of the bounds of the decoded\n * image, nullptr is returned.\n */\n MakeImageFromEncoded: (encoded: SkData) => SkImage | null;\n\n /**\n * Return an Image backed by a given native buffer.\n * The platform buffer must be a valid owning reference.\n *\n * For instance, this API is used by\n * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)\n * to render a Skia Camera preview.\n *\n * - On Android; This is an `AHardwareBuffer*`\n * - On iOS, this is a `CVPixelBufferRef`\n * @param nativeBuffer A strong `uintptr_t` pointer to the native platform buffer\n * @throws Throws an error if the Image could not be created, for example when the given\n * platform buffer is invalid.\n */\n MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;\n\n /**\n * Returns an image that will be a screenshot of the view represented by\n * the view tag\n * @param viewTag - The tag of the view to make an image from.\n * @returns Returns a valid SkImage, if the view tag is invalid, nullptr is returned.\n */\n MakeImageFromViewTag: (viewTag: number) => Promise<SkImage | null>;\n\n /**\n * Returns an image with the given pixel data and format.\n * Note that we will always make a copy of the pixel data, because of inconsistencies in\n * behavior between GPU and CPU (i.e. the pixel data will be turned into a GPU texture and\n * not modifiable after creation).\n *\n * @param info\n * @param data - bytes representing the pixel data.\n * @param bytesPerRow\n */\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): SkImage | null;\n}\n"],"mappings":";;;;;;IAKYA,SAAS,GAAAC,OAAA,CAAAD,SAAA,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA;AAAA,IAOTE,SAAS,GAAAD,OAAA,CAAAC,SAAA,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA,OAiBT"}
@@ -0,0 +1,18 @@
1
+ import type { SkImage } from "../Image";
2
+ export type NativeBuffer<T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown> = T;
3
+ export type NativeBufferAddr = NativeBuffer<bigint>;
4
+ export type NativeBufferWeb = NativeBuffer<CanvasImageSource>;
5
+ export type NativeBufferNode = NativeBuffer<ArrayBuffer>;
6
+ export declare const isNativeBufferAddr: (buffer: NativeBuffer) => buffer is bigint;
7
+ export declare const isNativeBufferWeb: (buffer: NativeBuffer) => buffer is CanvasImageSource;
8
+ export declare const isNativeBufferNode: (buffer: NativeBuffer) => buffer is ArrayBuffer;
9
+ export interface NativeBufferFactory {
10
+ /**
11
+ * Copy pixels to a platform buffer. (for testing purposes)
12
+ */
13
+ MakeFromImage: (image: SkImage) => NativeBuffer;
14
+ /**
15
+ * Release a platform buffer that was created with `MakeFromImage`.
16
+ */
17
+ Release: (platformBuffer: NativeBuffer) => void;
18
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isNativeBufferWeb = exports.isNativeBufferNode = exports.isNativeBufferAddr = void 0;
7
+ const isNativeBufferAddr = buffer => buffer instanceof BigInt;
8
+ exports.isNativeBufferAddr = isNativeBufferAddr;
9
+ const isNativeBufferWeb = buffer => buffer instanceof HTMLVideoElement || buffer instanceof HTMLCanvasElement || buffer instanceof ImageBitmap || buffer instanceof OffscreenCanvas || buffer instanceof VideoFrame || buffer instanceof HTMLImageElement || buffer instanceof SVGImageElement;
10
+ exports.isNativeBufferWeb = isNativeBufferWeb;
11
+ const isNativeBufferNode = buffer => buffer instanceof ArrayBuffer;
12
+ exports.isNativeBufferNode = isNativeBufferNode;
13
+ //# sourceMappingURL=NativeBufferFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isNativeBufferAddr","buffer","BigInt","exports","isNativeBufferWeb","HTMLVideoElement","HTMLCanvasElement","ImageBitmap","OffscreenCanvas","VideoFrame","HTMLImageElement","SVGImageElement","isNativeBufferNode","ArrayBuffer"],"sources":["NativeBufferFactory.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\n\nexport type NativeBuffer<\n T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown\n> = T;\n\nexport type NativeBufferAddr = NativeBuffer<bigint>;\nexport type NativeBufferWeb = NativeBuffer<CanvasImageSource>;\nexport type NativeBufferNode = NativeBuffer<ArrayBuffer>;\n\nexport const isNativeBufferAddr = (\n buffer: NativeBuffer\n): buffer is NativeBufferAddr => buffer instanceof BigInt;\nexport const isNativeBufferWeb = (\n buffer: NativeBuffer\n): buffer is NativeBufferWeb =>\n buffer instanceof HTMLVideoElement ||\n buffer instanceof HTMLCanvasElement ||\n buffer instanceof ImageBitmap ||\n buffer instanceof OffscreenCanvas ||\n buffer instanceof VideoFrame ||\n buffer instanceof HTMLImageElement ||\n buffer instanceof SVGImageElement;\n\nexport const isNativeBufferNode = (\n buffer: NativeBuffer\n): buffer is NativeBufferNode => buffer instanceof ArrayBuffer;\n\nexport interface NativeBufferFactory {\n /**\n * Copy pixels to a platform buffer. (for testing purposes)\n */\n MakeFromImage: (image: SkImage) => NativeBuffer;\n /**\n * Release a platform buffer that was created with `MakeFromImage`.\n */\n Release: (platformBuffer: NativeBuffer) => void;\n}\n"],"mappings":";;;;;;AAUO,MAAMA,kBAAkB,GAC7BC,MAAoB,IACWA,MAAM,YAAYC,MAAM;AAACC,OAAA,CAAAH,kBAAA,GAAAA,kBAAA;AACnD,MAAMI,iBAAiB,GAC5BH,MAAoB,IAEpBA,MAAM,YAAYI,gBAAgB,IAClCJ,MAAM,YAAYK,iBAAiB,IACnCL,MAAM,YAAYM,WAAW,IAC7BN,MAAM,YAAYO,eAAe,IACjCP,MAAM,YAAYQ,UAAU,IAC5BR,MAAM,YAAYS,gBAAgB,IAClCT,MAAM,YAAYU,eAAe;AAACR,OAAA,CAAAC,iBAAA,GAAAA,iBAAA;AAE7B,MAAMQ,kBAAkB,GAC7BX,MAAoB,IACWA,MAAM,YAAYY,WAAW;AAACV,OAAA,CAAAS,kBAAA,GAAAA,kBAAA"}
@@ -0,0 +1 @@
1
+ export * from "./NativeBufferFactory";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _NativeBufferFactory = require("./NativeBufferFactory");
7
+ Object.keys(_NativeBufferFactory).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _NativeBufferFactory[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _NativeBufferFactory[key];
14
+ }
15
+ });
16
+ });
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_NativeBufferFactory","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["index.ts"],"sourcesContent":["export * from \"./NativeBufferFactory\";\n"],"mappings":";;;;;AAAA,IAAAA,oBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,oBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,oBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,oBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA"}
@@ -26,6 +26,7 @@ import type { Color, SkColor } from "./Color";
26
26
  import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
27
27
  import type { AnimatedImageFactory } from "./AnimatedImage";
28
28
  import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
29
+ import type { NativeBufferFactory } from "./NativeBuffer";
29
30
  /**
30
31
  * Declares the interface for the native Skia API
31
32
  */
@@ -71,4 +72,5 @@ export interface Skia {
71
72
  TextBlob: TextBlobFactory;
72
73
  Surface: SurfaceFactory;
73
74
  ParagraphBuilder: ParagraphBuilderFactory;
75
+ NativeBuffer: NativeBufferFactory;
74
76
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["Skia.ts"],"sourcesContent":["import type { ImageFilterFactory } from \"./ImageFilter\";\nimport type { PathFactory } from \"./Path\";\nimport type { ColorFilterFactory } from \"./ColorFilter\";\nimport type { SkFont, FontMgrFactory } from \"./Font\";\nimport type { SkTypeface, TypefaceFactory } from \"./Typeface\";\nimport type { ImageFactory } from \"./Image\";\nimport type { MaskFilterFactory } from \"./MaskFilter\";\nimport type { SkPaint } from \"./Paint\";\nimport type { SkHostRect, SkRect } from \"./Rect\";\nimport type { SkRRect } from \"./RRect\";\nimport type {\n RuntimeEffectFactory,\n SkRuntimeEffect,\n SkRuntimeShaderBuilder,\n} from \"./RuntimeEffect\";\nimport type { ShaderFactory } from \"./Shader\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { PathEffectFactory } from \"./PathEffect\";\nimport type { SkPoint } from \"./Point\";\nimport type { SkVertices, VertexMode } from \"./Vertices/Vertices\";\nimport type { DataFactory } from \"./Data\";\nimport type { SVGFactory } from \"./SVG\";\nimport type { TextBlobFactory } from \"./TextBlob\";\nimport type { SurfaceFactory } from \"./Surface\";\nimport type { SkRSXform } from \"./RSXform\";\nimport type { SkPath } from \"./Path/Path\";\nimport type { SkContourMeasureIter } from \"./ContourMeasure\";\nimport type { PictureFactory, SkPictureRecorder } from \"./Picture\";\nimport type { Color, SkColor } from \"./Color\";\nimport type { TypefaceFontProviderFactory } from \"./Paragraph/TypefaceFontProviderFactory\";\nimport type { AnimatedImageFactory } from \"./AnimatedImage\";\nimport type { ParagraphBuilderFactory } from \"./Paragraph/ParagraphBuilder\";\n\n/**\n * Declares the interface for the native Skia API\n */\nexport interface Skia {\n Point: (x: number, y: number) => SkPoint;\n XYWHRect: (x: number, y: number, width: number, height: number) => SkHostRect;\n RuntimeShaderBuilder: (rt: SkRuntimeEffect) => SkRuntimeShaderBuilder;\n RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;\n RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;\n RSXformFromRadians: (\n scale: number,\n radians: number,\n tx: number,\n ty: number,\n px: number,\n py: number\n ) => SkRSXform;\n Color: (color: Color) => SkColor;\n ContourMeasureIter: (\n path: SkPath,\n forceClosed: boolean,\n resScale: number\n ) => SkContourMeasureIter;\n Paint: () => SkPaint;\n PictureRecorder: () => SkPictureRecorder;\n Picture: PictureFactory;\n Path: PathFactory;\n Matrix: (matrix?: readonly number[]) => SkMatrix;\n ColorFilter: ColorFilterFactory;\n Font: (typeface?: SkTypeface, size?: number) => SkFont;\n Typeface: TypefaceFactory;\n TypefaceFontProvider: TypefaceFontProviderFactory;\n FontMgr: FontMgrFactory;\n MaskFilter: MaskFilterFactory;\n RuntimeEffect: RuntimeEffectFactory;\n ImageFilter: ImageFilterFactory;\n Shader: ShaderFactory;\n PathEffect: PathEffectFactory;\n /**\n * Returns an Vertices based on the given positions and optional parameters.\n * See SkVertices.h (especially the Builder) for more details.\n * @param mode\n * @param positions\n * @param textureCoordinates\n * @param colors - either a list of int colors or a flattened color array.\n * @param indices\n * @param isVolatile\n */\n MakeVertices(\n mode: VertexMode,\n positions: SkPoint[],\n textureCoordinates?: SkPoint[] | null,\n colors?: SkColor[],\n indices?: number[] | null,\n isVolatile?: boolean\n ): SkVertices;\n Data: DataFactory;\n Image: ImageFactory;\n AnimatedImage: AnimatedImageFactory;\n SVG: SVGFactory;\n TextBlob: TextBlobFactory;\n Surface: SurfaceFactory;\n // Paragraph\n ParagraphBuilder: ParagraphBuilderFactory;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["Skia.ts"],"sourcesContent":["import type { ImageFilterFactory } from \"./ImageFilter\";\nimport type { PathFactory } from \"./Path\";\nimport type { ColorFilterFactory } from \"./ColorFilter\";\nimport type { SkFont, FontMgrFactory } from \"./Font\";\nimport type { SkTypeface, TypefaceFactory } from \"./Typeface\";\nimport type { ImageFactory } from \"./Image\";\nimport type { MaskFilterFactory } from \"./MaskFilter\";\nimport type { SkPaint } from \"./Paint\";\nimport type { SkHostRect, SkRect } from \"./Rect\";\nimport type { SkRRect } from \"./RRect\";\nimport type {\n RuntimeEffectFactory,\n SkRuntimeEffect,\n SkRuntimeShaderBuilder,\n} from \"./RuntimeEffect\";\nimport type { ShaderFactory } from \"./Shader\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { PathEffectFactory } from \"./PathEffect\";\nimport type { SkPoint } from \"./Point\";\nimport type { SkVertices, VertexMode } from \"./Vertices/Vertices\";\nimport type { DataFactory } from \"./Data\";\nimport type { SVGFactory } from \"./SVG\";\nimport type { TextBlobFactory } from \"./TextBlob\";\nimport type { SurfaceFactory } from \"./Surface\";\nimport type { SkRSXform } from \"./RSXform\";\nimport type { SkPath } from \"./Path/Path\";\nimport type { SkContourMeasureIter } from \"./ContourMeasure\";\nimport type { PictureFactory, SkPictureRecorder } from \"./Picture\";\nimport type { Color, SkColor } from \"./Color\";\nimport type { TypefaceFontProviderFactory } from \"./Paragraph/TypefaceFontProviderFactory\";\nimport type { AnimatedImageFactory } from \"./AnimatedImage\";\nimport type { ParagraphBuilderFactory } from \"./Paragraph/ParagraphBuilder\";\nimport type { NativeBufferFactory } from \"./NativeBuffer\";\n\n/**\n * Declares the interface for the native Skia API\n */\nexport interface Skia {\n Point: (x: number, y: number) => SkPoint;\n XYWHRect: (x: number, y: number, width: number, height: number) => SkHostRect;\n RuntimeShaderBuilder: (rt: SkRuntimeEffect) => SkRuntimeShaderBuilder;\n RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;\n RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;\n RSXformFromRadians: (\n scale: number,\n radians: number,\n tx: number,\n ty: number,\n px: number,\n py: number\n ) => SkRSXform;\n Color: (color: Color) => SkColor;\n ContourMeasureIter: (\n path: SkPath,\n forceClosed: boolean,\n resScale: number\n ) => SkContourMeasureIter;\n Paint: () => SkPaint;\n PictureRecorder: () => SkPictureRecorder;\n Picture: PictureFactory;\n Path: PathFactory;\n Matrix: (matrix?: readonly number[]) => SkMatrix;\n ColorFilter: ColorFilterFactory;\n Font: (typeface?: SkTypeface, size?: number) => SkFont;\n Typeface: TypefaceFactory;\n TypefaceFontProvider: TypefaceFontProviderFactory;\n FontMgr: FontMgrFactory;\n MaskFilter: MaskFilterFactory;\n RuntimeEffect: RuntimeEffectFactory;\n ImageFilter: ImageFilterFactory;\n Shader: ShaderFactory;\n PathEffect: PathEffectFactory;\n /**\n * Returns an Vertices based on the given positions and optional parameters.\n * See SkVertices.h (especially the Builder) for more details.\n * @param mode\n * @param positions\n * @param textureCoordinates\n * @param colors - either a list of int colors or a flattened color array.\n * @param indices\n * @param isVolatile\n */\n MakeVertices(\n mode: VertexMode,\n positions: SkPoint[],\n textureCoordinates?: SkPoint[] | null,\n colors?: SkColor[],\n indices?: number[] | null,\n isVolatile?: boolean\n ): SkVertices;\n Data: DataFactory;\n Image: ImageFactory;\n AnimatedImage: AnimatedImageFactory;\n SVG: SVGFactory;\n TextBlob: TextBlobFactory;\n Surface: SurfaceFactory;\n ParagraphBuilder: ParagraphBuilderFactory;\n NativeBuffer: NativeBufferFactory;\n}\n"],"mappings":""}
@@ -26,4 +26,12 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
26
26
  * Make sure any queued draws are sent to the screen or the GPU.
27
27
  */
28
28
  flush(): void;
29
+ /**
30
+ * Returns the possibly scaled width of the surface.
31
+ */
32
+ width(): number;
33
+ /**
34
+ * Returns the possibly scaled height of the surface.
35
+ */
36
+ height(): number;
29
37
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["Surface.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\nimport type { SkCanvas } from \"../Canvas\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\nimport type { SkRect } from \"../Rect\";\n\nexport interface SkSurface extends SkJSIInstance<\"Surface\"> {\n /** Returns Canvas that draws into the surface. Subsequent calls return the\n same Canvas. Canvas returned is managed and owned by Surface, and is\n deleted when Surface is deleted.\n\n @return drawing Canvas for Surface\n\n example: https://fiddle.skia.org/c/@Surface_getCanvas\n */\n getCanvas(): SkCanvas;\n\n /** Returns Image capturing Surface contents. Subsequent drawing to\n Surface contents are not captured.\n\n @param bounds A rectangle specifying the subset of the surface that\n is of interest.\n @return Image initialized with Surface contents\n\n example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot\n */\n makeImageSnapshot(bounds?: SkRect): SkImage;\n\n /**\n * Make sure any queued draws are sent to the screen or the GPU.\n */\n flush(): void;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["Surface.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\nimport type { SkCanvas } from \"../Canvas\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\nimport type { SkRect } from \"../Rect\";\n\nexport interface SkSurface extends SkJSIInstance<\"Surface\"> {\n /** Returns Canvas that draws into the surface. Subsequent calls return the\n same Canvas. Canvas returned is managed and owned by Surface, and is\n deleted when Surface is deleted.\n\n @return drawing Canvas for Surface\n\n example: https://fiddle.skia.org/c/@Surface_getCanvas\n */\n getCanvas(): SkCanvas;\n\n /** Returns Image capturing Surface contents. Subsequent drawing to\n Surface contents are not captured.\n\n @param bounds A rectangle specifying the subset of the surface that\n is of interest.\n @return Image initialized with Surface contents\n\n example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot\n */\n makeImageSnapshot(bounds?: SkRect): SkImage;\n\n /**\n * Make sure any queued draws are sent to the screen or the GPU.\n */\n flush(): void;\n\n /**\n * Returns the possibly scaled width of the surface.\n */\n width(): number;\n\n /**\n * Returns the possibly scaled height of the surface.\n */\n height(): number;\n}\n"],"mappings":""}
@@ -29,3 +29,4 @@ export * from "./TextBlob";
29
29
  export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
+ export * from "./NativeBuffer";