From 73aac708f14325ac6f267f4bcefb9fe2b25de9d4 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Sun, 19 Nov 2023 19:11:42 +0100 Subject: [PATCH] Fix gfx nits --- ctru-rs/src/services/gfx.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/ctru-rs/src/services/gfx.rs b/ctru-rs/src/services/gfx.rs index 8c8764a..6eb04f6 100644 --- a/ctru-rs/src/services/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -321,21 +321,7 @@ impl Gfx { top_fb_fmt: FramebufferFormat, bottom_fb_fmt: FramebufferFormat, ) -> Result { - let handler = ServiceReference::new( - &GFX_ACTIVE, - || unsafe { - ctru_sys::gfxInit(top_fb_fmt.into(), bottom_fb_fmt.into(), false); - - Ok(()) - }, - || unsafe { ctru_sys::gfxExit() }, - )?; - - Ok(Self { - top_screen: RefCell::new(TopScreen::new()), - bottom_screen: RefCell::new(BottomScreen), - _service_handler: handler, - }) + Self::with_configuration(top_fb_fmt, bottom_fb_fmt, false) } /// Initialize a new service handle with the chosen framebuffer formats on the VRAM for the top and bottom screens. @@ -371,11 +357,20 @@ impl Gfx { pub unsafe fn with_formats_vram( top_fb_fmt: FramebufferFormat, bottom_fb_fmt: FramebufferFormat, + ) -> Result { + Self::with_configuration(top_fb_fmt, bottom_fb_fmt, true) + } + + // Internal function to handle the initialization of `Gfx`. + fn with_configuration( + top_fb_fmt: FramebufferFormat, + bottom_fb_fmt: FramebufferFormat, + vram_buffer: bool, ) -> Result { let handler = ServiceReference::new( &GFX_ACTIVE, || unsafe { - ctru_sys::gfxInit(top_fb_fmt.into(), bottom_fb_fmt.into(), true); + ctru_sys::gfxInit(top_fb_fmt.into(), bottom_fb_fmt.into(), vram_buffer); Ok(()) },