Skip to content

Commit

Permalink
chore: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Jul 2, 2024
1 parent ce2e8ac commit 2f3f604
Show file tree
Hide file tree
Showing 148 changed files with 14,797 additions and 5,995 deletions.
197 changes: 197 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'gl_bindings'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=gl-bindings"
],
"filter": {
"name": "gl_bindings",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'canvas_core'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=canvas-core"
],
"filter": {
"name": "canvas_core",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'canvas_2d'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=canvas-2d"
],
"filter": {
"name": "canvas_2d",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'canvas_webgl'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=canvas-webgl"
],
"filter": {
"name": "canvas_webgl",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'canvas_c'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=canvas-c"
],
"filter": {
"name": "canvas_c",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'canvasnative'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=canvas-ios"
],
"filter": {
"name": "canvasnative",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'playground'",
"cargo": {
"args": [
"build",
"--bin=playground",
"--package=playground"
],
"filter": {
"name": "playground",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'playground'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=playground",
"--package=playground"
],
"filter": {
"name": "playground",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'canvas_cxx'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=canvas-cxx"
],
"filter": {
"name": "canvas_cxx",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'canvassvg'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=canvas-svg"
],
"filter": {
"name": "canvassvg",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::ffi::c_void;

use canvas_c::webgpu::gpu::CanvasWebGPUInstance;
use jni::objects::{JClass, JObject};
use jni::sys::{jboolean, jfloat, jint, jlong, jobject, JNI_FALSE, JNI_TRUE};
use jni::JNIEnv;
Expand All @@ -18,6 +19,33 @@ pub(crate) struct AndroidGLContext {
android_window: Option<NativeWindow>,
}

#[no_mangle]
pub extern "system" fn nativeInitWebGPU(
mut env: JNIEnv,
_: JClass,
instance: jlong,
surface: jobject,
width: jint,
height: jint,
) -> jlong {
unsafe {
let interface = env.get_native_interface();
if let Some(window) = NativeWindow::from_surface(interface, surface) {
let ptr = window.ptr().as_ptr();
let instance: *mut CanvasWebGPUInstance = instance as _;
let ret = canvas_c::webgpu::gpu_canvas_context::canvas_native_webgpu_context_create(
instance,
ptr as *mut c_void,
width as u32,
height as u32,
);

return ret as jlong;
}
}
0
}

#[no_mangle]
pub extern "system" fn nativeInitGL(
mut env: JNIEnv,
Expand Down
7 changes: 6 additions & 1 deletion crates/canvas-android/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::jni_compat::org_nativescript_canvas_NSCCanvas::{
nativeReleaseGLNormal, nativeReleaseGLPointer, nativeReleaseGLPointerNormal,
nativeUpdate2DSurface, nativeUpdate2DSurfaceNoSurface, nativeUpdate2DSurfaceNoSurfaceNormal,
nativeUpdateGLNoSurface, nativeUpdateGLNoSurfaceNormal, nativeUpdateGLSurface,
nativeWebGLC2DRender, nativeWriteCurrentGLContextToBitmap,
nativeWebGLC2DRender, nativeWriteCurrentGLContextToBitmap, nativeInitWebGPU
};
use crate::jni_compat::org_nativescript_canvas_NSCCanvasRenderingContext2D::{
nativeCreatePattern, nativeDrawAtlasWithBitmap, nativeDrawImageDxDyDwDhWithAsset,
Expand Down Expand Up @@ -102,6 +102,7 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _reserved: *const c_void) -> jint
"nativeContext2DPathTest",
"nativeContext2DRender",
"nativeWebGLC2DRender",
"nativeInitWebGPU"
];

let canvas_signatures = if ret >= ANDROID_O {
Expand All @@ -126,6 +127,7 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _reserved: *const c_void) -> jint
"(J)V",
"(J)V",
"(JJII)V",
"(JLandroid/view/Surface;II)J",
]
} else {
[
Expand All @@ -149,6 +151,7 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _reserved: *const c_void) -> jint
"!(J)V",
"!(J)V",
"!(JJII)V",
"!(JLandroid/view/Surface;II)J",
]
};

Expand All @@ -174,6 +177,7 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _reserved: *const c_void) -> jint
nativeContext2DPathTest as *mut c_void,
nativeContext2DRender as *mut c_void,
nativeWebGLC2DRender as *mut c_void,
nativeInitWebGPU as *mut c_void,
]
} else {
[
Expand All @@ -197,6 +201,7 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _reserved: *const c_void) -> jint
nativeContext2DPathTestNormal as *mut c_void,
nativeContext2DRender as *mut c_void,
nativeWebGLC2DRender as *mut c_void,
nativeInitWebGPU as *mut c_void,
]
};

Expand Down
15 changes: 10 additions & 5 deletions crates/canvas-c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ parking_lot = "0.12.0"
ureq = { version = "2.9.6", features = ["gzip"] }
bytes = "1.5.0"
log = { version = "0.4.20"}
wgpu-core = {version = "0.21.0", features = ["wgsl", "metal"]}
wgpu-types = "0.20.0"
futures = "0.3"
raw-window-handle = "0.5.2"
raw-window-handle = "0.6.2"

[target.'cfg(target_vendor="apple")'.dependencies]
display-link = "0.2.0"
[target.'cfg(target_os="ios")'.dependencies]
display-link = {version = "0.2.0"}
wgpu-core = {version = "0.21.0", features = ["wgsl", "metal","raw-window-handle"]}


# [target.'cfg(target_os="macos")'.dependencies]
# display-link = { git = "https://github.com/servo/display-link", branch = "no-transmute" }
# wgpu-core = {version = "0.21.0", features = ["wgsl", "metal","raw-window-handle"]}

[target.'cfg(target_os="android")'.dependencies]
ndk = { version = "0.7.0", features = ["bitmap"] }
once_cell = "1.14.0"
once_cell = "1.14.0"
wgpu-core = {version = "0.21.0", features = ["wgsl","vulkan","raw-window-handle"]}
7 changes: 5 additions & 2 deletions crates/canvas-c/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ crates = ["wgpu_types"]
[export]
include = ["GLConstants", "InvalidateState","CanvasGPUTextureFormat"]
exclude = ["AChoreographer", "AChoreographer_frameCallback", "AChoreographer_frameCallback64", "AChoreographer_getInstance", "AChoreographer_postFrameCallback", "AChoreographer_postFrameCallbackDelayed", "AChoreographer_postFrameCallback64", "AChoreographer_postFrameCallbackDelayed64"]

mangle.remove_underscores = true

[defines]
"target_os = ios" = "TARGET_OS_IOS"
"target_os = macos" = "TARGET_OS_MACOS"
"target_os = android" = "TARGET_OS_ANDROID"
"target_os = android" = "TARGET_OS_ANDROID"

[enum]
prefix_with_name = true
2 changes: 1 addition & 1 deletion crates/canvas-c/src/impl_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn draw_image_space_test(
crate::canvas_native_webgl_active_texture(gl_bindings::TEXTURE0, state);
crate::canvas_native_webgl_bind_texture(gl_bindings::TEXTURE_2D, texture, state);
crate::canvas_native_webgl_pixel_storei(
crate::GLConstants::UNPACK_FLIP_Y_WEBGL as u32,
crate::GLConstants::UnPackFlipYWebGL as u32,
0,
state,
);
Expand Down
Loading

0 comments on commit 2f3f604

Please sign in to comment.