Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(deps): Use winit 0.28.6 (Wayland support) + new keyboard API and …
…glutin 0.30.7 (#1789) The exact version of winit is f7a400ddf6a7822a1ac0cf80ca805dcf3298872e and includes the big keyboard API refactoring, a very big effort by the winit team - rust-windowing/winit#2662. Additionally the actual Winit version is several versions newer than the previous one (0.24.0), so a lot of other things have also been fixed. The biggest impact fix for Neovide is working Wayland support #1356 The winit update also fixes unhanded key up events #1631 There are probably also a lot of still unconfirmed fixes, and maybe also some new regression as with all big updates. --------- Co-authored-by: Fred Sundvik <fsundvik@gmail.com> Co-authored-by: rkuklik <90713105+rkuklik@users.noreply.github.com> Co-authored-by: MultisampledNight <contact@multisamplednight.com> Co-authored-by: Serhii Tereshchenko <serg.partizan@gmail.com>
- Loading branch information
1 parent
b2d66d2
commit f412399
Showing
8 changed files
with
723 additions
and
694 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,113 @@ | ||
use std::ffi::{c_void, CStr}; | ||
use std::num::NonZeroU32; | ||
|
||
use crate::cmd_line::CmdLineSettings; | ||
|
||
use glutin::{ContextBuilder, GlProfile, PossiblyCurrent, WindowedContext}; | ||
use gl::MAX_RENDERBUFFER_SIZE; | ||
use glutin::surface::SwapInterval; | ||
use glutin::{ | ||
config::{Config, ConfigTemplateBuilder}, | ||
context::{ContextAttributesBuilder, GlProfile, PossiblyCurrentContext}, | ||
display::GetGlDisplay, | ||
prelude::*, | ||
surface::{Surface, SurfaceAttributesBuilder, WindowSurface}, | ||
}; | ||
use glutin_winit::DisplayBuilder; | ||
use raw_window_handle::HasRawWindowHandle; | ||
use winit::dpi::PhysicalSize; | ||
use winit::{ | ||
event_loop::EventLoop, | ||
window::{Window, WindowBuilder}, | ||
}; | ||
|
||
pub struct Context { | ||
surface: Surface<WindowSurface>, | ||
context: PossiblyCurrentContext, | ||
window: Window, | ||
config: Config, | ||
} | ||
|
||
use winit::{event_loop::EventLoop, window::WindowBuilder}; | ||
pub fn clamp_render_buffer_size(size: PhysicalSize<u32>) -> PhysicalSize<u32> { | ||
PhysicalSize::new( | ||
size.width.clamp(1, MAX_RENDERBUFFER_SIZE), | ||
size.height.clamp(1, MAX_RENDERBUFFER_SIZE), | ||
) | ||
} | ||
|
||
impl Context { | ||
pub fn window(&self) -> &Window { | ||
&self.window | ||
} | ||
pub fn resize(&self, width: NonZeroU32, height: NonZeroU32) { | ||
GlSurface::resize(&self.surface, &self.context, width, height) | ||
} | ||
pub fn swap_buffers(&self) -> glutin::error::Result<()> { | ||
GlSurface::swap_buffers(&self.surface, &self.context) | ||
} | ||
pub fn get_proc_address(&self, addr: &CStr) -> *const c_void { | ||
GlDisplay::get_proc_address(&self.surface.display(), addr) | ||
} | ||
pub fn get_config(&self) -> &Config { | ||
&self.config | ||
} | ||
|
||
pub fn get_render_target_size(&self) -> PhysicalSize<u32> { | ||
clamp_render_buffer_size(self.window.inner_size()) | ||
} | ||
} | ||
|
||
pub type Context = WindowedContext<glutin::PossiblyCurrent>; | ||
fn gen_config(mut config_iterator: Box<dyn Iterator<Item = Config> + '_>) -> Config { | ||
config_iterator.next().unwrap() | ||
} | ||
|
||
pub fn build_context<TE>( | ||
cmd_line_settings: &CmdLineSettings, | ||
winit_window_builder: WindowBuilder, | ||
event_loop: &EventLoop<TE>, | ||
) -> WindowedContext<PossiblyCurrent> { | ||
let builder = ContextBuilder::new() | ||
.with_pixel_format(24, 8) | ||
.with_stencil_buffer(8) | ||
.with_gl_profile(GlProfile::Core) | ||
.with_srgb(cmd_line_settings.srgb) | ||
.with_vsync(cmd_line_settings.vsync); | ||
|
||
let ctx = match builder | ||
.clone() | ||
.build_windowed(winit_window_builder.clone(), event_loop) | ||
{ | ||
Ok(ctx) => ctx, | ||
Err(err) => { | ||
// haven't found any sane way to actually match on the pattern rabbithole CreationError | ||
// provides, so here goes nothing | ||
if err.to_string().contains("vsync") { | ||
builder | ||
.with_vsync(false) | ||
.build_windowed(winit_window_builder, event_loop) | ||
.unwrap() | ||
} else { | ||
panic!("{}", err); | ||
} | ||
} | ||
) -> Context { | ||
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"); | ||
|
||
let gl_display = config.display(); | ||
let raw_window_handle = window.raw_window_handle(); | ||
|
||
let size = clamp_render_buffer_size(window.inner_size()); | ||
|
||
let surface_attributes = SurfaceAttributesBuilder::<WindowSurface>::new() | ||
.with_srgb(Some(cmd_line_settings.srgb)) | ||
.build( | ||
raw_window_handle, | ||
NonZeroU32::new(size.width).unwrap(), | ||
NonZeroU32::new(size.height).unwrap(), | ||
); | ||
let surface = unsafe { gl_display.create_window_surface(&config, &surface_attributes) } | ||
.expect("Failed to create Windows Surface"); | ||
|
||
let context_attributes = ContextAttributesBuilder::new() | ||
.with_profile(GlProfile::Core) | ||
.build(Some(raw_window_handle)); | ||
let context = unsafe { gl_display.create_context(&config, &context_attributes) } | ||
.expect("Failed to create OpenGL context") | ||
.make_current(&surface) | ||
.unwrap(); | ||
|
||
// NOTE: We don't care if these fails, the driver can override the SwapInterval in any case, so it needs to work in all cases | ||
let _ = if cmd_line_settings.vsync { | ||
surface.set_swap_interval(&context, SwapInterval::Wait(NonZeroU32::new(1).unwrap())) | ||
} else { | ||
surface.set_swap_interval(&context, SwapInterval::DontWait) | ||
}; | ||
unsafe { ctx.make_current().unwrap() } | ||
|
||
Context { | ||
surface, | ||
context, | ||
window, | ||
config, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
f412399
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀🎉