react-native-skia-webgpu-video 0.1.0-beta.3 → 0.1.0

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 (81) hide show
  1. package/README.md +48 -43
  2. package/android/BUILD_VALIDATION.md +1 -1
  3. package/android/CMakeLists.txt +3 -2
  4. package/android/cpp/ExportHintSession.cpp +114 -0
  5. package/android/cpp/ExportHintSession.h +35 -0
  6. package/android/cpp/VideoEncoderHostObject.cpp +76 -101
  7. package/android/cpp/VideoEncoderHostObject.h +14 -9
  8. package/android/cpp/VideoFrame.cpp +3 -5
  9. package/android/cpp/cpp-adapter.cpp +7 -4
  10. package/android/src/main/java/com/azzapp/rnskv/GLFrameExtractor.java +3 -9
  11. package/android/src/main/java/com/azzapp/rnskv/VideoCompositionDecoder.java +8 -11
  12. package/android/src/main/java/com/azzapp/rnskv/VideoEncoder.java +68 -28
  13. package/docs/FRAME_PIXEL_FORMAT.md +17 -2
  14. package/docs/MIGRATION.md +1 -1
  15. package/docs/UPSTREAM_NOTES.md +42 -2
  16. package/ios/RNSVColorSpace.h +8 -3
  17. package/lib/module/canvas.js +3 -5
  18. package/lib/module/canvas.js.map +1 -1
  19. package/lib/module/exportFrames.js +8 -10
  20. package/lib/module/exportFrames.js.map +1 -1
  21. package/lib/module/exportTarget.js +183 -40
  22. package/lib/module/exportTarget.js.map +1 -1
  23. package/lib/module/exportVideoComposition.js +78 -35
  24. package/lib/module/exportVideoComposition.js.map +1 -1
  25. package/lib/module/frameInterop.js +323 -82
  26. package/lib/module/frameInterop.js.map +1 -1
  27. package/lib/module/gpu.js +1 -3
  28. package/lib/module/gpu.js.map +1 -1
  29. package/lib/module/gpuDevice.js +12 -0
  30. package/lib/module/gpuDevice.js.map +1 -1
  31. package/lib/module/memory.js +7 -0
  32. package/lib/module/memory.js.map +1 -1
  33. package/lib/module/previewLifecycle.js +2 -1
  34. package/lib/module/previewLifecycle.js.map +1 -1
  35. package/lib/module/videoCompositionPlayer.js +65 -14
  36. package/lib/module/videoCompositionPlayer.js.map +1 -1
  37. package/lib/module/videoFrameImage.js +1 -1
  38. package/lib/module/yuvBlit.js +31 -24
  39. package/lib/module/yuvBlit.js.map +1 -1
  40. package/lib/typescript/src/canvas.d.ts.map +1 -1
  41. package/lib/typescript/src/exportFrames.d.ts +3 -2
  42. package/lib/typescript/src/exportFrames.d.ts.map +1 -1
  43. package/lib/typescript/src/exportTarget.d.ts +53 -14
  44. package/lib/typescript/src/exportTarget.d.ts.map +1 -1
  45. package/lib/typescript/src/exportVideoComposition.d.ts +2 -1
  46. package/lib/typescript/src/exportVideoComposition.d.ts.map +1 -1
  47. package/lib/typescript/src/frameInterop.d.ts +16 -5
  48. package/lib/typescript/src/frameInterop.d.ts.map +1 -1
  49. package/lib/typescript/src/gpu.d.ts.map +1 -1
  50. package/lib/typescript/src/gpuDevice.d.ts +5 -1
  51. package/lib/typescript/src/gpuDevice.d.ts.map +1 -1
  52. package/lib/typescript/src/memory.d.ts +2 -0
  53. package/lib/typescript/src/memory.d.ts.map +1 -1
  54. package/lib/typescript/src/previewLifecycle.d.ts +2 -0
  55. package/lib/typescript/src/previewLifecycle.d.ts.map +1 -1
  56. package/lib/typescript/src/types.d.ts +18 -12
  57. package/lib/typescript/src/types.d.ts.map +1 -1
  58. package/lib/typescript/src/videoCompositionPlayer.d.ts +4 -5
  59. package/lib/typescript/src/videoCompositionPlayer.d.ts.map +1 -1
  60. package/lib/typescript/src/videoFrameImage.d.ts +1 -1
  61. package/lib/typescript/src/yuvBlit.d.ts +16 -14
  62. package/lib/typescript/src/yuvBlit.d.ts.map +1 -1
  63. package/package.json +6 -6
  64. package/patches/react-native-skia+3.10.0.patch +150 -0
  65. package/scripts/skia-canvas-patch.json +22 -258
  66. package/src/canvas.ts +3 -7
  67. package/src/exportFrames.ts +10 -11
  68. package/src/exportTarget.ts +217 -56
  69. package/src/exportVideoComposition.ts +130 -85
  70. package/src/frameInterop.ts +389 -96
  71. package/src/gpu.ts +1 -3
  72. package/src/gpuDevice.ts +26 -1
  73. package/src/memory.ts +6 -0
  74. package/src/previewLifecycle.ts +4 -1
  75. package/src/types.ts +18 -12
  76. package/src/videoCompositionPlayer.ts +76 -23
  77. package/src/videoFrameImage.ts +1 -1
  78. package/src/yuvBlit.ts +46 -31
  79. package/android/cpp/EncoderTargets.cpp +0 -226
  80. package/android/cpp/EncoderTargets.h +0 -70
  81. package/patches/react-native-skia+3.7.1.patch +0 -502
