Skip to content

Commit 2b3f02e

Browse files
committed
feat: update wgpu & skia to the latest
1 parent 8f8ab04 commit 2b3f02e

File tree

235 files changed

+17491
-12211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

235 files changed

+17491
-12211
lines changed

Cargo.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ members = [
1212
"crates/canvas-c",
1313
"crates/canvas-svg",
1414
"crates/canvas-napi",
15+
"crates/canvas-svg-ios",
16+
"crates/canvas-svg-android",
1517
]
1618

1719
[profile.release]
@@ -27,7 +29,7 @@ strip = true
2729
[workspace.dependencies.wgt]
2830
package = "wgpu-types"
2931
git = "https://github.com/triniwiz/wgpu"
30-
rev = "5b4f231697c7808bfade1206c4d420a1221ac0a5"
32+
rev = "56a46b75f1b400446d0b1139b2435aa95a0d5ab5"
3133

3234

3335

@@ -40,11 +42,12 @@ raw-window-handle = "0.6.2"
4042
canvas-2d = { path = "./crates/canvas-2d" }
4143
canvas-core = { path = "./crates/canvas-core" }
4244
canvas-webgl = { path = "./crates/canvas-webgl" }
45+
canvas-svg = { path = "./crates/canvas-svg" }
4346
gl-bindings = { path = "./crates/gl-bindings" }
4447
canvas-c = { path = "./crates/canvas-c" }
45-
skia-safe = { version = "0.86.0", features = ["textlayout"] }
48+
skia-safe = { version = "0.87.0", features = ["textlayout"] }
4649
itertools = "0.14.0"
47-
wgpu-core = { git = "https://github.com/triniwiz/wgpu", rev = "5b4f231697c7808bfade1206c4d420a1221ac0a5", features = ["wgsl", "vulkan", "metal", "raw-window-handle"] }
48-
wgpu-hal = { git = "https://github.com/triniwiz/wgpu", rev = "5b4f231697c7808bfade1206c4d420a1221ac0a5", features = ["metal", "vulkan"] }
50+
wgpu-core = { git = "https://github.com/triniwiz/wgpu", rev = "56a46b75f1b400446d0b1139b2435aa95a0d5ab5", features = ["wgsl", "vulkan", "metal", "raw-window-handle"] }
51+
wgpu-hal = { git = "https://github.com/triniwiz/wgpu", rev = "56a46b75f1b400446d0b1139b2435aa95a0d5ab5", features = ["metal", "vulkan"] }
4952
ureq = "2.10.1"
50-
jni = "0.21.1"
53+
jni = "0.21.1"

Makefile

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,61 @@
11
ARCHS_IOS = x86_64-apple-ios aarch64-apple-ios aarch64-apple-ios-sim
2-
# ARCHS_IOS = aarch64-apple-ios-sim
32
ARCHS_ANDROID = i686-linux-android x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
4-
# LIB = libcanvasative.dylib
3+
54
XCFRAMEWORK = CanvasNative.xcframework
65
RUST_LIB = canvasnative
76

8-
all:GENERATE_HEADERS ios android
7+
all: GENERATE_HEADERS ios android
98

109
ios: $(XCFRAMEWORK)
1110

1211
android: GENERATE_ANDROID
1312

14-
android_svg: GENERATE_ANDROID_SVG
13+
ios-svg: GENERATE_IOS_SVG
1514

16-
ios_svg: GENERATE_IOS_SVG
15+
android-svg: GENERATE_ANDROID_SVG
1716

1817
.PHONY: GENERATE_HEADERS
1918
GENERATE_HEADERS:
2019
./tools/scripts/build-headers.sh
2120

22-
# PHONY keyword on make means this is not a file, just an identifier for a target
21+
# --- iOS builds ---
2322
.PHONY: $(ARCHS_IOS)
2423
$(ARCHS_IOS): %:
25-
RUSTFLAGS="-Zlocation-detail=none -C panic=abort" cargo +nightly build -Z build-std='std,panic_abort' -Z build-std-features=panic_immediate_abort --target $@ --release -p canvas-ios
24+
RUSTFLAGS="-Zlocation-detail=none -C panic=abort" \
25+
cargo +nightly build -Z build-std='std,panic_abort' \
26+
-Z build-std-features=panic_immediate_abort \
27+
--target $@ --release -p canvas-ios
2628

