Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<a href="https://github.com/batical/react-native-skia-webgpu-video/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/batical/react-native-skia-webgpu-video/actions/workflows/ci.yml/badge.svg?branch=main" /></a>
<a href="https://www.npmjs.com/package/react-native-skia-webgpu-video"><img alt="npm" src="https://img.shields.io/npm/v/react-native-skia-webgpu-video" /></a>
<a href="#status"><img alt="Status: stable" src="https://img.shields.io/badge/status-stable-22c55e" /></a>
<img alt="React Native Skia 3.9.1" src="https://img.shields.io/badge/Skia-3.9.1-38bdf8" />
<img alt="React Native WebGPU 0.21.0" src="https://img.shields.io/badge/WebGPU-0.21.0-a78bfa" />
<img alt="React Native Skia 3.9.2" src="https://img.shields.io/badge/Skia-3.9.2-38bdf8" />
<img alt="React Native WebGPU 0.21.2" src="https://img.shields.io/badge/WebGPU-0.21.2-a78bfa" />
<a href="LICENSE"><img alt="MIT license" src="https://img.shields.io/badge/license-MIT-34d399" /></a>
</p>

Expand Down Expand Up @@ -37,8 +37,8 @@ A new Skia 3 / WebGPU frame-interop layer, written from scratch with explicit re
| --- | --- |
| React Native | `0.86.2` tested; declared peer range `>=0.83 <0.87` |
| React | `19.2.3` tested |
| React Native Skia | **`react-native-skia@3.9.1`** |
| React Native WebGPU | **`react-native-webgpu@0.21.0`** (both resolve `react-native-webgpu-dawn@157.1.0`) |
| React Native Skia | **`react-native-skia@3.9.2`** |
| React Native WebGPU | **`react-native-webgpu@0.21.2`** (both resolve `react-native-webgpu-dawn@157.1.0`) |
| Reanimated / Worklets | **`4.5.3` / `0.11.3`** |
| Native runtime | New Architecture and Hermes |
| Android | API **28+**, Vulkan 1.1 (declared as a required feature by Skia) |
Expand All @@ -50,7 +50,7 @@ On ProMotion iPhones, add `CADisableMinimumFrameDurationOnPhone` (Boolean, `YES`
### Install

```sh
npm install --save-exact react-native-skia@3.9.1 react-native-webgpu@0.21.0 react-native-reanimated@4.5.3 react-native-worklets@0.11.3
npm install --save-exact react-native-skia@3.9.2 react-native-webgpu@0.21.2 react-native-reanimated@4.5.3 react-native-worklets@0.11.3
npm install --save-exact react-native-skia-webgpu-video
```

Expand Down
2 changes: 1 addition & 1 deletion android/BUILD_VALIDATION.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Android validation and frame ownership

The Android example in `../example/android` pins React Native 0.86.2, Skia 3.9.1, WebGPU 0.21.0, the shared `react-native-webgpu-dawn` 157.1.0 (chrome-m157) and Graphite Android 157.1.0; Gradle needs `node` to resolve that Dawn package. Since WebGPU 0.19.0, export renders straight into the codec's input Surface through a WebGPU canvas context on it (`MakeWebGPUCanvasContextFromNativeWindow`, Vulkan swapchain), with no EGL; CPU readback, drawn into the Surface by EGL, stays the fallback. On API 29+, 8-bit SDR H.264/HEVC clips go through an `ImageReader`, whose YUV buffers WebGPU converts, crops, rotates and scales to the frame's size (capped or explicit sizes included since the 3.7.4 migration); since 3.6.1 each buffer is imported once, and exports sample the converted frame in place. The 3.7.0 build was assembled and run on a Pixel 8a on 2026-10-19 ([verification](../migration/skia-3.7.0/verification.md)), after the 3.6.1 build of 2026-10-16 ([verification](../migration/skia-3.6.1/verification.md)) and the 3.4.4 build of 2026-10-14/15 ([verification](../migration/skia-3.4.4/verification.md)); the evidence below is from Skia 3.0.6 / WebGPU 0.12.1 / Graphite 154.1.0. It uses Java 17, Gradle 9.3.1, Android SDK 36 and NDK 27.1.12297006. The library requires API 28; a consuming application with a lower minimum receives an explicit Gradle configuration error. The default example ABI is arm64-v8a; `RNSKV_ANDROID_ABI` selects another ABI for the validation script.
The Android example in `../example/android` pins React Native 0.86.2, Skia 3.9.2, WebGPU 0.21.2, the shared `react-native-webgpu-dawn` 157.1.0 (chrome-m157) and Graphite Android 157.1.0; Gradle needs `node` to resolve that Dawn package. Since WebGPU 0.19.0, export renders straight into the codec's input Surface through a WebGPU canvas context on it (`MakeWebGPUCanvasContextFromNativeWindow`, Vulkan swapchain), with no EGL; CPU readback, drawn into the Surface by EGL, stays the fallback. On API 29+, 8-bit SDR H.264/HEVC clips go through an `ImageReader`, whose YUV buffers WebGPU converts, crops, rotates and scales to the frame's size (capped or explicit sizes included since the 3.7.4 migration); since 3.6.1 each buffer is imported once, and exports sample the converted frame in place. The 3.7.0 build was assembled and run on a Pixel 8a on 2026-10-19 ([verification](../migration/skia-3.7.0/verification.md)), after the 3.6.1 build of 2026-10-16 ([verification](../migration/skia-3.6.1/verification.md)) and the 3.4.4 build of 2026-10-14/15 ([verification](../migration/skia-3.4.4/verification.md)); the evidence below is from Skia 3.0.6 / WebGPU 0.12.1 / Graphite 154.1.0. It uses Java 17, Gradle 9.3.1, Android SDK 36 and NDK 27.1.12297006. The library requires API 28; a consuming application with a lower minimum receives an explicit Gradle configuration error. The default example ABI is arm64-v8a; `RNSKV_ANDROID_ABI` selects another ABI for the validation script.

Run `android/scripts/validate.sh build` from the repository. It assembles the example Debug and unsigned Release APKs, library AAR, standalone instrumentation APK and JVM tests. Release uses the installed `hermes-compiler` package, and both native and Metro build concurrency are bounded to two workers. The Release APK is unsigned: device installation requires signing a separate local qualification artifact. The project supplies no publishing or release signing configuration.

Expand Down
12 changes: 11 additions & 1 deletion docs/UPSTREAM_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Points amont à revoir lors d'une mise à jour Skia

**Mise à jour du 9 novembre 2026 :** **`react-native-skia@3.9.2`** et **`react-native-webgpu@0.21.2`**, toujours sur Dawn/Graphite **157.1.0**. Le `main` amont du jour (`cf9240bd6`) ne diffère de la v3.9.2 que par un banc de performance de l'exemple et de la CI ([#4385](https://github.com/wcandillon/react-native-skia/pull/4385)) : le paquet publié est le même.
- **Patch :** `JsiSkSurface.h` et `JsiSkApi.h` sont identiques octet pour octet à ceux de la 3.9.1. `RNDawnContext.h` change, mais les 8 éditions s'y appliquent telles quelles.
- **Une ligne ajoutée au patch :** `submitRecordingChecked` marque son snap et son exécution comme travail GPU (`RNSkGpuActivity::Scope`), comme le fait désormais `submitRecording` en amont.
- La 3.9.2 compile en tâche de fond les pipelines courants et ceux du lancement précédent (`RNSkPipelineWarmup`, [#4398](https://github.com/wcandillon/react-native-skia/pull/4398)).
- Ce warmup ne compile que si aucun travail GPU n'est marqué, car chaque compilation tient le verrou du device Dawn.
- Sans le marquage, nos soumissions vérifiées (l'export) passeraient pour un device au repos.
- **Autres changements amont :** cadence des vues refaite ([#4398](https://github.com/wcandillon/react-native-skia/pull/4398)), le thread principal Android n'attend plus le thread de présentation ([#4395](https://github.com/wcandillon/react-native-skia/pull/4395)), `MakeGPUTextureFromImage` n'attend plus le CPU ([#4401](https://github.com/wcandillon/react-native-skia/pull/4401), non utilisé ici).
- **WebGPU 0.21.1 et 0.21.2 :** un `null` dans une liste d'emplacements garde son index ([#617](https://github.com/wcandillon/react-native-webgpu/pull/617)), `device.queue` rend toujours le même objet ([#614](https://github.com/wcandillon/react-native-webgpu/pull/614)), pod compatible `use_frameworks!` ([#612](https://github.com/wcandillon/react-native-webgpu/pull/612)).
- [#4276](https://github.com/wcandillon/react-native-skia/pull/4276) est toujours ouverte : le patch ne rétrécit pas.

**Mise à jour du 4 novembre 2026 :** **`react-native-skia@3.9.1`** et **`react-native-webgpu@0.21.0`**, sur Dawn/Graphite **157.1.0** ; les deux paquets montent ensemble.
- **Patch :** `RNDawnContext.h` et `JsiSkApi.h` changent en amont, mais les 8 éditions s'appliquent telles quelles ; seuls les empreintes et les décalages changent.
- **Readbacks asynchrones (3.9.0, [#4368](https://github.com/wcandillon/react-native-skia/pull/4368)) :** `canvas.readPixels` renvoie une promesse et ne prend plus de tableau de destination. Le readback CPU de secours de l'export attend donc la lecture avant d'encoder.
Expand Down Expand Up @@ -129,7 +139,7 @@ La [source Skia de ce build](https://chromium.googlesource.com/skia/+/2466dcf393

Fichiers inspectables :

- [`patches/react-native-skia+3.8.1.patch`](../patches/react-native-skia+3.8.1.patch) : diff du correctif courant ; ceux des versions précédentes sont conservés comme historique.
- [`patches/react-native-skia+3.9.2.patch`](../patches/react-native-skia+3.9.2.patch) : diff du correctif courant ; ceux des versions précédentes sont conservés comme historique.
- [`scripts/skia-canvas-patch.json`](../scripts/skia-canvas-patch.json) : version, empreintes avant/après et substitutions attendues.
- [`scripts/apply-skia-canvas-patch.mjs`](../scripts/apply-skia-canvas-patch.mjs) : vérifie tout avant toute écriture, accepte un patch déjà appliqué, refuse un paquet différent.

Expand Down
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ PODS:
- ReactCommon/turbomodule/core
- ReactNativeDependencies
- Yoga
- react-native-skia (3.9.1):
- react-native-skia (3.9.2):
- hermes-engine
- RCTRequired
- RCTTypeSafety
Expand Down Expand Up @@ -1473,7 +1473,7 @@ PODS:
- ReactCommon/turbomodule/core
- ReactNativeDependencies
- Yoga
- react-native-webgpu (0.21.0):
- react-native-webgpu (0.21.2):
- hermes-engine
- RCTRequired
- RCTTypeSafety
Expand Down Expand Up @@ -2350,9 +2350,9 @@ SPEC CHECKSUMS:
React-Mapbuffer: 44dd007f917e2396afa0e70bbd70273237d93fde
React-microtasksnativemodule: f413ee411341fb3c34d20e85e9f6f524921fab15
React-mutationobservernativemodule: 58f6d2adf7d98e72b241608dfa2ddce414d2a4e7
react-native-skia: bafae4183d4bbaf0dc433a6b48d59dc0dcbfde81
react-native-skia: 664894286ccbf0d0f9727c2f132499dbd4122792
react-native-skia-webgpu-video: 3dfd41b1018b347ade67c12d48b787b3ae4fc819
react-native-webgpu: c764ad1fab604bd41260f78844bbd16d167b0b6c
react-native-webgpu: d56183ba5d1b525477d49add6a8d43cd6b146bed
React-NativeModulesApple: 167e532fb9bae30f3c66636b8ee0092bab263667
React-networking: 89f6b69755a3176f30e56ba1ba8e214b1518ecfb
React-oscompat: db6675ddaef3bddd1b41533627f3d26ec710c05f
Expand Down
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"dependencies": {
"react": "19.2.3",
"react-native": "0.86.2",
"react-native-skia": "3.9.1",
"react-native-webgpu": "0.21.0",
"react-native-skia": "3.9.2",
"react-native-webgpu": "0.21.2",
"react-native-reanimated": "4.5.3",
"react-native-worklets": "0.11.3",
"react-native-skia-webgpu-video": "file:.."
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"!**/.*",
"scripts/apply-skia-canvas-patch.mjs",
"scripts/skia-canvas-patch.json",
"patches/react-native-skia+3.9.1.patch",
"patches/react-native-skia+3.9.2.patch",
"docs/UPSTREAM_NOTES.md",
"!ios/tests",
"!android/src/androidTest",
Expand Down Expand Up @@ -101,8 +101,8 @@
"react-native": "0.86.2",
"react-native-builder-bob": "^0.43.0",
"react-native-reanimated": "4.5.3",
"react-native-skia": "3.9.1",
"react-native-webgpu": "0.21.0",
"react-native-skia": "3.9.2",
"react-native-webgpu": "0.21.2",
"react-native-worklets": "0.11.3",
"react-test-renderer": "19.2.3",
"typescript": "^6.0.3"
Expand All @@ -111,8 +111,8 @@
"react": ">=19",
"react-native": ">=0.83 <0.87",
"react-native-reanimated": "4.5.3",
"react-native-skia": "3.9.1",
"react-native-webgpu": "0.21.0",
"react-native-skia": "3.9.2",
"react-native-webgpu": "0.21.2",
"react-native-worklets": "0.11.3"
},
"jest": {
Expand Down
150 changes: 150 additions & 0 deletions patches/react-native-skia+3.9.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
--- a/node_modules/react-native-skia/cpp/rnskia/RNDawnContext.h
+++ b/node_modules/react-native-skia/cpp/rnskia/RNDawnContext.h
@@ -492,6 +492,44 @@
}
current->context->submit(syncToCpu);
return inserted;
+ }
+
+ // Checked only for surfaces that explicitly opt into this contract: like
+ // submitRecording, but a recording that would not run throws instead of
+ // being dropped. A valid empty Recording is accepted; Recorder::snap()
+ // returns nullptr on failure.
+ void submitRecordingChecked(
+ skgpu::graphite::Recorder *recorder,
+ skgpu::graphite::SyncToCpu syncToCpu = skgpu::graphite::SyncToCpu::kNo) {
+ if (recorder == nullptr) {
+ throw std::runtime_error(
+ "Checked GPU submissions require a Graphite recorder");
+ }
+ // As in submitRecording: the snap compiles the pipelines the recording
+ // needs, inline, GPU work the pipeline warmup stays behind (see
+ // RNSkGpuActivity), as is the run.
+ RNSkGpuActivity::Scope activity;
+ auto recording = recorder->snap();
+ if (recording == nullptr) {
+ throw std::runtime_error("Cannot create checked Graphite recording");
+ }
+ std::lock_guard<std::mutex> lock(_mutex);
+ auto *current = _current.load(std::memory_order_acquire);
+ if (generationOf(recorder) != current->id ||
+ current->lost.load(std::memory_order_acquire)) {
+ throw std::runtime_error(
+ "The GPU device was lost; a checked recording cannot run");
+ }
+ skgpu::graphite::InsertRecordingInfo info;
+ info.fRecording = recording.get();
+ auto status = current->context->insertRecording(info);
+ if (!static_cast<bool>(status)) {
+ throw std::runtime_error("Graphite rejected a checked recording: " +
+ status.message());
+ }
+ if (!current->context->submit(syncToCpu)) {
+ throw std::runtime_error("Graphite checked submission failed");
+ }
}

/**
--- a/node_modules/react-native-skia/cpp/api/JsiSkSurface.h
+++ b/node_modules/react-native-skia/cpp/api/JsiSkSurface.h
@@ -52,6 +52,26 @@
}
}

+ // Opt-in for consumers that release native buffers after GPU completion.
+ // Other Skia surfaces preserve their existing flush/snapshot behavior.
+ void enableCheckedSubmissions() {
+ if (!getObject()->recorder()) {
+ throw std::runtime_error(
+ "Checked GPU submissions require a Graphite surface");
+ }
+ _checkedSubmissions = true;
+ }
+
+ void submitRecording(skgpu::graphite::Recorder *recorder,
+ skgpu::graphite::SyncToCpu syncToCpu =
+ skgpu::graphite::SyncToCpu::kNo) {
+ if (_checkedSubmissions) {
+ DawnContext::getInstance().submitRecordingChecked(recorder, syncToCpu);
+ } else {
+ DawnContext::getInstance().submitRecording(recorder, syncToCpu);
+ }
+ }
+
// TODO-API: Properties?
double width() { return static_cast<double>(getObject()->width()); }
double height() { return static_cast<double>(getObject()->height()); }
@@ -85,9 +105,8 @@
// only Graphite-backed surfaces need to snap and submit a recording. One
// made on a GPU device lost since submits nothing (see DawnContext).
if (auto *recorder = surface->recorder()) {
- DawnContext::getInstance().submitRecording(
- recorder, sync ? skgpu::graphite::SyncToCpu::kYes
- : skgpu::graphite::SyncToCpu::kNo);
+ submitRecording(recorder, sync ? skgpu::graphite::SyncToCpu::kYes
+ : skgpu::graphite::SyncToCpu::kNo);
}
}

@@ -120,10 +139,15 @@
} else {
image = surface->makeImageSnapshot();
}
+ // A checked surface keeps the previously published image if snapshot
+ // allocation failed.
+ if (!image && _checkedSubmissions) {
+ throw jsi::JSError(runtime, "Cannot allocate Skia surface snapshot");
+ }
// A raster surface (e.g. Skia.Surface.Make) has no Graphite recorder; its
// snapshot is already a valid CPU image, so skip the recording submit.
if (auto *recorder = surface->recorder()) {
- DawnContext::getInstance().submitRecording(recorder);
+ submitRecording(recorder);
}
if (count > 1 && arguments[1].isObject()) {
auto jsiImage = getJsiObject<JsiSkImage>(runtime, arguments[1]);
@@ -196,6 +220,8 @@
&JsiSkSurface::makeImageSnapshot);
installMethod(runtime, prototype, "asImage", &JsiSkSurface::asImage);
installMethod(runtime, prototype, "flush", &JsiSkSurface::flush);
+ installMethod(runtime, prototype, "enableCheckedSubmissions",
+ &JsiSkSurface::enableCheckedSubmissions);
}

protected:
@@ -222,6 +248,7 @@

std::shared_ptr<Dispatcher> _dispatcher;
std::shared_ptr<JsiSkCanvas> _canvas;
+ bool _checkedSubmissions = false;
};

} // namespace RNSkia
--- a/node_modules/react-native-skia/cpp/api/JsiSkApi.h
+++ b/node_modules/react-native-skia/cpp/api/JsiSkApi.h
@@ -162,6 +162,16 @@
}
JSI_HOST_FUNCTION(Color) {
return JsiSkColor::createCtor()(runtime, thisValue, arguments, count);
+ }
+ // Private video-export cleanup. Only the calling thread's recorders are
+ // trimmed; the shared Context cache and other threads' recorders are
+ // untouched.
+ JSI_HOST_FUNCTION(__rnskvTrimRecorderCache) {
+ auto &context = DawnContext::getInstance();
+ context.submitRecordingChecked(context.getRecorder(),
+ skgpu::graphite::SyncToCpu::kYes);
+ DawnContext::trimThreadRecorders(std::chrono::milliseconds(0), true);
+ return jsi::Value::undefined();
}
JSI_HOST_FUNCTION(getNativeDevice) {
// Raw WGPUDevice pointer of the Graphite device, as a BigInt. Consumed by
@@ -262,6 +272,8 @@
}

static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
+ installHostMethod(runtime, prototype, "__rnskvTrimRecorderCache",
+ &JsiSkApi::__rnskvTrimRecorderCache);
installHostMethod(runtime, prototype, "getNativeDevice",
&JsiSkApi::getNativeDevice);
installGetterWithRuntime(runtime, prototype, "gpu", &JsiSkApi::getGpu);
Loading