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
@@ -60,8 +60,6 @@ add_library(
60
60
 
61
61
  "${PROJECT_SOURCE_DIR}/cpp/jni/JniPlatformContext.cpp"
62
62
  "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkAndroidCanvasProvider.cpp"
63
- "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/AHardwareBufferUtils.cpp"
64
- "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkAndroidVideo.cpp"
65
63
 
66
64
  "${PROJECT_SOURCE_DIR}/../cpp/jsi/JSICache.cpp"
67
65
  "${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiPromises.cpp"
@@ -73,30 +73,6 @@ TSelf JniPlatformContext::initHybrid(jni::alias_ref<jhybridobject> jThis,
73
73
  return makeCxxInstance(jThis, pixelDensity);
74
74
  }
75
75
 
76
- jni::global_ref<jobject>
77
- JniPlatformContext::createVideo(const std::string &url) {
78
- jni::Environment::ensureCurrentThreadIsAttached();
79
-
80
- jni::ThreadScope ts; // Manages JNI thread attachment/detachment
81
-
82
- // Get the JNI environment
83
- JNIEnv *env = facebook::jni::Environment::current();
84
-
85
- // Convert std::string to jstring
86
- jstring jUrl = env->NewStringUTF(url.c_str());
87
-
88
- static auto method =
89
- javaPart_->getClass()->getMethod<jobject(jstring)>("createVideo");
90
-
91
- // Call the method and receive a local reference to the video object
92
- auto videoObject = method(javaPart_.get(), jUrl);
93
- env->DeleteLocalRef(jUrl);
94
-
95
- // Clean up the jstring local reference
96
- auto result = jni::make_global(videoObject);
97
- return result;
98
- }
99
-
100
76
  sk_sp<SkImage> JniPlatformContext::takeScreenshotFromViewTag(size_t tag) {
101
77
  // Call the java method for creating a view screenshot as a bitmap:
102
78
  auto env = jni::Environment::current();
@@ -44,8 +44,6 @@ public:
44
44
 
45
45
  sk_sp<SkImage> takeScreenshotFromViewTag(size_t tag);
46
46
 
47
- jni::global_ref<jobject> createVideo(const std::string &url);
48
-
49
47
  private:
50
48
  friend HybridBase;
51
49
  jni::global_ref<JniPlatformContext::javaobject> javaPart_;
@@ -1,10 +1,5 @@
1
1
  #pragma once
2
2
 
3
- #if __ANDROID_API__ >= 26
4
- #include <android/hardware_buffer.h>
5
- #endif
6
- #include <algorithm>
7
- #include <cstdint>
8
3
  #include <exception>
9
4
  #include <functional>
10
5
  #include <memory>
@@ -12,9 +7,7 @@
12
7
 
13
8
  #include "RNDawnContext.h"
14
9
 
15
- #include "AHardwareBufferUtils.h"
16
10
  #include "JniPlatformContext.h"
17
- #include "RNSkAndroidVideo.h"
18
11
  #include "RNSkPlatformContext.h"
19
12
 
20
13
  #pragma clang diagnostic push
@@ -54,139 +47,6 @@ public:
54
47
  useP3ColorSpace);
55
48
  }
56
49
 
