no hard dep on winit window for renderers

This commit is contained in:
Alex Janka 2023-10-04 09:57:30 +11:00
parent 1f71402915
commit ae9c35ed9a
4 changed files with 37 additions and 17 deletions

View file

@ -1,7 +1,9 @@
use std::sync::Arc;
use pixels::{Pixels, SurfaceTexture};
use winit::window::Window;
use pixels::{
raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle},
Pixels, SurfaceTexture,
};
use super::ResolutionData;
@ -20,9 +22,9 @@ pub struct RendererBackend {
}
impl RendererBackend {
pub fn new(
pub fn new<W: HasRawDisplayHandle + HasRawWindowHandle>(
resolutions: ResolutionData,
window: &Window,
window: &W,
_: WindowOptions,
_: Arc<RendererBackendManager>,
) -> Self {
@ -31,7 +33,11 @@ impl RendererBackend {
}
}
pub fn resize(&mut self, resolutions: ResolutionData, window: &Window) {
pub fn resize<W: HasRawDisplayHandle + HasRawWindowHandle>(
&mut self,
resolutions: ResolutionData,
window: &W,
) {
self.pixels = new_pixels(resolutions, window);
}
@ -46,8 +52,11 @@ impl RendererBackend {
}
}
fn new_pixels(resolutions: ResolutionData, window: &Window) -> Pixels {
let surface_texture: SurfaceTexture<'_, Window> =
fn new_pixels<W: HasRawDisplayHandle + HasRawWindowHandle>(
resolutions: ResolutionData,
window: &W,
) -> Pixels {
let surface_texture: SurfaceTexture<'_, W> =
SurfaceTexture::new(resolutions.real_width, resolutions.real_height, window);
pixels::PixelsBuilder::new(
resolutions.scaled_width,

View file

@ -3,7 +3,6 @@ use ash::{
vk, Device,
};
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use winit::window::Window;
use crate::window::ResolutionData;
@ -217,7 +216,10 @@ pub(super) struct SurfaceData {
}
impl SurfaceData {
pub(super) unsafe fn new(window: &Window, manager: &RendererBackendManager) -> Self {
pub(super) unsafe fn new<W: HasRawDisplayHandle + HasRawWindowHandle>(
window: &W,
manager: &RendererBackendManager,
) -> Self {
let surface = ash_window::create_surface(
&manager.entry,
&manager.instance,

View file

@ -3,8 +3,7 @@ use std::{mem, path::PathBuf, sync::Arc};
use ash::{util::Align, vk, Entry, Instance};
use ash_window::enumerate_required_extensions;
use librashader::runtime::vk::{FilterChain, FilterChainOptions, FrameOptions, VulkanObjects};
use raw_window_handle::RawDisplayHandle;
use winit::window::Window;
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle};
use self::{
types::{FramebufferData, SurfaceData, SwapchainData, Vertex, VulkanData, SHADER_INPUT_FORMAT},
@ -88,9 +87,9 @@ pub struct WindowOptions {
}
impl RendererBackend {
pub fn new(
pub fn new<W: HasRawDisplayHandle + HasRawWindowHandle>(
resolutions: ResolutionData,
window: &Window,
window: &W,
options: WindowOptions,
manager: Arc<RendererBackendManager>,
) -> Self {
@ -121,7 +120,11 @@ impl RendererBackend {
}
}
pub fn resize(&mut self, resolutions: ResolutionData, _window: &Window) {
pub fn resize<W: HasRawDisplayHandle + HasRawWindowHandle>(
&mut self,
resolutions: ResolutionData,
_window: &W,
) {
unsafe { self.inner.resize(resolutions, self.manager.as_ref()) };
}
@ -152,9 +155,9 @@ struct VulkanWindowInner {
}
impl VulkanWindowInner {
unsafe fn new(
unsafe fn new<W: HasRawDisplayHandle + HasRawWindowHandle>(
resolutions: ResolutionData,
window: &Window,
window: &W,
manager: &RendererBackendManager,
) -> Self {
let surface = SurfaceData::new(window, manager);

View file

@ -12,7 +12,11 @@ use gb_emu_lib::{
};
use keyboard_types::{Code, KeyState};
use nih_plug::prelude::*;
use pixels::{wgpu::PowerPreference, Pixels, SurfaceTexture};
use pixels::{
raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle},
wgpu::PowerPreference,
Pixels, SurfaceTexture,
};
use crate::{Frame, FrameReceiver, JoypadInfo, JoypadSender};
@ -100,6 +104,8 @@ impl EmulatorWindow {
frame_receiver: Arc<FrameReceiver>,
joypad_sender: Arc<JoypadSender>,
) -> Self {
window.raw_window_handle();
window.raw_display_handle();
let info = WindowInfo::from_logical_size(
Size::new(WIDTH as f64, HEIGHT as f64),
EXTRA_SCALE as f64,