Merge branch 'master' of ssh://git.ablecorp.us:20/able/ableos

master
Able 2022-01-28 07:42:41 -06:00
commit 8122de7453
Signed by untrusted user: able
GPG Key ID: D164AF5F5700BE51
4 changed files with 81 additions and 81 deletions

View File

@ -1,11 +1,9 @@
use crate::vga_e::VGAE;
use ab_glyph::{Font, FontRef, Glyph};
use alloc::{boxed::Box, vec, vec::Vec};
use shadeable::{
evaluate_shader,
pixel_format::{Rgba64},
};
use shadeable::{evaluate_shader, pixel_format::Rgba64};
use spin;
use vga::{writers::GraphicsWriter};
use vga::writers::GraphicsWriter;
#[derive(Debug)]
pub struct ScreenSize {
@ -13,6 +11,10 @@ pub struct ScreenSize {
pub y: usize,
}
const FONT_SCALE: f32 = 1.6;
const GLYPH_HEIGHT: f32 = 18.0;
const GLYPH_WIDTH: f32 = 10.0;
lazy_static::lazy_static! {
pub static ref SCREEN_BUFFER: spin::Mutex<ScreenBuffer> = spin::Mutex::new(ScreenBuffer::new(640, 480));
@ -122,14 +124,78 @@ impl ScreenBuffer {
info!("Shaders done");
}
// TODO force clear
pub fn force_redraw(&mut self) {
use shadeable::pixel_format::into_vga_16;
VGAE.lock().clear_screen(into_vga_16(self.clear_color));
}
/// Draw a glyph on the screen at the given position
///
/// # Arguments
/// * `x` - the x position of the glyph
/// * `y` - the y position of the glyph
/// * `glyph` - the glyph to draw
/// * `color` - the color of the glyph
pub fn draw_char(&mut self, mut x: u32, mut y: u32, character: char, color: Rgba64) {
// trace!["Judy Hopps is thicc af"];
// let mode = *VGAE.lock();
// trace!["She got them bouncy bunny buns"];
let basic_multingual_plane = FontRef::try_from_slice(include_bytes!(
"../../../ableos/assets/fonts/unifont-14.0.01.ttf"
))
.unwrap();
let supplementary_multilingual_plane = FontRef::try_from_slice(include_bytes!(
"../../../ableos/assets/fonts/unifont_upper-14.0.01.ttf"
))
.unwrap();
// let mut has_char = false;
// for x in font.codepoint_ids() {
// if x.1 == character {
// has_char = true;
// break;
// }
// }
let in_supp_plane = character as u32 > 0xffff;
let plane = match in_supp_plane {
false => basic_multingual_plane,
true => supplementary_multilingual_plane,
};
match character {
'\n' => {}
_ => {
let q_glyph: Glyph = plane.glyph_id(character).with_scale_and_position(
20.0 * FONT_SCALE,
ab_glyph::point(GLYPH_WIDTH * FONT_SCALE, GLYPH_HEIGHT * FONT_SCALE),
);
// elf: I don't know if GLYPH_HEIGHT is in the right units here. I'm just guessing.
if x as usize > self.size.x {
x = 0;
y += (GLYPH_HEIGHT * FONT_SCALE) as u32;
}
if let Some(q) = plane.outline_glyph(q_glyph) {
q.draw(|gx, gy, c| {
if c > 0.015 {
let corner = q.px_bounds().min;
self.set_pixel(
gx as usize + corner.x as usize + x as usize,
gy as usize + corner.y as usize + y as usize,
color,
);
}
});
}
}
}
}
}
pub trait VgaBuffer {
@ -140,7 +206,7 @@ impl VgaBuffer for ScreenBuffer {
let mode = VGAE.lock();
for y in 0..self.size.y {
for x in 0..self.size.x {
use shadeable::pixel_format::{into_vga_16};
use shadeable::pixel_format::into_vga_16;
// let vga_color = get_color16(self.buff[y * self.size.x + x]);
let vga_color = into_vga_16(self.buff[y * self.size.x + x]);

View File

@ -99,8 +99,8 @@ pub fn tick() {
crate::kernel_state::KERNEL_STATE.lock().update_state();
let mut scheduler = SCHEDULER.lock();
scheduler.bump_exec();
// let mut scheduler = SCHEDULER.lock();
// scheduler.bump_exec();
TICK.store(data, Relaxed)
}

View File

@ -6,6 +6,7 @@ use alloc::{
use picorand::PicoRandGenerate;
use rkyv::{ser::serializers::AllocSerializer, Deserialize};
use shadeable::pixel_format::from_vga_16;
use vga::colors::Color16;
use y_compositor_protocol::Version;
use crate::{
@ -92,9 +93,11 @@ pub fn screen_writer_test() {
// sock_print_id.write(format!("I look forward to ur ai stuff :^>").into());
// sock_print_id.write(format!("1....2....3....4....5....6....7....8....9").into());
let mut mode = SCREEN_BUFFER.lock();
for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() {
vga_e::draw_char(0, 0, current, 0xff000000);
mode.draw_char(0, 0, current, from_vga_16(Color16::Red));
}
mode.copy_to_buffer();
}
pub fn vga_boot_screen() {

View File

@ -20,75 +20,6 @@ lazy_static::lazy_static! {
pub static ref VGAE_BUFF_OFFSET_Y: spin::Mutex<u8> = spin::Mutex::new(0);
}
const FONT_SCALE: f32 = 1.6;
const GLYPH_HEIGHT: f32 = 18.0;
const GLYPH_WIDTH: f32 = 10.0;
/// Draw a glyph on the screen at the given position
///
/// # Arguments
/// * `x` - the x position of the glyph
/// * `y` - the y position of the glyph
/// * `glyph` - the glyph to draw
/// * `color` - the color of the glyph
pub fn draw_char(mut x: u32, mut y: u32, character: char, color: Rgba64) {
// let mode = *VGAE.lock();
let mut mode = SCREEN_BUFFER.lock();
let basic_multingual_plane = FontRef::try_from_slice(include_bytes!(
"../../ableos/assets/fonts/unifont-14.0.01.ttf"
))
.unwrap();
let supplementary_multilingual_plane = FontRef::try_from_slice(include_bytes!(
"../../ableos/assets/fonts/unifont_upper-14.0.01.ttf"
))
.unwrap();
// let mut has_char = false;
// for x in font.codepoint_ids() {
// if x.1 == character {
// has_char = true;
// break;
// }
// }
let is_in_basic_multilingual_plane = character as u32 <= 0xffff;
let plane = match is_in_basic_multilingual_plane {
true => basic_multingual_plane,
false => supplementary_multilingual_plane,
};
match character {
'\n' => {}
_ => {
let q_glyph: Glyph = plane.glyph_id(character).with_scale_and_position(
20.0 * FONT_SCALE,
ab_glyph::point(GLYPH_WIDTH * FONT_SCALE, GLYPH_HEIGHT * FONT_SCALE),
);
// elf: I don't know if GLYPH_HEIGHT is in the right units here. I'm just guessing.
if x as usize > mode.size.x {
x = 0;
y += (GLYPH_HEIGHT * FONT_SCALE) as u32;
}
if let Some(q) = plane.outline_glyph(q_glyph) {
q.draw(|gx, gy, c| {
if c > 0.015 {
let corner = q.px_bounds().min;
mode.set_pixel(
gx as usize + corner.x as usize + x as usize,
gy as usize + corner.y as usize + y as usize,
color,
);
}
});
}
}
}
}
/// Converts a number to ... i forgor 💀
pub fn num_to_vga16(num: u8) -> Color16 {