mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:37:34 +00:00
Kernel: Fix framebuffer resolution modesetting after boot
If we tried to change the resolution before of this patch, we triggered a kernel crash due to mmaping the framebuffer device again. Therefore, on mmaping of the framebuffer device, we create an entire new set of VMObjects and Regions for the new settings. Then, when we change the resolution, the framebuffersconsole needs to be updated with the new resolution and also to be refreshed with the new settings. To ensure we handle both shrinking of the resolution and growth of it, we only copy the right amount of available data from the cells Region.
This commit is contained in:
parent
5f718c6b05
commit
87f8f892d8
9 changed files with 88 additions and 13 deletions
|
@ -15,6 +15,13 @@ namespace Kernel {
|
|||
|
||||
static AK::Singleton<ConsoleManagement> s_the;
|
||||
|
||||
void ConsoleManagement::resolution_was_changed()
|
||||
{
|
||||
for (auto& console : m_consoles) {
|
||||
console.refresh_after_resolution_change();
|
||||
}
|
||||
}
|
||||
|
||||
bool ConsoleManagement::is_initialized()
|
||||
{
|
||||
if (!s_the.is_initialized())
|
||||
|
|
|
@ -26,6 +26,8 @@ public:
|
|||
void switch_to(unsigned);
|
||||
void initialize();
|
||||
|
||||
void resolution_was_changed();
|
||||
|
||||
void switch_to_debug() { switch_to(1); }
|
||||
|
||||
NonnullRefPtr<VirtualConsole> first_tty() const { return m_consoles[0]; }
|
||||
|
|
|
@ -134,12 +134,54 @@ UNMAP_AFTER_INIT void VirtualConsole::initialize()
|
|||
|
||||
// Add the lines, so we also ensure they will be flushed now
|
||||
for (size_t row = 0; row < rows(); row++) {
|
||||
m_lines.append({ true });
|
||||
m_lines.append({ true, 0 });
|
||||
}
|
||||
clear();
|
||||
VERIFY(m_cells);
|
||||
}
|
||||
|
||||
void VirtualConsole::refresh_after_resolution_change()
|
||||
{
|
||||
auto old_rows_count = rows();
|
||||
auto old_columns_count = columns();
|
||||
set_size(GraphicsManagement::the().console()->max_column(), GraphicsManagement::the().console()->max_row());
|
||||
m_console_impl.set_size(GraphicsManagement::the().console()->max_column(), GraphicsManagement::the().console()->max_row());
|
||||
|
||||
// Note: From now on, columns() and rows() are updated with the new settings.
|
||||
|
||||
auto size = GraphicsManagement::the().console()->max_column() * GraphicsManagement::the().console()->max_row() * sizeof(Cell) * 2;
|
||||
auto new_cells = MM.allocate_kernel_region(page_round_up(size), "Virtual Console Cells", Region::Access::Read | Region::Access::Write, AllocationStrategy::AllocateNow);
|
||||
|
||||
if (rows() < old_rows_count) {
|
||||
m_lines.shrink(rows());
|
||||
} else {
|
||||
for (size_t row = 0; row < (size_t)(rows() - old_rows_count); row++) {
|
||||
m_lines.append({ true, 0 });
|
||||
}
|
||||
}
|
||||
|
||||
// Note: A potential loss of displayed data occur when resolution width shrinks.
|
||||
if (columns() < old_columns_count) {
|
||||
for (size_t row = 0; row < rows(); row++) {
|
||||
auto& line = m_lines[row];
|
||||
memcpy(new_cells->vaddr().offset((row)*columns() * sizeof(Cell)).as_ptr(), m_cells->vaddr().offset((row) * (old_columns_count) * sizeof(Cell)).as_ptr(), columns() * sizeof(Cell));
|
||||
line.dirty = true;
|
||||
}
|
||||
} else {
|
||||
// Handle Growth of resolution
|
||||
for (size_t row = 0; row < rows(); row++) {
|
||||
auto& line = m_lines[row];
|
||||
memcpy(new_cells->vaddr().offset((row)*columns() * sizeof(Cell)).as_ptr(), m_cells->vaddr().offset((row) * (old_columns_count) * sizeof(Cell)).as_ptr(), old_columns_count * sizeof(Cell));
|
||||
line.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the new cells Region
|
||||
m_cells = move(new_cells);
|
||||
m_console_impl.m_need_full_flush = true;
|
||||
flush_dirty_lines();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT VirtualConsole::VirtualConsole(const unsigned index)
|
||||
: TTY(4, index)
|
||||
, m_index(index)
|
||||
|
@ -409,6 +451,10 @@ void VirtualConsole::put_character_at(unsigned row, unsigned column, u32 code_po
|
|||
cell.ch = code_point;
|
||||
cell.attribute.flags |= VT::Attribute::Flags::Touched;
|
||||
line.dirty = true;
|
||||
// FIXME: Maybe we should consider to change length after printing a special char in a column
|
||||
if (code_point <= 20)
|
||||
return;
|
||||
line.length = max<size_t>(line.length, column);
|
||||
}
|
||||
|
||||
void VirtualConsole::invalidate_cursor(size_t row)
|
||||
|
|
|
@ -60,6 +60,7 @@ class VirtualConsole final : public TTY
|
|||
public:
|
||||
struct Line {
|
||||
bool dirty;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
struct Cell {
|
||||
|
@ -80,6 +81,8 @@ public:
|
|||
|
||||
size_t index() const { return m_index; }
|
||||
|
||||
void refresh_after_resolution_change();
|
||||
|
||||
bool is_graphical() { return m_graphical; }
|
||||
void set_graphical(bool graphical);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue