Skip to content

Commit cc02858

Browse files
authored
feat: macOS NAPI (#133)
* feat: macOS NAPI * chore: updates * fix: shadow paint * fix: macos bool * feat: shadow color string * chore: updates * chore: updates * chore: flappyBird * feat: save & restore * chore: updates * chore: update demo * chore: updates * chore: updates * chore: updates * feat: webgl2 * chore: updates * chore: updates * chore: updates * chore: updates * chore: updates * chore(node-demo): start script * chore: node start script * chore: updates * chore: updates * chore: updates * chore: updates * chore: updates * chore: updates * feat: 0.0.1 * feat: 0.0.2 * chore: 0.0.5 * fix: magnify -> wheel event * chore: demo * chore: bump * chore: updates * chore: fix build * chore: move napi into crates
1 parent 42ff74a commit cc02858

File tree

305 files changed

+57515
-630
lines changed

Some content is hidden

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

305 files changed

+57515
-630
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"new": "cpp"
4+
}
5+
}

.yarn/releases/yarn-4.5.2.cjs

Lines changed: 934 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarnPath: .yarn/releases/yarn-4.5.2.cjs

Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ members = [
1010
"crates/canvas-ios",
1111
"crates/playground",
1212
"crates/canvas-c",
13-
"crates/canvas-svg"]
13+
"crates/canvas-svg",
14+
"crates/canvas-napi",
15+
]
1416

1517
[profile.release]
1618
panic = "abort"
@@ -25,7 +27,7 @@ strip = true
2527
[workspace.dependencies.wgt]
2628
package = "wgpu-types"
2729
git = "https://github.com/triniwiz/wgpu"
28-
rev = "48f663f70d5b6e99a5b8a708876ce9642d78fbde"
30+
rev = "6f163cdf622bd183fcfc20224294b797312550bb"
2931

3032
[workspace.dependencies]
3133
env_logger = "0.11.5"
@@ -37,9 +39,9 @@ canvas-core = { path = "./crates/canvas-core" }
3739
canvas-webgl = { path = "./crates/canvas-webgl" }
3840
gl-bindings = { path = "./crates/gl-bindings" }
3941
canvas-c = { path = "./crates/canvas-c" }
40-
skia-safe = { version = "0.78.2", features = ["textlayout"] }
42+
skia-safe = { version = "0.80.0", features = ["textlayout"] }
4143
itertools = "0.13.0"
42-
wgpu-core = { git = "https://github.com/triniwiz/wgpu", rev = "48f663f70d5b6e99a5b8a708876ce9642d78fbde", features = ["wgsl", "vulkan", "metal", "raw-window-handle"] }
43-
wgpu-types = { git = "https://github.com/triniwiz/wgpu", rev = "48f663f70d5b6e99a5b8a708876ce9642d78fbde" }
44+
wgpu-core = { git = "https://github.com/triniwiz/wgpu", rev = "6f163cdf622bd183fcfc20224294b797312550bb", features = ["wgsl", "vulkan", "metal", "raw-window-handle"] }
45+
wgpu-types = { git = "https://github.com/triniwiz/wgpu", rev = "6f163cdf622bd183fcfc20224294b797312550bb" }
4446
ureq = "2.10.1"
4547
jni = "0.21.1"

crates/canvas-2d/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ raw-window-handle.workspace = true
2626
bitflags = "2.6.0"
2727

2828
[target.'cfg(any(target_os = "ios", target_os="macos"))'.dependencies]
29-
foreign-types-shared = "0.3.1"
29+
foreign-types-shared = "0.3.1"
30+
objc2-foundation = { version = "0.2.2", features = ["NSAutoreleasePool"] }

crates/canvas-2d/src/context/drawing_images/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ impl Context {
147147
}
148148

