@shopify/react-native-skia 2.6.3 → 2.6.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.
- package/android/CMakeLists.txt +7 -4
- package/android/build.gradle +22 -3
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +62 -0
- package/apple/RNSkApplePlatformContext.h +2 -0
- package/apple/RNSkApplePlatformContext.mm +71 -0
- package/apple/RNWebGPUAppleNativeBuffer.mm +33 -0
- package/cpp/api/JsiNativeBuffer.h +9 -1
- package/cpp/api/JsiSkAnimatedImageFactory.h +1 -1
- package/cpp/api/JsiSkApi.h +2 -2
- package/cpp/api/JsiSkCanvas.h +1 -1
- package/cpp/api/JsiSkDataFactory.h +1 -1
- package/cpp/api/JsiSkFont.h +1 -1
- package/cpp/api/JsiSkFontMgr.h +1 -1
- package/cpp/api/JsiSkHostObjects.h +3 -3
- package/cpp/api/JsiSkImage.h +2 -2
- package/cpp/api/JsiSkImageFactory.h +2 -2
- package/cpp/api/JsiSkPath.h +1 -1
- package/cpp/api/JsiSkPathFactory.h +1 -1
- package/cpp/api/JsiSkSurface.h +13 -5
- package/cpp/api/JsiSkTypeface.h +1 -1
- package/cpp/api/JsiSkTypefaceFontProvider.h +1 -1
- package/cpp/api/JsiSkiaContext.h +2 -2
- package/cpp/api/JsiTextureInfo.h +1 -1
- package/cpp/api/JsiVideo.h +2 -2
- package/cpp/api/recorder/Drawings.h +1 -1
- package/cpp/api/recorder/JsiRecorder.h +4 -4
- package/cpp/api/recorder/RNRecorder.h +1 -1
- package/cpp/jsi/JsiHostObject.cpp +5 -7
- package/cpp/jsi/ViewProperty.h +1 -1
- package/cpp/rnskia/RNDawnContext.h +13 -0
- package/cpp/rnskia/RNDawnUtils.h +11 -1
- package/cpp/rnskia/RNSkJsiViewApi.h +2 -2
- package/cpp/rnskia/RNSkManager.cpp +88 -2
- package/cpp/rnskia/RNSkPictureView.h +4 -4
- package/cpp/rnskia/RNSkPlatformContext.h +7 -0
- package/cpp/rnskia/RNSkView.h +9 -6
- package/cpp/rnwgpu/ArrayBuffer.h +51 -7
- package/cpp/rnwgpu/api/AppleNativeBuffer.h +22 -0
- package/cpp/rnwgpu/api/Convertors.h +33 -11
- package/cpp/rnwgpu/api/GPUAdapter.cpp +28 -2
- package/cpp/rnwgpu/api/GPUBuffer.h +1 -1
- package/cpp/rnwgpu/api/GPUDevice.cpp +29 -2
- package/cpp/rnwgpu/api/GPUDevice.h +6 -0
- package/cpp/rnwgpu/api/GPUExternalTexture.cpp +139 -0
- package/cpp/rnwgpu/api/GPUExternalTexture.h +52 -2
- package/cpp/rnwgpu/api/GPUQueue.cpp +50 -45
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +82 -0
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +70 -0
- package/cpp/rnwgpu/api/ImageBitmap.h +62 -0
- package/cpp/rnwgpu/api/NativeBufferUtils.h +87 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +4 -1
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +56 -0
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +10 -0
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +43 -24
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +9 -9
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +2 -2
- package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +73 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +1 -1
- package/cpp/skia/include/core/SkRegion.h +10 -5
- package/cpp/skia/include/effects/SkRuntimeEffect.h +2 -2
- package/cpp/skia/include/gpu/graphite/Context.h +1 -1
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +10 -1
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
- package/lib/commonjs/skia/types/WebGPU.d.ts +88 -0
- package/lib/commonjs/skia/types/WebGPU.js +6 -0
- package/lib/commonjs/skia/types/WebGPU.js.map +1 -0
- package/lib/commonjs/skia/types/index.d.ts +1 -0
- package/lib/commonjs/skia/types/index.js +11 -0
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +1 -0
- package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js +19 -0
- package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +10 -1
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
- package/lib/module/skia/types/WebGPU.d.ts +88 -0
- package/lib/module/skia/types/WebGPU.js +2 -0
- package/lib/module/skia/types/WebGPU.js.map +1 -0
- package/lib/module/skia/types/index.d.ts +1 -0
- package/lib/module/skia/types/index.js +1 -0
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +1 -0
- package/lib/module/skia/web/JsiSkNativeBufferFactory.js +19 -0
- package/lib/module/skia/web/JsiSkNativeBufferFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkPath.js.map +1 -1
- package/lib/module/web/LoadSkiaWeb.js +1 -2
- package/lib/module/web/LoadSkiaWeb.js.map +1 -1
- package/lib/typescript/lib/commonjs/skia/types/WebGPU.d.ts +1 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/WebGPU.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/index.d.ts +1 -0
- package/lib/typescript/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +1 -0
- package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +10 -1
- package/lib/typescript/src/skia/types/WebGPU.d.ts +88 -0
- package/lib/typescript/src/skia/types/index.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkNativeBufferFactory.d.ts +1 -0
- package/package.json +12 -10
- package/react-native-skia.podspec +59 -7
- package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +10 -1
- package/src/skia/types/WebGPU.ts +108 -0
- package/src/skia/types/index.ts +1 -0
- package/src/skia/web/JsiSkNativeBufferFactory.ts +20 -0
- package/src/skia/web/JsiSkPath.ts +8 -2
- package/scripts/install-libs.js +0 -133
package/android/CMakeLists.txt
CHANGED
|
@@ -4,7 +4,8 @@ cmake_minimum_required(VERSION 3.4.1)
|
|
|
4
4
|
set (CMAKE_VERBOSE_MAKEFILE ON)
|
|
5
5
|
set (CMAKE_CXX_STANDARD 20)
|
|
6
6
|
|
|
7
|
-
# SKIA_LIBS_PATH is passed from Gradle (pointing
|
|
7
|
+
# SKIA_LIBS_PATH is passed from Gradle (pointing at the prebuilt Skia binaries,
|
|
8
|
+
# read straight from the react-native-skia-android npm package, or libs/android for Graphite)
|
|
8
9
|
# Append the ABI to get the full path
|
|
9
10
|
set (SKIA_LIBS_PATH "${SKIA_LIBS_PATH}/${ANDROID_ABI}")
|
|
10
11
|
|
|
@@ -17,12 +18,12 @@ if(NOT EXISTS "${SKIA_LIBS_PATH}/libskia.a")
|
|
|
17
18
|
message("│ │")
|
|
18
19
|
message("│ Could not find libskia.a at: ${SKIA_LIBS_PATH} │")
|
|
19
20
|
message("│ │")
|
|
20
|
-
message("│
|
|
21
|
-
message("│
|
|
21
|
+
message("│ Make sure dependencies are installed: │")
|
|
22
|
+
message("│ yarn install (or npm install) │")
|
|
22
23
|
message("│ │")
|
|
23
24
|
message("└─────────────────────────────────────────────────────────────────────────────┘")
|
|
24
25
|
message("")
|
|
25
|
-
message(FATAL_ERROR "Skia prebuilt binaries not found. Run `
|
|
26
|
+
message(FATAL_ERROR "Skia prebuilt binaries not found. Run `yarn install` to fix this.")
|
|
26
27
|
endif()
|
|
27
28
|
|
|
28
29
|
# Import libskia
|
|
@@ -134,12 +135,14 @@ if(SK_GRAPHITE)
|
|
|
134
135
|
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPUComputePipeline.cpp"
|
|
135
136
|
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPUDevice.cpp"
|
|
136
137
|
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPUDeviceLostInfo.cpp"
|
|
138
|
+
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPUExternalTexture.cpp"
|
|
137
139
|
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPUQuerySet.cpp"
|
|
138
140
|
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPUQueue.cpp"
|
|
139
141
|
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPURenderBundleEncoder.cpp"
|
|
140
142
|
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPURenderPassEncoder.cpp"
|
|
141
143
|
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPURenderPipeline.cpp"
|
|
142
144
|
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPUShaderModule.cpp"
|
|
145
|
+
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPUSharedTextureMemory.cpp"
|
|
143
146
|
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPUSupportedLimits.cpp"
|
|
144
147
|
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/api/GPUTexture.cpp"
|
|
145
148
|
|
package/android/build.gradle
CHANGED
|
@@ -58,10 +58,29 @@ static def findNodeModules(baseDir) {
|
|
|
58
58
|
|
|
59
59
|
def nodeModules = findNodeModules(projectDir)
|
|
60
60
|
|
|
61
|
-
//
|
|
62
|
-
//
|
|
61
|
+
// Resolve a node package directory using Node's own module resolution, so we
|
|
62
|
+
// pick up the prebuilt Skia binaries straight from node_modules (no postinstall
|
|
63
|
+
// copy step needed). Mirrors `require.resolve(pkg/package.json)`.
|
|
64
|
+
static def resolveNodePackage(packageName, baseDir) {
|
|
65
|
+
def script = "process.stdout.write(require('path').dirname(require.resolve('${packageName}/package.json')))"
|
|
66
|
+
def proc = ["node", "-e", script].execute(null, baseDir)
|
|
67
|
+
proc.waitFor()
|
|
68
|
+
if (proc.exitValue() != 0) {
|
|
69
|
+
throw new GradleException(
|
|
70
|
+
"react-native-skia: Could not resolve the '${packageName}' package. " +
|
|
71
|
+
"Make sure dependencies are installed (yarn install / npm install).\n" + proc.err.text
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
return proc.text.trim()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Graphite is detected via a marker file created by install-skia-graphite, which
|
|
78
|
+
// downloads its binaries directly into libs/. For the default (Ganesh) build the
|
|
79
|
+
// binaries live in the react-native-skia-android npm package and are read in place.
|
|
63
80
|
def useGraphite = file("${projectDir}/../libs/.graphite").exists()
|
|
64
|
-
def skiaLibsPath =
|
|
81
|
+
def skiaLibsPath = useGraphite
|
|
82
|
+
? "${projectDir}/../libs/android"
|
|
83
|
+
: "${resolveNodePackage('react-native-skia-android', projectDir)}/libs"
|
|
65
84
|
|
|
66
85
|
logger.warn("react-native-skia: SK_GRAPHITE: ${useGraphite}")
|
|
67
86
|
logger.warn("react-native-skia: Skia libs: ${skiaLibsPath}")
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
#if __ANDROID_API__ >= 26
|
|
4
4
|
#include <android/hardware_buffer.h>
|
|
5
5
|
#endif
|
|
6
|
+
#include <algorithm>
|
|
7
|
+
#include <cstdint>
|
|
6
8
|
#include <exception>
|
|
7
9
|
#include <functional>
|
|
8
10
|
#include <memory>
|
|
@@ -120,6 +122,13 @@ public:
|
|
|
120
122
|
|
|
121
123
|
uint64_t makeNativeBuffer(sk_sp<SkImage> image) override {
|
|
122
124
|
#if __ANDROID_API__ >= 26
|
|
125
|
+
#if defined(SK_GRAPHITE)
|
|
126
|
+
// A Graphite GPU texture can't be read with readPixels(nullptr); read it
|
|
127
|
+
// back to a raster image first or the buffer ends up uninitialized/black.
|
|
128
|
+
if (image && image->isTextureBacked()) {
|
|
129
|
+
image = DawnContext::getInstance().MakeRasterImage(image);
|
|
130
|
+
}
|
|
131
|
+
#endif
|
|
123
132
|
auto bytesPerPixel = image->imageInfo().bytesPerPixel();
|
|
124
133
|
int bytesPerRow = image->width() * bytesPerPixel;
|
|
125
134
|
auto buf = SkData::MakeUninitialized(image->width() * image->height() *
|
|
@@ -177,6 +186,59 @@ public:
|
|
|
177
186
|
#endif
|
|
178
187
|
}
|
|
179
188
|
|
|
189
|
+
uint64_t makeTestNativeBuffer(int width, int height) override {
|
|
190
|
+
#if __ANDROID_API__ >= 26
|
|
191
|
+
// Allocate an RGBA8 AHardwareBuffer and fill it with a procedural test
|
|
192
|
+
// pattern (RGB gradient + diagonal stripes), entirely on the CPU. We read
|
|
193
|
+
// the buffer's actual row stride after locking (the allocator may pad it),
|
|
194
|
+
// so the upload is correct regardless of width alignment.
|
|
195
|
+
AHardwareBuffer_Desc desc = {};
|
|
196
|
+
desc.width = static_cast<uint32_t>(width);
|
|
197
|
+
desc.height = static_cast<uint32_t>(height);
|
|
198
|
+
desc.layers = 1;
|
|
199
|
+
desc.format = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
|
|
200
|
+
desc.usage = AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY |
|
|
201
|
+
AHARDWAREBUFFER_USAGE_CPU_READ_RARELY |
|
|
202
|
+
AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
|
|
203
|
+
|
|
204
|
+
AHardwareBuffer *buffer = nullptr;
|
|
205
|
+
if (AHardwareBuffer_allocate(&desc, &buffer) != 0) {
|
|
206
|
+
return 0;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
AHardwareBuffer_Desc allocated = {};
|
|
210
|
+
AHardwareBuffer_describe(buffer, &allocated);
|
|
211
|
+
const size_t rowBytes = static_cast<size_t>(allocated.stride) * 4;
|
|
212
|
+
|
|
213
|
+
void *mappedBuffer = nullptr;
|
|
214
|
+
AHardwareBuffer_lock(buffer, AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY, -1,
|
|
215
|
+
nullptr, &mappedBuffer);
|
|
216
|
+
if (mappedBuffer == nullptr) {
|
|
217
|
+
AHardwareBuffer_release(buffer);
|
|
218
|
+
return 0;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
auto *base = static_cast<uint8_t *>(mappedBuffer);
|
|
222
|
+
for (int y = 0; y < height; ++y) {
|
|
223
|
+
uint8_t *row = base + y * rowBytes;
|
|
224
|
+
for (int x = 0; x < width; ++x) {
|
|
225
|
+
uint8_t r = static_cast<uint8_t>((x * 255) / std::max(width - 1, 1));
|
|
226
|
+
uint8_t g = static_cast<uint8_t>((y * 255) / std::max(height - 1, 1));
|
|
227
|
+
uint8_t b = static_cast<uint8_t>(((x + y) & 0x20) ? 220 : 30);
|
|
228
|
+
row[x * 4 + 0] = r; // RGBA byte order
|
|
229
|
+
row[x * 4 + 1] = g;
|
|
230
|
+
row[x * 4 + 2] = b;
|
|
231
|
+
row[x * 4 + 3] = 0xFF;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
AHardwareBuffer_unlock(buffer, nullptr);
|
|
236
|
+
return reinterpret_cast<uint64_t>(buffer);
|
|
237
|
+
#else
|
|
238
|
+
return 0;
|
|
239
|
+
#endif
|
|
240
|
+
}
|
|
241
|
+
|
|
180
242
|
#if !defined(SK_GRAPHITE)
|
|
181
243
|
GrDirectContext *getDirectContext() override {
|
|
182
244
|
return OpenGLContext::getInstance().getDirectContext();
|
|
@@ -57,6 +57,8 @@ public:
|
|
|
57
57
|
|
|
58
58
|
uint64_t makeNativeBuffer(sk_sp<SkImage> image) override;
|
|
59
59
|
|
|
60
|
+
uint64_t makeTestNativeBuffer(int width, int height) override;
|
|
61
|
+
|
|
60
62
|
void releaseNativeBuffer(uint64_t pointer) override;
|
|
61
63
|
|
|
62
64
|
std::shared_ptr<RNSkVideo> createVideo(const std::string &url) override;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#import <CoreMedia/CMSampleBuffer.h>
|
|
4
4
|
#include <Metal/Metal.h>
|
|
5
5
|
#import <React/RCTUtils.h>
|
|
6
|
+
#include <algorithm>
|
|
6
7
|
#include <set>
|
|
7
8
|
#include <thread>
|
|
8
9
|
#include <utility>
|
|
@@ -82,6 +83,15 @@ void RNSkApplePlatformContext::releaseNativeBuffer(uint64_t pointer) {
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
uint64_t RNSkApplePlatformContext::makeNativeBuffer(sk_sp<SkImage> image) {
|
|
86
|
+
#if defined(SK_GRAPHITE)
|
|
87
|
+
// A Graphite GPU texture can't be read with readPixels(nullptr) (and can't be
|
|
88
|
+
// drawn onto a raster surface) — both yield uninitialized/black pixels. Read
|
|
89
|
+
// it back to a raster image first. (JsiNativeBuffer calls the Ganesh-only
|
|
90
|
+
// SkImage::makeNonTextureImage(), which is a no-op on Graphite.)
|
|
91
|
+
if (image && image->isTextureBacked()) {
|
|
92
|
+
image = DawnContext::getInstance().MakeRasterImage(image);
|
|
93
|
+
}
|
|
94
|
+
#endif
|
|
85
95
|
// 0. If Image is not in BGRA, convert to BGRA as only BGRA is supported.
|
|
86
96
|
if (image->colorType() != kBGRA_8888_SkColorType) {
|
|
87
97
|
const SkImageInfo bgraInfo =
|
|
@@ -170,6 +180,67 @@ uint64_t RNSkApplePlatformContext::makeNativeBuffer(sk_sp<SkImage> image) {
|
|
|
170
180
|
return reinterpret_cast<uint64_t>(pixelBuffer);
|
|
171
181
|
}
|
|
172
182
|
|
|
183
|
+
uint64_t RNSkApplePlatformContext::makeTestNativeBuffer(int width, int height) {
|
|
184
|
+
// Allocate a BGRA IOSurface and fill it with a procedural test pattern (RGB
|
|
185
|
+
// gradient + diagonal stripes), entirely on the CPU. No GPU / SkImage round
|
|
186
|
+
// trip, so this works the same on every backend.
|
|
187
|
+
const int bytesPerElement = 4;
|
|
188
|
+
const int pitch = width * bytesPerElement;
|
|
189
|
+
const int allocSize = width * height * bytesPerElement;
|
|
190
|
+
OSType pixelFormat = kCVPixelFormatType_32BGRA;
|
|
191
|
+
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(
|
|
192
|
+
kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks,
|
|
193
|
+
&kCFTypeDictionaryValueCallBacks);
|
|
194
|
+
auto setInt = [&](CFStringRef key, int value) {
|
|
195
|
+
CFNumberRef num =
|
|
196
|
+
CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value);
|
|
197
|
+
CFDictionarySetValue(dict, key, num);
|
|
198
|
+
CFRelease(num);
|
|
199
|
+
};
|
|
200
|
+
setInt(kIOSurfaceWidth, width);
|
|
201
|
+
setInt(kIOSurfaceHeight, height);
|
|
202
|
+
setInt(kIOSurfaceBytesPerRow, pitch);
|
|
203
|
+
setInt(kIOSurfaceBytesPerElement, bytesPerElement);
|
|
204
|
+
setInt(kIOSurfacePixelFormat, static_cast<int>(pixelFormat));
|
|
205
|
+
setInt(kIOSurfaceAllocSize, allocSize);
|
|
206
|
+
IOSurfaceRef surface = IOSurfaceCreate(dict);
|
|
207
|
+
CFRelease(dict);
|
|
208
|
+
if (surface == nil) {
|
|
209
|
+
throw std::runtime_error("Failed to create " + std::to_string(width) + "x" +
|
|
210
|
+
std::to_string(height) + " test IOSurface!");
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
IOSurfaceLock(surface, 0, nil);
|
|
214
|
+
auto *base = static_cast<uint8_t *>(IOSurfaceGetBaseAddress(surface));
|
|
215
|
+
const size_t rowBytes = IOSurfaceGetBytesPerRow(surface);
|
|
216
|
+
for (int y = 0; y < height; ++y) {
|
|
217
|
+
uint8_t *row = base + y * rowBytes;
|
|
218
|
+
for (int x = 0; x < width; ++x) {
|
|
219
|
+
uint8_t r = static_cast<uint8_t>((x * 255) / std::max(width - 1, 1));
|
|
220
|
+
uint8_t g = static_cast<uint8_t>((y * 255) / std::max(height - 1, 1));
|
|
221
|
+
uint8_t b = static_cast<uint8_t>(((x + y) & 0x20) ? 220 : 30);
|
|
222
|
+
row[x * 4 + 0] = b; // BGRA byte order
|
|
223
|
+
row[x * 4 + 1] = g;
|
|
224
|
+
row[x * 4 + 2] = r;
|
|
225
|
+
row[x * 4 + 3] = 0xFF;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
IOSurfaceUnlock(surface, 0, nil);
|
|
229
|
+
|
|
230
|
+
CVPixelBufferRef pixelBuffer = nullptr;
|
|
231
|
+
CVReturn result =
|
|
232
|
+
CVPixelBufferCreateWithIOSurface(nil, surface, nil, &pixelBuffer);
|
|
233
|
+
// The CVPixelBuffer retains the IOSurface; drop our reference so the
|
|
234
|
+
// CVPixelBuffer is its sole owner (freed by releaseNativeBuffer).
|
|
235
|
+
CFRelease(surface);
|
|
236
|
+
if (result != kCVReturnSuccess) {
|
|
237
|
+
throw std::runtime_error("Failed to create CVPixelBuffer for test native "
|
|
238
|
+
"buffer! Return value: " +
|
|
239
|
+
std::to_string(result));
|
|
240
|
+
}
|
|
241
|
+
return reinterpret_cast<uint64_t>(pixelBuffer);
|
|
242
|
+
}
|
|
243
|
+
|
|
173
244
|
#if !defined(SK_GRAPHITE)
|
|
174
245
|
GrDirectContext *RNSkApplePlatformContext::getDirectContext() {
|
|
175
246
|
return MetalContext::getInstance().getDirectContext();
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#ifdef SK_GRAPHITE
|
|
2
|
+
|
|
3
|
+
#import <CoreVideo/CoreVideo.h>
|
|
4
|
+
|
|
5
|
+
#include "rnwgpu/api/AppleNativeBuffer.h"
|
|
6
|
+
|
|
7
|
+
namespace rnwgpu {
|
|
8
|
+
|
|
9
|
+
void *GetIOSurfaceFromNativeBuffer(void *cvPixelBuffer, uint32_t *outWidth,
|
|
10
|
+
uint32_t *outHeight) {
|
|
11
|
+
auto pixelBuffer = reinterpret_cast<CVPixelBufferRef>(cvPixelBuffer);
|
|
12
|
+
if (pixelBuffer == nullptr) {
|
|
13
|
+
if (outWidth != nullptr) {
|
|
14
|
+
*outWidth = 0;
|
|
15
|
+
}
|
|
16
|
+
if (outHeight != nullptr) {
|
|
17
|
+
*outHeight = 0;
|
|
18
|
+
}
|
|
19
|
+
return nullptr;
|
|
20
|
+
}
|
|
21
|
+
if (outWidth != nullptr) {
|
|
22
|
+
*outWidth = static_cast<uint32_t>(CVPixelBufferGetWidth(pixelBuffer));
|
|
23
|
+
}
|
|
24
|
+
if (outHeight != nullptr) {
|
|
25
|
+
*outHeight = static_cast<uint32_t>(CVPixelBufferGetHeight(pixelBuffer));
|
|
26
|
+
}
|
|
27
|
+
// The IOSurface is owned by the CVPixelBuffer; we don't retain it here.
|
|
28
|
+
return CVPixelBufferGetIOSurface(pixelBuffer);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
} // namespace rnwgpu
|
|
32
|
+
|
|
33
|
+
#endif // SK_GRAPHITE
|
|
@@ -24,6 +24,13 @@ public:
|
|
|
24
24
|
return jsi::BigInt::fromUint64(runtime, pointer);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
JSI_HOST_FUNCTION(MakeTestBuffer) {
|
|
28
|
+
auto width = static_cast<int>(arguments[0].asNumber());
|
|
29
|
+
auto height = static_cast<int>(arguments[1].asNumber());
|
|
30
|
+
uint64_t pointer = getContext()->makeTestNativeBuffer(width, height);
|
|
31
|
+
return jsi::BigInt::fromUint64(runtime, pointer);
|
|
32
|
+
}
|
|
33
|
+
|
|
27
34
|
JSI_HOST_FUNCTION(Release) {
|
|
28
35
|
|
|
29
36
|
jsi::BigInt pointer = arguments[0].asBigInt(runtime);
|
|
@@ -34,7 +41,8 @@ public:
|
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiNativeBufferFactory, Release),
|
|
37
|
-
JSI_EXPORT_FUNC(JsiNativeBufferFactory, MakeFromImage)
|
|
44
|
+
JSI_EXPORT_FUNC(JsiNativeBufferFactory, MakeFromImage),
|
|
45
|
+
JSI_EXPORT_FUNC(JsiNativeBufferFactory, MakeTestBuffer))
|
|
38
46
|
|
|
39
47
|
size_t getMemoryPressure() const override { return 1024; }
|
|
40
48
|
|
package/cpp/api/JsiSkApi.h
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
#include <memory>
|
|
4
4
|
|
|
5
|
-
#include "RNSkPlatformContext.h"
|
|
5
|
+
#include "rnskia/RNSkPlatformContext.h"
|
|
6
6
|
|
|
7
7
|
#include "JsiSkHostObjects.h"
|
|
8
8
|
|
|
9
9
|
#ifdef SK_GRAPHITE
|
|
10
|
-
#include "RNDawnContext.h"
|
|
10
|
+
#include "rnskia/RNDawnContext.h"
|
|
11
11
|
#include "rnwgpu/api/GPUDevice.h"
|
|
12
12
|
#include "rnwgpu/async/AsyncRunner.h"
|
|
13
13
|
#endif
|
package/cpp/api/JsiSkCanvas.h
CHANGED
package/cpp/api/JsiSkFont.h
CHANGED
package/cpp/api/JsiSkFontMgr.h
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
#include <string>
|
|
6
6
|
#include <utility>
|
|
7
7
|
|
|
8
|
-
#include "JsiHostObject.h"
|
|
9
|
-
#include "RNSkLog.h"
|
|
10
|
-
#include "RNSkPlatformContext.h"
|
|
8
|
+
#include "jsi/JsiHostObject.h"
|
|
9
|
+
#include "utils/RNSkLog.h"
|
|
10
|
+
#include "rnskia/RNSkPlatformContext.h"
|
|
11
11
|
|
|
12
12
|
namespace RNSkia {
|
|
13
13
|
|
package/cpp/api/JsiSkImage.h
CHANGED
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
#include "api/third_party/base64.h"
|
|
13
13
|
|
|
14
14
|
#include "JsiTextureInfo.h"
|
|
15
|
-
#include "RNSkTypedArray.h"
|
|
15
|
+
#include "utils/RNSkTypedArray.h"
|
|
16
16
|
|
|
17
17
|
#if defined(SK_GRAPHITE)
|
|
18
|
-
#include "RNDawnContext.h"
|
|
18
|
+
#include "rnskia/RNDawnContext.h"
|
|
19
19
|
#include "include/gpu/graphite/Context.h"
|
|
20
20
|
#else
|
|
21
21
|
#include "include/gpu/ganesh/GrDirectContext.h"
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
#include <jsi/jsi.h>
|
|
7
7
|
|
|
8
|
-
#include "JsiPromises.h"
|
|
8
|
+
#include "jsi/JsiPromises.h"
|
|
9
9
|
#include "JsiSkData.h"
|
|
10
10
|
#include "JsiSkHostObjects.h"
|
|
11
11
|
#include "JsiSkImage.h"
|
|
12
12
|
#include "JsiSkImageInfo.h"
|
|
13
13
|
|
|
14
14
|
#ifdef SK_GRAPHITE
|
|
15
|
-
#include "RNDawnContext.h"
|
|
15
|
+
#include "rnskia/RNDawnContext.h"
|
|
16
16
|
#include "rnwgpu/api/GPUTexture.h"
|
|
17
17
|
#endif
|
|
18
18
|
|
package/cpp/api/JsiSkPath.h
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
#pragma clang diagnostic push
|
|
18
18
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
19
19
|
|
|
20
|
-
#include "RNSkLog.h"
|
|
20
|
+
#include "utils/RNSkLog.h"
|
|
21
21
|
#include "include/core/SkPath.h"
|
|
22
22
|
#include "include/core/SkPathBuilder.h"
|
|
23
23
|
#include "include/core/SkPathUtils.h"
|
package/cpp/api/JsiSkSurface.h
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
#include "JsiSkImage.h"
|
|
16
16
|
|
|
17
17
|
#if defined(SK_GRAPHITE)
|
|
18
|
-
#include "RNDawnContext.h"
|
|
18
|
+
#include "rnskia/RNDawnContext.h"
|
|
19
19
|
#endif
|
|
20
20
|
|
|
21
21
|
#pragma clang diagnostic push
|
|
@@ -81,8 +81,12 @@ public:
|
|
|
81
81
|
JSI_HOST_FUNCTION(flush) {
|
|
82
82
|
auto surface = getObject();
|
|
83
83
|
#if defined(SK_GRAPHITE)
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
// A raster surface (e.g. Skia.Surface.Make) has no Graphite recorder;
|
|
85
|
+
// only Graphite-backed surfaces need to snap and submit a recording.
|
|
86
|
+
if (auto *recorder = surface->recorder()) {
|
|
87
|
+
auto recording = recorder->snap();
|
|
88
|
+
DawnContext::getInstance().submitRecording(recording.get());
|
|
89
|
+
}
|
|
86
90
|
#else
|
|
87
91
|
if (auto dContext = GrAsDirectContext(surface->recordingContext())) {
|
|
88
92
|
dContext->flushAndSubmit();
|
|
@@ -102,8 +106,12 @@ public:
|
|
|
102
106
|
image = surface->makeImageSnapshot();
|
|
103
107
|
}
|
|
104
108
|
#if defined(SK_GRAPHITE)
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
// A raster surface (e.g. Skia.Surface.Make) has no Graphite recorder; its
|
|
110
|
+
// snapshot is already a valid CPU image, so skip the recording submit.
|
|
111
|
+
if (auto *recorder = surface->recorder()) {
|
|
112
|
+
auto recording = recorder->snap();
|
|
113
|
+
DawnContext::getInstance().submitRecording(recording.get());
|
|
114
|
+
}
|
|
107
115
|
#endif
|
|
108
116
|
if (count > 1 && arguments[1].isObject()) {
|
|
109
117
|
auto jsiImage =
|
package/cpp/api/JsiSkTypeface.h
CHANGED
package/cpp/api/JsiSkiaContext.h
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#include <vector>
|
|
7
7
|
|
|
8
8
|
#include "JsiSkHostObjects.h"
|
|
9
|
-
#include "RNSkLog.h"
|
|
9
|
+
#include "utils/RNSkLog.h"
|
|
10
10
|
#include <jsi/jsi.h>
|
|
11
11
|
|
|
12
12
|
#include "JsiSkPaint.h"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
#include "JsiSkRect.h"
|
|
15
15
|
#include "JsiSkTypeface.h"
|
|
16
16
|
|
|
17
|
-
#include "RNWindowContext.h"
|
|
17
|
+
#include "rnskia/RNWindowContext.h"
|
|
18
18
|
|
|
19
19
|
#pragma clang diagnostic push
|
|
20
20
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
package/cpp/api/JsiTextureInfo.h
CHANGED
package/cpp/api/JsiVideo.h
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#include <vector>
|
|
7
7
|
|
|
8
8
|
#include "JsiSkHostObjects.h"
|
|
9
|
-
#include "RNSkLog.h"
|
|
9
|
+
#include "utils/RNSkLog.h"
|
|
10
10
|
#include <jsi/jsi.h>
|
|
11
11
|
|
|
12
12
|
#include "JsiSkPaint.h"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
#include "JsiSkRect.h"
|
|
15
15
|
#include "JsiSkTypeface.h"
|
|
16
16
|
|
|
17
|
-
#include "RNSkVideo.h"
|
|
17
|
+
#include "rnskia/RNSkVideo.h"
|
|
18
18
|
|
|
19
19
|
#pragma clang diagnostic push
|
|
20
20
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
#include <utility>
|
|
6
6
|
#include <vector>
|
|
7
7
|
|
|
8
|
-
#include "JsiSkCanvas.h"
|
|
9
|
-
#include "JsiSkHostObjects.h"
|
|
10
|
-
#include "JsiSkPicture.h"
|
|
8
|
+
#include "api/JsiSkCanvas.h"
|
|
9
|
+
#include "api/JsiSkHostObjects.h"
|
|
10
|
+
#include "api/JsiSkPicture.h"
|
|
11
11
|
|
|
12
12
|
#include "DrawingCtx.h"
|
|
13
13
|
#include "RNRecorder.h"
|
|
14
|
-
#include "RNSkLog.h"
|
|
14
|
+
#include "utils/RNSkLog.h"
|
|
15
15
|
|
|
16
16
|
#include <jsi/jsi.h>
|
|
17
17
|
|
|
@@ -24,12 +24,6 @@ void JsiHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name,
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
jsi::Value eval(jsi::Runtime &runtime, const std::string &js) {
|
|
28
|
-
return runtime.global()
|
|
29
|
-
.getPropertyAsFunction(runtime, "eval")
|
|
30
|
-
.call(runtime, js);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
27
|
jsi::Value JsiHostObject::get(jsi::Runtime &runtime,
|
|
34
28
|
const jsi::PropNameID &name) {
|
|
35
29
|
auto nameStr = name.utf8(runtime);
|
|
@@ -86,7 +80,11 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime,
|
|
|
86
80
|
// Check for dispose symbol as last resort
|
|
87
81
|
static const auto disposeSymbol = jsi::PropNameID::forSymbol(
|
|
88
82
|
runtime,
|
|
89
|
-
|
|
83
|
+
runtime.global()
|
|
84
|
+
.getPropertyAsObject(runtime, "Symbol")
|
|
85
|
+
.getPropertyAsFunction(runtime, "for")
|
|
86
|
+
.call(runtime, "Symbol.dispose")
|
|
87
|
+
.getSymbol(runtime));
|
|
90
88
|
if (jsi::PropNameID::compare(runtime, disposeSymbol, name)) {
|
|
91
89
|
// Recursively call get with "dispose" string
|
|
92
90
|
auto disposeName = jsi::PropNameID::forAscii(runtime, "dispose");
|
package/cpp/jsi/ViewProperty.h
CHANGED
|
@@ -138,6 +138,15 @@ public:
|
|
|
138
138
|
wgpu::SharedTextureMemoryBeginAccessDescriptor beginAccessDesc;
|
|
139
139
|
beginAccessDesc.initialized = true;
|
|
140
140
|
beginAccessDesc.fenceCount = 0;
|
|
141
|
+
#if defined(__ANDROID__)
|
|
142
|
+
// Dawn's Vulkan backend requires the acquired VkImageLayout to be chained.
|
|
143
|
+
// UNDEFINED (= 0) on both ends is the canonical "no prior GPU producer"
|
|
144
|
+
// pattern (matches GPUSharedTextureMemory::beginAccess).
|
|
145
|
+
wgpu::SharedTextureMemoryVkImageLayoutBeginState vkBegin = {};
|
|
146
|
+
vkBegin.oldLayout = 0;
|
|
147
|
+
vkBegin.newLayout = 0;
|
|
148
|
+
beginAccessDesc.nextInChain = &vkBegin;
|
|
149
|
+
#endif
|
|
141
150
|
bool success = memory.BeginAccess(texture, &beginAccessDesc);
|
|
142
151
|
|
|
143
152
|
if (success) {
|
|
@@ -149,6 +158,10 @@ public:
|
|
|
149
158
|
[](void *context) {
|
|
150
159
|
auto ctx = static_cast<SharedTextureContext *>(context);
|
|
151
160
|
wgpu::SharedTextureMemoryEndAccessState endState = {};
|
|
161
|
+
#if defined(__ANDROID__)
|
|
162
|
+
wgpu::SharedTextureMemoryVkImageLayoutEndState vkEnd = {};
|
|
163
|
+
endState.nextInChain = &vkEnd;
|
|
164
|
+
#endif
|
|
152
165
|
ctx->sharedTextureMemory.EndAccess(ctx->texture, &endState);
|
|
153
166
|
delete ctx;
|
|
154
167
|
},
|