use uefi::proto::console::gop::{GraphicsOutput, Mode};

pub trait GraphicsOutputExt {
    fn match_mode(&self, width: u32, height: u32) -> Option<Mode>;
}

impl GraphicsOutputExt for GraphicsOutput {
    fn match_mode(&self, width: u32, height: u32) -> Option<Mode> {
        for mode in self.modes() {
            let mode_info = mode.info();
            let (mode_w, mode_h) = mode_info.resolution();

            if (mode_w as u32 == width) && (mode_h as u32 == height) {
                return Some(mode);
            }
        }

        None
    }
}
