Skip to content

Commit

Permalink
chore: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Jul 31, 2024
1 parent 20b1bc9 commit b4b8bc2
Show file tree
Hide file tree
Showing 144 changed files with 18,156 additions and 18,252 deletions.
34 changes: 23 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
[workspace]

resolver = "2"

members = [
"crates/gl-bindings",
"crates/canvas-core",
"crates/canvas-2d",
"crates/canvas-webgl",
"crates/canvas-android",
"crates/canvas-ios",
"crates/playground",
"crates/canvas-c",
"crates/canvas-svg"]
"crates/gl-bindings",
"crates/canvas-core",
"crates/canvas-2d",
"crates/canvas-webgl",
"crates/canvas-android",
"crates/canvas-ios",
"crates/playground",
"crates/canvas-c",
"crates/canvas-svg"]

[profile.release]
panic = "abort"
Expand All @@ -25,4 +24,17 @@ strip = true

[workspace.dependencies.wgt]
package = "wgpu-types"
version = "22.0.0"
version = "22.0.0"

[workspace.dependencies]
wgpu-types = "22.0.0"
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.75.0", features = ["textlayout"] }
itertools = "0.13.0"
wgpu-core = { version = "22.0.0", features = ["wgsl", "raw-window-handle"] }
25 changes: 7 additions & 18 deletions crates/canvas-2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,19 @@ edition = "2021"
[features]
metal = ["skia-safe/metal"]
gl = ["skia-safe/gl"]
vulkan = ["skia-safe/vulkan"]
vulkan = ["skia-safe/vulkan", "ash"]
default = ["gl"]

[dependencies]
canvas-core = { path = "../canvas-core", features = ["2d"] }
parking_lot = "0.12.3"
canvas-core = { workspace = true, features = ["2d"] }
parking_lot.workspace = true
regex = "1.10.5"
base64 = "0.22.1"
encoding_rs = "0.8.34"
gl-bindings = { path = "../gl-bindings" }
gl-bindings = { workspace = true }
csscolorparser = { git = "https://github.com/triniwiz/csscolorparser-rs.git", rev = "c8c7e86", features = ["named-colors"] }
log = "0.4.21"
skia-safe = { version = "0.75.0", features = ["gl", "textlayout"] }
skia-safe = { workspace = true, features = ["textlayout"] }
bytes = "1.6.1"
env_logger = "0.11.2"
ash = { version = "0.38.0" }


[target.'cfg(target_os="ios")'.dependencies]
skia-safe = { version = "0.75.0", features = ["gl", "metal", "textlayout"] }


[target.'cfg(target_os="macos")'.dependencies]
skia-safe = { version = "0.75.0", features = ["gl", "metal", "textlayout"] }

[target.'cfg(target_os="android")'.dependencies]
skia-safe = { version = "0.75.0", features = ["gl", "vulkan", "textlayout"] }
ash = { version = "0.38.0" }
ash = { version = "0.38.0", optional = true , features = ["libloading"]}
6 changes: 4 additions & 2 deletions crates/canvas-2d/src/android.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::os::raw::c_void;
use std::sync::Arc;

#[cfg(feature = "vulkan")]
use ash::vk;
#[cfg(feature = "vulkan")]
use ash::vk::Handle;
use skia_safe::{gpu, Color};

Expand Down Expand Up @@ -32,7 +34,7 @@ impl Context {
Some(f) => f as _,
None => {
println!("resolve of {} failed", of.name().to_str().unwrap());
str::ptr::null()
std::ptr::null()
}
}
};
Expand Down Expand Up @@ -69,7 +71,7 @@ impl Context {
};

