Skip to content

Commit

Permalink
Start to implement skia renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
geom3trik committed Mar 12, 2024
1 parent d982b06 commit 5e5d657
Show file tree
Hide file tree
Showing 77 changed files with 3,745 additions and 2,845 deletions.
Binary file modified .DS_Store
Binary file not shown.
5 changes: 2 additions & 3 deletions crates/vizia_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ vizia_window = { path = "../vizia_window" }
vizia_style = { path = "../vizia_style"}
accesskit = "0.12.0"

femtovg = "0.8.2"
# femtovg = "0.8.2"
skia-safe = { version = "0.71", features = ["textlayout"] }
image = { version = "0.24.8", default-features = false, features = ["png"] } # inherited from femtovg
# morphorm = {path = "../../../morphorm" }
morphorm = {git = "https://github.com/vizia/morphorm.git", branch = "auto-min-size2"}
Expand All @@ -39,8 +40,6 @@ copypasta = {version = "0.10.1", optional = true, default-features = false }
instant = "0.1.12"
chrono = "0.4.34"
hashbrown = "0.14.3"
cosmic-text = { git="https://github.com/pop-os/cosmic-text", rev="19b4d8336e34073bb51b83578d3d803c8c953787" }
swash = "0.1.12"
log = "0.4.20"
indexmap = "2.2.3"
qfilter = "0.1.6"
Expand Down
Binary file not shown.
Binary file added crates/vizia_core/resources/fonts/FiraCode.ttf
Binary file not shown.
Binary file removed crates/vizia_core/resources/fonts/Roboto-Bold.ttf
Binary file not shown.
Binary file removed crates/vizia_core/resources/fonts/Roboto-Italic.ttf
Binary file not shown.
Binary file not shown.
Binary file added crates/vizia_core/resources/fonts/RobotoFlex.ttf
Binary file not shown.
Binary file modified crates/vizia_core/resources/fonts/tabler-icons.ttf
Binary file not shown.
26 changes: 13 additions & 13 deletions crates/vizia_core/src/animation/interpolator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use vizia_style::{
LinearGradient, Opacity, PercentageOrNumber, Rect, Scale, Transform, Translate, RGBA,
};

use femtovg::Transform2D;
// use femtovg::Transform2D;

use crate::style::ImageOrGradient;

Expand Down Expand Up @@ -200,18 +200,18 @@ impl Interpolator for Transform {
}

// TODO: Split this into interpolated matrices for translation, rotation, scale, and skew
impl Interpolator for Transform2D {
fn interpolate(start: &Self, end: &Self, t: f32) -> Self {
let mut transform = *start;
transform[0] = f32::interpolate(&start[0], &end[0], t);
transform[1] = f32::interpolate(&start[1], &end[1], t);
transform[2] = f32::interpolate(&start[2], &end[2], t);
transform[3] = f32::interpolate(&start[3], &end[3], t);
transform[4] = f32::interpolate(&start[4], &end[4], t);
transform[5] = f32::interpolate(&start[5], &end[5], t);
transform
}
}
// impl Interpolator for Transform2D {
// fn interpolate(start: &Self, end: &Self, t: f32) -> Self {
// let mut transform = *start;
// transform[0] = f32::interpolate(&start[0], &end[0], t);
// transform[1] = f32::interpolate(&start[1], &end[1], t);
// transform[2] = f32::interpolate(&start[2], &end[2], t);
// transform[3] = f32::interpolate(&start[3], &end[3], t);
// transform[4] = f32::interpolate(&start[4], &end[4], t);
// transform[5] = f32::interpolate(&start[5], &end[5], t);
// transform
// }
// }