57
- sk_sp<SkImage> makeImageFromNativeBuffer(void *buffer) override {
58
- return DawnContext::getInstance().MakeImageFromBuffer(buffer);
59
- }
60
-
61
- std::shared_ptr<RNSkVideo> createVideo(const std::string &url) override {
62
- auto jniVideo = _jniPlatformContext->createVideo(url);
63
- return std::make_shared<RNSkAndroidVideo>(jniVideo);
64
- }
65
-
66
- void releaseNativeBuffer(uint64_t pointer) override {
67
- #if __ANDROID_API__ >= 26
68
- auto *buffer = reinterpret_cast<AHardwareBuffer *>(pointer);
69
- AHardwareBuffer_release(buffer);
70
- #endif
71
- }
72
-
73
- uint64_t makeNativeBuffer(sk_sp<SkImage> image) override {
74
- #if __ANDROID_API__ >= 26
75
- // A Graphite GPU texture can't be read with readPixels(nullptr); read it
76
- // back to a raster image first or the buffer ends up uninitialized/black.
77
- if (image && image->isTextureBacked()) {
78
- image = DawnContext::getInstance().MakeRasterImage(image);
79
- }
80
- auto bytesPerPixel = image->imageInfo().bytesPerPixel();
81
- int bytesPerRow = image->width() * bytesPerPixel;
82
- auto buf = SkData::MakeUninitialized(image->width() * image->height() *
83
- bytesPerPixel);
84
- SkImageInfo info =
85
- SkImageInfo::Make(image->width(), image->height(), image->colorType(),
86
- image->alphaType());
87
- image->readPixels(nullptr, info, const_cast<void *>(buf->data()),
88
- bytesPerRow, 0, 0);
89
- const void *pixelData = buf->data();
90
-
91
- // Define the buffer description
92
- AHardwareBuffer_Desc desc = {};
93
- // TODO: use image info here
94
- desc.width = image->width();
95
- desc.height = image->height();
96
- desc.layers = 1; // Single image layer
97
- desc.format = GetBufferFormatFromSkColorType(
98
- image->colorType()); // Assuming the image
99
- // is in this format
100
- desc.usage = AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN |
101
- AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
102
- AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT |
103
- AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
104
- desc.stride = bytesPerRow; // Stride in pixels, not in bytes
105
-
106
- // Allocate the buffer
107
- AHardwareBuffer *buffer = nullptr;
108
- if (AHardwareBuffer_allocate(&desc, &buffer) != 0) {
109
- // Handle allocation failure
110
- return 0;
111
- }
112
-
113
- // Map the buffer to gain access to its memory
114
- void *mappedBuffer = nullptr;
115
- AHardwareBuffer_lock(buffer, AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, -1,
116
- nullptr, &mappedBuffer);
117
- if (mappedBuffer == nullptr) {
118
- // Handle mapping failure
119
- AHardwareBuffer_release(buffer);
120
- return 0;
121
- }
122
-
123
- // Copy the image data to the buffer
124
- memcpy(mappedBuffer, pixelData, desc.height * bytesPerRow);
125
-
126
- // Unmap the buffer
127
- AHardwareBuffer_unlock(buffer, nullptr);
128
-
129
- // Return the buffer pointer as a uint64_t. It's the caller's responsibility
130
- // to manage this buffer.
131
- return reinterpret_cast<uint64_t>(buffer);
132
- #else
133
- return 0;
134
- #endif
135
- }
136
-
137
- uint64_t makeTestNativeBuffer(int width, int height) override {
138
- #if __ANDROID_API__ >= 26
139
- // Allocate an RGBA8 AHardwareBuffer and fill it with a procedural test
140
- // pattern (RGB gradient + diagonal stripes), entirely on the CPU. We read
141
- // the buffer's actual row stride after locking (the allocator may pad it),
142
- // so the upload is correct regardless of width alignment.
143
- AHardwareBuffer_Desc desc = {};
144
- desc.width = static_cast<uint32_t>(width);
145
- desc.height = static_cast<uint32_t>(height);
146
- desc.layers = 1;
147
- desc.format = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
148
- desc.usage = AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY |
149
- AHARDWAREBUFFER_USAGE_CPU_READ_RARELY |
150
- AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
151
-
152
- AHardwareBuffer *buffer = nullptr;
153
- if (AHardwareBuffer_allocate(&desc, &buffer) != 0) {
154
- return 0;
155
- }
156
-
157
- AHardwareBuffer_Desc allocated = {};
158
- AHardwareBuffer_describe(buffer, &allocated);
159
- const size_t rowBytes = static_cast<size_t>(allocated.stride) * 4;
160
-
161
- void *mappedBuffer = nullptr;
162
- AHardwareBuffer_lock(buffer, AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY, -1,
163
- nullptr, &mappedBuffer);
164
- if (mappedBuffer == nullptr) {
165
- AHardwareBuffer_release(buffer);
166
- return 0;
167
- }
168
-
169
- auto *base = static_cast<uint8_t *>(mappedBuffer);
170
- for (int y = 0; y < height; ++y) {
171
- uint8_t *row = base + y * rowBytes;
172
- for (int x = 0; x < width; ++x) {
173
- uint8_t r = static_cast<uint8_t>((x * 255) / std::max(width - 1, 1));
174
- uint8_t g = static_cast<uint8_t>((y * 255) / std::max(height - 1, 1));
175
- uint8_t b = static_cast<uint8_t>(((x + y) & 0x20) ? 220 : 30);
176
- row[x * 4 + 0] = r; // RGBA byte order
177
- row[x * 4 + 1] = g;
178
- row[x * 4 + 2] = b;
179
- row[x * 4 + 3] = 0xFF;
180
- }
181
- }
182
-
183
- AHardwareBuffer_unlock(buffer, nullptr);
184
- return reinterpret_cast<uint64_t>(buffer);
185
- #else
186
- return 0;
187
- #endif
188
- }
189
-
190
50
  sk_sp<SkFontMgr> createFontMgr() override {
191
51
  return SkFontMgr_New_Android(nullptr, SkFontScanner_Make_FreeType());
192
52
  }
