Skip to content

Commit 6bbcf8b

Browse files
committed
feat: 0.0.1
1 parent fdfcaf9 commit 6bbcf8b

Some content is hidden

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

48 files changed

+1432
-2948
lines changed

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: 1 addition & 0 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| {

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);

crates/canvas-c/src/lib.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ pub enum InvalidateState {
4949
Invalidating,
5050
}
5151

52+
impl Into<u32> for InvalidateState {
53+
fn into(self) -> u32 {
54+
match self {
55+
InvalidateState::None => 0,
56+
InvalidateState::Pending => 1,
57+
InvalidateState::Invalidating => 2,
58+
}
59+
}
60+
}
61+
5262
/* Helpers */
5363

5464
#[no_mangle]
@@ -83,7 +93,6 @@ pub extern "C" fn canvas_native_font_add_family(
8393
}
8494
}
8595

86-
8796
#[no_mangle]
8897
pub extern "C" fn canvas_native_font_add_family_with_bytes(
8998
alias: *const c_char,
@@ -106,7 +115,6 @@ pub extern "C" fn canvas_native_font_add_family_with_bytes(
106115
}
107116
}
108117

109-
110118
#[no_mangle]
111119
pub extern "C" fn canvas_native_context_2d_test(context: i64) {
112120
if context == 0 {
@@ -124,7 +132,6 @@ pub extern "C" fn canvas_native_context_2d_test(context: i64) {
124132
context.render();
125133
}
126134

127-
128135
#[no_mangle]
129136
pub extern "C" fn canvas_native_context_2d_path_test(context: i64) {
130137
if context == 0 {
@@ -157,7 +164,6 @@ pub extern "C" fn canvas_native_context_2d_path_test(context: i64) {
157164
context.render();
158165
}
159166

160-
161167
#[no_mangle]
162168
pub extern "C" fn canvas_native_context_2d_conic_test(context: i64) {
163169
if context == 0 {
@@ -184,8 +190,10 @@ pub extern "C" fn canvas_native_context_2d_conic_test(context: i64) {
184190
gradient.add_color_stop(1., Color::BLUE);
185191

186192
// Set the fill style and draw a rectangle
187-
ctx.set_fill_style(canvas_2d::context::fill_and_stroke_styles::paint::PaintStyle::Gradient(gradient));
193+
ctx.set_fill_style(
194+
canvas_2d::context::fill_and_stroke_styles::paint::PaintStyle::Gradient(gradient),
195+
);
188196
ctx.fill_rect_xywh(20., 20., 200., 200.);
189197
}
190198
context.render();
191-
}
199+
}

0 commit comments

Comments
 (0)