react-native-webgpu 0.21.3 → 0.22.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.
- package/android/CMakeLists.txt +8 -7
- package/android/build.gradle +111 -20
- package/android/src/main/java/com/webgpu/WebGPUTextureView.java +12 -0
- package/android/src/main/java/com/webgpu/WebGPUViewManager.java +10 -0
- package/apple/MetalLayerColorSpace.h +17 -0
- package/apple/MetalLayerColorSpace.mm +36 -57
- package/apple/MetalView.h +4 -0
- package/apple/MetalView.mm +14 -0
- package/apple/RNWGUIKit.h +4 -1
- package/apple/WebGPUModule.mm +26 -1
- package/apple/WebGPUView.h +2 -1
- package/apple/WebGPUView.mm +6 -0
- package/binaries.json +156 -0
- package/cpp/jsi/NativeObject.h +12 -5
- package/cpp/rnwgpu/CanvasColorSpace.h +16 -0
- package/cpp/rnwgpu/SurfaceRegistry.h +26 -30
- package/cpp/rnwgpu/api/GPUAdapter.cpp +21 -9
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +41 -3
- package/cpp/rnwgpu/api/GPUCanvasContext.h +7 -3
- package/lib/commonjs/Canvas.js +33 -1
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -1
- package/lib/commonjs/WebGPUViewNativeComponent.web.js +2 -0
- package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -1
- package/lib/module/Canvas.js +33 -1
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/WebGPUViewNativeComponent.js.map +1 -1
- package/lib/module/WebGPUViewNativeComponent.web.js +2 -0
- package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -1
- package/lib/typescript/lib/commonjs/Canvas.d.ts +3 -1
- package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/lib/typescript/lib/module/Canvas.d.ts +3 -1
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/lib/typescript/src/Canvas.d.ts +17 -1
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +2 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +2 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/Canvas.tsx +67 -1
- package/src/WebGPUViewNativeComponent.ts +4 -0
- package/src/WebGPUViewNativeComponent.web.ts +6 -0
package/android/CMakeLists.txt
CHANGED
|
@@ -17,15 +17,16 @@ else()
|
|
|
17
17
|
add_definitions(-DRNF_ENABLE_LOGS=0)
|
|
18
18
|
endif()
|
|
19
19
|
|
|
20
|
-
# Dawn
|
|
21
|
-
#
|
|
20
|
+
# Dawn is in DAWN_DIR, passed by build.gradle: the directory its
|
|
21
|
+
# prepareDawnBinaries task extracts the released archives into, with the shared
|
|
22
|
+
# library per ABI and the headers under include/. It is not required to be
|
|
23
|
+
# there yet: Android Studio configures this project when it syncs, before any
|
|
24
|
+
# task has run. Gradle is what guarantees the files, and verifies them, before
|
|
25
|
+
# the library is built.
|
|
22
26
|
if(NOT DAWN_DIR)
|
|
23
|
-
message(FATAL_ERROR "react-native-webgpu: DAWN_DIR is not set (the
|
|
24
|
-
endif()
|
|
25
|
-
set (WEBGPU_LIBS_PATH "${DAWN_DIR}/libs/android/${ANDROID_ABI}")
|
|
26
|
-
if(NOT EXISTS "${WEBGPU_LIBS_PATH}/libwebgpu_dawn.so")
|
|
27
|
-
message(FATAL_ERROR "react-native-webgpu: libwebgpu_dawn.so not found at ${WEBGPU_LIBS_PATH}. Reinstall dependencies (yarn install / npm install).")
|
|
27
|
+
message(FATAL_ERROR "react-native-webgpu: DAWN_DIR is not set (the directory holding the Dawn binaries)")
|
|
28
28
|
endif()
|
|
29
|
+
set (WEBGPU_LIBS_PATH "${DAWN_DIR}/${ANDROID_ABI}")
|
|
29
30
|
|
|
30
31
|
find_package(ReactAndroid REQUIRED CONFIG)
|
|
31
32
|
find_package(fbjni REQUIRED CONFIG)
|
package/android/build.gradle
CHANGED
|
@@ -45,27 +45,27 @@ static def findNodeModules(baseDir) {
|
|
|
45
45
|
|
|
46
46
|
def nodeModules = findNodeModules(projectDir)
|
|
47
47
|
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return proc.text.trim()
|
|
61
|
-
}
|
|
48
|
+
// Dawn, the WebGPU implementation, is an asset of the GitHub release
|
|
49
|
+
// binaries-<version> of react-native-skia: one archive per ABI holding
|
|
50
|
+
// <abi>/libwebgpu_dawn.so, and one holding the headers under include/.
|
|
51
|
+
// binaries.json pins that version and the sha256 of every asset. Gradle
|
|
52
|
+
// downloads the archives of the ABIs being built as dependencies (see the
|
|
53
|
+
// repository and prepareDawnBinaries below), so they sit in the Gradle user
|
|
54
|
+
// home cache like any other dependency, and prepareDawnBinaries extracts them
|
|
55
|
+
// into build/binaries. react-native-skia's Graphite backend links the Dawn of
|
|
56
|
+
// the same release, so an app installing both contains exactly one Dawn.
|
|
57
|
+
def binaries = new groovy.json.JsonSlurper().parse(file("${projectDir}/../binaries.json"))
|
|
58
|
+
def dawnDir = file("${buildDir}/binaries")
|
|
59
|
+
logger.warn("react-native-webgpu: Dawn ${binaries.version} in ${dawnDir}")
|
|
62
60
|
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
// Where the releases are downloaded from: <url>/binaries-<version>/<asset>.
|
|
62
|
+
// A mirror, or a directory (file:///...) for builds without network access,
|
|
63
|
+
// is set with the reactNativeSkiaBinariesUrl Gradle property or the
|
|
64
|
+
// REACT_NATIVE_SKIA_BINARIES_URL environment variable, the ones
|
|
65
|
+
// react-native-skia reads too.
|
|
66
|
+
def binariesUrl = (project.findProperty('reactNativeSkiaBinariesUrl')
|
|
67
|
+
?: System.getenv('REACT_NATIVE_SKIA_BINARIES_URL')
|
|
68
|
+
?: 'https://github.com/wcandillon/react-native-skia/releases/download').toString()
|
|
69
69
|
|
|
70
70
|
def getExtOrDefault(name) {
|
|
71
71
|
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Wgpu_" + name]
|
|
@@ -167,12 +167,103 @@ android {
|
|
|
167
167
|
repositories {
|
|
168
168
|
mavenCentral()
|
|
169
169
|
google()
|
|
170
|
+
// The assets of the binaries-<version> releases, as a repository: Gradle
|
|
171
|
+
// then caches them in its user home and resolves them offline. Only this
|
|
172
|
+
// group is looked up here, and it is looked up nowhere else.
|
|
173
|
+
exclusiveContent {
|
|
174
|
+
forRepository {
|
|
175
|
+
ivy {
|
|
176
|
+
name = "ReactNativeSkiaBinaries"
|
|
177
|
+
url = uri(binariesUrl)
|
|
178
|
+
patternLayout {
|
|
179
|
+
artifact "binaries-[revision]/[module](-[classifier]).[ext]"
|
|
180
|
+
}
|
|
181
|
+
metadataSources { artifact() }
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
filter { includeGroup "react-native-skia-binaries" }
|
|
185
|
+
}
|
|
170
186
|
}
|
|
171
187
|
|
|
188
|
+
configurations {
|
|
189
|
+
dawnBinaries {
|
|
190
|
+
canBeConsumed = false
|
|
191
|
+
transitive = false
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// sha256 → asset, for the archives this build downloads.
|
|
196
|
+
def binaryChecksums = [:]
|
|
197
|
+
def dawnBinary = { String module, String abi ->
|
|
198
|
+
def name = abi == null ? "${module}.zip".toString() : "${module}-${abi}.zip".toString()
|
|
199
|
+
def asset = binaries.assets[name]
|
|
200
|
+
if (asset == null) {
|
|
201
|
+
throw new GradleException("react-native-webgpu: binaries ${binaries.version} have no ${name}.")
|
|
202
|
+
}
|
|
203
|
+
binaryChecksums[asset.sha256.toString()] = name
|
|
204
|
+
return "react-native-skia-binaries:${module}:${binaries.version}" + (abi == null ? "" : ":${abi}") + "@zip"
|
|
205
|
+
}
|
|
172
206
|
|
|
173
207
|
dependencies {
|
|
174
208
|
// For < 0.71, this will be from the local maven repo
|
|
175
209
|
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
176
210
|
//noinspection GradleDynamicVersion
|
|
177
211
|
implementation "com.facebook.react:react-native:+"
|
|
212
|
+
|
|
213
|
+
dawnBinaries dawnBinary('dawn-headers', null)
|
|
214
|
+
reactNativeArchitectures().each { abi ->
|
|
215
|
+
dawnBinaries dawnBinary('dawn-android', abi)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Extracts the downloaded archives into build/binaries (<abi>/ and include/),
|
|
220
|
+
// where CMake reads them from, once each matches the sha256 binaries.json pins
|
|
221
|
+
// for it.
|
|
222
|
+
def prepareDawnBinaries = tasks.register('prepareDawnBinaries') {
|
|
223
|
+
def archives = configurations.dawnBinaries
|
|
224
|
+
def checksums = binaryChecksums
|
|
225
|
+
def destination = dawnDir
|
|
226
|
+
def version = binaries.version
|
|
227
|
+
inputs.files(archives)
|
|
228
|
+
inputs.property('checksums', checksums)
|
|
229
|
+
outputs.dir(destination)
|
|
230
|
+
doLast {
|
|
231
|
+
destination.deleteDir()
|
|
232
|
+
destination.mkdirs()
|
|
233
|
+
def root = destination.canonicalPath + File.separator
|
|
234
|
+
def pending = new HashMap(checksums)
|
|
235
|
+
archives.files.each { File archive ->
|
|
236
|
+
def digest = java.security.MessageDigest.getInstance('SHA-256')
|
|
237
|
+
archive.eachByte(1 << 20) { buffer, read -> digest.update(buffer, 0, read) }
|
|
238
|
+
def sha256 = digest.digest().encodeHex().toString()
|
|
239
|
+
if (pending.remove(sha256) == null) {
|
|
240
|
+
throw new GradleException(
|
|
241
|
+
"react-native-webgpu: ${archive} (sha256 ${sha256}) is not one of the " +
|
|
242
|
+
"archives of binaries ${version}: its checksum is not in binaries.json. " +
|
|
243
|
+
"Build with --refresh-dependencies to download it again.")
|
|
244
|
+
}
|
|
245
|
+
new java.util.zip.ZipFile(archive).withCloseable { zip ->
|
|
246
|
+
Collections.list(zip.entries()).each { entry ->
|
|
247
|
+
def target = new File(destination, entry.name)
|
|
248
|
+
if (!target.canonicalPath.startsWith(root)) {
|
|
249
|
+
throw new GradleException(
|
|
250
|
+
"react-native-webgpu: ${archive.name} has an entry outside of the archive: ${entry.name}")
|
|
251
|
+
}
|
|
252
|
+
if (entry.directory) {
|
|
253
|
+
target.mkdirs()
|
|
254
|
+
} else {
|
|
255
|
+
target.parentFile.mkdirs()
|
|
256
|
+
zip.getInputStream(entry).withCloseable { input ->
|
|
257
|
+
target.withOutputStream { output -> output << input }
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (!pending.isEmpty()) {
|
|
264
|
+
throw new GradleException(
|
|
265
|
+
"react-native-webgpu: archives missing from binaries ${version}: ${pending.values().join(', ')}")
|
|
266
|
+
}
|
|
267
|
+
}
|
|
178
268
|
}
|
|
269
|
+
preBuild.dependsOn(prepareDawnBinaries)
|
|
@@ -3,6 +3,7 @@ package com.webgpu;
|
|
|
3
3
|
import android.annotation.SuppressLint;
|
|
4
4
|
import android.content.Context;
|
|
5
5
|
import android.graphics.SurfaceTexture;
|
|
6
|
+
import android.os.Build;
|
|
6
7
|
import android.view.Surface;
|
|
7
8
|
import android.view.TextureView;
|
|
8
9
|
import androidx.annotation.NonNull;
|
|
@@ -20,6 +21,17 @@ public class WebGPUTextureView extends TextureView implements TextureView.Surfac
|
|
|
20
21
|
setSurfaceTextureListener(this);
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
// Android 10 draws an opaque TextureView with SkBlendMode::kSrc, and under
|
|
25
|
+
// a rotated, rounded clip its Skia (m75) can clear the stencil the clip was
|
|
26
|
+
// written in before that draw, which leaves the canvas blank (fixed in
|
|
27
|
+
// Skia m77, https://skia-review.googlesource.com/c/skia/+/223970). The
|
|
28
|
+
// view blends on that release, whatever the GL: a canvas that covers its
|
|
29
|
+
// bounds draws the same pixels.
|
|
30
|
+
@Override
|
|
31
|
+
public void setOpaque(boolean opaque) {
|
|
32
|
+
super.setOpaque(opaque && Build.VERSION.SDK_INT != Build.VERSION_CODES.Q);
|
|
33
|
+
}
|
|
34
|
+
|
|
23
35
|
@Override
|
|
24
36
|
public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surfaceTexture, int width, int height) {
|
|
25
37
|
mSurface = new Surface(surfaceTexture);
|
|
@@ -54,6 +54,16 @@ public class WebGPUViewManager extends WebGPUViewManagerSpec<WebGPUView> {
|
|
|
54
54
|
view.setZOrderMediaOverlay(value);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
// The colorspace props of the canvas, read on Apple platforms only: Android
|
|
58
|
+
// renders in sRGB.
|
|
59
|
+
@Override
|
|
60
|
+
@ReactProp(name = "appleDisplayP3")
|
|
61
|
+
public void setAppleDisplayP3(WebGPUView view, boolean value) {}
|
|
62
|
+
|
|
63
|
+
@Override
|
|
64
|
+
@ReactProp(name = "appleExtendedDynamicRange")
|
|
65
|
+
public void setAppleExtendedDynamicRange(WebGPUView view, boolean value) {}
|
|
66
|
+
|
|
57
67
|
@Override
|
|
58
68
|
protected void onAfterUpdateTransaction(@NonNull WebGPUView view) {
|
|
59
69
|
super.onAfterUpdateTransaction(view);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#import <QuartzCore/CAMetalLayer.h>
|
|
4
|
+
|
|
5
|
+
#include "CanvasColorSpace.h"
|
|
6
|
+
|
|
7
|
+
namespace rnwgpu {
|
|
8
|
+
|
|
9
|
+
// Tags a new CAMetalLayer with the colorspace of the canvas, and opts it into
|
|
10
|
+
// the display's extended dynamic range for an "extended" toneMapping mode.
|
|
11
|
+
// Main thread only, where the platform view calls it as the canvas mounts (see
|
|
12
|
+
// -[MetalView configure]): the threads that configure and present the surface
|
|
13
|
+
// (JS, worklet runtimes) never touch a CATransaction.
|
|
14
|
+
void applyCAMetalLayerColorSpace(CAMetalLayer *layer,
|
|
15
|
+
CanvasLayerColorSpace colorSpace);
|
|
16
|
+
|
|
17
|
+
} // namespace rnwgpu
|
|
@@ -1,79 +1,58 @@
|
|
|
1
1
|
#import <CoreGraphics/CoreGraphics.h>
|
|
2
2
|
#import <Foundation/Foundation.h>
|
|
3
3
|
#import <QuartzCore/CAMetalLayer.h>
|
|
4
|
-
#import <QuartzCore/CATransaction.h>
|
|
5
4
|
|
|
6
|
-
#include "
|
|
7
|
-
#include "webgpu/webgpu_cpp.h"
|
|
5
|
+
#include "MetalLayerColorSpace.h"
|
|
8
6
|
|
|
9
7
|
namespace rnwgpu {
|
|
10
8
|
|
|
11
9
|
// WebGPU canvas values are encoded with the sRGB transfer function regardless
|
|
12
|
-
// of the texture format, and
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
10
|
+
// of the texture format, and the canvas's colorSpace says which primaries they
|
|
11
|
+
// are in: "srgb" (the default) or "display-p3". The same shader output must
|
|
12
|
+
// display identically on bgra8unorm and rgba16float surfaces. Core Animation
|
|
13
|
+
// interprets a float-format layer with a nil colorspace as extended *linear*
|
|
14
|
+
// sRGB, which displays the same values noticeably brighter. The layer is
|
|
15
|
+
// tagged before the format is known (configure() comes later, from JS), so it
|
|
16
|
+
// gets the gamma-encoded extended variant of its gamut: on an 8-bit format it
|
|
17
|
+
// reads the same values as the plain colorspace, and on a float format it
|
|
18
|
+
// gives identical colors with the extra precision of float16, as in a browser.
|
|
19
|
+
// For "display-p3" the values reach a wide-gamut display without being
|
|
20
|
+
// converted from sRGB first.
|
|
22
21
|
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
void applyCAMetalLayerColorSpace(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
if (name != nullptr) {
|
|
47
|
-
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(name);
|
|
48
|
-
metalLayer.colorspace = colorSpace;
|
|
49
|
-
CGColorSpaceRelease(colorSpace);
|
|
50
|
-
} else if (metalLayer.colorspace != nil) {
|
|
51
|
-
// Restore the default (no color matching) when reconfiguring back to an
|
|
52
|
-
// 8-bit sRGB canvas.
|
|
53
|
-
metalLayer.colorspace = nil;
|
|
54
|
-
}
|
|
22
|
+
// The toneMapping mode says what happens to values above 1.0 on a float
|
|
23
|
+
// canvas. Core Animation keeps an extended colorspace inside the display's
|
|
24
|
+
// SDR range unless the layer asks for extended dynamic range content, so
|
|
25
|
+
// without it the values clip at white: that is "standard". For "extended" the
|
|
26
|
+
// layer opts in, and the values use the display's headroom (EDR) as they do in
|
|
27
|
+
// a browser. An 8-bit canvas cannot hold values above 1.0, so the flag has no
|
|
28
|
+
// visible effect there.
|
|
29
|
+
void applyCAMetalLayerColorSpace(CAMetalLayer *layer,
|
|
30
|
+
CanvasLayerColorSpace colorSpace) {
|
|
31
|
+
// Main thread only: the properties land in the calling thread's implicit
|
|
32
|
+
// CATransaction, which the main run loop commits. Committing it from any
|
|
33
|
+
// other thread ([CATransaction flush]) commits the whole layer tree there,
|
|
34
|
+
// and lays out whatever UIKit view has a layout pending, off the main
|
|
35
|
+
// thread (react-native-skia #4474).
|
|
36
|
+
NSCAssert(NSThread.isMainThread,
|
|
37
|
+
@"applyCAMetalLayerColorSpace must be called on the main thread");
|
|
38
|
+
CGColorSpaceRef cgColorSpace = CGColorSpaceCreateWithName(
|
|
39
|
+
colorSpace.colorSpace == CanvasColorSpace::DisplayP3
|
|
40
|
+
? kCGColorSpaceExtendedDisplayP3
|
|
41
|
+
: kCGColorSpaceExtendedSRGB);
|
|
42
|
+
layer.colorspace = cgColorSpace;
|
|
43
|
+
CGColorSpaceRelease(cgColorSpace);
|
|
55
44
|
const bool extendedRange =
|
|
56
|
-
|
|
45
|
+
colorSpace.toneMappingMode == CanvasToneMappingMode::Extended;
|
|
57
46
|
// The property does not exist on tvOS (the SDK marks it unavailable, which
|
|
58
47
|
// @available cannot work around), so it is compiled only where it exists.
|
|
59
48
|
// On tvOS "extended" behaves like "standard".
|
|
60
49
|
#if TARGET_OS_IOS || TARGET_OS_OSX || TARGET_OS_VISION
|
|
61
50
|
if (@available(iOS 16.0, macOS 10.11, visionOS 1.0, *)) {
|
|
62
|
-
|
|
63
|
-
metalLayer.wantsExtendedDynamicRangeContent = extendedRange;
|
|
64
|
-
}
|
|
51
|
+
layer.wantsExtendedDynamicRangeContent = extendedRange;
|
|
65
52
|
}
|
|
66
53
|
#else
|
|
67
54
|
(void)extendedRange;
|
|
68
55
|
#endif
|
|
69
|
-
// The change must be set synchronously so the first present already sees
|
|
70
|
-
// it, and it must reach the render server. On a non-main thread (RN JS or
|
|
71
|
-
// worklet runtime) the property lands in that thread's implicit
|
|
72
|
-
// CATransaction, which may never commit on threads without a spinning
|
|
73
|
-
// runloop, so flush it now. On the main thread the runloop commits it.
|
|
74
|
-
if (!NSThread.isMainThread) {
|
|
75
|
-
[CATransaction flush];
|
|
76
|
-
}
|
|
77
56
|
}
|
|
78
57
|
|
|
79
58
|
} // namespace rnwgpu
|
package/apple/MetalView.h
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
@interface MetalView : RNWGPlatformView
|
|
7
7
|
|
|
8
8
|
@property NSNumber *contextId;
|
|
9
|
+
// The colorSpace and toneMapping props of the Canvas, as they are when it
|
|
10
|
+
// mounts: set before configure, which tags the layer with them.
|
|
11
|
+
@property BOOL displayP3;
|
|
12
|
+
@property BOOL extendedDynamicRange;
|
|
9
13
|
|
|
10
14
|
- (void)configure;
|
|
11
15
|
- (void)update;
|
package/apple/MetalView.mm
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#import "MetalView.h"
|
|
2
|
+
#include "MetalLayerColorSpace.h"
|
|
2
3
|
#import "WebGPURuntime.h"
|
|
3
4
|
#import "webgpu/webgpu_cpp.h"
|
|
4
5
|
|
|
@@ -27,6 +28,18 @@
|
|
|
27
28
|
if (manager == nullptr) {
|
|
28
29
|
return;
|
|
29
30
|
}
|
|
31
|
+
// The layer is tagged with its colorspace here, on the main thread, before
|
|
32
|
+
// it is attached: the threads that configure and present the surface (JS,
|
|
33
|
+
// worklet runtimes) then never change the layer in a CATransaction of
|
|
34
|
+
// theirs. The tag comes from the Canvas props when it mounts and is kept
|
|
35
|
+
// (see -[WebGPUView updateProps:oldProps:]).
|
|
36
|
+
const rnwgpu::CanvasLayerColorSpace layerColorSpace{
|
|
37
|
+
_displayP3 ? rnwgpu::CanvasColorSpace::DisplayP3
|
|
38
|
+
: rnwgpu::CanvasColorSpace::SRGB,
|
|
39
|
+
_extendedDynamicRange ? rnwgpu::CanvasToneMappingMode::Extended
|
|
40
|
+
: rnwgpu::CanvasToneMappingMode::Standard};
|
|
41
|
+
rnwgpu::applyCAMetalLayerColorSpace((CAMetalLayer *)self.layer,
|
|
42
|
+
layerColorSpace);
|
|
30
43
|
// Retain the layer for as long as SurfaceInfo holds the pointer: the
|
|
31
44
|
// latched attach (and the flush lambda that adopts it) can outlive this
|
|
32
45
|
// view, e.g. across a dev reload where the registry is cleared before
|
|
@@ -47,6 +60,7 @@
|
|
|
47
60
|
CFBridgingRelease(layer);
|
|
48
61
|
});
|
|
49
62
|
});
|
|
63
|
+
info->setLayerColorSpace(layerColorSpace);
|
|
50
64
|
// The attach is adopted at the next frame boundary by the rendering thread;
|
|
51
65
|
// schedule a flush so contexts that are not currently rendering still pick
|
|
52
66
|
// it up (and present their last offscreen frame).
|
package/apple/RNWGUIKit.h
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
#ifndef PACKAGES_WEBGPU_APPLE_RNWGUIKIT_H_
|
|
2
2
|
#define PACKAGES_WEBGPU_APPLE_RNWGUIKIT_H_
|
|
3
3
|
|
|
4
|
+
// Select UIKit or AppKit before importing either framework.
|
|
5
|
+
#import <TargetConditionals.h>
|
|
6
|
+
|
|
4
7
|
#if !TARGET_OS_OSX
|
|
5
8
|
#import <UIKit/UIKit.h>
|
|
6
9
|
#else
|
|
7
|
-
#import <
|
|
10
|
+
#import <AppKit/AppKit.h>
|
|
8
11
|
#endif
|
|
9
12
|
|
|
10
13
|
#if !TARGET_OS_OSX
|
package/apple/WebGPUModule.mm
CHANGED
|
@@ -46,13 +46,38 @@ static std::shared_ptr<rnwgpu::RNWebGPUManager> webgpuManager;
|
|
|
46
46
|
return webgpuManager;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
#pragma Setup and invalidation
|
|
49
|
+
#pragma mark - Setup and invalidation
|
|
50
50
|
|
|
51
51
|
+ (BOOL)requiresMainQueueSetup {
|
|
52
52
|
return YES;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
#if TARGET_OS_OSX
|
|
56
|
+
- (instancetype)init {
|
|
57
|
+
if (self = [super init]) {
|
|
58
|
+
[[NSNotificationCenter defaultCenter]
|
|
59
|
+
addObserver:self
|
|
60
|
+
selector:@selector(applicationWillTerminate:)
|
|
61
|
+
name:NSApplicationWillTerminateNotification
|
|
62
|
+
object:nil];
|
|
63
|
+
}
|
|
64
|
+
return self;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
- (void)applicationWillTerminate:(NSNotification *)notification {
|
|
68
|
+
// AppKit exits without necessarily invalidating the React instance. Release
|
|
69
|
+
// the manager before static teardown destroys SurfaceRegistry and its mutex.
|
|
70
|
+
[self invalidate];
|
|
71
|
+
}
|
|
72
|
+
#endif
|
|
73
|
+
|
|
55
74
|
- (void)invalidate {
|
|
75
|
+
#if TARGET_OS_OSX
|
|
76
|
+
[[NSNotificationCenter defaultCenter]
|
|
77
|
+
removeObserver:self
|
|
78
|
+
name:NSApplicationWillTerminateNotification
|
|
79
|
+
object:nil];
|
|
80
|
+
#endif
|
|
56
81
|
webgpuManager = nil;
|
|
57
82
|
}
|
|
58
83
|
|
package/apple/WebGPUView.h
CHANGED
package/apple/WebGPUView.mm
CHANGED
|
@@ -66,10 +66,16 @@ static const std::shared_ptr<const WebGPUViewProps> &defaultWebGPUViewProps() {
|
|
|
66
66
|
/*
|
|
67
67
|
The context is set only once during mounting the component
|
|
68
68
|
and never changes because it isn't available for users to modify.
|
|
69
|
+
The colorspace props are read here too, and only here: the layer is
|
|
70
|
+
tagged with them as it is attached, on the main thread, and a change on
|
|
71
|
+
a mounted canvas is ignored (with a warning in development from JS, see
|
|
72
|
+
Canvas.tsx).
|
|
69
73
|
*/
|
|
70
74
|
MetalView *metalView = [MetalView new];
|
|
71
75
|
self.contentView = metalView;
|
|
72
76
|
[metalView setContextId:@(newViewProps.contextId)];
|
|
77
|
+
metalView.displayP3 = newViewProps.appleDisplayP3;
|
|
78
|
+
metalView.extendedDynamicRange = newViewProps.appleExtendedDynamicRange;
|
|
73
79
|
[metalView configure];
|
|
74
80
|
}
|
|
75
81
|
|
package/binaries.json
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "158.0.0",
|
|
3
|
+
"tag": "binaries-158.0.0",
|
|
4
|
+
"skia": "m158",
|
|
5
|
+
"dawn": {
|
|
6
|
+
"commit": "1716e88cc9e58398fab5d4473f7f2e858667b677",
|
|
7
|
+
"repository": "https://dawn.googlesource.com/dawn.git",
|
|
8
|
+
"patches": [
|
|
9
|
+
"metal-maccatalyst.patch",
|
|
10
|
+
"metal-suspend-submissions-in-background.patch",
|
|
11
|
+
"vulkan-fifo-three-images-android.patch"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
"assets": {
|
|
15
|
+
"skia-graphite-android-armeabi-v7a.zip": {
|
|
16
|
+
"sha256": "ed4e7772d97cac8c03d759451711de69cd723c60cf5e6571fe78da5f21cdf9a3",
|
|
17
|
+
"size": 17220410
|
|
18
|
+
},
|
|
19
|
+
"dawn-android-armeabi-v7a.zip": {
|
|
20
|
+
"sha256": "0d15912b225a079f850af8195ce7be50c4e63d337a63aebd2cbebe1173b110f4",
|
|
21
|
+
"size": 4885803
|
|
22
|
+
},
|
|
23
|
+
"skia-graphite-android-arm64-v8a.zip": {
|
|
24
|
+
"sha256": "2a2e2fdc22aebe827ccc4d613c1336b1f8ec68384df68f057c3aa6b5e8a5da43",
|
|
25
|
+
"size": 18419606
|
|
26
|
+
},
|
|
27
|
+
"dawn-android-arm64-v8a.zip": {
|
|
28
|
+
"sha256": "5a48fdafbf73ae870b073a20cce9e46a9b3fbb9aecdc312fc900af2a3e83312f",
|
|
29
|
+
"size": 5308117
|
|
30
|
+
},
|
|
31
|
+
"skia-graphite-android-x86.zip": {
|
|
32
|
+
"sha256": "d5ce0c75db0016986a4840996bc66ae345806f4f41fb7820e9ee11815ed928a0",
|
|
33
|
+
"size": 18838978
|
|
34
|
+
},
|
|
35
|
+
"dawn-android-x86.zip": {
|
|
36
|
+
"sha256": "13e3f79fc2447f0b71d6ad559df7a8f2e7857bd02faac83a2ca7e5670963b8ed",
|
|
37
|
+
"size": 6066809
|
|
38
|
+
},
|
|
39
|
+
"skia-graphite-android-x86_64.zip": {
|
|
40
|
+
"sha256": "b69568bffb06a14cfea785c4ebfdc0f292986a6bd51bba37774d65233602f778",
|
|
41
|
+
"size": 18422759
|
|
42
|
+
},
|
|
43
|
+
"dawn-android-x86_64.zip": {
|
|
44
|
+
"sha256": "2e41a8983a379f8798d1d26ae223b123b2347b593190fd1c7d344956a796240a",
|
|
45
|
+
"size": 5659211
|
|
46
|
+
},
|
|
47
|
+
"dawn-headers.zip": {
|
|
48
|
+
"sha256": "fe255214b596fd884a480078d417571a7fd7b4beb04e8ce1a93f140b12a0a4a8",
|
|
49
|
+
"size": 150497
|
|
50
|
+
},
|
|
51
|
+
"dawn-LICENSE.txt": {
|
|
52
|
+
"sha256": "0493f897193af1796d5054659f45ec7d4c5af648fa67a99f01d30e55cc805abc",
|
|
53
|
+
"size": 11829
|
|
54
|
+
},
|
|
55
|
+
"skia-graphite-apple-ios-libskia.xcframework.zip": {
|
|
56
|
+
"sha256": "93e76f7320bc5b782b847b4b26aeec8730cdf6b7f06575d583e626eb9ed53350",
|
|
57
|
+
"size": 33541685
|
|
58
|
+
},
|
|
59
|
+
"skia-graphite-apple-ios-libsvg.xcframework.zip": {
|
|
60
|
+
"sha256": "ea5b1bb251faad33e7f3799286d8f57479cf80cdc741d436fc7d2d9c64c9c8e6",
|
|
61
|
+
"size": 9658038
|
|
62
|
+
},
|
|
63
|
+
"skia-graphite-apple-ios-libskshaper.xcframework.zip": {
|
|
64
|
+
"sha256": "35b68ae901b50d41a6c353a34f81f4a69efec9420f9976414428636544f6595f",
|
|
65
|
+
"size": 12905519
|
|
66
|
+
},
|
|
67
|
+
"skia-graphite-apple-ios-libskparagraph.xcframework.zip": {
|
|
68
|
+
"sha256": "b17b30a587b7d5248e0f1d716c938d19d09855772e2b63dc29590ca409b2370b",
|
|
69
|
+
"size": 1132911
|
|
70
|
+
},
|
|
71
|
+
"skia-graphite-apple-ios-libskunicode_core.xcframework.zip": {
|
|
72
|
+
"sha256": "52f4a1001f9d88e957091bebbf65f72f9f9e4d6fb18f15e50335e8b76cfb4ec4",
|
|
73
|
+
"size": 18600
|
|
74
|
+
},
|
|
75
|
+
"skia-graphite-apple-ios-libskunicode_libgrapheme.xcframework.zip": {
|
|
76
|
+
"sha256": "9419f8f0467095d331ec5dcc0c83652e4719d94d7553e9bf1bfd3c3a9c8bdb82",
|
|
77
|
+
"size": 824822
|
|
78
|
+
},
|
|
79
|
+
"skia-graphite-apple-ios-libskottie.xcframework.zip": {
|
|
80
|
+
"sha256": "dc2a5842b7f5732e578ee349883a01784c75ca607f89137ee6e381eba1769a61",
|
|
81
|
+
"size": 10719542
|
|
82
|
+
},
|
|
83
|
+
"skia-graphite-apple-ios-libsksg.xcframework.zip": {
|
|
84
|
+
"sha256": "d25a3e0571393f36a6fac0c0dbcfd729019626ebac2cf8d840a40e5c72c2a1cb",
|
|
85
|
+
"size": 9024381
|
|
86
|
+
},
|
|
87
|
+
"skia-graphite-apple-tvos-libskia.xcframework.zip": {
|
|
88
|
+
"sha256": "4d29ae8db6e106267bed8ba693ac097d97c4436a981a036b8d7d59aa578c72b2",
|
|
89
|
+
"size": 19847689
|
|
90
|
+
},
|
|
91
|
+
"skia-graphite-apple-tvos-libsvg.xcframework.zip": {
|
|
92
|
+
"sha256": "c3f6bf08448ad5e1cce10b32d2c43d062bb56ac84dff2af6b5d95a8d019c3af9",
|
|
93
|
+
"size": 5705277
|
|
94
|
+
},
|
|
95
|
+
"skia-graphite-apple-tvos-libskshaper.xcframework.zip": {
|
|
96
|
+
"sha256": "f18b368fad922e5a6bd736b84509c51364b4c9b8ca9cbca14a1404996cfe0d59",
|
|
97
|
+
"size": 7664970
|
|
98
|
+
},
|
|
99
|
+
"skia-graphite-apple-tvos-libskparagraph.xcframework.zip": {
|
|
100
|
+
"sha256": "495fcfef1b0094def9c7b514f0f27290ff43ebdfaa6f7f73c7409b545f2958c8",
|
|
101
|
+
"size": 670608
|
|
102
|
+
},
|
|
103
|
+
"skia-graphite-apple-tvos-libskunicode_core.xcframework.zip": {
|
|
104
|
+
"sha256": "f73bb1ce3cee1d2fbd940b8b5b91ed4512cb618f91a0009f49cf718945826812",
|
|
105
|
+
"size": 11546
|
|
106
|
+
},
|
|
107
|
+
"skia-graphite-apple-tvos-libskunicode_libgrapheme.xcframework.zip": {
|
|
108
|
+
"sha256": "c515f56f998e6ea7e2b74b853915e1627e3efcf406b7ec29316fd0769ca5c1e3",
|
|
109
|
+
"size": 491185
|
|
110
|
+
},
|
|
111
|
+
"skia-graphite-apple-tvos-libskottie.xcframework.zip": {
|
|
112
|
+
"sha256": "384f861b6c635199a249f2b76d4c2bbd55a3f3480b4fc0f5f0879d6862f0daf9",
|
|
113
|
+
"size": 6335725
|
|
114
|
+
},
|
|
115
|
+
"skia-graphite-apple-tvos-libsksg.xcframework.zip": {
|
|
116
|
+
"sha256": "929096f800fcfe775218625eb4eb9ecba3e5c8a547f6eb3d6a2867e175531a8e",
|
|
117
|
+
"size": 5328696
|
|
118
|
+
},
|
|
119
|
+
"skia-graphite-apple-macos-libskia.xcframework.zip": {
|
|
120
|
+
"sha256": "96526c51628b7ac52360c3ea6c4c86f16c8e28801fc9428fc42b36e6555b01bc",
|
|
121
|
+
"size": 13678266
|
|
122
|
+
},
|
|
123
|
+
"skia-graphite-apple-macos-libsvg.xcframework.zip": {
|
|
124
|
+
"sha256": "636d4d2c6e38ea1bb4e7c19dba98ed013745975bef38ffd53d96d901b3206e8c",
|
|
125
|
+
"size": 3939058
|
|
126
|
+
},
|
|
127
|
+
"skia-graphite-apple-macos-libskshaper.xcframework.zip": {
|
|
128
|
+
"sha256": "80d719fb0c9cb5311791170204102d0a5901e92d43f428f856ee60a32706dc7c",
|
|
129
|
+
"size": 5251775
|
|
130
|
+
},
|
|
131
|
+
"skia-graphite-apple-macos-libskparagraph.xcframework.zip": {
|
|
132
|
+
"sha256": "15a6fe0ade4e5d08661c0282aadc76a5f9293745dfb77e2d3cfe20f5258c315a",
|
|
133
|
+
"size": 462769
|
|
134
|
+
},
|
|
135
|
+
"skia-graphite-apple-macos-libskunicode_core.xcframework.zip": {
|
|
136
|
+
"sha256": "a0f5173dcee332280e72dd49411fa4534256fd6540dfa69ec71463d822fca238",
|
|
137
|
+
"size": 7659
|
|
138
|
+
},
|
|
139
|
+
"skia-graphite-apple-macos-libskunicode_libgrapheme.xcframework.zip": {
|
|
140
|
+
"sha256": "8129e8ab9bfa8d9ced3793db079e0977cdbd9c7436d057eb1ce4b48fb03b082b",
|
|
141
|
+
"size": 334680
|
|
142
|
+
},
|
|
143
|
+
"skia-graphite-apple-macos-libskottie.xcframework.zip": {
|
|
144
|
+
"sha256": "ffbcc4ccb3dd37ac634d394f263488c5f216bdaa2aa5a819093edc5ca03a0fc4",
|
|
145
|
+
"size": 4373140
|
|
146
|
+
},
|
|
147
|
+
"skia-graphite-apple-macos-libsksg.xcframework.zip": {
|
|
148
|
+
"sha256": "58b85895c87561cc4904e1c24b2b05faf6776e5f2fcf49469d6808f0421f5f8f",
|
|
149
|
+
"size": 3684323
|
|
150
|
+
},
|
|
151
|
+
"dawn-apple-libwebgpu_dawn.xcframework.zip": {
|
|
152
|
+
"sha256": "b1844ccfb27809361a9724cf5dac4b1a4b7f9e40f26dc7cf60d40a5013dd7114",
|
|
153
|
+
"size": 53231891
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|