@@ -32,11 +32,6 @@ public class PlatformContext {
32
32
  mHybridData = initHybrid(reactContext.getResources().getDisplayMetrics().density);
33
33
  }
34
34
 
35
- @DoNotStrip
36
- public Object createVideo(String url) {
37
- return new RNSkVideo(mContext, url);
38
- }
39
-
40
35
  private byte[] getStreamAsBytes(InputStream is) throws IOException {
41
36
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
42
37
  int nRead;
@@ -51,16 +51,6 @@ public:
51
51
 
52
52
  sk_sp<SkImage> takeScreenshotFromViewTag(size_t tag) override;
53
53
 
54
- sk_sp<SkImage> makeImageFromNativeBuffer(void *buffer) override;
55
-
56
- uint64_t makeNativeBuffer(sk_sp<SkImage> image) override;
57
-
58
- uint64_t makeTestNativeBuffer(int width, int height) override;
59
-
60
- void releaseNativeBuffer(uint64_t pointer) override;
61
-
62
- std::shared_ptr<RNSkVideo> createVideo(const std::string &url) override;
63
-
64
54
  virtual void performStreamOperation(
65
55
  const std::string &sourceUri,
66
56
  const std::function<void(std::unique_ptr<SkStreamAsset>)> &op) override;
@@ -1,25 +1,16 @@
1
1
  #import "RNSkApplePlatformContext.h"
2
2
 
3
- #import <CoreMedia/CMSampleBuffer.h>
4
3
  #import <React/RCTUtils.h>
5
- #include <algorithm>
6
4
  #include <set>
7
5
  #include <thread>
8
6
  #include <utility>
9
7
 
10
8
  #include "RNDawnContext.h"
11
- #include "RNSkAppleVideo.h"
12
9
 
13
10
  #pragma clang diagnostic push
14
11
  #pragma clang diagnostic ignored "-Wdocumentation"
15
12
 
16
- #include "include/core/SkBlendMode.h"
17
- #include "include/core/SkCanvas.h"
18
- #include "include/core/SkColor.h"
19
- #import "include/core/SkColorSpace.h"
20
13
  #include "include/core/SkFontMgr.h"
21
- #include "include/core/SkPaint.h"
22
- #include "include/core/SkSamplingOptions.h"
23
14
  #include "include/core/SkSurface.h"
24
15
 
25
16
  #include "include/ports/SkFontMgr_mac_ct.h"
@@ -70,174 +61,6 @@ void RNSkApplePlatformContext::performStreamOperation(
70
61
  std::thread(loader).detach();
71
62
  }
72
63
 
73
- void RNSkApplePlatformContext::releaseNativeBuffer(uint64_t pointer) {
74
- CVPixelBufferRef pixelBuffer = reinterpret_cast<CVPixelBufferRef>(pointer);
75
- if (pixelBuffer) {
76
- CFRelease(pixelBuffer);
77
- }
78
- }
79
-
80
- uint64_t RNSkApplePlatformContext::makeNativeBuffer(sk_sp<SkImage> image) {
81
- // A Graphite GPU texture can't be read with readPixels(nullptr) (and can't be
82
- // drawn onto a raster surface): both yield uninitialized/black pixels. Read
83
- // it back to a raster image first.
84
- if (image && image->isTextureBacked()) {
85
- image = DawnContext::getInstance().MakeRasterImage(image);
86
- }
87
- // 0. If Image is not in BGRA, convert to BGRA as only BGRA is supported.
88
- if (image->colorType() != kBGRA_8888_SkColorType) {
89
- const SkImageInfo bgraInfo =
90
- SkImageInfo::Make(image->dimensions(), kBGRA_8888_SkColorType,
91
- kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
92
- auto surface = SkSurfaces::Raster(bgraInfo);
93
- if (!surface) {
94
- throw std::runtime_error(
95
- "Failed to allocate raster surface for BGRA conversion");
96
- }
97
- SkCanvas *canvas = surface->getCanvas();
98
- canvas->clear(SK_ColorTRANSPARENT);
99
- SkPaint paint;
100
- paint.setBlendMode(SkBlendMode::kSrc);
101
- canvas->drawImage(image.get(), 0.0f, 0.0f, SkSamplingOptions(), &paint);
102
- auto bgraImage = surface->makeImageSnapshot();
103
- if (bgraImage == nullptr) {
104
- throw std::runtime_error(
105
- "Failed to convert image to BGRA_8888 colortype! Only BGRA_8888 "
106
- "NativeBuffers are supported.");
107
- }
108
- image = std::move(bgraImage);
109
- }
110
-
111
- // 1. Get image info
112
- auto bytesPerPixel = image->imageInfo().bytesPerPixel();
113
- int bytesPerRow = image->width() * bytesPerPixel;
114
- auto buf = SkData::MakeUninitialized(image->width() * image->height() *
115
- bytesPerPixel);
116
- SkImageInfo info = SkImageInfo::Make(image->width(), image->height(),
117
- image->colorType(), image->alphaType());
118
- // 2. Copy pixels into our buffer
119
- image->readPixels(nullptr, info, const_cast<void *>(buf->data()), bytesPerRow,
120
- 0, 0);
121
-
122
- // 3. Create an IOSurface (GPU + CPU memory)
123
- CFMutableDictionaryRef dict = CFDictionaryCreateMutable(
124
- kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks,
125
- &kCFTypeDictionaryValueCallBacks);
126
- int width = image->width();
127
- int height = image->height();
128
- int pitch = width * bytesPerPixel;
129
- int size = width * height * bytesPerPixel;
130
- OSType pixelFormat = kCVPixelFormatType_32BGRA;
131
- CFDictionarySetValue(
132
- dict, kIOSurfaceBytesPerRow,
133
- CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &pitch));
134
- CFDictionarySetValue(
135
- dict, kIOSurfaceBytesPerElement,
136
- CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &bytesPerPixel));
137
- CFDictionarySetValue(
138
- dict, kIOSurfaceWidth,
139
- CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &width));
140
- CFDictionarySetValue(
141
- dict, kIOSurfaceHeight,
142
- CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &height));
143
- CFDictionarySetValue(
144
- dict, kIOSurfacePixelFormat,
145
- CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &pixelFormat));
146
- CFDictionarySetValue(
147
- dict, kIOSurfaceAllocSize,
148
- CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &size));
149
- IOSurfaceRef surface = IOSurfaceCreate(dict);
150
- if (surface == nil) {
151
- throw std::runtime_error("Failed to create " + std::to_string(width) + "x" +
152
- std::to_string(height) + " IOSurface!");
153
- }
154
-
155
- // 4. Copy over the memory from the pixels into the IOSurface
156
- IOSurfaceLock(surface, 0, nil);
157
- void *base = IOSurfaceGetBaseAddress(surface);
158
- memcpy(base, buf->data(), buf->size());
159
- IOSurfaceUnlock(surface, 0, nil);
160
-
161
- // 5. Create a CVPixelBuffer from the IOSurface
162
- CVPixelBufferRef pixelBuffer = nullptr;
163
- CVReturn result =
164
- CVPixelBufferCreateWithIOSurface(nil, surface, nil, &pixelBuffer);
165
- if (result != kCVReturnSuccess) {
166
- throw std::runtime_error(
167
- "Failed to create CVPixelBuffer from SkImage! Return value: " +
168
- std::to_string(result));
169
- }
170
-
171
- // 8. Return CVPixelBuffer casted to uint64_t
172
- return reinterpret_cast<uint64_t>(pixelBuffer);
173
- }
174
-
175
- uint64_t RNSkApplePlatformContext::makeTestNativeBuffer(int width, int height) {
176
- // Allocate a BGRA IOSurface and fill it with a procedural test pattern (RGB
177
- // gradient + diagonal stripes), entirely on the CPU. No GPU / SkImage round
178
- // trip, so this works the same on every backend.
179
- const int bytesPerElement = 4;
180
- const int pitch = width * bytesPerElement;
181
- const int allocSize = width * height * bytesPerElement;
182
- OSType pixelFormat = kCVPixelFormatType_32BGRA;
183
- CFMutableDictionaryRef dict = CFDictionaryCreateMutable(
184
- kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks,
185
- &kCFTypeDictionaryValueCallBacks);
186
- auto setInt = [&](CFStringRef key, int value) {
187
- CFNumberRef num =
188
- CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value);
189
- CFDictionarySetValue(dict, key, num);
190
- CFRelease(num);
191
- };
192
- setInt(kIOSurfaceWidth, width);
193
- setInt(kIOSurfaceHeight, height);
194
- setInt(kIOSurfaceBytesPerRow, pitch);
195
- setInt(kIOSurfaceBytesPerElement, bytesPerElement);
196
- setInt(kIOSurfacePixelFormat, static_cast<int>(pixelFormat));
197
- setInt(kIOSurfaceAllocSize, allocSize);
198
- IOSurfaceRef surface = IOSurfaceCreate(dict);
199
- CFRelease(dict);
200
- if (surface == nil) {
201
- throw std::runtime_error("Failed to create " + std::to_string(width) + "x" +
202
- std::to_string(height) + " test IOSurface!");
203
- }
204
-
205
- IOSurfaceLock(surface, 0, nil);
206
- auto *base = static_cast<uint8_t *>(IOSurfaceGetBaseAddress(surface));
207
- const size_t rowBytes = IOSurfaceGetBytesPerRow(surface);
208
- for (int y = 0; y < height; ++y) {
209
- uint8_t *row = base + y * rowBytes;
210
- for (int x = 0; x < width; ++x) {
211
- uint8_t r = static_cast<uint8_t>((x * 255) / std::max(width - 1, 1));
212
- uint8_t g = static_cast<uint8_t>((y * 255) / std::max(height - 1, 1));
213
- uint8_t b = static_cast<uint8_t>(((x + y) & 0x20) ? 220 : 30);
214
- row[x * 4 + 0] = b; // BGRA byte order
215
- row[x * 4 + 1] = g;
216
- row[x * 4 + 2] = r;
217
- row[x * 4 + 3] = 0xFF;
218
- }
219
- }
220
- IOSurfaceUnlock(surface, 0, nil);
221
-
222
- CVPixelBufferRef pixelBuffer = nullptr;
223
- CVReturn result =
224
- CVPixelBufferCreateWithIOSurface(nil, surface, nil, &pixelBuffer);
225
- // The CVPixelBuffer retains the IOSurface; drop our reference so the
226
- // CVPixelBuffer is its sole owner (freed by releaseNativeBuffer).
227
- CFRelease(surface);
228
- if (result != kCVReturnSuccess) {
229
- throw std::runtime_error("Failed to create CVPixelBuffer for test native "
230
- "buffer! Return value: " +
231
- std::to_string(result));
232
- }
233
- return reinterpret_cast<uint64_t>(pixelBuffer);
234
- }
235
-
236
- std::shared_ptr<RNSkVideo>
237
- RNSkApplePlatformContext::createVideo(const std::string &url) {
238
- return std::make_shared<RNSkAppleVideo>(url, this);
239
- }
240
-
241
64
  void RNSkApplePlatformContext::raiseError(const std::exception &err) {
242
65
  RCTFatal(RCTErrorWithMessage([NSString stringWithUTF8String:err.what()]));
243
66
  }
