Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Avarel committed Jan 1, 2024
1 parent b1d18bd commit 2ed7cf4
Show file tree
Hide file tree
Showing 9 changed files with 433 additions and 1,007 deletions.
1,159 changes: 324 additions & 835 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "MIT"

[workspace]
members = [
"libs/egui_dock",
# "libs/egui_dock",
"libs/lz4_flex"
]

Expand All @@ -27,23 +27,23 @@ thiserror = "1.0"
regex = "1.6"
image = { version = "0.24", default-features = false, features = ["png", "jpeg", "tga", "tiff", "webp", "bmp"] }
once_cell = "1"
memmap2 = "0.7"
memmap2 = "0.9"
rayon = "1"
# GPU rendering
wgpu = "0.16"
wgpu = "0.18"
bytemuck = { version = "1.12", features = ["derive"] }
# Synchronization
parking_lot = "0.12"
# Display GUI
egui = "0.22"
egui-wgpu = "0.22"
egui-winit = { version = "0.22", default-features = false }
winit = "0.28"
egui_dock = "0.6"
egui = "0.24"
egui-wgpu = "0.24"
egui-winit = { version = "0.24", default-features = false }
# winit = "0.29"
egui_dock = "0.9"
# egui_dock = { path = "libs/egui_dock" }
egui-notify = "0.7"
egui-notify = "0.11"
# Async runtime
rfd = { version = "0.11", default-features = false, features = ["xdg-portal"] }
rfd = { version = "0.12", default-features = false, features = ["xdg-portal"] }
tokio = { version = "1.21", features = ["sync", "rt", "rt-multi-thread", "time"] }
futures = "0.3"

Expand Down
18 changes: 11 additions & 7 deletions src/compositor/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ pub struct GpuHandle {
}

impl GpuHandle {
const INSTANCE_OPTIONS: wgpu::InstanceDescriptor = wgpu::InstanceDescriptor {
backends: wgpu::Backends::PRIMARY,
dx12_shader_compiler: wgpu::Dx12Compiler::Fxc,
};
pub fn instance_descriptor() -> wgpu::InstanceDescriptor {
wgpu::InstanceDescriptor {
backends: wgpu::Backends::PRIMARY,
dx12_shader_compiler: wgpu::Dx12Compiler::Fxc,
flags: wgpu::InstanceFlags::default(),
gles_minor_version: wgpu::Gles3MinorVersion::Automatic,
}
}

const ADAPTER_OPTIONS: wgpu::RequestAdapterOptions<'static> = wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
Expand All @@ -26,14 +30,14 @@ impl GpuHandle {
#[allow(dead_code)]
/// Create a bare GPU handle with no surface target.
pub async fn new() -> Option<Self> {
let instance = wgpu::Instance::new(Self::INSTANCE_OPTIONS);
let instance = wgpu::Instance::new(Self::instance_descriptor());
let adapter = instance.request_adapter(&Self::ADAPTER_OPTIONS).await?;
Self::from_adapter(instance, adapter).await
}

/// Create a GPU handle with a surface target compatible with the window.
pub async fn with_window(window: &winit::window::Window) -> Option<(Self, wgpu::Surface)> {
let instance = wgpu::Instance::new(Self::INSTANCE_OPTIONS);
pub async fn with_window(window: &egui_winit::winit::window::Window) -> Option<(Self, wgpu::Surface)> {
let instance = wgpu::Instance::new(Self::instance_descriptor());
let surface = unsafe { instance.create_surface(window) }.ok()?;
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
Expand Down
6 changes: 4 additions & 2 deletions src/compositor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl<'dev> CompositorTarget<'dev> {
})
.unwrap_or(wgpu::Color::TRANSPARENT),
),
store: true,
store: wgpu::StoreOp::Store,
},
}),
// compositing pass
Expand All @@ -402,11 +402,13 @@ impl<'dev> CompositorTarget<'dev> {
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
store: wgpu::StoreOp::Store,
},
}),
],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});

