Skip to content

Commit 9643122

Browse files
committed
Use tracing crate for logging instead of println
1 parent bc590aa commit 9643122

File tree

6 files changed

+29
-27
lines changed

6 files changed

+29
-27
lines changed

desktop/src/app.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
6767
self.window = Some(window.clone());
6868
s.graphics_state = Some(graphics_state);
6969

70-
println!("Winit window created and ready");
70+
tracing::info!("Winit window created and ready");
7171
}
7272
})
7373
.unwrap();
@@ -91,7 +91,7 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
9191

9292
match event {
9393
WindowEvent::CloseRequested => {
94-
println!("The close button was pressed; stopping");
94+
tracing::info!("The close button was pressed; stopping");
9595
event_loop.exit();
9696
}
9797
WindowEvent::Resized(physical_size) => {
@@ -118,7 +118,7 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
118118
width: Some(width),
119119
height: Some(height),
120120
graphics_state: Some(graphics_state),
121-
ui_fb,
121+
ui_frame_buffer: ui_fb,
122122
..
123123
} = s
124124
{
@@ -139,7 +139,7 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
139139
Err(wgpu::SurfaceError::OutOfMemory) => {
140140
event_loop.exit();
141141
}
142-
Err(e) => eprintln!("{:?}", e),
142+
Err(e) => tracing::error!("{:?}", e),
143143
}
144144
}
145145
})
File renamed without changes.
File renamed without changes.
File renamed without changes.

desktop/src/main.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::process::exit;
33
use std::sync::{Arc, Mutex, MutexGuard, PoisonError};
44
use std::time::Instant;
55

6-
use winit::event_loop::{self, EventLoop, EventLoopProxy};
6+
use tracing_subscriber::EnvFilter;
7+
use winit::event_loop::{EventLoop, EventLoopProxy};
78

89
mod cef;
910
use cef::Setup;
@@ -20,11 +21,12 @@ pub(crate) enum CustomEvent {
2021
ScheduleBrowserWork(Instant),
2122
}
2223

24+
#[derive(Debug)]
2325
pub(crate) struct WindowState {
2426
width: Option<usize>,
2527
height: Option<usize>,
26-
ui_fb: Option<FrameBuffer>,
27-
preview_fb: Option<FrameBuffer>,
28+
ui_frame_buffer: Option<FrameBuffer>,
29+
_viewport_frame_buffer: Option<FrameBuffer>,
2830
graphics_state: Option<GraphicsState>,
2931
event_loop_proxy: Option<EventLoopProxy<CustomEvent>>,
3032
}
@@ -34,8 +36,8 @@ impl WindowState {
3436
Self {
3537
width: None,
3638
height: None,
37-
ui_fb: None,
38-
preview_fb: None,
39+
ui_frame_buffer: None,
40+
_viewport_frame_buffer: None,
3941
graphics_state: None,
4042
event_loop_proxy: None,
4143
}
@@ -46,18 +48,6 @@ impl WindowState {
4648
}
4749
}
4850

49-
impl Debug for WindowState {
50-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51-
f.debug_struct("WindowState")
52-
.field("width", &self.width.is_some())
53-
.field("height", &self.height.is_some())
54-
.field("ui_fb", &self.ui_fb.is_some())
55-
.field("preview_fb", &self.preview_fb.is_some())
56-
.field("graphics_state", &self.graphics_state.is_some())
57-
.finish()
58-
}
59-
}
60-
6151
pub(crate) struct WindowStateHandle {
6252
inner: Arc<Mutex<WindowState>>,
6353
}
@@ -126,7 +116,7 @@ impl cef::CefEventHandler for CefHandler {
126116
if frame_buffer.width() != s.width.unwrap_or(1) || frame_buffer.height() != s.height.unwrap_or(1) {
127117
correct_size = false;
128118
} else {
129-
s.ui_fb = Some(frame_buffer);
119+
s.ui_frame_buffer = Some(frame_buffer);
130120
}
131121
})
132122
.unwrap();
@@ -145,11 +135,13 @@ impl cef::CefEventHandler for CefHandler {
145135
}
146136

147137
fn main() {
138+
tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init();
139+
148140
let cef_context = match cef::Context::<Setup>::new() {
149141
Ok(c) => c,
150142
Err(cef::SetupError::Subprocess) => exit(0),
151143
Err(cef::SetupError::SubprocessFailed(t)) => {
152-
println!("Subprocess of type {t} failed");
144+
tracing::error!("Subprocess of type {t} failed");
153145
exit(1);
154146
}
155147
};
@@ -170,12 +162,12 @@ fn main() {
170162
let cef_context = match cef_context.init(CefHandler::new(window_state.clone())) {
171163
Ok(c) => c,
172164
Err(cef::InitError::InitializationFailed) => {
173-
println!("Cef initialization failed");
165+
tracing::error!("Cef initialization failed");
174166
exit(1);
175167
}
176168
};
177169

178-
println!("Cef initialized successfully");
170+
tracing::info!("Cef initialized successfully");
179171

180172
let mut winit_app = WinitApp::new(window_state, cef_context);
181173

desktop/src/render/mod.rs renamed to desktop/src/render.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ pub(crate) struct FrameBuffer {
88
width: usize,
99
height: usize,
1010
}
11+
impl std::fmt::Debug for FrameBuffer {
12+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13+
f.debug_struct("WindowState")
14+
.field("width", &self.width)
15+
.field("height", &self.height)
16+
.field("len", &self.buffer.len())
17+
.finish()
18+
}
19+
}
1120

1221
#[derive(Error, Debug)]
1322
pub(crate) enum FrameBufferError {
@@ -48,6 +57,7 @@ impl FrameBuffer {
4857
}
4958
}
5059

60+
#[derive(Debug)]
5161
pub(crate) struct GraphicsState {
5262
surface: wgpu::Surface<'static>,
5363
device: wgpu::Device,
@@ -109,7 +119,7 @@ impl GraphicsState {
109119
surface.configure(&device, &config);
110120

111121
// Create shader module
112-
let shader = device.create_shader_module(wgpu::include_wgsl!("fullscreen_texture.wgsl"));
122+
let shader = device.create_shader_module(wgpu::include_wgsl!("render/fullscreen_texture.wgsl"));
113123

114124
// Create sampler
115125
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
@@ -317,7 +327,7 @@ impl GraphicsState {
317327
render_pass.set_bind_group(0, bind_group, &[]);
318328
render_pass.draw(0..6, 0..1); // Draw 3 vertices for fullscreen triangle
319329
} else {
320-
println!("No bind group available - showing clear color only");
330+
tracing::warn!("No bind group available - showing clear color only");
321331
}
322332
}
323333
self.queue.submit(std::iter::once(encoder.finish()));

0 commit comments

Comments
 (0)