@@ -266,11 +89,6 @@ RNSkApplePlatformContext::makeOffscreenSurface(int width, int height,
266
89
  useP3ColorSpace);
267
90
  }
268
91
 
269
- sk_sp<SkImage>
270
- RNSkApplePlatformContext::makeImageFromNativeBuffer(void *buffer) {
271
- return DawnContext::getInstance().MakeImageFromBuffer(buffer);
272
- }
273
-
274
92
  sk_sp<SkFontMgr> RNSkApplePlatformContext::createFontMgr() {
275
93
  return SkFontMgr_New_CoreText(nullptr);
276
94
  }
@@ -0,0 +1,48 @@
1
+ #pragma once
2
+
3
+ #include <stdexcept>
4
+ #include <string>
5
+
6
+ #include <jsi/jsi.h>
7
+
8
+ #include "webgpu/webgpu_cpp.h"
9
+
10
+ namespace RNSkia {
11
+
12
+ namespace jsi = facebook::jsi;
13
+
14
+ // Reads a GPUTexture argument: the react-native-webgpu object, whose
15
+ // nativePointer (a non-spec extension) holds the WGPUTexture handle, or the
16
+ // handle itself as a BigInt for libraries that export textures without
17
+ // react-native-webgpu. The returned wgpu::Texture holds a reference of its
18
+ // own, so the image or surface wrapping it keeps the texture alive while the
19
+ // caller keeps ownership of the JS object.
20
+ inline wgpu::Texture gpuTextureFromValue(jsi::Runtime &runtime,
21
+ const jsi::Value &value,
22
+ const char *method) {
23
+ uint64_t raw = 0;
24
+ if (value.isBigInt()) {
25
+ raw = value.asBigInt(runtime).asUint64(runtime);
26
+ } else if (value.isObject()) {
27
+ auto pointer =
28
+ value.asObject(runtime).getProperty(runtime, "nativePointer");
29
+ if (!pointer.isBigInt()) {
30
+ throw std::runtime_error(
31
+ std::string(method) +
32
+ " expects a GPUTexture created with react-native-webgpu on the "
33
+ "shared device (or a WGPUTexture pointer as a BigInt)");
34
+ }
35
+ raw = pointer.asBigInt(runtime).asUint64(runtime);
36
+ } else {
37
+ throw std::runtime_error(std::string(method) +
38
+ " expects a GPUTexture or a WGPUTexture pointer");
39
+ }
40
+ auto texture = reinterpret_cast<WGPUTexture>(raw);
41
+ if (texture == nullptr) {
42
+ throw std::runtime_error(std::string(method) + ": the texture is null");
43
+ }
44
+ wgpuTextureAddRef(texture);
45
+ return wgpu::Texture::Acquire(texture);
46
+ }
47
+
48
+ } // namespace RNSkia
@@ -8,7 +8,6 @@
8
8
 