// Finish and set the render pass's binding groups and data
Expand Down
4 changes: 3 additions & 1 deletion src/compositor/tex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ impl GpuTexture {
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(color),
store: true,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});

encoder.finish()
Expand Down
25 changes: 14 additions & 11 deletions src/gui/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ pub struct CanvasView {
data_aspect: Option<f32>,
show_background: bool,

image: Option<Image>,
image: Option<Image<'static>>,
image_rotation: f32,

show_grid: bool,
Expand Down Expand Up @@ -304,7 +304,7 @@ impl ViewMemory {

impl CanvasView {
/// Give a unique id for each plot within the same [`Ui`].
pub fn new(id_source: impl std::hash::Hash, image: Option<Image>) -> Self {
pub fn new(id_source: impl std::hash::Hash, image: Option<Image<'static>>) -> Self {
Self {
id_source: Id::new(id_source),
allow_zoom: true,
Expand Down Expand Up @@ -406,6 +406,8 @@ impl CanvasView {
rounding: Rounding::same(2.0),
fill: ui.visuals().extreme_bg_color,
stroke: ui.visuals().widgets.noninteractive.bg_stroke,
fill_texture_id: TextureId::default(),
uv: Rect::ZERO,
});
}

Expand All @@ -431,11 +433,12 @@ impl CanvasView {
bounds.set_y(&min_auto_bounds);
}

if let Some(image) = self.image {
if let Some(image) = image.as_ref() {
let image_size = image.size().unwrap();
let image_bounds = {
let mut bounds = CanvasViewBounds::NOTHING;
let left_top = Vec2::new(-image.size().x / 2.0, -image.size().y / 2.0);
let right_bottom = Vec2::new(image.size().x / 2.0, image.size().y / 2.0);
let left_top = Vec2::new(-image_size.x / 2.0, -image_size.y / 2.0);
let right_bottom = Vec2::new(image_size.x / 2.0, image_size.y / 2.0);
bounds.extend_with(&left_top);
bounds.extend_with(&right_bottom);
bounds
Expand Down Expand Up @@ -581,7 +584,7 @@ impl CanvasView {
}

struct PreparedView {
image: Option<Image>,
image: Option<Image<'static>>,
transform: ScreenTransform,
image_rotation: f32,
show_grid: bool,
Expand Down Expand Up @@ -622,15 +625,15 @@ impl PreparedView {
}

if let Some(image) = self.image {
let image_size = image.size().unwrap();
let rect = {
let size = image.size();
let left_top = Vec2::new(-size.x / 2.0, -size.y / 2.0);
let right_bottom = Vec2::new(size.x / 2.0, size.y / 2.0);
let left_top = Vec2::new(-image_size.x / 2.0, -image_size.y / 2.0);
let right_bottom = Vec2::new(image_size.x / 2.0, image_size.y / 2.0);
let left_top_tf = transform.position_from_point(&left_top);
let right_bottom_tf = transform.position_from_point(&right_bottom);
Rect::from_two_pos(left_top_tf, right_bottom_tf)
};
let image_screen_center = ((rect.max - rect.min) / 2.0) / image.size();
let image_screen_center = ((rect.max - rect.min) / 2.0) / image_size;

let painter = plot_ui.painter();
painter.add(Shape::mesh({
Expand All @@ -653,7 +656,7 @@ impl PreparedView {
}
mesh.rotate(
emath::Rot2::from_angle(self.image_rotation),
rect.min + image_screen_center * image.size(),
rect.min + image_screen_center * image_size,
);
mesh
}));
Expand Down
42 changes: 28 additions & 14 deletions src/gui/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use crate::{
compositor::CompositorPipeline,
silica::{BlendingMode, SilicaHierarchy},
};
use egui::load::SizedTexture;
use egui::*;
use egui_dock::NodeIndex;
use egui_dock::{NodeIndex, SurfaceIndex};
use parking_lot::{Mutex, RwLock};
use std::collections::HashMap;
use std::sync::atomic::Ordering::{Acquire, Release};
Expand All @@ -19,8 +20,8 @@ pub struct SharedData {
pub dev: &'static GpuHandle,
pub compositor: &'static CompositorHandle,
pub toasts: &'static Mutex<egui_notify::Toasts>,
pub added_instances: &'static Mutex<Vec<(NodeIndex, InstanceKey)>>,
pub eloop: winit::event_loop::EventLoopProxy<super::UserEvent>,
pub added_instances: &'static Mutex<Vec<(SurfaceIndex, NodeIndex, InstanceKey)>>,
pub eloop: egui_winit::winit::event_loop::EventLoopProxy<super::UserEvent>,
}

#[derive(Hash, Clone, Copy, PartialEq, Eq, Default, Debug)]
Expand Down Expand Up @@ -55,7 +56,7 @@ pub struct CompositorHandle {
pub pipeline: CompositorPipeline,
}

async fn load_dialog(shared: SharedData, node_index: NodeIndex) {
async fn load_dialog(shared: SharedData, surface_index: SurfaceIndex, node_index: NodeIndex) {
if let Some(handle) = {
let mut dialog = rfd::AsyncFileDialog::new();
dialog = dialog.add_filter("All Files", &["*"]);
Expand All @@ -78,7 +79,10 @@ async fn load_dialog(shared: SharedData, node_index: NodeIndex) {
.toasts
.lock()
.success(format!("File {} successfully opened.", handle.file_name()));
shared.added_instances.lock().push((node_index, key));
shared
.added_instances
.lock()
.push((surface_index, node_index, key));
}
}
} else {
Expand Down Expand Up @@ -385,7 +389,12 @@ impl egui_dock::TabViewer for CanvasGui<'_> {
let tex = self.canvases.get(tab);
canvas::CanvasView::new(
*tab,
tex.map(|(tex, size)| Image::new(*tex, (size.width as f32, size.height as f32))),
tex.map(|(tex, size)| {
Image::from_texture(SizedTexture::new(
*tex,
(size.width as f32, size.height as f32),
))
}),
)
.with_rotation(self.view_options.rotation)
.show_extended_crosshair(self.view_options.extended_crosshair)
Expand All @@ -402,8 +411,9 @@ impl egui_dock::TabViewer for CanvasGui<'_> {
true
}

fn on_add(&mut self, node: egui_dock::NodeIndex) {
self.rt.spawn(load_dialog(self.shared.clone(), node));
fn on_add(&mut self, surface: egui_dock::SurfaceIndex, node: egui_dock::NodeIndex) {
self.rt
.spawn(load_dialog(self.shared.clone(), surface, node));
}

fn title(&mut self, tab: &mut Self::Tab) -> WidgetText {
Expand All @@ -422,8 +432,8 @@ pub struct ViewerGui {
pub canvases: HashMap<InstanceKey, (TextureId, BufferDimensions)>,
pub selected_canvas: InstanceKey,
pub view_options: ViewOptions,
pub canvas_tree: egui_dock::Tree<InstanceKey>,
pub viewer_tree: egui_dock::Tree<ViewerTab>,
pub canvas_tree: egui_dock::DockState<InstanceKey>,
pub viewer_tree: egui_dock::DockState<ViewerTab>,
}

impl ViewerGui {
Expand All @@ -445,14 +455,18 @@ impl ViewerGui {
ui.vertical_centered(|ui| {
ui.label("Drag and drop Procreate file to view it.");
if ui.button("Load Procreate File").clicked() {
self.rt
.spawn(load_dialog(self.shared.clone(), NodeIndex::root()));
self.rt.spawn(load_dialog(
self.shared.clone(),
SurfaceIndex::main(),
NodeIndex::root(),
));
}
});
} else {
if let Some(mut added_instances) = self.shared.added_instances.try_lock() {
for (node, id) in added_instances.drain(..) {
self.canvas_tree.set_focused_node(node);
for (surface, node, id) in added_instances.drain(..) {
self.canvas_tree
.set_focused_node_and_surface((surface, node));
self.canvas_tree.push_to_focused_leaf(id);
}
}
Expand Down
Loading

0 comments on commit 2ed7cf4

Please sign in to comment.