-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ui: display: display a background image on all screens #35
Draft
hnez
wants to merge
2
commits into
linux-automation:main
Choose a base branch
from
hnez:backgrounds
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−23
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,24 +29,24 @@ mod backend { | |
pub device: (), | ||
pub var_screen_info: VarScreeninfo, | ||
pub fix_screen_info: FixScreeninfo, | ||
pub frame: [u8; 240 * 240 * 2], | ||
pub frame: [u8; 240 * 240 * 4], | ||
} | ||
|
||
impl Framebuffer { | ||
pub fn new(_: &str) -> Result<Self, ()> { | ||
Ok(Self { | ||
device: (), | ||
var_screen_info: VarScreeninfo { | ||
bits_per_pixel: 16, | ||
bits_per_pixel: 32, | ||
xres: 240, | ||
yres: 240, | ||
..Default::default() | ||
}, | ||
fix_screen_info: FixScreeninfo { | ||
line_length: 480, | ||
line_length: 240 * 4, | ||
..Default::default() | ||
}, | ||
frame: [0; 240 * 240 * 2], | ||
frame: [0; 240 * 240 * 4], | ||
}) | ||
} | ||
|
||
|
@@ -63,6 +63,8 @@ mod backend { | |
|
||
use backend::Framebuffer; | ||
|
||
const BACKGROUND: &[(u8, u8, u8)] = include!(concat!(env!("OUT_DIR"), "/background.rs")); | ||
|
||
pub struct DisplayExclusive(Framebuffer); | ||
|
||
pub struct Display { | ||
|
@@ -93,7 +95,7 @@ impl Display { | |
} | ||
|
||
pub fn clear(&self) { | ||
self.with_lock(|target| target.0.frame.iter_mut().for_each(|p| *p = 0x00)); | ||
self.with_lock(|target| target.clear(BinaryColor::Off).unwrap()); | ||
} | ||
|
||
pub fn screenshooter(&self) -> ScreenShooter { | ||
|
@@ -108,23 +110,30 @@ impl ScreenShooter { | |
let (image, xres, yres) = { | ||
let fb = &self.inner.lock().unwrap().0; | ||
|
||
let bpp = (fb.var_screen_info.bits_per_pixel / 8) as usize; | ||
let xres = fb.var_screen_info.xres; | ||
let yres = fb.var_screen_info.yres; | ||
let res = (xres as usize) * (yres as usize); | ||
assert!(fb.var_screen_info.bits_per_pixel == 32); | ||
let xres = fb.var_screen_info.xres as usize; | ||
let yres = fb.var_screen_info.yres as usize; | ||
|
||
let mut image = vec![0; xres * yres * 3]; | ||
|
||
let image: Vec<u8> = (0..res) | ||
.map(|i| if fb.frame[i * bpp] != 0 { 0xff } else { 0 }) | ||
.collect(); | ||
for y in 0..yres { | ||
for x in 0..xres { | ||
let idx = y * xres + x; | ||
|
||
image[idx * 3] = fb.frame[idx * 4 + 2]; | ||
image[idx * 3 + 1] = fb.frame[idx * 4 + 1]; | ||
image[idx * 3 + 2] = fb.frame[idx * 4]; | ||
} | ||
} | ||
|
||
(image, xres, yres) | ||
}; | ||
|
||
let mut dst = Cursor::new(Vec::new()); | ||
|
||
let mut writer = { | ||
let mut enc = Encoder::new(&mut dst, xres, yres); | ||
enc.set_color(ColorType::Grayscale); | ||
let mut enc = Encoder::new(&mut dst, xres as u32, yres as u32); | ||
enc.set_color(ColorType::Rgb); | ||
enc.set_depth(BitDepth::Eight); | ||
enc.write_header().unwrap() | ||
}; | ||
|
@@ -144,7 +153,7 @@ impl DrawTarget for DisplayExclusive { | |
where | ||
I: IntoIterator<Item = Pixel<Self::Color>>, | ||
{ | ||
let bpp = self.0.var_screen_info.bits_per_pixel / 8; | ||
assert!(self.0.var_screen_info.bits_per_pixel == 32); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of a potential panic please return an appropriate error in this case. |
||
let xres = self.0.var_screen_info.xres; | ||
let yres = self.0.var_screen_info.yres; | ||
let line_length = self.0.fix_screen_info.line_length; | ||
|
@@ -157,14 +166,17 @@ impl DrawTarget for DisplayExclusive { | |
continue; | ||
} | ||
|
||
let offset = line_length * y + bpp * x; | ||
let offset_bg = (y * xres + x) as usize; | ||
let offset_fb = (line_length * y + 4 * x) as usize; | ||
|
||
for b in 0..bpp { | ||
self.0.frame[(offset + b) as usize] = match color { | ||
BinaryColor::Off => 0x00, | ||
BinaryColor::On => 0xff, | ||
} | ||
} | ||
let rgb = match color { | ||
BinaryColor::Off => BACKGROUND[offset_bg], | ||
BinaryColor::On => (255, 255, 255), | ||
}; | ||
|
||
self.0.frame[offset_fb] = rgb.2; | ||
self.0.frame[offset_fb + 1] = rgb.1; | ||
self.0.frame[offset_fb + 2] = rgb.0; | ||
} | ||
|
||
Ok(()) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a potential panic please return an appropriate error in this case.