9
9
  #include "rnskia/RNDawnContext.h"
10
10
 
11
- #include "JsiNativeBuffer.h"
12
11
  #include "JsiSkAnimatedImage.h"
13
12
  #include "JsiSkAnimatedImageFactory.h"
14
13
  #include "JsiSkColor.h"
@@ -55,7 +54,6 @@
55
54
  #include "JsiSkTypefaceFontProviderFactory.h"
56
55
  #include "JsiSkVertices.h"
57
56
  #include "JsiSkottieFactory.h"
58
- #include "JsiVideo.h"
59
57
  #include "api/recorder/JsiRecorder.h"
60
58
 
61
59
  namespace RNSkia {
@@ -98,9 +96,7 @@ public:
98
96
  _typefaceFontProviderFactory(
99
97
  std::make_shared<JsiSkTypefaceFontProviderFactory>(context)),
100
98
  _paragraphBuilderFactory(
101
- std::make_shared<JsiSkParagraphBuilderFactory>(context)),
102
- _nativeBufferFactory(
103
- std::make_shared<JsiNativeBufferFactory>(context)) {
99
+ std::make_shared<JsiSkParagraphBuilderFactory>(context)) {
104
100
  // We create the system font manager eagerly since it has proven to be too
105
101
  // slow to do it on demand
106
102
  JsiSkFontMgrFactory::getFontMgr(getContext());
@@ -109,10 +105,6 @@ public:
109
105
  // Constructor functions: each delegates to the class's createCtor host
110
106
  // function using the platform context resolved from native state, so the
111
107
  // prototype stays context-free and can be installed on any runtime.
112
- JSI_HOST_FUNCTION(Video) {
113
- return JsiVideo::createCtor(getContext())(runtime, thisValue, arguments,
114
- count);
115
- }
116
108
  JSI_HOST_FUNCTION(Font) {
117
109
  return JsiSkFont::createCtor(getContext())(runtime, thisValue, arguments,
118
110
  count);
@@ -234,12 +226,8 @@ public:
234
226
  std::shared_ptr<JsiSkParagraphBuilderFactory> getParagraphBuilderFactory() {
235
227
  return _paragraphBuilderFactory;
236
228
  }
237
- std::shared_ptr<JsiNativeBufferFactory> getNativeBufferFactory() {
238
- return _nativeBufferFactory;
239
- }
240
229
 
241
230
  static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
242
- installHostMethod(runtime, prototype, "Video", &JsiSkApi::Video);
243
231
  installHostMethod(runtime, prototype, "getNativeDevice",
244
232
  &JsiSkApi::getNativeDevice);
245
233
  installHostMethod(runtime, prototype, "Font", &JsiSkApi::Font);
@@ -292,8 +280,6 @@ public:
292
280
  &JsiSkApi::getTypefaceFontProviderFactory);
293
281
  installGetter(runtime, prototype, "ParagraphBuilder",
294
282
  &JsiSkApi::getParagraphBuilderFactory);
295
- installGetter(runtime, prototype, "NativeBuffer",
296
- &JsiSkApi::getNativeBufferFactory);
297
283
  }
298
284
 
299
285
  private:
@@ -318,6 +304,5 @@ private:
318
304
  std::shared_ptr<JsiSkTypefaceFontProviderFactory>
319
305
  _typefaceFontProviderFactory;
320
306
  std::shared_ptr<JsiSkParagraphBuilderFactory> _paragraphBuilderFactory;
321
- std::shared_ptr<JsiNativeBufferFactory> _nativeBufferFactory;
322
307
  };