impl<T: Interpolator> Interpolator for Vec<T> {
fn interpolate(start: &Self, end: &Self, t: f32) -> Self {
Expand Down
3 changes: 3 additions & 0 deletions crates/vizia_core/src/binding/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ impl_data_simple!(Entity);
impl_data_simple!(Localized);
impl_data_simple!(Length);
impl_data_simple!(KeyChord);
impl_data_simple!(FamilyOwned);
impl_data_simple!(FontWeight);
impl_data_simple!(TextAlign);

impl Data for &'static str {
fn same(&self, other: &Self) -> bool {
Expand Down
6 changes: 4 additions & 2 deletions crates/vizia_core/src/binding/res.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,18 @@ impl_res_simple!(Overflow);
impl_res_simple!(LengthValue);
impl_res_simple!(FontWeight);
impl_res_simple!(FontWeightKeyword);
impl_res_simple!(FontStyle);
impl_res_simple!(FontSlant);
impl_res_simple!(BorderCornerShape);
impl_res_simple!(Angle);
impl_res_simple!(TextAlign);
impl_res_simple!(TextOverflow);
impl_res_simple!(LineClamp);
impl_res_clone!(BoxShadow);
impl_res_clone!(LinearGradientBuilder);
impl_res_clone!(BoxShadowBuilder);
impl_res_clone!(Filter);
impl_res_simple!(Opacity);
impl_res_simple!(FontStretch);
impl_res_simple!(FontWidth);
impl_res_clone!(Translate);
impl_res_clone!(Scale);
impl_res_clone!(Position);
Expand Down
13 changes: 6 additions & 7 deletions crates/vizia_core/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//! results. The main type here is CachedData, usually accessed via `cx.cache`.

use crate::prelude::*;
use femtovg::ImageId;
use vizia_storage::SparseSet;

#[derive(Debug, Default, Clone, Copy, PartialEq)]
Expand All @@ -19,9 +18,9 @@ pub(crate) struct Pos {
pub struct CachedData {
pub(crate) bounds: SparseSet<BoundingBox>,
pub(crate) relative_position: SparseSet<Pos>,
pub(crate) shadow_images: SparseSet<Vec<Option<(ImageId, ImageId)>>>,
pub(crate) filter_image: SparseSet<Option<(ImageId, ImageId)>>,
pub(crate) screenshot_image: SparseSet<Option<ImageId>>,
// pub(crate) shadow_images: SparseSet<Vec<Option<(ImageId, ImageId)>>>,
// pub(crate) filter_image: SparseSet<Option<(ImageId, ImageId)>>,
// pub(crate) screenshot_image: SparseSet<Option<ImageId>>,
pub(crate) geo_changed: SparseSet<GeoChanged>,
}

Expand All @@ -35,9 +34,9 @@ impl CachedData {
pub(crate) fn remove(&mut self, entity: Entity) {
self.bounds.remove(entity);
self.relative_position.remove(entity);
self.shadow_images.remove(entity);
self.filter_image.remove(entity);
self.screenshot_image.remove(entity);
// self.shadow_images.remove(entity);
// self.filter_image.remove(entity);
// self.screenshot_image.remove(entity);
self.geo_changed.remove(entity);
}

Expand Down
28 changes: 11 additions & 17 deletions crates/vizia_core/src/context/backend.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::any::Any;

use femtovg::{renderer::OpenGl, Canvas};
use skia_safe::Surface;
use vizia_window::WindowDescription;

use super::EventProxy;
use crate::events::EventManager;
use crate::{cache::CachedData, prelude::*, systems::*};

pub use crate::text::cosmic::TextConfig;
pub use crate::text::text_context::TextConfig;

#[cfg(feature = "clipboard")]
use copypasta::ClipboardProvider;
Expand All @@ -27,9 +27,9 @@ impl<'a> BackendContext<'a> {
}

/// Helper function for mutating the state of the root window.
pub fn mutate_window<W: Any, F: Fn(&mut BackendContext, &W)>(&mut self, f: F) {
if let Some(window_event_handler) = self.0.views.remove(&Entity::root()) {
if let Some(window) = window_event_handler.downcast_ref::<W>() {
pub fn mutate_window<W: Any, F: Fn(&mut BackendContext, &mut W)>(&mut self, f: F) {
if let Some(mut window_event_handler) = self.0.views.remove(&Entity::root()) {
if let Some(window) = window_event_handler.downcast_mut::<W>() {
f(self, window);
}

Expand Down Expand Up @@ -62,6 +62,10 @@ impl<'a> BackendContext<'a> {
self.0.focused
}

pub fn get_surface_mut(&mut self, entity: Entity) -> Option<&mut Surface> {
self.0.canvases.get_mut(&entity)
}

/// The window's size in logical pixels, before
/// [`user_scale_factor()`][Self::user_scale_factor()] gets applied to it. If this value changed
/// during a frame then the window will be resized and a [`WindowEvent::GeometryChanged`] will be
Expand All @@ -82,22 +86,12 @@ impl<'a> BackendContext<'a> {
pub fn add_main_window(
&mut self,
window_description: &WindowDescription,
mut canvas: Canvas<OpenGl>,
surface: Surface,
dpi_factor: f32,
) {
let physical_width = window_description.inner_size.width as f32 * dpi_factor;
let physical_height = window_description.inner_size.height as f32 * dpi_factor;

// Scale factor is set to 1.0 here because scaling is applied prior to rendering
canvas.set_size(physical_width as u32, physical_height as u32, 1.0);
canvas.clear_rect(
0,
0,
physical_width as u32,
physical_height as u32,
femtovg::Color::rgba(0, 0, 0, 0),
);

self.0.style.dpi_factor = dpi_factor as f64;

self.0.cache.set_width(Entity::root(), physical_width);
Expand All @@ -117,7 +111,7 @@ impl<'a> BackendContext<'a> {
self.0.style.pseudo_classes.insert(Entity::root(), PseudoClassFlags::OVER);
self.0.style.restyle.insert(Entity::root()).unwrap();
self.0.style.reaccess.insert(Entity::root()).unwrap();
self.0.canvases.insert(Entity::root(), canvas);
self.0.canvases.insert(Entity::root(), surface);
}

/// Returns a reference to the [`Environment`] model.
Expand Down

0 comments on commit 5e5d657

Please sign in to comment.