Browse Source

On second thought, it seems better to reuse traits

Rename to flush_buffers, and just have TopScreen3D's impl do both. This
still allows individual flushing of left and right if needed but most
people would probably just use `TopScreen3D::flush_buffers`.
pull/118/head
Ian Chamberlain 2 years ago
parent
commit
a417218182
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 2
      ctru-rs/examples/camera-image.rs
  2. 2
      ctru-rs/examples/graphics-bitmap.rs
  3. 32
      ctru-rs/src/services/gfx.rs

2
ctru-rs/examples/camera-image.rs

@ -88,7 +88,7 @@ fn main() {
rotate_image_to_screen(&buf, top_screen.raw_framebuffer().ptr, WIDTH, HEIGHT); rotate_image_to_screen(&buf, top_screen.raw_framebuffer().ptr, WIDTH, HEIGHT);
// We will only flush the "camera" screen, since the other screen is handled by `Console` // We will only flush the "camera" screen, since the other screen is handled by `Console`
top_screen.flush_buffer(); top_screen.flush_buffers();
top_screen.swap_buffers(); top_screen.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();

2
ctru-rs/examples/graphics-bitmap.rs

@ -48,7 +48,7 @@ fn main() {
} }
// Flush and swap framebuffers // Flush and swap framebuffers
bottom_screen.flush_buffer(); bottom_screen.flush_buffers();
bottom_screen.swap_buffers(); bottom_screen.swap_buffers();
//Wait for VBlank //Wait for VBlank

32
ctru-rs/src/services/gfx.rs

@ -112,18 +112,13 @@ impl Swap for BottomScreen {
} }
pub trait Flush: private::Sealed { pub trait Flush: private::Sealed {
/// Flushes the video buffer for this screen. /// Flushes the video buffer(s) for this screen. Note that you must still call
fn flush_buffer(&mut self); /// [`Swap::swap_buffers`] after this method for the buffer contents to be displayed.
fn flush_buffers(&mut self);
} }
trait FlushableScreen: Screen {} impl<S: Screen> Flush for S {
impl FlushableScreen for TopScreen {} fn flush_buffers(&mut self) {
impl FlushableScreen for BottomScreen {}
impl FlushableScreen for TopScreenLeft {}
impl FlushableScreen for TopScreenRight {}
impl<S: FlushableScreen> Flush for S {
fn flush_buffer(&mut self) {
let framebuffer = self.raw_framebuffer(); let framebuffer = self.raw_framebuffer();
// Flush the data array. `self.raw_framebuffer` should get the correct parameters for all kinds of screens // Flush the data array. `self.raw_framebuffer` should get the correct parameters for all kinds of screens
@ -136,6 +131,16 @@ impl<S: FlushableScreen> Flush for S {
} }
} }
impl Flush for TopScreen3D<'_> {
/// Unlike most other implementations of [`Flush`], this flushes the buffers for both
/// the left and right sides of the top screen.
fn flush_buffers(&mut self) {
let (mut left, mut right) = self.split_mut();
left.flush_buffers();
right.flush_buffers();
}
}
/// The left side of the top screen, when using 3D mode. /// The left side of the top screen, when using 3D mode.
#[derive(Debug)] #[derive(Debug)]
#[non_exhaustive] #[non_exhaustive]
@ -248,13 +253,6 @@ impl TopScreen3D<'_> {
(&mut screen.left as _, &mut screen.right as _) (&mut screen.left as _, &mut screen.right as _)
}) })
} }
/// Convenient helper to flush the buffers for both the left and right sides of the screen.
pub fn flush_buffers(&mut self) {
let (mut left, mut right) = self.split_mut();
left.flush_buffer();
right.flush_buffer();
}
} }
impl<'top_screen> From<&'top_screen RefCell<TopScreen>> for TopScreen3D<'top_screen> { impl<'top_screen> From<&'top_screen RefCell<TopScreen>> for TopScreen3D<'top_screen> {

Loading…
Cancel
Save