323
308
  } // namespace RNSkia
@@ -14,7 +14,6 @@
14
14
  #include "JsiSkShader.h"
15
15
  #include "api/third_party/base64.h"
16
16
 
17
- #include "JsiTextureInfo.h"
18
17
  #include "utils/RNSkTypedArray.h"
19
18
 
20
19
  #include "include/gpu/graphite/Context.h"
@@ -314,15 +313,6 @@ public:
314
313
  return std::make_shared<JsiSkImage>(getContext(), std::move(rasterImage));
315
314
  }
316
315
 
317
- JSI_HOST_FUNCTION(getNativeTextureUnstable) {
318
- auto image = getObject();
319
- if (!image->isTextureBacked()) {
320
- return jsi::Value::null();
321
- }
322
- auto texInfo = getContext()->getTexture(image);
323
- return JsiTextureInfo::toValue(runtime, texInfo);
324
- }
325
-
326
316
  bool isTextureBacked() { return getObject()->isTextureBacked(); }
327
317
 
328
318
  /**
@@ -351,8 +341,6 @@ public:
351
341
  &JsiSkImage::readPixels);
352
342
  installMethod(runtime, prototype, "makeNonTextureImage",
353
343
  &JsiSkImage::makeNonTextureImage);
354
- installHostMethod(runtime, prototype, "getNativeTextureUnstable",
355
- &JsiSkImage::getNativeTextureUnstable);
356
344
  installMethod(runtime, prototype, "isTextureBacked",
357
345
  &JsiSkImage::isTextureBacked);
358
346
  }