diff options
Diffstat (limited to 'glutin/src/application.rs')
-rw-r--r-- | glutin/src/application.rs | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 45ff37f0..f43a47b9 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -245,18 +245,7 @@ where ) })?; - let (width, height) = window.inner_size().into(); - let surface_attributes = - SurfaceAttributesBuilder::<WindowSurface>::new() - .with_srgb(Some(true)) - .build( - window_handle, - NonZeroU32::new(width).unwrap_or(ONE), - NonZeroU32::new(height).unwrap_or(ONE), - ); - - let surface = display - .create_window_surface(configuration.as_ref(), &surface_attributes) + let surface = gl_surface(&display, configuration.as_ref(), &window) .map_err(|error| { Error::GraphicsCreationFailed( iced_graphics::Error::BackendError(format!( @@ -616,3 +605,23 @@ async fn run_instance<A, E, C>( // Manually drop the user interface drop(ManuallyDrop::into_inner(user_interface)); } + +#[allow(unsafe_code)] +/// Creates a new [`glutin::Surface<WindowSurface>`]. +pub fn gl_surface( + display: &Display, + gl_config: &Config, + window: &winit::window::Window, +) -> Result<Surface<WindowSurface>, glutin::error::Error> { + let (width, height) = window.inner_size().into(); + + let surface_attributes = SurfaceAttributesBuilder::<WindowSurface>::new() + .with_srgb(Some(true)) + .build( + window.raw_window_handle(), + NonZeroU32::new(width).unwrap_or(ONE), + NonZeroU32::new(height).unwrap_or(ONE), + ); + + unsafe { display.create_window_surface(gl_config, &surface_attributes) } +} |