From 2c08bee567357fbd5b2cd51270b19f90b6004f14 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sat, 24 Sep 2016 18:07:58 +0200 Subject: [PATCH] Offscreen painting --- kernel/include/console.hpp | 8 ++++++-- kernel/include/terminal.hpp | 3 --- kernel/include/vesa_console.hpp | 12 ++++++++++-- kernel/src/console.cpp | 28 +++++++++++++++++++++++++--- kernel/src/stdio.cpp | 10 +++++++--- kernel/src/terminal.cpp | 18 +++++++++++++----- kernel/src/vesa_console.cpp | 17 +++++++++++++++-- 7 files changed, 76 insertions(+), 20 deletions(-) diff --git a/kernel/include/console.hpp b/kernel/include/console.hpp index f7a58b5e..7b0feb08 100644 --- a/kernel/include/console.hpp +++ b/kernel/include/console.hpp @@ -19,6 +19,8 @@ namespace stdio { void init_console(); struct console { + void init(); + size_t get_columns() const ; size_t get_rows() const ; @@ -26,16 +28,18 @@ struct console { void wipeout(); + void set_active(bool active); void save(); void restore(); private: void next_line(); - size_t current_line = 0; + size_t current_line = 0; size_t current_column = 0; - void* buffer; + void* buffer = nullptr; + bool active = false; }; } // end of namespace stdio diff --git a/kernel/include/terminal.hpp b/kernel/include/terminal.hpp index f777b918..c7d85348 100644 --- a/kernel/include/terminal.hpp +++ b/kernel/include/terminal.hpp @@ -83,9 +83,6 @@ struct virtual_terminal { void set_active(bool); - void save(); - void restore(); - console& get_console(); size_t id; diff --git a/kernel/include/vesa_console.hpp b/kernel/include/vesa_console.hpp index d2d80fff..b87a15dc 100644 --- a/kernel/include/vesa_console.hpp +++ b/kernel/include/vesa_console.hpp @@ -12,11 +12,19 @@ struct vesa_console { void init(); - size_t lines(); - size_t columns(); + + size_t lines() const ; + size_t columns() const ; + void clear(); + void clear(void* buffer); + void scroll_up(); + void scroll_up(void* buffer); + void print_char(size_t line, size_t column, char c); + void print_char(void* buffer, size_t line, size_t column, char c); + void* save(void* buffer); void restore(void* buffer); }; diff --git a/kernel/src/console.cpp b/kernel/src/console.cpp index f3c03e92..26520cbf 100644 --- a/kernel/src/console.cpp +++ b/kernel/src/console.cpp @@ -35,6 +35,12 @@ void stdio::init_console(){ } } +void stdio::console::init(){ + if(!text){ + buffer = vesa::create_buffer(); + } +} + size_t stdio::console::get_rows() const { if(text){ return t_console.lines(); @@ -67,7 +73,11 @@ void stdio::console::print(char key){ if(text){ t_console.print_char(current_line, current_column, key); } else { - v_console.print_char(current_line, current_column, key); + if(active){ + v_console.print_char(current_line, current_column, key); + } else { + v_console.print_char(buffer, current_line, current_column, key); + } } ++current_column; @@ -82,7 +92,11 @@ void stdio::console::wipeout(){ if(text){ t_console.clear(); } else { - v_console.clear(); + if(active){ + v_console.clear(); + } else { + v_console.clear(buffer); + } } current_line = 0; @@ -101,6 +115,10 @@ void stdio::console::restore(){ v_console.restore(buffer); } +void stdio::console::set_active(bool active){ + this->active = active; +} + void stdio::console::next_line(){ ++current_line; @@ -108,7 +126,11 @@ void stdio::console::next_line(){ if(text){ t_console.scroll_up(); } else { - v_console.scroll_up(); + if(active){ + v_console.scroll_up(); + } else { + v_console.scroll_up(buffer); + } } --current_line; diff --git a/kernel/src/stdio.cpp b/kernel/src/stdio.cpp index d3c59831..db9f3498 100644 --- a/kernel/src/stdio.cpp +++ b/kernel/src/stdio.cpp @@ -136,8 +136,11 @@ void stdio::init_terminals(){ terminal.mouse = false; } + // Initialize the active terminal + active_terminal = 0; terminals[active_terminal].active = true; + terminals[active_terminal].get_console().set_active(true); } void stdio::register_devices(){ @@ -162,7 +165,7 @@ void stdio::finalize(){ terminal.input_thread_pid = input_process.pid; // Save the initial image of the terminal - terminal.save(); + terminal.get_console().save(); } } @@ -184,8 +187,9 @@ void stdio::switch_terminal(size_t id){ if(active_terminal != id){ logging::logf(logging::log_level::TRACE, "stdio: Switch activate virtual terminal %u\n", id); - terminals[active_terminal].save(); - terminals[id].restore(); + // Effectively switch the terminal + terminals[active_terminal].set_active(false); + terminals[id].set_active(true); active_terminal = id; } diff --git a/kernel/src/terminal.cpp b/kernel/src/terminal.cpp index 26b1c5ad..83916615 100644 --- a/kernel/src/terminal.cpp +++ b/kernel/src/terminal.cpp @@ -130,12 +130,20 @@ bool stdio::virtual_terminal::is_canonical() const { return canonical; } -void stdio::virtual_terminal::save(){ - cons.save(); -} +void stdio::virtual_terminal::set_active(bool active){ + if(this->active == active){ + return; + } -void stdio::virtual_terminal::restore(){ - cons.restore(); + this->active = active; + + cons.set_active(active); + + if(active){ + cons.restore(); + } else { + cons.save(); + } } stdio::console& stdio::virtual_terminal::get_console(){ diff --git a/kernel/src/vesa_console.cpp b/kernel/src/vesa_console.cpp index eabc7097..12395068 100644 --- a/kernel/src/vesa_console.cpp +++ b/kernel/src/vesa_console.cpp @@ -47,11 +47,11 @@ void vesa_console::init() { vesa::draw_char(title_left + 24, PADDING + MARGIN, 'R', _color); } -size_t vesa_console::lines() { +size_t vesa_console::lines() const { return _lines; } -size_t vesa_console::columns() { +size_t vesa_console::columns() const { return _columns; } @@ -59,15 +59,28 @@ void vesa_console::clear() { vesa::draw_rect(LEFT, TOP, _columns * 8, _lines * 16, vesa::make_color(0, 0, 0)); } +void vesa_console::clear(void* buffer) { + vesa::draw_rect(buffer, LEFT, TOP, _columns * 8, _lines * 16, vesa::make_color(0, 0, 0)); +} + void vesa_console::scroll_up() { vesa::move_lines_up(TOP + 16, LEFT, _columns * 8, (_lines - 1) * 16, 16); vesa::draw_rect(LEFT, TOP + (_lines - 1) * 16, _columns * 8, 16, vesa::make_color(0, 0, 0)); } +void vesa_console::scroll_up(void* buffer) { + vesa::move_lines_up(buffer, TOP + 16, LEFT, _columns * 8, (_lines - 1) * 16, 16); + vesa::draw_rect(buffer, LEFT, TOP + (_lines - 1) * 16, _columns * 8, 16, vesa::make_color(0, 0, 0)); +} + void vesa_console::print_char(size_t line, size_t column, char c) { vesa::draw_char(LEFT + 8 * column, TOP + 16 * line, c, _color); } +void vesa_console::print_char(void* buffer, size_t line, size_t column, char c) { + vesa::draw_char(buffer, LEFT + 8 * column, TOP + 16 * line, c, _color); +} + void* vesa_console::save(void* buffer) { void* buffer32 = static_cast(buffer); if (!buffer32) {