try to improve performance

This commit is contained in:
Michael Sippel 2021-10-15 17:25:31 +02:00
parent 8f329e091d
commit c33dab5644
2 changed files with 53 additions and 45 deletions

View file

@ -43,19 +43,25 @@ pub struct SdfTerm {
fg_layers: HashMap<Point2<i16>, (bool, LayerId2d)>,
font_height: u32,
//font: Mutex<Font>,
font: Arc<Vec<u8>>,
renderer: Arc<Mutex<MarpBackend>>
}
impl SdfTerm {
pub fn new(renderer: Arc<Mutex<MarpBackend>>) -> Self {
let font_path = Path::new("/usr/share/fonts/TTF/FiraCode-Medium.ttf");
let mut font_file = File::open(font_path).unwrap();
let mut font_data = Vec::new();
font_file.read_to_end(&mut font_data).unwrap();
SdfTerm {
src_view: None,
bg_layers: HashMap::new(),
fg_layers: HashMap::new(),
font_height: 30,
//font: Mutex::new(Font::from_path(Path::new("/usr/share/fonts/TTF/FiraCode-Medium.ttf"),0).unwrap()),
font: Arc::new(font_data),
renderer
}
}
@ -147,8 +153,9 @@ impl SdfTerm {
// foreground layer
if let Some(c) = atom.c {
let font = Font::from_path(Path::new("/usr/share/fonts/TTF/FiraCode-Light.ttf"),0).unwrap();
let mut ch = Character::from_font(&font, c).with_size(1.0).with_tesselation_factor(0.01);
let font_index = 0;
let fontkit = Font::from_bytes(self.font.clone(), font_index).unwrap();
let mut ch = Character::from_font(&fontkit, c).with_size(1.0);
let (r,g,b) = atom.style.fg_color.unwrap_or((0, 0, 0));

View file

@ -145,17 +145,6 @@ async fn main() {
//now check if a rerender was requested, or if we worked on all
//events on that batch
term_port.update();
renderer.lock().unwrap().set_layer_order(
vec![
//vec![ color_layer_id.into() ].into_iter(),
sdf_term.read().unwrap().get_order().into_iter()
]
.into_iter()
.flatten()
.collect::<Vec<_>>()
.as_slice()
);
match event{
winit::event::Event::WindowEvent{window_id: _, event: winit::event::WindowEvent::Resized(newsize)} => {
@ -163,6 +152,7 @@ async fn main() {
}
winit::event::Event::WindowEvent{window_id: _, event: winit::event::WindowEvent::KeyboardInput{ device_id, input, is_synthetic }} => {
if input.state == winit::event::ElementState::Pressed {
if let Some(kc) = input.virtual_keycode {
match kc {
winit::event::VirtualKeyCode::Space => {
@ -321,47 +311,58 @@ async fn main() {
}
}
}
status_chars.clear();
let cur = process_list_editor.get_cursor();
if cur.tree_addr.len() > 0 {
status_chars.push(TerminalAtom::new('@', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true))));
for x in cur.tree_addr {
for c in format!("{}", x).chars() {
status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((0, 100, 20))));
}
status_chars.push(TerminalAtom::new('.', TerminalStyle::fg_color((120, 80, 80))));
}
status_chars.push(TerminalAtom::new(':', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true))));
for c in
match cur.leaf_mode {
ListCursorMode::Insert => "INSERT",
ListCursorMode::Select => "SELECT",
ListCursorMode::Modify => "MODIFY"
}.chars()
{
status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((200, 200, 20))));
}
status_chars.push(TerminalAtom::new(':', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true))));
} else {
for c in "Press <DN> to enter".chars() {
status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((200, 200, 20))));
}
}
}
}
winit::event::Event::MainEventsCleared => {
window.request_redraw();
}
winit::event::Event::RedrawRequested(_) => {
//term_port.update();
term_port.update();
renderer.lock().unwrap().set_layer_order(
vec![
//vec![ color_layer_id.into() ].into_iter(),
sdf_term.read().unwrap().get_order().into_iter()
]
.into_iter()
.flatten()
.collect::<Vec<_>>()
.as_slice()
);
renderer.lock().unwrap().render(&window);
}
_ => {},
}
status_chars.clear();
let cur = process_list_editor.get_cursor();
if cur.tree_addr.len() > 0 {
status_chars.push(TerminalAtom::new('@', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true))));
for x in cur.tree_addr {
for c in format!("{}", x).chars() {
status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((0, 100, 20))));
}
status_chars.push(TerminalAtom::new('.', TerminalStyle::fg_color((120, 80, 80))));
}
status_chars.push(TerminalAtom::new(':', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true))));
for c in
match cur.leaf_mode {
ListCursorMode::Insert => "INSERT",
ListCursorMode::Select => "SELECT",
ListCursorMode::Modify => "MODIFY"
}.chars()
{
status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((200, 200, 20))));
}
status_chars.push(TerminalAtom::new(':', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true))));
} else {
for c in "Press <DN> to enter".chars() {
status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((200, 200, 20))));
}
}
});
/*
async_std::task::spawn(