2729
$(XCFRAMEWORK): $(ARCHS_IOS)
2830

31+
# --- Android builds ---
2932
.PHONY: $(ARCHS_ANDROID)
3033
$(ARCHS_ANDROID): %:
3134
./tools/scripts/build-android.sh $@
3235

3336
.PHONY: GENERATE_ANDROID
3437
GENERATE_ANDROID: $(ARCHS_ANDROID)
3538

36-
# .PHONY: $(ARCHS_IOS)_SVG
37-
# $(ARCHS_IOS)_SVG: %_svg:
38-
# ./tools/scripts/build-svg-ios.sh $* && ./tools/scripts/copy-svg-ios.sh $*
39-
40-
# .PHONY: GENERATE_IOS_SVG
41-
# GENERATE_IOS_SVG: $(addsuffix _svg,$(ARCHS_IOS))
39+
# --- iOS SVG builds ---
40+
.PHONY: $(addsuffix _svg,$(ARCHS_IOS))
41+
$(addsuffix _svg,$(ARCHS_IOS)): %_svg:
42+
RUSTFLAGS="-Zlocation-detail=none -C panic=abort" \
43+
cargo +nightly build -Z build-std='std,panic_abort' \
44+
-Z build-std-features=panic_immediate_abort \
45+
--target $* --release -p canvas-svg-ios
4246

43-
# .PHONY: $(ARCHS_ANDROID)_SVG
44-
# $(ARCHS_ANDROID)_SVG: %_svg:
45-
# ./tools/scripts/build-svg-android.sh $* && ./tools/scripts/copy-svg-android.sh $*
47+
.PHONY: GENERATE_IOS_SVG
48+
GENERATE_IOS_SVG: $(addsuffix _svg,$(ARCHS_IOS))
4649

47-
# .PHONY: GENERATE_ANDROID_SVG
48-
# GENERATE_ANDROID_SVG: $(addsuffix _svg,$(ARCHS_ANDROID))
49-
50-
.PHONY: clean
51-
clean:
52-
rm -rf target
50+
# --- Android SVG builds ---
51+
.PHONY: $(addsuffix _svg,$(ARCHS_ANDROID))
52+
$(addsuffix _svg,$(ARCHS_ANDROID)): %_svg:
53+
./tools/scripts/build-svg-android.sh $* svg
5354

55+
.PHONY: GENERATE_ANDROID_SVG
56+
GENERATE_ANDROID_SVG: $(addsuffix _svg,$(ARCHS_ANDROID))
5457

58+
# --- Debug targets ---
5559
.PHONY: ios_debug
5660
ios_debug: $(addsuffix _debug,$(ARCHS_IOS))
5761

@@ -64,4 +68,9 @@ $(addsuffix _debug,$(ARCHS_IOS)): %_debug:
6468

6569
.PHONY: $(addsuffix _debug,$(ARCHS_ANDROID))
6670
$(addsuffix _debug,$(ARCHS_ANDROID)): %_debug:
67-
./tools/scripts/build-android.sh $* debug
71+
./tools/scripts/build-android.sh $* debug
72+
73+
# --- Clean ---
74+
.PHONY: clean
75+
clean:
76+
rm -rf target

apps/demo/src/plugin-demos/canvas-media.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Observable, EventData, Page } from '@nativescript/core';
22
import { DemoSharedCanvasMedia } from '@demo/shared';
3-
import {} from '@nativescript/canvas-media';
43

