mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-25 18:23:22 +00:00
修复内核的clippy检查报错 (#637)
修复内核的clippy检查报错 --------- Co-authored-by: Samuel Dai <947309196@qq.com> Co-authored-by: Donkey Kane <109840258+xiaolin2004@users.noreply.github.com> Co-authored-by: themildwind <107623059+themildwind@users.noreply.github.com> Co-authored-by: GnoCiYeH <heyicong@dragonos.org> Co-authored-by: MemoryShore <105195940+MemoryShore@users.noreply.github.com> Co-authored-by: 曾俊 <110876916+ZZJJWarth@users.noreply.github.com> Co-authored-by: sun5etop <146408999+sun5etop@users.noreply.github.com> Co-authored-by: hmt <114841534+1037827920@users.noreply.github.com> Co-authored-by: laokengwt <143977175+laokengwt@users.noreply.github.com> Co-authored-by: TTaq <103996388+TTaq@users.noreply.github.com> Co-authored-by: Jomo <2512364506@qq.com> Co-authored-by: Samuel Dai <samuka007@qq.com> Co-authored-by: sspphh <112558065+sspphh@users.noreply.github.com>
This commit is contained in:
@ -81,10 +81,10 @@ impl BlittingFbConsole {
|
||||
其中颜色0映射为黑色,颜色1到6映射为白色,
|
||||
颜色7到8映射为灰色,其他颜色映射为强烈的白色。
|
||||
*/
|
||||
if color >= 1 && color <= 6 {
|
||||
if (1..=6).contains(&color) {
|
||||
// 白色
|
||||
color = 2;
|
||||
} else if color >= 7 && color <= 8 {
|
||||
} else if (7..=8).contains(&color) {
|
||||
// 灰色
|
||||
color = 1;
|
||||
} else {
|
||||
@ -138,17 +138,16 @@ impl BlittingFbConsole {
|
||||
let byte_width = vc_data.font.width as usize / 8;
|
||||
let font_height = vc_data.font.height as usize;
|
||||
// let mut char_offset = 0;
|
||||
for char_offset in 0..cnt as usize {
|
||||
for (char_offset, char_item) in buf.iter().enumerate().take(cnt as usize) {
|
||||
// 在字符表中的index
|
||||
let ch = buf[char_offset] & charmask;
|
||||
let ch = char_item & charmask;
|
||||
// 计算出在font表中的偏移量
|
||||
let font_offset = ch as usize * cellsize as usize;
|
||||
let font_offset_end = font_offset + cellsize as usize;
|
||||
// 设置image的data
|
||||
|
||||
let src = &vc_data.font.data[font_offset..font_offset_end];
|
||||
let mut dst = Vec::new();
|
||||
dst.resize(src.len(), 0);
|
||||
let mut dst = vec![0; src.len()];
|
||||
dst.copy_from_slice(src);
|
||||
|
||||
if !attr.is_empty() {
|
||||
@ -255,18 +254,18 @@ impl ConsoleSwitch for BlittingFbConsole {
|
||||
}
|
||||
|
||||
let y_break = (fb_data.display.virt_rows - fb_data.display.yscroll) as usize;
|
||||
if sy < y_break && sy + height - 1 >= y_break {
|
||||
if sy < y_break && sy + height > y_break {
|
||||
// 分两次clear
|
||||
let b = y_break - sy;
|
||||
let _ = self.clear(
|
||||
&vc_data,
|
||||
vc_data,
|
||||
fb_data.display.real_y(sy as u32),
|
||||
sx as u32,
|
||||
b as u32,
|
||||
width as u32,
|
||||
);
|
||||
let _ = self.clear(
|
||||
&vc_data,
|
||||
vc_data,
|
||||
fb_data.display.real_y((sy + b) as u32),
|
||||
sx as u32,
|
||||
(height - b) as u32,
|
||||
@ -274,7 +273,7 @@ impl ConsoleSwitch for BlittingFbConsole {
|
||||
);
|
||||
} else {
|
||||
let _ = self.clear(
|
||||
&vc_data,
|
||||
vc_data,
|
||||
fb_data.display.real_y(sy as u32),
|
||||
sx as u32,
|
||||
height as u32,
|
||||
@ -337,6 +336,7 @@ impl ConsoleSwitch for BlittingFbConsole {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::if_same_then_else)]
|
||||
fn con_cursor(
|
||||
&self,
|
||||
vc_data: &VirtualConsoleData,
|
||||
@ -671,7 +671,7 @@ impl FrameBufferConsole for BlittingFbConsole {
|
||||
let attr = FbConAttr::get_attr(c, fb_info.color_depth());
|
||||
let char_offset = (c as usize & charmask) * ((w * vc_data.font.height) as usize);
|
||||
|
||||
if fbcon_data.cursor_state.image.data != &vc_data.font.data[char_offset..]
|
||||
if fbcon_data.cursor_state.image.data != vc_data.font.data[char_offset..]
|
||||
|| fbcon_data.cursor_reset
|
||||
{
|
||||
fbcon_data.cursor_state.image.data = vc_data.font.data[char_offset..].to_vec();
|
||||
|
@ -367,6 +367,7 @@ pub trait FrameBufferConsole {
|
||||
/// ### dx: 目标位置的x坐标
|
||||
/// ### height: 位图高度
|
||||
/// ### width: 位图宽度
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn bmove(
|
||||
&self,
|
||||
vc_data: &VirtualConsoleData,
|
||||
@ -401,6 +402,7 @@ pub trait FrameBufferConsole {
|
||||
/// ### x: 起始位置的x坐标、
|
||||
/// ### fg: 前景色
|
||||
/// ### bg: 背景色
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn put_string(
|
||||
&self,
|
||||
vc_data: &VirtualConsoleData,
|
||||
|
@ -10,14 +10,14 @@ use crate::{
|
||||
|
||||
use self::fbmem::{FbDevice, FrameBufferManager};
|
||||
|
||||
const COLOR_TABLE_8: &'static [u32] = &[
|
||||
const COLOR_TABLE_8: &[u32] = &[
|
||||
0x00000000, 0xff000000, 0x00ff0000, 0xffff0000, 0x0000ff00, 0xff00ff00, 0x00ffff00, 0xffffff00,
|
||||
0x000000ff, 0xff0000ff, 0x00ff00ff, 0xffff00ff, 0x0000ffff, 0xff00ffff, 0x00ffffff, 0xffffffff,
|
||||
];
|
||||
|
||||
const COLOR_TABLE_16: &'static [u32] = &[0x00000000, 0xffff0000, 0x0000ffff, 0xffffffff];
|
||||
const COLOR_TABLE_16: &[u32] = &[0x00000000, 0xffff0000, 0x0000ffff, 0xffffffff];
|
||||
|
||||
const COLOR_TABLE_32: &'static [u32] = &[0x00000000, 0xffffffff];
|
||||
const COLOR_TABLE_32: &[u32] = &[0x00000000, 0xffffffff];
|
||||
|
||||
pub mod fbcon;
|
||||
pub mod fbmem;
|
||||
@ -80,7 +80,7 @@ pub trait FrameBuffer: FrameBufferInfo + FrameBufferOps + Device {
|
||||
return;
|
||||
}
|
||||
let mut dst1 = dst1.unwrap();
|
||||
dst1 = dst1 + VirtAddr::new(bitstart as usize);
|
||||
dst1 += VirtAddr::new(bitstart as usize);
|
||||
|
||||
let _ = self.fb_sync();
|
||||
|
||||
@ -102,8 +102,7 @@ pub trait FrameBuffer: FrameBufferInfo + FrameBufferOps + Device {
|
||||
&& start_index == 0
|
||||
&& pitch_index == 0
|
||||
&& image.width & (32 / bit_per_pixel - 1) == 0
|
||||
&& bit_per_pixel >= 8
|
||||
&& bit_per_pixel <= 32
|
||||
&& (8..=32).contains(&bit_per_pixel)
|
||||
{
|
||||
unsafe { self.fast_imageblit(image, dst1, fg, bg) }
|
||||
} else {
|
||||
@ -126,23 +125,16 @@ pub trait FrameBuffer: FrameBufferInfo + FrameBufferOps + Device {
|
||||
let mut bgx = bg;
|
||||
let ppw = 32 / bpp;
|
||||
let spitch = (image.width + 7) / 8;
|
||||
let tab: &[u32];
|
||||
let mut color_tab: [u32; 16] = [0; 16];
|
||||
|
||||
match bpp {
|
||||
8 => {
|
||||
tab = COLOR_TABLE_8;
|
||||
}
|
||||
16 => {
|
||||
tab = COLOR_TABLE_16;
|
||||
}
|
||||
32 => {
|
||||
tab = COLOR_TABLE_32;
|
||||
}
|
||||
let tab: &[u32] = match bpp {
|
||||
8 => COLOR_TABLE_8,
|
||||
16 => COLOR_TABLE_16,
|
||||
32 => COLOR_TABLE_32,
|
||||
_ => {
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for _ in (0..(ppw - 1)).rev() {
|
||||
fgx <<= bpp;
|
||||
@ -175,7 +167,7 @@ pub trait FrameBuffer: FrameBufferInfo + FrameBufferOps + Device {
|
||||
while j >= 2 {
|
||||
*dst = color_tab[(image.data[src] as usize >> 4) & bitmask];
|
||||
dst = dst.add(1);
|
||||
*dst = color_tab[(image.data[src] as usize >> 0) & bitmask];
|
||||
*dst = color_tab[(image.data[src] as usize) & bitmask];
|
||||
dst = dst.add(1);
|
||||
j -= 2;
|
||||
src += 1;
|
||||
@ -191,7 +183,7 @@ pub trait FrameBuffer: FrameBufferInfo + FrameBufferOps + Device {
|
||||
dst = dst.add(1);
|
||||
*dst = color_tab[(image.data[src] as usize >> 2) & bitmask];
|
||||
dst = dst.add(1);
|
||||
*dst = color_tab[(image.data[src] as usize >> 0) & bitmask];
|
||||
*dst = color_tab[(image.data[src] as usize) & bitmask];
|
||||
dst = dst.add(1);
|
||||
src += 1;
|
||||
j -= 4;
|
||||
@ -215,7 +207,7 @@ pub trait FrameBuffer: FrameBufferInfo + FrameBufferOps + Device {
|
||||
dst = dst.add(1);
|
||||
*dst = color_tab[(image.data[src] as usize >> 1) & bitmask];
|
||||
dst = dst.add(1);
|
||||
*dst = color_tab[(image.data[src] as usize >> 0) & bitmask];
|
||||
*dst = color_tab[(image.data[src] as usize) & bitmask];
|
||||
dst = dst.add(1);
|
||||
src += 1;
|
||||
j -= 8;
|
||||
@ -224,6 +216,11 @@ pub trait FrameBuffer: FrameBufferInfo + FrameBufferOps + Device {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
/*
|
||||
* For image widths that are not a multiple of 8, there
|
||||
* are trailing pixels left on the current line. Print
|
||||
* them as well.
|
||||
*/
|
||||
while j != 0 {
|
||||
shift -= ppw;
|
||||
*dst = color_tab[(image.data[src] as usize >> shift) & bitmask];
|
||||
@ -232,6 +229,7 @@ pub trait FrameBuffer: FrameBufferInfo + FrameBufferOps + Device {
|
||||
shift = 8;
|
||||
src += 1;
|
||||
}
|
||||
j -= 1;
|
||||
}
|
||||
|
||||
dst1 += VirtAddr::new(self.current_fb_fix().line_length as usize);
|
||||
@ -441,7 +439,7 @@ pub trait FrameBufferOps {
|
||||
}
|
||||
}
|
||||
|
||||
let _ = self.fb_image_blit(&image);
|
||||
self.fb_image_blit(&image);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -660,22 +658,17 @@ impl Default for FbVarScreenInfo {
|
||||
///
|
||||
/// 默认为彩色
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
|
||||
pub enum FbColorMode {
|
||||
/// 灰度
|
||||
GrayScale,
|
||||
/// 彩色
|
||||
#[default]
|
||||
Color,
|
||||
/// FOURCC
|
||||
FourCC,
|
||||
}
|
||||
|
||||
impl Default for FbColorMode {
|
||||
fn default() -> Self {
|
||||
FbColorMode::Color
|
||||
}
|
||||
}
|
||||
|
||||
/// `FbBitfield` 结构体用于描述颜色字段的位域。
|
||||
///
|
||||
/// 所有的偏移量都是从右边开始,位于一个精确为'bits_per_pixel'宽度的"像素"值内。
|
||||
@ -684,7 +677,7 @@ impl Default for FbColorMode {
|
||||
/// 对于伪颜色:所有颜色组件的偏移和长度应该相同。
|
||||
/// 偏移指定了调色板索引在像素值中的最低有效位的位置。
|
||||
/// 长度表示可用的调色板条目的数量(即条目数 = 1 << 长度)。
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
|
||||
pub struct FbBitfield {
|
||||
/// 位域的起始位置
|
||||
pub offset: u32,
|
||||
@ -705,16 +698,6 @@ impl FbBitfield {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for FbBitfield {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
offset: Default::default(),
|
||||
length: Default::default(),
|
||||
msb_right: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// `FbActivateFlags` 用于描述帧缓冲区的激活标志。
|
||||
///
|
||||
@ -750,8 +733,9 @@ impl Default for FbActivateFlags {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
|
||||
pub enum FbPixelFormat {
|
||||
#[default]
|
||||
Standard,
|
||||
/// Hold And Modify
|
||||
HAM,
|
||||
@ -759,12 +743,6 @@ pub enum FbPixelFormat {
|
||||
Reserved,
|
||||
}
|
||||
|
||||
impl Default for FbPixelFormat {
|
||||
fn default() -> Self {
|
||||
FbPixelFormat::Standard
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
pub struct FbSyncFlags: u32 {
|
||||
/// 水平同步高电平有效
|
||||
@ -806,9 +784,10 @@ bitflags! {
|
||||
|
||||
/// 视频颜色空间
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
|
||||
pub enum V4l2Colorspace {
|
||||
/// 默认颜色空间,即让驱动程序自行判断。只能用于视频捕获。
|
||||
#[default]
|
||||
Default = 0,
|
||||
/// SMPTE 170M:用于广播NTSC/PAL SDTV
|
||||
Smpte170m = 1,
|
||||
@ -840,12 +819,6 @@ pub enum V4l2Colorspace {
|
||||
Last,
|
||||
}
|
||||
|
||||
impl Default for V4l2Colorspace {
|
||||
fn default() -> Self {
|
||||
V4l2Colorspace::Default
|
||||
}
|
||||
}
|
||||
|
||||
/// `FixedScreenInfo` 结构体用于描述屏幕的固定属性。
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
@ -964,19 +937,14 @@ pub enum FbVisual {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
|
||||
pub enum FbCapability {
|
||||
#[default]
|
||||
Default = 0,
|
||||
/// 设备支持基于FOURCC的格式。
|
||||
FourCC,
|
||||
}
|
||||
|
||||
impl Default for FbCapability {
|
||||
fn default() -> Self {
|
||||
FbCapability::Default
|
||||
}
|
||||
}
|
||||
|
||||
/// 视频模式
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
@ -1012,9 +980,10 @@ pub struct FbVideoMode {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
|
||||
pub enum FbAccel {
|
||||
/// 没有硬件加速器
|
||||
#[default]
|
||||
None,
|
||||
|
||||
AtariBlitter = 1,
|
||||
@ -1078,12 +1047,6 @@ pub enum FbAccel {
|
||||
// Add other accelerators here
|
||||
}
|
||||
|
||||
impl Default for FbAccel {
|
||||
fn default() -> Self {
|
||||
FbAccel::None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct BootTimeScreenInfo {
|
||||
pub origin_x: u8,
|
||||
|
@ -390,14 +390,14 @@ impl FrameBufferOps for VesaFb {
|
||||
.screen_info
|
||||
.lfb_virt_base
|
||||
.ok_or(SystemError::ENODEV)?;
|
||||
let fg;
|
||||
if self.current_fb_fix().visual == FbVisual::TrueColor
|
||||
|
||||
let fg = if self.current_fb_fix().visual == FbVisual::TrueColor
|
||||
|| self.current_fb_fix().visual == FbVisual::DirectColor
|
||||
{
|
||||
fg = self.fb_data.read().pesudo_palette[rect.color as usize];
|
||||
self.fb_data.read().pesudo_palette[rect.color as usize]
|
||||
} else {
|
||||
fg = rect.color;
|
||||
}
|
||||
rect.color
|
||||
};
|
||||
|
||||
let bpp = self.current_fb_var().bits_per_pixel;
|
||||
// 每行像素数
|
||||
@ -533,8 +533,7 @@ impl FrameBufferOps for VesaFb {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let mut tmp: Vec<u32> = Vec::with_capacity(size);
|
||||
tmp.resize(size, 0);
|
||||
let mut tmp: Vec<u32> = vec![0; size];
|
||||
let mut tmp_ptr = tmp.as_mut_ptr();
|
||||
|
||||
// 这里是一个可以优化的点,现在为了避免指针拷贝时覆盖,统一先拷贝进入buf再拷贝到dst
|
||||
@ -575,11 +574,11 @@ impl FrameBufferInfo for VesaFb {
|
||||
}
|
||||
|
||||
fn current_fb_var(&self) -> FbVarScreenInfo {
|
||||
VESAFB_DEFINED.read().clone()
|
||||
*VESAFB_DEFINED.read()
|
||||
}
|
||||
|
||||
fn current_fb_fix(&self) -> FixedScreenInfo {
|
||||
VESAFB_FIX_INFO.read().clone()
|
||||
*VESAFB_FIX_INFO.read()
|
||||
}
|
||||
|
||||
fn video_mode(&self) -> Option<&FbVideoMode> {
|
||||
|
@ -25,12 +25,12 @@ static mut __MAMAGER: Option<VideoRefreshManager> = None;
|
||||
|
||||
pub fn video_refresh_manager() -> &'static VideoRefreshManager {
|
||||
return unsafe {
|
||||
&__MAMAGER
|
||||
__MAMAGER
|
||||
.as_ref()
|
||||
.expect("Video refresh manager has not been initialized yet!")
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
///管理显示刷新变量的结构体
|
||||
pub struct VideoRefreshManager {
|
||||
device_buffer: RwLock<ScmBufferInfo>,
|
||||
@ -69,11 +69,7 @@ impl VideoRefreshManager {
|
||||
let res = self
|
||||
.running
|
||||
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst);
|
||||
if res.is_ok() {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return res.is_ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,7 +148,7 @@ impl VideoRefreshManager {
|
||||
}
|
||||
return Err(SystemError::EINVAL);
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
#[allow(dead_code)]
|
||||
pub fn refresh_target(&self) -> RwLockReadGuard<'_, Option<Arc<SpinLock<Box<[u32]>>>>> {
|
||||
let x = self.refresh_target.read();
|
||||
@ -244,6 +240,7 @@ impl TimerFunction for VideoRefreshExecutor {
|
||||
* @brief 交给定时器执行的任务,此方法不应手动调用
|
||||
* @return Ok(())
|
||||
*/
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn run(&mut self) -> Result<(), SystemError> {
|
||||
// 获得Manager
|
||||
let manager = video_refresh_manager();
|
||||
@ -276,7 +273,7 @@ impl TimerFunction for VideoRefreshExecutor {
|
||||
let refresh_target = refresh_target.unwrap();
|
||||
|
||||
if let ScmBuffer::DeviceBuffer(vaddr) = manager.device_buffer().buf {
|
||||
let p = vaddr.as_ptr() as *mut u8;
|
||||
let p: *mut u8 = vaddr.as_ptr();
|
||||
let mut target_guard = None;
|
||||
for _ in 0..2 {
|
||||
if let Ok(guard) = refresh_target.as_ref().unwrap().try_lock_irqsave() {
|
||||
|
Reference in New Issue
Block a user