#![feature(test)] use himpp::{ hifb, hitde::{TdeColorFmt, TdeDev, TdeJob, TdePatternFillOpt, TdeSurfaceLoader}, 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 poller::{EventContext, Events, Poller}; use std::cell::{Cell, RefCell}; use std::fs::File; use std::io::prelude::*; use std::sync::{Arc, Mutex}; #[macro_use] 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_quick_copy(b: &mut Bencher) { let tde = TdeDev::new(); let src_surf = TdeSurfaceLoader::from_bytes( include_bytes!("../examples/data/images/dog_bike_car.jpg"), None, ) .unwrap(); let dst_surf = TdeSurfaceLoader::new(src_surf.size(), src_surf.color_fmt()).unwrap(); let src_rect = Rect::with_size(src_surf.size()); let dst_rect = Rect::with_size(dst_surf.size()); b.iter(|| { let job = TdeJob::new(&tde).unwrap(); job.quick_copy(&src_surf, &src_rect, &dst_surf, &dst_rect) .unwrap(); }); } #[bench] fn bench_quick_copy_pan_display(b: &mut Bencher) { let mut state = State::new(); if let Some(ref mut fb) = state.fb { let vo_size: Size = fb.resolution().into(); let tde = TdeDev::new(); let pic_surf = TdeSurfaceLoader::from_bytes( include_bytes!("../examples/data/images/dog_bike_car.jpg"), Some(TdeColorFmt::Argb8888), ) .unwrap(); let pic_rect = Rect::with_size(pic_surf.inner().size()); let fb_rect = Rect::with_size(vo_size); b.iter(|| { let fb_surf = TdeSurfaceLoader::from_hifb(&fb).unwrap(); let job = TdeJob::new(&tde).unwrap(); job.quick_copy(&pic_surf, &pic_rect, &fb_surf, &fb_rect) .unwrap(); fb.pan().unwrap(); }); } }