Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable metal and vulkan as 2d backends #128

Merged
merged 13 commits into from
Nov 12, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 0 additions & 9 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
"-C", "target-cpu=native",
"-C", "panic=abort"
]

[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
"-C", "target-cpu=native",
"-C", "panic=abort"
]

Expand All @@ -42,34 +40,27 @@ rustflags = [
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
"-C", "target-cpu=native",
"-C", "panic=abort"
]

[target.armv7-linux-androideabi]
rustflags = [
"-C", "target-cpu=native",
"-C", "panic=abort",
"-C", "target-feature=-outline-atomics"
]

[target.aarch64-linux-android]
rustflags = [
"-C", "target-cpu=native",
"-C", "panic=abort",
"-C", "target-feature=-outline-atomics"
]

[target.i686-linux-android]
rustflags = [
"-C", "target-cpu=native",
"-C", "panic=abort",
"-C", "target-feature=-outline-atomics"
]

[target.x86_64-linux-android]
rustflags = [
"-C", "target-cpu=native",
"-C", "panic=abort",
"-C", "target-feature=-outline-atomics"
]
14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@ strip = true

[workspace.dependencies.wgt]
package = "wgpu-types"
git = "https://github.com/gfx-rs/wgpu"
rev = "690a3fb3fb4c6652b6a1e0b9df9b40de5d6ba091"
git = "https://github.com/triniwiz/wgpu"
rev = "48f663f70d5b6e99a5b8a708876ce9642d78fbde"

[workspace.dependencies]
env_logger = "0.11.5"
log = "0.4.22"
parking_lot = "0.12.3"
raw-window-handle = "0.6.2"
canvas-2d = { path = "./crates/canvas-2d" }
canvas-core = { path = "./crates/canvas-core" }
canvas-webgl = { path = "./crates/canvas-webgl" }
gl-bindings = { path = "./crates/gl-bindings" }
canvas-c = { path = "./crates/canvas-c" }
skia-safe = { version = "0.73.0", features = ["textlayout"] }
skia-safe = { version = "0.78.2", features = ["textlayout"] }
itertools = "0.13.0"
wgpu-core = { git = "https://github.com/gfx-rs/wgpu", rev = "690a3fb3fb4c6652b6a1e0b9df9b40de5d6ba091", features = ["wgsl", "vulkan", "metal", "raw-window-handle"] }
wgpu-types = { git = "https://github.com/gfx-rs/wgpu", rev = "690a3fb3fb4c6652b6a1e0b9df9b40de5d6ba091" }
wgpu-core = { git = "https://github.com/triniwiz/wgpu", rev = "48f663f70d5b6e99a5b8a708876ce9642d78fbde", features = ["wgsl", "vulkan", "metal", "raw-window-handle"] }
wgpu-types = { git = "https://github.com/triniwiz/wgpu", rev = "48f663f70d5b6e99a5b8a708876ce9642d78fbde" }
ureq = "2.10.1"
jni = "0.21.1"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $(XCFRAMEWORK): $(ARCHS_IOS)

.PHONY: $(ARCHS_ANDROID)
$(ARCHS_ANDROID): %:
./tools/scripts/build-android.sh $@ && ./tools/scripts/copy-android.sh $@
./tools/scripts/build-android.sh $@

.PHONY: GENERATE_ANDROID
GENERATE_ANDROID: $(ARCHS_ANDROID)
Expand Down
3 changes: 2 additions & 1 deletion apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
},
"devDependencies": {
"@nativescript/android": "~8.8.0",
"@nativescript/ios": "~8.8.1",
"@nativescript/devtools": "~0.0.1",
"@nativescript/ios": "~8.8.0",
"@nativescript/visionos": "~8.8.0"
}
}
44 changes: 42 additions & 2 deletions apps/demo/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,54 @@ Helpers.initialize();
require('@nativescript/canvas-polyfill');
*/
import '@nativescript/canvas-polyfill';
import { Canvas } from '@nativescript/canvas';
// import { DomainDispatcher, initDevtools, ProtocolWrapper } from '@nativescript/devtools';
// initDevtools();

