fix dupe frames

This commit is contained in:
lifning 2021-12-11 01:55:08 -08:00
parent 709a23307a
commit 72366248d7
1 changed files with 10 additions and 10 deletions

View File

@ -11,7 +11,6 @@ use sdl2::video::FullscreenType;
pub(crate) fn paint_frame_on_canvas(frame: &VideoFrame, canvas: &mut WindowCanvas) -> bool {
if let Ok(surf) = frame_to_surface(frame) {
let (cw, ch) = canvas.output_size().unwrap();
let should_intscale = if cw >= surf.width() && ch >= surf.height() {
sdl2::sys::SDL_bool::SDL_TRUE
} else {
@ -20,15 +19,16 @@ pub(crate) fn paint_frame_on_canvas(frame: &VideoFrame, canvas: &mut WindowCanva
unsafe {
sdl2::sys::SDL_RenderSetIntegerScale(canvas.raw(), should_intscale);
}
if surf.pixel_format_enum() != PixelFormatEnum::Unknown {
let format = sdl2::pixels::PixelFormat::try_from(canvas.default_pixel_format()).unwrap();
let surface = surf.convert(&format).unwrap();
let format = sdl2::pixels::PixelFormat::try_from(canvas.default_pixel_format()).unwrap();
let surface = surf.convert(&format).unwrap();
if let Ok(tex) = canvas
.texture_creator()
.create_texture_from_surface(surface)
{
canvas.copy(&tex, None, None).unwrap();
if let Ok(tex) = canvas
.texture_creator()
.create_texture_from_surface(surface)
{
canvas.copy(&tex, None, None).unwrap();
}
}
canvas.present();
true
@ -63,7 +63,7 @@ pub(crate) fn frame_to_surface<'a>(frame: &'a VideoFrame) -> crate::base::Result
let pixel_format = frame
.pixel_format()
.map(sdl2_pixfmt)
.unwrap_or(PixelFormatEnum::ARGB8888);
.unwrap_or(PixelFormatEnum::Unknown);
sdl2::surface::Surface::new(width, height, pixel_format)
.map_err(Into::into)
}