54
export function navigatingTo(args: EventData) {
65
const page = <Page>args.object;

apps/demo/src/plugin-demos/canvas-media.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:ui="@nativescript/canvas-media" navigatingTo="navigatingTo"
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:ui="@nativescript/canvas-media" xmlns:audio="@nativescript/canvas-media/audio" xmlns:video="@nativescript/canvas-media/video" navigatingTo="navigatingTo"
22
class="page">
33
<Page.actionBar>
44
<ActionBar title="canvas-media" icon="" class="action-bar">
55
</ActionBar>
66
</Page.actionBar>
77
<GridLayout rows="*,*" loaded="{{loaded}}">
8-
<!--<ui:Video playsinline="true" height="300">
9-
<ui:source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm"
8+
<video:Video id="video" playsinline="true" autoplay="true" loop="true" height="300">
9+
<ui:Source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm"
1010
type="video/webm"/>
1111

12-
<ui:source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4"
12+
<ui:Source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4"
1313
type="video/mp4"/>
14-
</ui:Video>
14+
</video:Video>
1515

16-
<ui:Audio margin="0 10" controls="true" row="1" playsinline="true" height="300">
16+
<!-- <ui:Audio margin="0 10" controls="true" row="1" playsinline="true" height="300">
1717
<ui:source src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3"
1818
type="audio/mp3"/>
1919
</ui:Audio> -->

crates/canvas-android/build.rs

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ use std::path::Path;
66
//const DEFAULT_CLANG_VERSION: &str = "14.0.7";
77
const DEFAULT_CLANG_VERSION: &str = "12.0.9";
88
fn main() {
9+
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set");
10+
if target_os == "android" {
11+
println!("cargo:rustc-link-arg=-Wl,-z,max-page-size=16384");
12+
}
913
setup_aarch64_android_workaround();
10-
setup_x86_64_android_workaround();
14+
1115
println!("cargo:rerun-if-changed=src/lib.rs");
1216
println!("cargo:rerun-if-changed=src/jni_compat/mod.rs");
1317
println!("cargo:rerun-if-changed=src/jni_compat/org_nativescript_canvas_NSCCanvas.rs");
@@ -16,56 +20,6 @@ fn main() {
1620
println!("cargo:rerun-if-changed=src/jni_compat/org_nativescript_canvas_NSCSVG.rs");
1721
}
1822

19-
#[allow(dead_code)]
20-
fn setup_x86_64_android_workaround() {
21-
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set");
22-
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH not set");
23-
if target_arch == "x86_64" && target_os == "android" {
24-
println!("cargo:rustc-link-arg=-Wl,-z,max-page-size=16384");
25-
/*
26-
let android_ndk_home = if let Ok(android_ndk_home) = env::var("ANDROID_NDK") {
27-
android_ndk_home
28-
} else {
29-
env::var("ANDROID_NDK_HOME").expect("ANDROID_NDK_HOME not set")
30-
};
31-
32-
let build_os = match env::consts::OS {
33-
"linux" => "linux",
34-
"macos" => "darwin",
35-
"windows" => "windows",
36-
_ => panic!(
37-
"Unsupported OS. You must use either Linux, MacOS or Windows to build the crate."
38-
),
39-
};
40-
41-
let ndk_clang_version = if let Ok(mut android_version_txt) = File::open(format!(
42-
"{android_ndk_home}/toolchains/llvm/prebuilt/{build_os}-x86_64/AndroidVersion.txt"
43-
)) {
44-
let mut data = String::new();
45-
let _ = android_version_txt.read_to_string(&mut data);
46-
let line = data.lines().take(1).next();
47-
line.unwrap_or("").to_string()
48-
} else {
49-
DEFAULT_CLANG_VERSION.to_string()
50-
};
51-
52-
let clang_version = env::var("NDK_CLANG_VERSION").unwrap_or(ndk_clang_version);
53-
54-
let linux_x86_64_lib_dir = format!(
55-
"toolchains/llvm/prebuilt/{build_os}-x86_64/lib64/clang/{clang_version}/lib/linux/"
56-
);
57-
let linkpath = format!("{android_ndk_home}/{linux_x86_64_lib_dir}");
58-
if Path::new(&linkpath).exists() {
59-
println!("cargo:rustc-link-search={android_ndk_home}/{linux_x86_64_lib_dir}");
60-
println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
61-
} else {
62-
panic!("Path {linkpath} not exists");
63-
}
64-
65-
*/
66-
}
67-
}
68-
6923
fn setup_aarch64_android_workaround() {
7024
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set");
7125
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH not set");
@@ -93,6 +47,15 @@ fn setup_aarch64_android_workaround() {
9347
let line = data.lines().take(1).next();
9448
let mut line = line.unwrap_or("").to_string();
9549
// in ndk 27 the clang version is 18.0.1 but the directory is named 18 ... let tweak it
50+
let ndk_version = android_ndk_home.replace(".", "_").parse::<i64>();
51+
if let Ok(ndk_version) = ndk_version {
52+
let min_round_version: i64 = 27_0_12077973;
53+
if ndk_version >= min_round_version {
54+
if let Some(round_version) = line.split(".").next() {
55+
line = round_version.to_string();
56+
}
57+
}
58+
}
9659
if android_ndk_home.contains("27.0.12077973") {
9760
line = "18".to_string();
9861
}
@@ -117,8 +80,6 @@ fn setup_aarch64_android_workaround() {
11780
let linux_aarch64_lib_dir_other_27_plus =
11881
format!("toolchains/llvm/prebuilt/{build_os}-x86_64/lib/clang/{version}/lib/linux/");
11982

120-
println!("cargo:rustc-link-arg=-Wl,-z,max-page-size=16384");
121-
12283
let linkpath_other = format!("{android_ndk_home}/{linux_aarch64_lib_dir_other}");
12384

12485
let linkpath_other_27_plus =

crates/canvas-c/src/webgpu/enums.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ use std::{
44
};
55

66
use wgpu_core::binding_model::{BindGroupEntry, BufferBinding};
7-
use wgt::{
8-
AddressMode, BindGroupLayoutEntry, BufferBindingType, CompareFunction, FilterMode, QueryType,
9-
SamplerBindingType, StorageTextureAccess, TextureFormat, TextureSampleType, VertexFormat,
10-
};
7+
use wgt::{AddressMode, BindGroupLayoutEntry, BufferBindingType, CompareFunction, Features, FilterMode, QueryType, SamplerBindingType, StorageTextureAccess, TextureFormat, TextureSampleType, VertexFormat};
118

129
use crate::webgpu::gpu_buffer::CanvasGPUBuffer;
1310
use crate::webgpu::gpu_sampler::CanvasGPUSampler;
@@ -327,6 +324,23 @@ pub enum CanvasGPUTextureFormat {
327324
/// [`Features::TEXTURE_FORMAT_NV12`] must be enabled to use this texture format.
328325
NV12,
329326

327+
/// YUV 4:2:0 chroma subsampled format.
328+
///
329+
/// Contains two planes:
330+
/// - 0: Single 16 bit channel luminance, of which only the high 10 bits
331+
/// are used.
332+
/// - 1: Dual 16 bit channel chrominance at half width and half height, of
333+
/// which only the high 10 bits are used.
334+
///
335+
/// Valid view formats for luminance are [`TextureFormat::R16Unorm`].
336+
///
337+
/// Valid view formats for chrominance are [`TextureFormat::Rg16Unorm`].
338+
///
339+
/// Width and height must be even.
340+
///
341+
/// [`Features::TEXTURE_FORMAT_P010`] must be enabled to use this texture format.
342+
P010,
343+
330344
// Compressed textures usable with `TEXTURE_COMPRESSION_BC` feature.
331345
/// 4x4 block compressed texture. 8 bytes per block (4 bit/px). 4 color + alpha pallet. 5 bit R + 6 bit G + 5 bit B + 1 bit alpha.
332346
/// [0, 63] ([0, 1] for alpha) converted to/from float [0, 1] in shader.
@@ -573,6 +587,7 @@ impl From<wgt::TextureFormat> for CanvasGPUTextureFormat {
573587
block: block.into(),
574588
channel: channel.into(),
575589
},
590+
TextureFormat::P010 => CanvasGPUTextureFormat::P010
576591
}
577592
}
578593
}
@@ -633,6 +648,7 @@ impl Into<wgt::TextureFormat> for CanvasGPUTextureFormat {
633648
wgt::TextureFormat::Depth32FloatStencil8
634649
}
635650
CanvasGPUTextureFormat::NV12 => wgt::TextureFormat::NV12,
651+
CanvasGPUTextureFormat::P010 => wgt::TextureFormat::P010,
636652
CanvasGPUTextureFormat::Bc1RgbaUnorm => wgt::TextureFormat::Bc1RgbaUnorm,
637653
CanvasGPUTextureFormat::Bc1RgbaUnormSrgb => wgt::TextureFormat::Bc1RgbaUnormSrgb,
638654
CanvasGPUTextureFormat::Bc2RgbaUnorm => wgt::TextureFormat::Bc2RgbaUnorm,
@@ -742,6 +758,7 @@ impl Into<String> for CanvasGPUTextureFormat {
742758
CanvasGPUTextureFormat::Depth24Plus => "depth24plus",
743759
CanvasGPUTextureFormat::Depth24PlusStencil8 => "depth24plus-stencil8",
744760
CanvasGPUTextureFormat::NV12 => "nv12",
761+
CanvasGPUTextureFormat::P010 => "p010",
745762
CanvasGPUTextureFormat::Rgb9e5Ufloat => "rgb9e5ufloat",
746763
CanvasGPUTextureFormat::Bc1RgbaUnorm => "bc1-rgba-unorm",
747764
CanvasGPUTextureFormat::Bc1RgbaUnormSrgb => "bc1-rgba-unorm-srgb",
@@ -855,6 +872,7 @@ pub extern "C" fn canvas_native_webgpu_enum_gpu_texture_to_string(
855872
CanvasGPUTextureFormat::Depth24Plus => "depth24plus",
856873
CanvasGPUTextureFormat::Depth24PlusStencil8 => "depth24plus-stencil8",
857874
CanvasGPUTextureFormat::NV12 => "nv12",
875+
CanvasGPUTextureFormat::P010 => "p010",
858876
CanvasGPUTextureFormat::Rgb9e5Ufloat => "rgb9e5ufloat",
859877
CanvasGPUTextureFormat::Bc1RgbaUnorm => "bc1-rgba-unorm",
860878
CanvasGPUTextureFormat::Bc1RgbaUnormSrgb => "bc1-rgba-unorm-srgb",

crates/canvas-c/src/webgpu/error.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,6 @@ impl From<wgpu_core::command::CreateRenderBundleError> for CanvasGPUError {
248248
}
249249
}
250250

251-
impl From<wgpu_core::command::CopyError> for CanvasGPUError {
252-
fn from(err: wgpu_core::command::CopyError) -> Self {
253-
CanvasGPUError::Validation(fmt_err(&err))
254-
}
255-
}
256251

257252
impl From<wgpu_core::command::CommandEncoderError> for CanvasGPUError {
258253
fn from(err: wgpu_core::command::CommandEncoderError) -> Self {

crates/canvas-c/src/webgpu/gpu_canvas_context.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,16 @@ fn to_data_url_with_texture(
262262
depth_or_array_layers: 1,
263263
};
264264

265-
let texture_copy = wgt::ImageCopyTexture {
265+
let texture_copy = wgt::TexelCopyTextureInfo {
266266
texture,
267267
mip_level: 0,
268268
origin: wgt::Origin3d::ZERO,
269269
aspect: wgt::TextureAspect::All,
270270
};
271271

272-
let buffer_copy = wgt::ImageCopyBuffer {
272+
let buffer_copy = wgt::TexelCopyBufferInfo {
273273
buffer: output_buffer,
274-
layout: wgt::ImageDataLayout {
274+
layout: wgt::TexelCopyBufferLayout {
275275
offset: 0,
276276
bytes_per_row: Some(round_up_to_256(4 * width)),
277277
rows_per_image: Some(height),
@@ -303,7 +303,7 @@ fn to_data_url_with_texture(
303303

304304
let desc = wgt::CommandBufferDescriptor { label: None };
305305

306-
let (id, error) = global.command_encoder_finish(encoder, &desc);
306+
let (id, error) = global.command_encoder_finish(encoder, &desc, None);
307307

308308
if let Some(_) = error {
309309
return None;
@@ -1423,14 +1423,14 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_present_surface(
14231423
depth_or_array_layers: 1,
14241424
};
14251425

1426-
let texture_src_copy = wgpu_core::command::ImageCopyTexture {
1426+
let texture_src_copy = wgpu_core::command::TexelCopyTextureInfo {
14271427
texture: texture.texture,
14281428
mip_level: 0,
14291429
origin: wgt::Origin3d::ZERO,
14301430
aspect: wgt::TextureAspect::All,
14311431
};
14321432

1433-
let texture_dst_copy = wgpu_core::command::ImageCopyTexture {
1433+
let texture_dst_copy = wgpu_core::command::TexelCopyTextureInfo {
14341434
texture: dst_texture.texture,
14351435
mip_level: 0,
14361436
origin: wgt::Origin3d::ZERO,
@@ -1459,7 +1459,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_present_surface(
14591459
Ok(_) => {
14601460
let desc = wgt::CommandBufferDescriptor { label: None };
14611461

1462-
let (id, error) = global.command_encoder_finish(encoder, &desc);
1462+
let (id, error) = global.command_encoder_finish(encoder, &desc, None);
14631463

14641464
if error.is_none() {
14651465
global.queue_submit(data.device.queue.queue.id, &[id]).ok();

0 commit comments

Comments
 (0)