// @DomainDispatcher('Inspector')
// class Inspector extends ProtocolWrapper {}

// @DomainDispatcher('Runtime')
// class Runtime extends ProtocolWrapper {
// evaluate() {
// console.log('evaluate', arguments);
// }

// runScript() {
// console.log('runScript', arguments);
// }
// }
/*

@DomainDispatcher('Page')
class CustomPage extends ProtocolWrapper {
addScriptToEvaluateOnNewDocument(params) {
if (params.worldName === 'DevTools Performance Metrics') {
this.emit('Runtime.executionContextCreated', {
context: {
id: 2,
name: params.worldName,
origin: '',
uniqueId: performance.now(),
},
});
return;
}

this.emit('Page.addScriptToEvaluateOnNewDocument', {});
}
}
*/

// require('@nativescript/canvas-polyfill');
// import { Svg } from '@nativescript/canvas-svg';
// import { ImageAsset } from '@nativescript/canvas';
declare const jp, GDPerformanceMonitor, android, java, UIColor;
let monitor;
import { Application, path as filePath, knownFolders, Utils, path as nsPath, ImageSource, Trace, Screen } from '@nativescript/core';

Canvas.useSurface = false;
Canvas.forceGL = false;
Application.on('discardedError', (args) => {
console.log('discardedError', args.error, args);
});
Expand All @@ -27,7 +68,7 @@ Application.on('uncaughtError', (args) => {

Application.on('launch', (args) => {
//require('@nativescript/canvas-polyfill');
/*if (global.isAndroid) {
if (global.isAndroid) {
jp.wasabeef.takt.Takt.stock(Utils.android.getApplicationContext()).seat(jp.wasabeef.takt.Seat.TOP_CENTER).color(-65536);
} else {
monitor = GDPerformanceMonitor.new();
Expand All @@ -39,7 +80,6 @@ Application.on('launch', (args) => {
monitor.appVersionHidden = true;
monitor.deviceVersionHidden = true;
}
*/
});

// fetch('https://github.com/mrdoob/three.js/blob/dev/examples/models/gltf/DamagedHelmet/glTF/Default_metalRoughness.jpg?raw=true')
Expand Down
2 changes: 2 additions & 0 deletions apps/demo/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = (env) => {
config.resolve.alias.set('@demo/shared', resolve(__dirname, '..', '..', 'tools', 'demo'));
// config.resolve.alias.set('three', 'three/webgpu');
// config.resolve.alias.set('three/tsl', 'three/tsl');

config.resolve.alias.set('three', resolve(__dirname, '..', '..', 'node_modules', 'three', 'build', 'three.webgpu.js'));
});

webpack.Utils.addCopyRule('**/*.svg');
Expand Down
13 changes: 9 additions & 4 deletions crates/canvas-2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2021"

[features]
metal = ["skia-safe/metal"]
metal = ["skia-safe/metal", "canvas-core/metal"]
gl = ["skia-safe/gl"]
vulkan = ["skia-safe/vulkan", "ash"]
vulkan = ["skia-safe/vulkan", "canvas-core/vulkan"]
default = ["gl"]

[dependencies]
Expand All @@ -17,8 +17,13 @@ base64 = "0.22.1"
encoding_rs = "0.8.34"
gl-bindings = { workspace = true }
csscolorparser = { git = "https://github.com/triniwiz/csscolorparser-rs.git", rev = "c8c7e86", features = ["named-colors"] }
log = "0.4.22"
log.workspace = true
skia-safe = { workspace = true, features = ["textlayout"] }
bytes = "1.6.1"
env_logger = "0.11.2"
ash = { version = "0.38.0", optional = true, features = ["libloading"] }
ash = { version = "0.38.0", optional = true, features = ["libloading"] }
raw-window-handle.workspace = true
bitflags = "2.6.0"

[target.'cfg(any(target_os = "ios", target_os="macos"))'.dependencies]
foreign-types-shared = "0.3.1"
150 changes: 0 additions & 150 deletions crates/canvas-2d/src/android.rs

This file was deleted.

Loading
Loading