Skip to content

Commit

Permalink
Add a render thread
Browse files Browse the repository at this point in the history
The default event loop on winit, at least on Windows is too slow. See
rust-windowing/winit#2782
  • Loading branch information
fredizzimo committed Jun 27, 2023
1 parent 33a863d commit 29445d1
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 136 deletions.
3 changes: 2 additions & 1 deletion src/renderer/cursor_renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
renderer::animation_utils::*,
renderer::{GridRenderer, RenderedWindow},
settings::{ParseFromValue, SETTINGS},
window::UserEvent,
};

use blink::*;
Expand Down Expand Up @@ -198,7 +199,7 @@ impl CursorRenderer {
renderer
}

pub fn handle_event(&mut self, event: &Event<()>) {
pub fn handle_event(&mut self, event: &Event<UserEvent>) {
if let Event::WindowEvent {
event: WindowEvent::Focused(is_focused),
..
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
event_aggregator::EVENT_AGGREGATOR,
profiling::tracy_zone,
settings::*,
window::UserEvent,
WindowSettings,
};

Expand All @@ -34,7 +35,7 @@ pub use rendered_window::{
LineFragment, RenderedWindow, WindowDrawCommand, WindowDrawDetails, WindowPadding,
};

pub use opengl::{build_context, Context as WindowedContext};
pub use opengl::{build_context, build_window, Context as WindowedContext};
pub use vsync::*;

#[derive(SettingGroup, Clone)]
Expand Down Expand Up @@ -134,7 +135,7 @@ impl Renderer {
}
}

pub fn handle_event(&mut self, event: &Event<()>) {
pub fn handle_event(&mut self, event: &Event<UserEvent>) {
self.cursor_renderer.handle_event(event);
}

Expand Down
13 changes: 9 additions & 4 deletions src/renderer/opengl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,25 @@ fn gen_config(mut config_iterator: Box<dyn Iterator<Item = Config> + '_>) -> Con
config_iterator.next().unwrap()
}

pub fn build_context<TE>(
cmd_line_settings: &CmdLineSettings,
pub fn build_window<TE>(
winit_window_builder: WindowBuilder,
event_loop: &EventLoop<TE>,
) -> Context {
) -> (Window, Config) {
let template_builder = ConfigTemplateBuilder::new()
.with_stencil_size(8)
.with_transparency(true);
let (window, config) = DisplayBuilder::new()
.with_window_builder(Some(winit_window_builder))
.build(event_loop, template_builder, gen_config)
.expect("Failed to create Window");
let window = window.expect("Could not create Window");
(window.expect("Could not create Window"), config)
}

pub fn build_context(
window: Window,
config: Config,
cmd_line_settings: &CmdLineSettings,
) -> Context {
let gl_display = config.display();
let raw_window_handle = window.raw_window_handle();

Expand Down
4 changes: 2 additions & 2 deletions src/window/keyboard_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
bridge::{SerialCommand, UiCommand},
event_aggregator::EVENT_AGGREGATOR,
settings::SETTINGS,
window::KeyboardSettings,
window::{KeyboardSettings, UserEvent},
};
use winit::{
event::{ElementState, Event, Ime, KeyEvent, WindowEvent},
Expand Down Expand Up @@ -37,7 +37,7 @@ impl KeyboardManager {
}
}

pub fn handle_event(&mut self, event: &Event<()>) {
pub fn handle_event(&mut self, event: &Event<UserEvent>) {
match event {
Event::WindowEvent {
event: WindowEvent::Focused(_focused),
Expand Down
Loading

0 comments on commit 29445d1

Please sign in to comment.