149149
pub fn draw_image_dx_dy(&mut self, image: &Image, x: f32, y: f32) {
150+
#[cfg(any(target_os = "macos", target_os = "ios"))]
151+
let _ = unsafe { objc2_foundation::NSAutoreleasePool::new() };
150152
#[cfg(feature = "gl")]{
151153
if let Some(ref context) = self.gl_context {
152154
context.make_current();
@@ -174,6 +176,8 @@ impl Context {
174176
}
175177

176178
fn draw_image(&mut self, image: &Image, src_rect: impl Into<Rect>, dst_rect: impl Into<Rect>) {
179+
#[cfg(any(target_os = "macos", target_os = "ios"))]
180+
let _ = unsafe { objc2_foundation::NSAutoreleasePool::new() };
177181
#[cfg(feature = "gl")]{
178182
if let Some(ref context) = self.gl_context {
179183
context.make_current();
@@ -209,7 +213,8 @@ impl Context {
209213
}
210214

211215
fn draw_image_with_rect(&mut self, image: &Image, dst_rect: impl Into<Rect>) {
212-
216+
#[cfg(any(target_os = "macos", target_os = "ios"))]
217+
let _ = unsafe { objc2_foundation::NSAutoreleasePool::new() };
213218
#[cfg(feature = "gl")]{
214219
if let Some(ref context) = self.gl_context {
215220
context.make_current();

crates/canvas-2d/src/context/drawing_paths/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@ use std::borrow::BorrowMut;
22

33
use skia_safe::{ClipOp, Matrix, Point};
44

5-
use crate::context::Context;
65
use crate::context::drawing_paths::fill_rule::FillRule;
76
use crate::context::paths::path::Path;
7+
use crate::context::Context;
88

99
pub mod fill_rule;
1010

1111
impl Context {
12-
fn fill_or_stroke(&mut self, is_fill: bool, path: Option<&mut Path>, fill_rule: Option<FillRule>) {
13-
14-
#[cfg(feature = "gl")]{
12+
fn fill_or_stroke(
13+
&mut self,
14+
is_fill: bool,
15+
path: Option<&mut Path>,
16+
fill_rule: Option<FillRule>,
17+
) {
18+
#[cfg(feature = "gl")]
19+
{
1520
if let Some(ref context) = self.gl_context {
1621
context.make_current();
1722
}
@@ -42,6 +47,9 @@ impl Context {
4247
)
4348
};
4449

50+
#[cfg(any(target_os = "macos", target_os = "ios"))]
51+
let pool = unsafe { objc2_foundation::NSAutoreleasePool::new() };
52+
4553
self.render_to_canvas(&paint, |canvas, paint| {
4654
if let Some(paint) = &shadow_paint {
4755
canvas.draw_path(path, paint);

crates/canvas-2d/src/context/fill_and_stroke_styles/paint.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl PaintStyle {
5151
blue
5252
}
5353

54+
#[inline]
5455
pub fn new_color_str(color: &str) -> Option<Self> {
5556
parse(color)
5657
.map(|color| {
@@ -201,7 +202,7 @@ impl Paint {
201202
color: Color,
202203
blur: c_float,
203204
) -> Option<skia_safe::Paint> {
204-
if !(color != Color::TRANSPARENT && blur > 0.0) {
205+
if color == Color::TRANSPARENT && blur > 0.0 {
205206
return None;
206207
}
207208
let mut paint = self.fill_paint().clone();
@@ -215,7 +216,7 @@ impl Paint {
215216
color: Color,
216217
blur: c_float,
217218
) -> Option<skia_safe::Paint> {
218-
if !(color != Color::TRANSPARENT && blur > 0.0) {
219+
if color == Color::TRANSPARENT && blur > 0.0 {
219220
return None;
220221
}
221222
let mut paint = self.stroke_paint().clone();

crates/canvas-2d/src/context/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,14 @@ impl Context {
560560
};
561561
}
562562

563+
pub fn reset(&mut self) {
564+
self.reset_state();
565+
self.reset_transform();
566+
self.with_canvas_dirty(|canvas| {
567+
canvas.clear(Color::TRANSPARENT);
568+
});
569+
}
570+
563571
pub fn reset_state(&mut self) {
564572
let direction = self.state.direction;
565573
self.state = State::default();

crates/canvas-2d/src/context/pixel_manipulation/image_data.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct ImageDataInner {
1414
}
1515

1616
unsafe impl Send for ImageDataInner {}
17+
unsafe impl Sync for ImageDataInner {}
1718

1819
#[derive(Debug, Clone)]
1920
pub struct ImageData(ImageDataInner);

0 commit comments

Comments
 (0)