#![feature(test)] use himpp::{ hifb, mpi::hdmi::{HdmiCore, HdmiId, HdmiPort, HdmiPortBuilder}, mpi::sys::SysManager, mpi::types::{DynamicRange, PixelFormat, Rect, Size, VideoInterface, VideoStandard, WdrMode}, mpi::vb::{VbConfigBuilder, VbManager, VbRemapMode}, mpi::vo::{VoChn, VoChnAttrBuilder, VoDev, VoLayer, VoPubAttrBuilder, VoVideoLayerAttrBuilder}, }; use pavo_traits::{AlignUpwards, InnerRefer}; use std::cell::{Cell, RefCell}; use std::fs::File; use std::io::prelude::*; use std::sync::{Arc, Mutex}; extern crate test; use test::Bencher; struct State { fb: Option, hdmi_port: Option, vo_dev: Option, sys_mgr: Option, } impl Drop for State { fn drop(&mut self) {} } impl State { fn new() -> Self { let fps: u32 = 60; let vo_size = Size::new(1920, 1080); let vb_pool1 = (vo_size.width * vo_size.height * 4).align_upwards(64); let vb_pool2 = (vo_size.width * vo_size.height * 3).align_upwards(64); let vb_pool3 = (vo_size.width * vo_size.height * 2).align_upwards(64); let vb_pool4 = (vo_size.width * vo_size.height * 3 / 2).align_upwards(64); let vb_conf = VbConfigBuilder::new() .pool(vb_pool1.into(), 4, VbRemapMode::None, "") .pool(vb_pool2.into(), 4, VbRemapMode::None, "") .pool(vb_pool3.into(), 4, VbRemapMode::None, "") .pool(vb_pool3.into(), 4, VbRemapMode::None, "") .build(); let vb_mgr = VbManager::new(&vb_conf); let sys_mgr = SysManager::with_align(64, Some(vb_mgr)); let vo_attr = VoPubAttrBuilder::new() .with_bg_color(0x0000ffff) .with_video_interface(VideoInterface::Hdmi) .with_video_standard(VideoStandard::Hd1080p60) .build(); let vo_dev = VoDev::new(0, &vo_attr); let hdmi_core = Arc::new(HdmiCore::new()); let hdmi_port = HdmiPortBuilder::with_dvi_1080p60(HdmiId::Hdmi0, Arc::clone(&hdmi_core)).build(); hdmi_port.start().unwrap(); let mut fb = hifb::FrameBuffer::new("/dev/fb0").unwrap(); fb.set_pixel_format(hifb::PixelFormat::Argb8888).unwrap(); fb.set_resolution(vo_size.width, vo_size.height).unwrap(); fb.set_num_buffers(2).unwrap(); fb.show().unwrap(); Self { sys_mgr: Some(sys_mgr), vo_dev: Some(vo_dev), hdmi_port: Some(hdmi_port), fb: Some(fb), } } } #[bench] fn bench_visible(b: &mut Bencher) { let mut state = State::new(); if let Some(ref mut fb) = state.fb { b.iter(|| { fb.hide().unwrap(); fb.show().unwrap(); }); } } #[bench] fn bench_pan(b: &mut Bencher) { let mut state = State::new(); if let Some(ref mut fb) = state.fb { b.iter(|| { fb.pan().unwrap(); }); } } #[bench] fn bench_resolution(b: &mut Bencher) { let state = State::new(); if let Some(ref fb) = state.fb { b.iter(|| { let (w, h) = fb.resolution(); }); } } #[bench] fn bench_set_resolution(b: &mut Bencher) { let mut state = State::new(); let mut idx = 0; let list = &[(1280, 720), (1920, 1080)]; if let Some(ref mut fb) = state.fb { b.iter(|| { let (w, h) = list[idx]; fb.set_resolution(w, h).unwrap(); idx = (idx + 1) % list.len(); }); } } #[bench] fn bench_memory_phy(b: &mut Bencher) { let state = State::new(); if let Some(ref fb) = state.fb { b.iter(|| { let (p, l) = fb.memory_phy(); }); } } #[bench] fn bench_memory_phy_paned(b: &mut Bencher) { let state = State::new(); if let Some(ref fb) = state.fb { b.iter(|| { let (p, l) = fb.memory_phy_paned(); }); } }