@@ -1 +1 @@
1
- {"version":3,"names":["assertExportRecorderCacheSupport","trimExportRecorderCache","getVideoCanvas","createWorkletRuntime","createSynchronizable","runOnRuntime","scheduleOnRN","AlphaType","BlendMode","ColorType","Skia","Platform","RNSkiaVideoModule","clearVideoFrameImages","ownVideoFrames","releaseVideoFrameImage","frameByteSize","releaseVideoMemory","reserveVideoMemory","enqueueExport","exportAbortError","acquireEncoderTarget","closeEncoderTarget","probeEncoderTarget","supportsEncoderTargets","yieldToRuntime","createExportFrameImports","ownExportFrames","releaseExportFrames","exportRuntime","getExportRuntime","name","runWithVideoAutoreleasePool","fn","runWithAutoreleasePool","body","exportVideoComposition","args","executeExport","abortSignal","Promise","resolve","reject","videoComposition","drawFrame","beforeDrawFrame","afterDrawFrame","onProgress","createFrameProcessor","onProfile","options","aborted","bytes","nbFrames","width","height","Number","isFinite","frameRate","duration","bitRate","outPath","Error","Math","ceil","isSafeInteger","error","cancelled","onAbort","setBlocking","addEventListener","settle","failed","removeEventListener","runtime","getBlocking","bgra","OS","gpuExport","getBackendInfo","gpuDirectExport","step","frameWorklet","storage","globalThis","state","__rnskwgpuExport","isCancelled","profile","frames","totalMs","decodeMs","importMs","prepareMs","targetMs","drawMs","gpuMs","encodeMs","yieldMs","clock","last","lap","stage","now","performance","finish","cleanup","failure","safeToRelease","clean","e","surface","flush","target","pendingAfterDraw","processor","dispose","extractor","encoder","frame","Object","values","imports","canvas","hasRecorder","i","reservations","length","splice","readback","poisoned","setupError","work","time","index","owned","decoded","decodeCompositionFrames","imported","key","previous","entries","producers","has","producerId","prepareFrame","currentTime","draw","gpu","drawColor","Color","Clear","context","drawn","undefined","drained","encodeFrame","kind","nativeBuffer","pointer","fences","readbackCanvas","pixels","readPixels","colorType","BGRA_8888","RGBA_8888","alphaType","Premul","Uint8Array","byteLength","byteOffset","buffer","slice","data","bytesPerRow","releaseContext","framesCompleted","finishWriting","run","setup","allocateReadback","push","Surface","MakeOffscreen","createVideoEncoder","audioBitRate","audioSampleRate","audioChannelCount","prepare","console","warn","String","createVideoCompositionFramesExtractorSync","start"],"sourceRoot":"../../src","sources":["exportVideoComposition.ts"],"mappings":";;AAAA,SACEA,gCAAgC,EAChCC,uBAAuB,QAClB,kBAAe;AACtB,SAASC,cAAc,QAAQ,aAAU;AACzC,SACEC,oBAAoB,EACpBC,oBAAoB,EACpBC,YAAY,EACZC,YAAY,QAEP,uBAAuB;AAC9B,SAASC,SAAS,EAAEC,SAAS,EAAEC,SAAS,EAAEC,IAAI,QAAQ,mBAAmB;AAEzE,SAASC,QAAQ,QAAQ,cAAc;AASvC,OAAOC,iBAAiB,MAAM,wBAAqB;AACnD,SACEC,qBAAqB,EACrBC,cAAc,EACdC,sBAAsB,QACjB,mBAAgB;AACvB,SACEC,aAAa,EACbC,kBAAkB,EAClBC,kBAAkB,QACb,aAAU;AACjB,SAASC,aAAa,EAAEC,gBAAgB,QAAQ,kBAAe;AAC/D,SACEC,oBAAoB,EACpBC,kBAAkB,EAClBC,kBAAkB,EAClBC,sBAAsB,QAEjB,mBAAgB;AACvB,SAASC,cAAc,QAAQ,mBAAgB;AAC/C,SACEC,wBAAwB,EACxBC,eAAe,EACfC,mBAAmB,QAEd,mBAAgB;;AAWvB;AACA;;AAQA;AACA;;AA+CA;AACA;AACA;;AAgCA,IAAIC,aAAoC,GAAG,IAAI;AAC/C,MAAMC,gBAAgB,GAAGA,CAAA,KAAM;EAC7B,IAAI,CAACD,aAAa,EAChBA,aAAa,GAAG1B,oBAAoB,CAAC;IAAE4B,I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;EAC9C;AACF,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["assertExportRecorderCacheSupport","trimExportRecorderCache","getVideoCanvas","createWorkletRuntime","createSynchronizable","runOnRuntime","scheduleOnRN","AlphaType","BlendMode","ColorType","Skia","Platform","RNSkiaVideoModule","clearVideoFrameImages","ownVideoFrames","releaseVideoFrameImage","frameByteSize","releaseVideoMemory","reserveVideoMemory","enqueueExport","exportAbortError","acquireEncoderTarget","acquireWindowTarget","closeEncoderTarget","closeEncoderWindow","presentWindowTarget","probeEncoderTarget","probeEncoderWindow","releaseEncoderWindow","supportsEncoderTargets","yieldToRuntime","createExportFrameImports","ownExportFrames","releaseExportFrames","exportRuntime","getExportRuntime","name","runWithVideoAutoreleasePool","fn","runWithAutoreleasePool","body","exportVideoComposition","args","executeExport","abortSignal","Promise","resolve","reject","videoComposition","drawFrame","beforeDrawFrame","afterDrawFrame","onProgress","createFrameProcessor","onProfile","options","aborted","bytes","nbFrames","width","height","Number","isFinite","frameRate","duration","bitRate","outPath","Error","Math","ceil","isSafeInteger","error","cancelled","onAbort","setBlocking","addEventListener","settle","failed","removeEventListener","runtime","getBlocking","bgra","OS","gpuExport","getBackendInfo","gpuDirectExport","step","frameWorklet","storage","globalThis","state","__rnskwgpuExport","isCancelled","profile","frames","totalMs","decodeMs","importMs","prepareMs","targetMs","drawMs","gpuMs","encodeMs","yieldMs","clock","last","lap","stage","now","performance","checkWindowFrame","unchecked","window","slots","next","surface","flush","finish","cleanup","failure","safeToRelease","clean","e","target","pendingAfterDraw","processor","dispose","extractor","encoder","frame","Object","values","imports","canvas","hasRecorder","i","reservations","length","splice","poisoned","setupError","work","time","index","owned","decoded","decodeCompositionFrames","imported","key","previous","entries","producers","has","producerId","prepareFrame","currentTime","readback","pixels","draw","gpu","drawColor","Color","Clear","context","drawn","undefined","drained","encodeFrame","kind","nativeBuffer","pointer","readPixels","colorType","BGRA_8888","RGBA_8888","alphaType","Premul","releaseContext","ArrayBuffer","isView","byteLength","byteOffset","buffer","slice","data","bytesPerRow","framesCompleted","finishWriting","run","setup","allocateReadback","push","Surface","MakeOffscreen","createVideoEncoder","audioBitRate","audioSampleRate","audioChannelCount","prepare","probe","console","warn","String","createVideoCompositionFramesExtractorSync","start"],"sourceRoot":"../../src","sources":["exportVideoComposition.ts"],"mappings":";;AAAA,SACEA,gCAAgC,EAChCC,uBAAuB,QAClB,kBAAe;AACtB,SAASC,cAAc,QAAQ,aAAU;AACzC,SACEC,oBAAoB,EACpBC,oBAAoB,EACpBC,YAAY,EACZC,YAAY,QAEP,uBAAuB;AAC9B,SAASC,SAAS,EAAEC,SAAS,EAAEC,SAAS,EAAEC,IAAI,QAAQ,mBAAmB;AAEzE,SAASC,QAAQ,QAAQ,cAAc;AASvC,OAAOC,iBAAiB,MAAM,wBAAqB;AACnD,SACEC,qBAAqB,EACrBC,cAAc,EACdC,sBAAsB,QACjB,mBAAgB;AACvB,SACEC,aAAa,EACbC,kBAAkB,EAClBC,kBAAkB,QACb,aAAU;AACjB,SAASC,aAAa,EAAEC,gBAAgB,QAAQ,kBAAe;AAC/D,SACEC,oBAAoB,EACpBC,mBAAmB,EACnBC,kBAAkB,EAClBC,kBAAkB,EAClBC,mBAAmB,EACnBC,kBAAkB,EAClBC,kBAAkB,EAClBC,oBAAoB,EACpBC,sBAAsB,QAGjB,mBAAgB;AACvB,SAASC,cAAc,QAAQ,mBAAgB;AAC/C,SACEC,wBAAwB,EACxBC,eAAe,EACfC,mBAAmB,QAEd,mBAAgB;;AAWvB;AACA;;AAQA;AACA;;AAyEA,IAAIC,aAAoC,GAAG,IAAI;AAC/C,MAAMC,gBAAgB,GAAGA,CAAA,KAAM;EAC7B,IAAI,CAACD,aAAa,EAChBA,aAAa,GAAG/B,oBAAoB,CAAC;IAAEiC,IAAI,EAAE;EAA0B,CAAC,CAAC;EAC3E,OAAOF,aAAa;AACtB,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMG,2BAA2B,GAAOC,EAAW,IAAQ;EACz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as.js";
4
4
  import { Platform } from "react-native";
5
5
  import { AlphaType, BlendMode, ColorType, Skia } from "react-native-skia";
6
6
  import { getVideoGpuDevice, createNativeVideoGpuFrame, nativeVideoTextureUsage, rgbaVideoTextureUsage } from "./gpuDevice.js";
7
- import { frameByteSize, releaseVideoMemory, reserveVideoMemory } from "./memory.js";
8
- import { blitNv12Frame, blitYuvFrame, releaseYuvImports, yuvFrameOrigin } from "./yuvBlit.js";
7
+ import { frameByteSize, releaseVideoMemory, reserveVideoMemory, videoMemoryBudget } from "./memory.js";
8
+ import { blitNv12Frame, blitYuvFrame, releaseYuvImports, yuvFrameRegion } from "./yuvBlit.js";
9
+
10
+ /** A decoder buffer an import's GPU copy still reads. */
11
+
12
+ /** A texture frames are converted into, and that their images wrap. */
13
+
14
+ /** The textures of a producer: its frames go into them in turn, so that the
15
+ * image of the previous frame stays whole while the next is written. One
16
+ * texture only, written in place, when the memory budget is short. */
17
+
18
+ // Imports whose GPU copy may still be running, their decoder buffers out. Kept
19
+ // below the YUV imports cached per producer (yuvBlit.ts), so that the one it
20
+ // evicts, the least recently drawn, is never still being read.
21
+ const maxInFlightImports = 2;
22
+
23
+ /** Whether the memory budget affords keeping a decoder buffer of `bytes` out
24
+ * until the GPU is done with it: a buffer within a sixteenth of the budget
25
+ * (two out stay within an eighth), and room left for the decoder's next two
26
+ * frames, which it reserves ahead. With the default 256 MB, a 4K BGRA frame
27
+ * (33 MB) is waited for; two 4K NV12 ones (12 MB each) are not. */
28
+ const affordsInFlight = bytes => {
29
+ "worklet";
30
+
31
+ const budget = videoMemoryBudget();
32
+ return !!budget && bytes <= budget.maxBytes / 16 && budget.maxBytes - budget.currentBytes >= 2 * bytes;
33
+ };
34
+
9
35
  // Capture a scalar on the RN runtime instead of importing Platform inside a
10
36
  // worklet. iOS keeps its existing native-buffer and RGBA compatibility paths.
11
37
  const uploadAndroidRgba = Platform.OS === "android";
@@ -18,16 +44,16 @@ const getCache = () => {
18
44
  images: new Map(),
19
45
  stage: null,
20
46
  canvas: null,
21
- width: 0,
22
- height: 0,
23
- format: null,
24
47
  uploadTexture: null,
25
- uploadReservation: 0,
48
+ targets: new Map(),
49
+ freeTextures: [],
26
50
  cpuPixels: null,
27
51
  cpuReservation: 0,
28
52
  cpuBytesPerRow: 0,
29
53
  pendingSources: [],
30
- yuvImports: new Map()
54
+ yuvImports: new Map(),
55
+ checkedWaits: 0,
56
+ inFlight: []
31
57
  };
32
58
  }
