Remove scale_factor from iced_wgpu::Viewport

This commit is contained in:
Héctor Ramón Jiménez 2020-02-09 03:36:59 +01:00
parent 8edb04fddd
commit 8f0b59a4b2
6 changed files with 12 additions and 15 deletions

View file

@ -38,7 +38,6 @@ pub trait Backend: Sized {
surface: &Self::Surface, surface: &Self::Surface,
width: u32, width: u32,
height: u32, height: u32,
scale_factor: f64,
) -> Self::SwapChain; ) -> Self::SwapChain;
/// Draws the output primitives to the next frame of the given [`SwapChain`]. /// Draws the output primitives to the next frame of the given [`SwapChain`].
@ -50,6 +49,7 @@ pub trait Backend: Sized {
renderer: &mut Self::Renderer, renderer: &mut Self::Renderer,
swap_chain: &mut Self::SwapChain, swap_chain: &mut Self::SwapChain,
output: &<Self::Renderer as crate::Renderer>::Output, output: &<Self::Renderer as crate::Renderer>::Output,
scale_factor: f64,
overlay: &[T], overlay: &[T],
) -> MouseCursor; ) -> MouseCursor;
} }

View file

@ -73,12 +73,13 @@ impl Renderer {
encoder: &mut wgpu::CommandEncoder, encoder: &mut wgpu::CommandEncoder,
target: Target<'_>, target: Target<'_>,
(primitive, mouse_cursor): &(Primitive, MouseCursor), (primitive, mouse_cursor): &(Primitive, MouseCursor),
scale_factor: f64,
overlay: &[T], overlay: &[T],
) -> MouseCursor { ) -> MouseCursor {
log::debug!("Drawing"); log::debug!("Drawing");
let (width, height) = target.viewport.dimensions(); let (width, height) = target.viewport.dimensions();
let scale_factor = target.viewport.scale_factor(); let scale_factor = scale_factor as f32;
let transformation = target.viewport.transformation(); let transformation = target.viewport.transformation();
let mut layers = Vec::new(); let mut layers = Vec::new();

View file

@ -1,31 +1,28 @@
use crate::Transformation; use crate::Transformation;
/// A viewing region for displaying computer graphics.
#[derive(Debug)] #[derive(Debug)]
pub struct Viewport { pub struct Viewport {
width: u32, width: u32,
height: u32, height: u32,
scale_factor: f32,
transformation: Transformation, transformation: Transformation,
} }
impl Viewport { impl Viewport {
pub fn new(width: u32, height: u32, scale_factor: f64) -> Viewport { /// Creates a new [`Viewport`] with the given dimensions.
pub fn new(width: u32, height: u32) -> Viewport {
Viewport { Viewport {
width, width,
height, height,
scale_factor: scale_factor as f32,
transformation: Transformation::orthographic(width, height), transformation: Transformation::orthographic(width, height),
} }
} }
/// Returns the dimensions of the [`Viewport`].
pub fn dimensions(&self) -> (u32, u32) { pub fn dimensions(&self) -> (u32, u32) {
(self.width, self.height) (self.width, self.height)
} }
pub fn scale_factor(&self) -> f32 {
self.scale_factor
}
pub(crate) fn transformation(&self) -> Transformation { pub(crate) fn transformation(&self) -> Transformation {
self.transformation self.transformation
} }

View file

@ -47,9 +47,8 @@ impl iced_native::window::Backend for Backend {
surface: &Self::Surface, surface: &Self::Surface,
width: u32, width: u32,
height: u32, height: u32,
scale_factor: f64,
) -> SwapChain { ) -> SwapChain {
SwapChain::new(&self.device, surface, width, height, scale_factor) SwapChain::new(&self.device, surface, width, height)
} }
fn draw<T: AsRef<str>>( fn draw<T: AsRef<str>>(
@ -57,6 +56,7 @@ impl iced_native::window::Backend for Backend {
renderer: &mut Self::Renderer, renderer: &mut Self::Renderer,
swap_chain: &mut SwapChain, swap_chain: &mut SwapChain,
output: &<Self::Renderer as iced_native::Renderer>::Output, output: &<Self::Renderer as iced_native::Renderer>::Output,
scale_factor: f64,
overlay: &[T], overlay: &[T],
) -> MouseCursor { ) -> MouseCursor {
let (frame, viewport) = swap_chain.next_frame(); let (frame, viewport) = swap_chain.next_frame();
@ -89,6 +89,7 @@ impl iced_native::window::Backend for Backend {
viewport, viewport,
}, },
output, output,
scale_factor,
overlay, overlay,
); );

View file

@ -17,11 +17,10 @@ impl SwapChain {
surface: &wgpu::Surface, surface: &wgpu::Surface,
width: u32, width: u32,
height: u32, height: u32,
scale_factor: f64,
) -> SwapChain { ) -> SwapChain {
SwapChain { SwapChain {
raw: new_swap_chain(surface, width, height, device), raw: new_swap_chain(surface, width, height, device),
viewport: Viewport::new(width, height, scale_factor), viewport: Viewport::new(width, height),
} }
} }

View file

@ -175,7 +175,6 @@ pub trait Application: Sized {
&surface, &surface,
physical_size.width, physical_size.width,
physical_size.height, physical_size.height,
size.scale_factor(),
) )
}; };
@ -313,7 +312,6 @@ pub trait Application: Sized {
&surface, &surface,
physical_size.width, physical_size.width,
physical_size.height, physical_size.height,
size.scale_factor(),
); );
resized = false; resized = false;
@ -323,6 +321,7 @@ pub trait Application: Sized {
&mut renderer, &mut renderer,
&mut swap_chain, &mut swap_chain,
&primitive, &primitive,
size.scale_factor(),
&debug.overlay(), &debug.overlay(),
); );