let info = skia_safe::ImageInfo::new(
skia_safe::ISize::new(width, height),
skia_safe::ISize::new(width as i32, height as i32),
skia_safe::ColorType::N32,
alpha_type,
Some(skia_safe::ColorSpace::new_srgb()),
Expand Down
6 changes: 3 additions & 3 deletions crates/canvas-2d/src/context/drawing_images/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Context {

let paint = self.state.paint.image_paint();

self.with_canvas(|canvas| {
self.with_canvas_dirty(|canvas| {
canvas.draw_image_with_sampling_options(
image,
skia_safe::Point::new(x, y),
Expand Down Expand Up @@ -175,7 +175,7 @@ impl Context {

let paint = self.state.paint.image_paint();

self.with_canvas(|canvas| {
self.with_canvas_dirty(|canvas| {
canvas.draw_image_rect_with_sampling_options(
image,
Some((&src, SrcRectConstraint::Strict)),
Expand Down Expand Up @@ -204,7 +204,7 @@ impl Context {
.image_smoothing_quality_set(self.state.image_filter_quality());
let paint = self.state.paint.image_paint();

self.with_canvas(|canvas| {
self.with_canvas_dirty(|canvas| {
canvas.draw_image_rect_with_sampling_options(
image,
Some((&src, SrcRectConstraint::Strict)),
Expand Down
21 changes: 10 additions & 11 deletions crates/canvas-2d/src/context/drawing_paths/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::borrow::BorrowMut;

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

use crate::context::Context;
use crate::context::drawing_paths::fill_rule::FillRule;
use crate::context::paths::path::Path;
use crate::context::Context;

pub mod fill_rule;

Expand All @@ -22,7 +22,7 @@ impl Context {
path.0.set_fill_type(rule.to_fill_type());
let path = path.path();

self.with_canvas(|canvas| {
self.with_canvas_dirty(|canvas| {
if let Some(paint) = self.state.paint.fill_shadow_paint(
self.state.shadow_offset,
self.state.shadow_color,
Expand All @@ -34,11 +34,11 @@ impl Context {
canvas.draw_path(path, &paint);
});
} else {
let path = path.map(|path| path.clone()).unwrap_or(self.path.clone());

let mut path = path.map(|path| path.clone()).unwrap_or(self.path.clone());
path.0.set_fill_type(skia_safe::path::FillType::Winding);
let path = path.path();

self.with_canvas(|canvas| {
self.with_canvas_dirty(|canvas| {
if is_fill {
if let Some(paint) = self.state.paint.fill_shadow_paint(
self.state.shadow_offset,
Expand Down Expand Up @@ -78,6 +78,7 @@ impl Context {
let mut clip = path
.map(|path| path.clone())
.unwrap_or_else(|| self.path.clone());

clip.set_fill_type(fill_rule.unwrap_or(FillRule::NonZero));

self.state.clip = match &self.state.clip {
Expand All @@ -91,17 +92,15 @@ impl Context {
None => Some(clip.clone()),
};

self.with_canvas(|canvas| {
if let Some(clip) = &self.state.clip {
canvas.clip_path(clip.path(), Some(ClipOp::Intersect), Some(true));
}
self.with_recorder(|mut recorder| {
recorder.set_clip(&self.state.clip)
});
}

pub fn point_in_path(&self, path: Option<&Path>, x: f32, y: f32, rule: FillRule) -> bool {
let path = path.unwrap_or(&self.path);

let total_matrix = self.state.matrix.to_m33();
let total_matrix = self.state.matrix;
let invertible = is_invertible(&total_matrix);
if !invertible {
return false;
Expand All @@ -120,7 +119,7 @@ impl Context {

pub fn point_in_stroke(&self, path: Option<&Path>, x: f32, y: f32) -> bool {
let path = path.unwrap_or(&self.path);
let matrix = self.state.matrix.0.to_m33();
let matrix = self.state.matrix;
let invertible = is_invertible(&matrix);
if !invertible {
return false;
Expand Down
13 changes: 6 additions & 7 deletions crates/canvas-2d/src/context/drawing_rectangles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ impl Context {
match self
.state
.matrix
.0
.to_m33()
.map_rect(Rect::new(x, y, width, height))
.0
.contains(&self.surface_data.bounds)
Expand All @@ -20,7 +18,7 @@ impl Context {
true => {
let mut recorder = skia_safe::PictureRecorder::new();
let canvas = recorder.begin_recording(self.surface_data.bounds, None);
canvas.set_matrix(&self.state.matrix.0);
canvas.set_matrix(&self.state.matrix.into());

if let Some(clip) = self.state.clip.as_ref() {
canvas.clip_path(clip.path(), skia_safe::ClipOp::Intersect, Some(true));
Expand All @@ -29,17 +27,18 @@ impl Context {
self.recorder = Arc::new(parking_lot::Mutex::new(Recorder {
bounds: self.surface_data.bounds,
current: recorder,
is_dirty: false,
is_dirty: true,
layers: vec![],
cache: None,
matrix: skia_safe::Matrix::new_identity(),
clip: None,
}));

}

// otherwise, paint over the specified region but preserve overdrawn vectors
false => {
self.with_canvas(|canvas| {
self.with_canvas_dirty(|canvas| {
let mut paint = Paint::default();
paint
.set_anti_alias(true)
Expand All @@ -58,7 +57,7 @@ impl Context {
}

pub fn fill_rect(&mut self, rect: &Rect) {
self.with_canvas(|canvas| {
self.with_canvas_dirty(|canvas| {
if let Some(paint) = self.state.paint.fill_shadow_paint(
self.state.shadow_offset,
self.state.shadow_color,
Expand All @@ -76,7 +75,7 @@ impl Context {
}

pub fn stroke_rect(&mut self, rect: &Rect) {
self.with_canvas(|canvas| {
self.with_canvas_dirty(|canvas| {
if let Some(paint) = &mut self.state.paint.stroke_shadow_paint(
self.state.shadow_offset,
self.state.shadow_color,
Expand Down
Loading

0 comments on commit b4b8bc2

Please sign in to comment.