Skip to content

Commit

Permalink
glium: Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dcz-self committed Oct 9, 2024
1 parent 9dd6f45 commit d50a57a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ v4l-sys = { path = "v4l-sys", version = "0.3.0", optional = true }
v4l2-sys = { path = "v4l2-sys", version = "0.3.0", package="v4l2-sys-mit", optional = true }

[dev-dependencies]
glium = "0.34"
glium = "0.35"
jpeg-decoder = "0.3.0"
winit = "0.29"
winit = "0.30"

[features]
default = ["v4l2"]
Expand Down
47 changes: 34 additions & 13 deletions examples/glium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ use v4l::video::capture::Parameters;
use v4l::video::Capture;
use v4l::{Format, FourCC};

use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event_loop::ActiveEventLoop;
use winit::window::WindowId;

#[derive(Debug, Clone, Copy)]
enum UserEvent {
WakeUp,
Expand Down Expand Up @@ -155,9 +160,33 @@ fn main() -> io::Result<()> {
tx.send(data).unwrap();
}
});

struct LoopHandler<F> {
user_event: F,
}

impl<F: Fn(UserEvent)> ApplicationHandler<UserEvent> for LoopHandler<F> {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {}

fn window_event(
&mut self,
event_loop: &ActiveEventLoop,
window_id: WindowId,
event: WindowEvent,
) {
// polling and handling the events received by the window
if let winit::event::WindowEvent::CloseRequested = event {
event_loop.exit();
}
}

fn user_event(&mut self, event_loop: &ActiveEventLoop, event: UserEvent) {
(self.user_event)(event)
}
}

event_loop
.run(move |event, elwt| {
event_loop.run_app(&mut LoopHandler {
user_event: move |_event| {
let t0 = Instant::now();
let data = rx.recv().unwrap();
let t1 = Instant::now();
Expand Down Expand Up @@ -194,20 +223,12 @@ fn main() -> io::Result<()> {
.unwrap();
target.finish().unwrap();

// polling and handling the events received by the window
if let winit::event::Event::WindowEvent {
event: winit::event::WindowEvent::CloseRequested,
..
} = event
{
elwt.exit();
}

println!(
"ms: {}\t (buffer) + {}\t (UI)",
t1.duration_since(t0).as_millis(),
t1.elapsed().as_millis()
);
})
.map_err(io::Error::other)
}
})
.map_err(io::Error::other)
}

0 comments on commit d50a57a

Please sign in to comment.