33
59
  return runtime.__rnskwgpuFrames;
@@ -49,11 +75,174 @@ const clearEntry = (cache, producer) => {
49
75
  const clearSurfaceView = cache => {
50
76
  "worklet";
51
77
 
52
- cache.canvas?.dispose();
53
78
  cache.canvas = null;
54
79
  cache.stage?.dispose();
55
80
  cache.stage = null;
56
81
  };
82
+
83
+ /** Waits for all the GPU work submitted so far, on the shared context. */
84
+ const waitForGpu = cache => {
85
+ "worklet";
86
+
87
+ if (cache.stage) cache.stage.flush(true);else {
88
+ let texture = cache.uploadTexture ?? cache.freeTextures[0]?.texture;
89
+ if (!texture) {
90
+ for (const target of cache.targets.values()) {
91
+ texture = target.textures[0]?.texture;
92
+ if (texture) break;
93
+ }
94
+ }
95
+ // A released producer's textures may all be gone (too big to keep free)
96
+ // while its imports are still in flight: any Graphite surface's checked
97
+ // flush waits on the shared context just the same.
98
+ const view = texture ? Skia.Surface.MakeFromGPUTexture(texture) : Skia.Surface.MakeOffscreen(1, 1);
99
+ if (!view) throw new Error("Video import drain surface is unavailable");
100
+ try {
101
+ view.flush(true);
102
+ } finally {
103
+ view.dispose();
104
+ }
105
+ }
106
+ cache.checkedWaits++;
107
+ };
108
+
109
+ /** Hands the decoder buffers of the first `count` imports in flight back,
110
+ * once the GPU is done with them: because the GPU reported the last of these
111
+ * imports done (in order: the work before it is done too), or after a wait
112
+ * for it, made here when `count` is all of them and nobody `waited`. */
113
+ const settleInFlightImports = (cache, count, waited = false) => {
114
+ "worklet";
115
+
116
+ if (!count) return;
117
+ if (count === cache.inFlight.length && !waited) waitForGpu(cache);
118
+ for (let i = 0; i < count; i++) {
119
+ const entry = cache.inFlight.shift();
120
+ try {
121
+ entry.nativeSource?.release();
122
+ entry.nativeSource = null;
123
+ entry.frame.dispose?.();
124
+ } catch (error) {
125
+ // Like a failed release at import: only the final drain retries it.
126
+ cache.pendingSources.push({
127
+ nativeSource: entry.nativeSource,
128
+ owned: null,
129
+ reservation: 0,
130
+ frame: entry.frame,
131
+ needsDrain: false,
132
+ sourceReleased: false
133
+ });
134
+ throw error;
135
+ }
136
+ }
137
+ };
138
+
139
+ // Free textures kept for the next producer, when they are small enough.
140
+ const maxFreeImportTextures = 2;
141
+
142
+ /** Work already submitted still completes on a destroyed texture; a caller
143
+ * that cannot tell whether everything reading it was submitted waits first. */
144
+ const destroyImportTexture = (cache, entry) => {
145
+ "worklet";
146
+
147
+ if (cache.uploadTexture === entry.texture) {
148
+ clearSurfaceView(cache);
149
+ cache.uploadTexture = null;
150
+ }
151
+ entry.texture.destroy();
152
+ releaseVideoMemory(entry.reservation);
153
+ entry.reservation = 0;
154
+ };
155
+
156
+ // A texture leaves its list only once destroyed: a failed teardown is
157
+ // retried by the next one, its memory still accounted.
158
+ const releaseFreeImportTextures = cache => {
159
+ "worklet";
160
+
161
+ while (cache.freeTextures.length) {
162
+ destroyImportTexture(cache, cache.freeTextures[cache.freeTextures.length - 1]);
163
+ cache.freeTextures.pop();
164
+ }
165
+ };
166
+
167
+ /** Gives up the textures of a producer whose image is disposed. Small ones
168
+ * are kept for the next producer of that size (a montage goes from clip to
169
+ * clip), within the budget's sixteenth each, as for imports in flight. */
170
+ const releaseImportTarget = (cache, producer, keep = true) => {
171
+ "worklet";
172
+
173
+ const target = cache.targets.get(producer);
174
+ if (!target) return;
175
+ const budget = videoMemoryBudget();
176
+ while (target.textures.length) {
177
+ const entry = target.textures[target.textures.length - 1];
178
+ if (keep && cache.freeTextures.length < maxFreeImportTextures && !!budget && frameByteSize(entry.width, entry.height) <= budget.maxBytes / 16) cache.freeTextures.push(entry);else destroyImportTexture(cache, entry);
179
+ target.textures.pop();
180
+ }
181
+ cache.targets.delete(producer);
182
+ };
183
+
184
+ /** The texture the next frame of `producer` goes into: one that its current
185
+ * image does not wrap, when the producer has or can afford a second one. */
186
+ const acquireImportTexture = (cache, device, producer, width, height, format, usage, label) => {
187
+ "worklet";
188
+
189
+ let target = cache.targets.get(producer);
190
+ if (target && target.textures.some(entry => entry.width !== width || entry.height !== height || entry.format !== format)) {
191
+ // The producer changed size: its image wraps a texture given up here.
192
+ clearEntry(cache, producer);
193
+ releaseImportTarget(cache, producer, false);
194
+ target = undefined;
195
+ }
196
+ if (!target) {
197
+ target = {
198
+ textures: []
199
+ };
200
+ cache.targets.set(producer, target);
201
+ }
202
+ const shown = cache.images.get(producer);
203
+ const live = shown?.image ? target.textures.findIndex(entry => entry.texture === shown.texture) : -1;
204
+ let index = target.textures.findIndex((_, i) => i !== live);
205
+ if (index < 0) {
206
+ const free = cache.freeTextures.findIndex(entry => entry.width === width && entry.height === height && entry.format === format);
207
+ const bytes = frameByteSize(width, height);
208
+ const budget = videoMemoryBudget();
209
+ if (free >= 0) {
210
+ target.textures.push(cache.freeTextures.splice(free, 1)[0]);
211
+ index = target.textures.length - 1;
212
+ } else if (!target.textures.length || !budget || budget.maxBytes - budget.currentBytes >= 3 * bytes) {
213
+ // Free textures of another size only hold memory back from here on.
214
+ releaseFreeImportTextures(cache);
215
+ const reservation = reserveVideoMemory(bytes, label);
216
+ let texture;
217
+ try {
218
+ texture = device.createTexture({
219
+ size: {
220
+ width,
221
+ height
222
+ },
223
+ format,
224
+ usage,
225
+ label
226
+ });
227
+ } catch (error) {
228
+ releaseVideoMemory(reservation);
229
+ throw error;
230
+ }
231
+ target.textures.push({
232
+ texture,
233
+ width,
234
+ height,
235
+ format,
236
+ reservation
237
+ });
238
+ index = target.textures.length - 1;
239
+ } else {
240
+ // No room for a second texture: write over the current frame.
241
+ index = live;
242
+ }
243
+ }
244
+ return target.textures[index].texture;
245
+ };
57
246
  const clearCpuPixels = cache => {
58
247
  "worklet";
59
248
 
@@ -65,35 +254,45 @@ const clearCpuPixels = cache => {
65
254
  const clearStagingSurface = cache => {
66
255
  "worklet";
67
256
 
257
+ settleInFlightImports(cache, cache.inFlight.length);
68
258
  cache.stage?.flush(true);
69
259
  clearSurfaceView(cache);
70
- cache.uploadTexture?.destroy();
260
+ for (const producer of [...cache.targets.keys()]) releaseImportTarget(cache, producer, false);
261
+ releaseFreeImportTextures(cache);
71
262
  cache.uploadTexture = null;
72
- releaseVideoMemory(cache.uploadReservation);
73
- cache.uploadReservation = 0;
74
263
  clearCpuPixels(cache);
75
- cache.width = cache.height = 0;
76
- cache.format = null;
77
264
  };
78
265
 
79
266
  /** Record explicit recovery work after a possibly submitted external copy.
80
- * Clearing scratch cannot modify an already owned snapshot. The checked fence
81
- * must succeed before either native lease or the texture can be released. */
267
+ * It clears the texture of the import that failed, whose image is dropped;
268
+ * with two textures, the producer's previous image is in the other one. The
269
+ * checked fence must succeed before either native lease or the texture can be released. */
82
270
  const drainNativeCopies = cache => {
83
271
  "worklet";
84
272
 
85
273
  if (!cache.stage || !cache.canvas) throw new Error("Video import drain surface is unavailable");
86
274
  cache.canvas.drawColor(Skia.Color("#00000000"), BlendMode.Clear);
87
275
  cache.stage.flush(true);
276
+ cache.checkedWaits++;
277
+ };
278
+
279
+ /** The checked GPU waits this runtime's imports have made so far, and the
280
+ * completions the GPU reported for them. Each one covers all the GPU work
281
+ * submitted before it, on the shared context. */
282
+ export const videoFrameImportWaits = () => {
283
+ "worklet";
284
+
285
+ return getCache().checkedWaits;
88
286
  };
89
287
 
90
288
  /** Clear a runtime's imported images after ending all its producers.
91
289
  * Do not clear a paused producer's current frame: its native source has
92
- * already been released, and the owned snapshot is its remaining pixels. */
290
+ * already been released, and its image's texture is its remaining pixels. */
93
291
  export const clearVideoFrameImages = (releaseStagingSurface = false) => {
94
292
  "worklet";
95
293
 
96
294
  const cache = getCache();
295
+ settleInFlightImports(cache, cache.inFlight.length);
97
296
  if (cache.pendingSources.length) {
98
297
  // A failed drain retains leases; only a successful fence can release them.
99
298
  if (cache.pendingSources.some(source => source.needsDrain)) {
@@ -133,17 +332,30 @@ export const releaseVideoFrameImage = frame => {
133
332
  const producer = frame.producerId ?? frame.id ?? -1;
134
333
  const cache = getCache();
135
334
  const entry = cache.images.get(producer);
136
- if (entry && entry.id === (frame.id ?? -1)) clearEntry(cache, producer);
137
- // Each import ends with a checked flush; after a failed one, only the
138
- // drain in clearVideoFrameImages may release the decoder buffers.
139
- if (!cache.pendingSources.length) releaseYuvImports(cache.yuvImports, producer);
335
+ if (entry && entry.id === (frame.id ?? -1)) {
336
+ clearEntry(cache, producer);
337
+ releaseImportTarget(cache, producer);
338
+ }
339
+ // Every import is done once the GPU is; after a failed one, only the drain
340
+ // in clearVideoFrameImages may release the decoder buffers.
341
+ if (!cache.pendingSources.length && cache.yuvImports.has(producer)) {
342
+ settleInFlightImports(cache, cache.inFlight.length);
343
+ releaseYuvImports(cache.yuvImports, producer);
344
+ }
140
345
  if (cache.images.size === 0) clearVideoFrameImages(true);
141
346
  };
142
347
 
143
- /** Returns immutable, owned pixels. WebGPU uploads Android RGBA pixels or blits
144
- * native buffers into one reusable texture, then snapshots a fresh Skia view.
145
- * Graphite-backed snapshots bypass the raster ImageProvider's image-count LRU.
146
- * Wait for completion before releasing sources or rewriting the scratch texture. */
348
+ /** Returns owned pixels. WebGPU uploads Android RGBA pixels or blits native
349
+ * buffers into a texture of the frame's producer, which the image wraps: no
350
+ * copy into a snapshot, and no entry in the raster ImageProvider's LRU.
351
+ * Sources go back once the GPU is done with them.
352
+ *
353
+ * The image is the producer's until its next frame is imported, which
354
+ * disposes it. A producer has two textures and writes its frames into them in
355
+ * turn, so the texture of an image is only written again by the import after
356
+ * the one that disposed it; with a memory budget too short for a second
357
+ * texture, the next frame is written over it, in queue order after the draws
358
+ * already submitted. */
147
359
  export const imageFromVideoFrame = frame => {
148
360
  "worklet";
149
361
 
@@ -153,7 +365,7 @@ export const imageFromVideoFrame = frame => {
153
365
  const existing = cache.images.get(producer);
154
366
  if (existing?.id === frame.id && existing.image) {
155
367
  // Android can issue a fresh lease for the same paused picture. The
156
- // snapshot already owns its pixels, so close that unused native lease.
368
+ // image already owns its pixels, so close that unused native lease.
157
369
  // Weak tracking avoids retaining raw buffers or closing one wrapper twice.
158
370
  if (!existing.releasedSources.has(frame)) {
159
371
  frame.dispose?.();
@@ -168,6 +380,9 @@ export const imageFromVideoFrame = frame => {
168
380
  let ownsSurfaceView = false;
169
381
  let nativeSource = null;
170
382
  let sourceDrained = false;
383
+ let completion = null;
384
+ let sourceBytes = 0;
385
+ let importTexture = null;
171
386
  let releaseSource = true;
172
387
  let importFailed = false;
173
388
  try {
@@ -215,7 +430,7 @@ export const imageFromVideoFrame = frame => {
215
430
  reservation = reserveVideoMemory(pixels.byteLength, "owned video image");
216
431
  const data = Skia.Data.fromBytes(pixels);
217
432
  try {
218
- image = Skia.Image.MakeRasterImage({
433
+ image = Skia.Image.MakeRaster({
219
434
  width: frame.width,
220
435
  height: frame.height,
221
436
  colorType: ColorType.RGBA_8888,
@@ -235,37 +450,14 @@ export const imageFromVideoFrame = frame => {
235
450
  if (!Number.isSafeInteger(extentLimit) || extentLimit <= 0 || frame.width > extentLimit || frame.height > extentLimit) throw new Error("Video frame exceeds the WebGPU texture extent limit");
236
451
  }
237
452
  const format = uploadRgba || uploadAndroidRgba ? "rgba8unorm" : "bgra8unorm";
238
- reservation = reserveVideoMemory(bytes, "owned video image");
239
- if (!cache.uploadTexture || cache.width !== frame.width || cache.height !== frame.height || cache.format !== format) {
240
- clearStagingSurface(cache);
241
- cache.uploadReservation = reserveVideoMemory(bytes, uploadRgba ? "RGBA frame WebGPU upload texture" : "native frame WebGPU upload texture");
242
- try {
243
- // One scratch texture per runtime. COPY_SRC lets Graphite snapshot
244
- // it with a GPU blit rather than draw into another staging target.
245
- cache.uploadTexture = device.createTexture({
246
- size: {
247
- width: frame.width,
248
- height: frame.height
249
- },
250
- format,
251
- // Android AHB and CPU frames share the RGBA scratch. Include
252
- // COPY_DST even for a first AHB frame, so a later CPU fallback
253
- // cannot reuse a texture that forbids writeTexture.
254
- usage: uploadRgba || uploadAndroidRgba ? rgbaVideoTextureUsage : nativeVideoTextureUsage,
255
- label: uploadRgba ? "video RGBA frame upload" : "video native frame upload"
256
- });
257
- cache.width = frame.width;
258
- cache.height = frame.height;
259
- cache.format = format;
260
- } catch (error) {
261
- try {
262
- clearStagingSurface(cache);
263
- } catch {
264
- /* unfinished cleanup/accounting stays reachable */
265
- }
266
- throw error;
267
- }
268
- }
453
+ // The frame is converted straight into a texture of its producer, which
454
+ // the image wraps: no copy into a snapshot. Android AHB and CPU frames
455
+ // share RGBA textures, COPY_DST included even for a first AHB frame, so
456
+ // that a later CPU fallback can write into them.
457
+ clearSurfaceView(cache);
458
+ cache.uploadTexture = null;
459
+ cache.uploadTexture = acquireImportTexture(cache, device, key, frame.width, frame.height, format, uploadRgba || uploadAndroidRgba ? rgbaVideoTextureUsage : nativeVideoTextureUsage, uploadRgba ? "video RGBA frame" : "video native frame");
460
+ importTexture = cache.uploadTexture;
269
461
  if (copyRgbaPixels && texture.kind === "rgba") {
270
462
  if (!cache.cpuPixels || cache.cpuPixels.byteLength !== requiredRgbaBytes || cache.cpuBytesPerRow !== texture.bytesPerRow) {
271
463
  clearCpuPixels(cache);
@@ -293,9 +485,8 @@ export const imageFromVideoFrame = frame => {
293
485
  clearCpuPixels(cache);
294
486
  }
295
487
  clearSurfaceView(cache);
296
- // WebGPU writes do not invalidate SkSurface's cached snapshot. A fresh
297
- // surface wrapper for every frame prevents stale pixels without another
298
- // GPU allocation or a write through Skia that would overwrite the input.
488
+ // The surface only carries the checked submissions and waits of this
489
+ // import, and its recovery drain; the image wraps the texture itself.
299
490
  cache.stage = Skia.Surface.MakeFromGPUTexture(cache.uploadTexture);
300
491
  if (!cache.stage) throw new Error("Cannot wrap video upload texture");
301
492
  ownsSurfaceView = true;
@@ -320,17 +511,15 @@ export const imageFromVideoFrame = frame => {
320
511
  const region = texture.region;
321
512
  const rotation = texture.rotation ?? 0;
322
513
  const nv12 = !region && texture.format === "nv12";
323
- let origin = {
324
- x: 0,
325
- y: 0
326
- };
514
+ let upright = null;
327
515
  if (region) {
328
516
  // An Android codec buffer: padded, YUV, in encoded orientation. The
329
- // blit converts, crops and turns it into the display-sized scratch,
330
- // as the GL path's SurfaceTexture transform did. RN WebGPU labels
331
- // driver-defined YUV formats "bgra8", yet Dawn imports them as YUV:
332
- // the native side checked the format, so the label is not read.
333
- origin = yuvFrameOrigin(region, rotation, nativeSource, frame);
517
+ // blit converts, crops, turns and scales it into the frame-sized
518
+ // scratch, as the GL path's SurfaceTexture transform did. RN WebGPU
519
+ // labels driver-defined YUV formats "bgra8", yet Dawn imports them
520
+ // as YUV: the native side checked the format, so the label is not
521
+ // read.
522
+ upright = yuvFrameRegion(region, rotation, nativeSource);
334
523
  } else if (nv12) {
335
524
  if (nativeSource.width !== frame.width || nativeSource.height !== frame.height) throw new Error("Native video buffer dimensions mismatch");
336
525
  } else if (
@@ -346,7 +535,7 @@ export const imageFromVideoFrame = frame => {
346
535
  if (region) {
347
536
  // copyExternalImageToTexture would also convert the video's
348
537
  // transfer function and primaries to sRGB (see yuvBlit.ts).
349
- blitYuvFrame(device, cache.yuvImports, key, nativeSource, rotation, origin, frame.width, frame.height, cache.uploadTexture);
538
+ blitYuvFrame(device, cache.yuvImports, key, nativeSource, rotation, upright, cache.uploadTexture);
350
539
  } else if (nv12) {
351
540
  // Decoded orientation, as below: drawVideoFrame applies rotation.
352
541
  blitNv12Frame(device, nativeSource, cache.uploadTexture);
@@ -368,27 +557,79 @@ export const imageFromVideoFrame = frame => {
368
557
  }
369
558
  // Snapshot records an independent texture copy and submits it after
370
559
  // the external blit on the shared queue. The wrapper never draws.
371
- image = cache.stage.makeImageSnapshot();
372
- cache.stage.flush(true);
373
- sourceDrained = true;
560
+ image = Skia.Image.MakeFromGPUTexture(cache.uploadTexture);
561
+ // Submitted without waiting for the GPU, which held the UI thread for
562
+ // the work of every Skia view on the shared context: the decoder buffer
563
+ // is handed back once the GPU reports the copy done. A wait still
564
+ // bounds the buffers out, and stands in where nothing can report.
565
+ // NV12 and Android's YUV buffers take a byte and a half per pixel.
566
+ sourceBytes = texture.kind === "native-buffer" && (texture.region || texture.format === "nv12") ? Math.ceil(bytes * 0.375) : bytes;
567
+ const wait = typeof device.queue.onSubmittedWorkDone !== "function" || cache.inFlight.length >= maxInFlightImports || !affordsInFlight(sourceBytes);
568
+ cache.stage.flush(wait);
569
+ if (!wait) {
570
+ try {
571
+ completion = device.queue.onSubmittedWorkDone();
572
+ } catch {
573
+ // A runtime WebGPU cannot settle promises on.
574
+ completion = null;
575
+ }
576
+ }
577
+ if (wait || !completion) {
578
+ if (!wait) cache.stage.flush(true);
579
+ cache.checkedWaits++;
580
+ // Every import before this one is done too.
581
+ settleInFlightImports(cache, cache.inFlight.length, true);
582
+ completion = null;
583
+ sourceDrained = true;
584
+ }
374
585
  }
375
586
  if (!image) throw new Error("Cannot create a video frame image");
376
- // Complete the native handoff before replacing published pixels. A failed
377
- // source close must not evict a paused image or leave an unpublished cache
378
- // entry behind when the caller receives an import error.
379
- if (ownsSurfaceView) {
380
- clearSurfaceView(cache);
587
+ if (completion) {
588
+ // The GPU copy may still read the decoder buffer: it goes back once the
589
+ // GPU reports the copy done, or after a wait (settleInFlightImports).
590
+ // The view stays for that wait.
591
+ const entry = {
592
+ frame,
593
+ nativeSource,
594
+ bytes: sourceBytes
595
+ };
596
+ cache.inFlight.push(entry);
597
+ nativeSource = null;
598
+ releaseSource = false;
381
599
  ownsSurfaceView = false;
600
+ completion.then(() => {
601
+ const settled = cache.inFlight.indexOf(entry) + 1;
602
+ // Zero: a wait handed it back already.
603
+ if (!settled) return;
604
+ cache.checkedWaits++;
605
+ try {
606
+ settleInFlightImports(cache, settled, true);
607
+ } catch (error) {
608
+ console.warn("Video frame release failed", error);
609
+ }
610
+ },
611
+ // Handed back by the next wait instead.
612
+ () => undefined);
613
+ } else {
614
+ // Complete the native handoff before replacing published pixels. A
615
+ // failed source close must not evict a paused image or leave an
616
+ // unpublished cache entry behind when the caller receives an import
617
+ // error.
618
+ if (ownsSurfaceView) {
619
+ clearSurfaceView(cache);
620
+ ownsSurfaceView = false;
621
+ }
622
+ nativeSource?.release();
623
+ nativeSource = null;
624
+ frame.dispose?.();
625
+ releaseSource = false;
382
626
  }
383
- nativeSource?.release();
384
- nativeSource = null;
385
- frame.dispose?.();
386
- releaseSource = false;
387
627
  clearEntry(cache, key);
388
628
  cache.images.set(key, {
389
629
  id: frame.id ?? -1,
390
630
  image,
391
631
  reservation,
632
+ texture: importTexture,
392
633
  releasedSources: new WeakSet([frame])
393
634
  });
394
635
  return image;