Compare commits

..

3 Commits

Author SHA1 Message Date
Bananymous 1f5073d0ac ports/doom: Allow doomgeneric to write directly to window framebuffer
This prevents an unnecessary `malloc` of the framebuffer and a copy
every frame.
2024-11-27 13:39:21 +02:00
Bananymous 8dbbbc1a1a Kernel: Add command line option `readonly`
This prevents calls to write_sectors_impl and all dirty pages are always
kept in RAM.
2024-11-27 13:31:55 +02:00
Bananymous f985673dc3 LibGUI: Add API to retrieve Window's underlying framebuffer 2024-11-27 13:29:42 +02:00
7 changed files with 65 additions and 0 deletions

View File

@ -55,5 +55,6 @@ namespace Kernel
BAN::StringView get_early_boot_command_line(uint32_t magic, uint32_t info); BAN::StringView get_early_boot_command_line(uint32_t magic, uint32_t info);
extern BootInfo g_boot_info; extern BootInfo g_boot_info;
extern bool g_disable_disk_write;
} }

View File

@ -6,6 +6,7 @@ namespace Kernel
{ {
BootInfo g_boot_info; BootInfo g_boot_info;
bool g_disable_disk_write { false };
static MemoryMapEntry::Type bios_number_to_memory_type(uint32_t number) static MemoryMapEntry::Type bios_number_to_memory_type(uint32_t number)
{ {

View File

@ -1,3 +1,4 @@
#include <kernel/BootInfo.h>
#include <kernel/Lock/LockGuard.h> #include <kernel/Lock/LockGuard.h>
#include <kernel/Memory/Heap.h> #include <kernel/Memory/Heap.h>
#include <kernel/Memory/PageTable.h> #include <kernel/Memory/PageTable.h>
@ -105,6 +106,9 @@ namespace Kernel
BAN::ErrorOr<void> DiskCache::sync() BAN::ErrorOr<void> DiskCache::sync()
{ {
if (g_disable_disk_write)
return {};
for (auto& cache : m_cache) for (auto& cache : m_cache)
{ {
if (cache.dirty_mask == 0) if (cache.dirty_mask == 0)

View File

@ -2,6 +2,7 @@
#include <BAN/ScopeGuard.h> #include <BAN/ScopeGuard.h>
#include <BAN/StringView.h> #include <BAN/StringView.h>
#include <BAN/UTF8.h> #include <BAN/UTF8.h>
#include <kernel/BootInfo.h>
#include <kernel/FS/DevFS/FileSystem.h> #include <kernel/FS/DevFS/FileSystem.h>
#include <kernel/FS/VirtualFileSystem.h> #include <kernel/FS/VirtualFileSystem.h>
#include <kernel/Lock/LockGuard.h> #include <kernel/Lock/LockGuard.h>
@ -265,6 +266,13 @@ namespace Kernel
LockGuard _(m_mutex); LockGuard _(m_mutex);
if (g_disable_disk_write)
{
if (!m_disk_cache.has_value())
return BAN::Error::from_errno(EIO);
return m_disk_cache->write_to_cache(lba, buffer, true);
}
if (!m_disk_cache.has_value()) if (!m_disk_cache.has_value())
return write_sectors_impl(lba, sector_count, buffer); return write_sectors_impl(lba, sector_count, buffer);

View File

@ -85,6 +85,8 @@ static void parse_command_line()
cmdline.disable_usb = true; cmdline.disable_usb = true;
else if (argument == "noacpi") else if (argument == "noacpi")
cmdline.disable_acpi = true; cmdline.disable_acpi = true;
else if (argument == "readonly")
Kernel::g_disable_disk_write = true;
else if (argument == "nodebug") else if (argument == "nodebug")
g_disable_debug = true; g_disable_debug = true;
else if (argument.starts_with("ps2=")) else if (argument.starts_with("ps2="))

View File

@ -0,0 +1,47 @@
From 70c235938f0b64c4f08a478d3107e5254ad904c6 Mon Sep 17 00:00:00 2001
From: Bananymous <bananymousosq@gmail.com>
Date: Wed, 27 Nov 2024 13:28:42 +0200
Subject: [PATCH] Remove unnecessary copy from framebuffer
---
doomgeneric/doomgeneric.c | 2 --
doomgeneric/doomgeneric_banan_os.cpp | 6 +++---
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/doomgeneric/doomgeneric.c b/doomgeneric/doomgeneric.c
index 782a7e7..f4eb63e 100644
--- a/doomgeneric/doomgeneric.c
+++ b/doomgeneric/doomgeneric.c
@@ -18,8 +18,6 @@ void doomgeneric_Create(int argc, char **argv)
M_FindResponseFile();
- DG_ScreenBuffer = malloc(DOOMGENERIC_RESX * DOOMGENERIC_RESY * 4);
-
DG_Init();
D_DoomMain ();
diff --git a/doomgeneric/doomgeneric_banan_os.cpp b/doomgeneric/doomgeneric_banan_os.cpp
index d00c30d..9d13b43 100644
--- a/doomgeneric/doomgeneric_banan_os.cpp
+++ b/doomgeneric/doomgeneric_banan_os.cpp
@@ -80,13 +80,13 @@ void DG_Init()
s_key_write_index = (s_key_write_index + 1) % s_key_queue_size;
}
);
+
+ ASSERT(DG_ScreenBuffer == nullptr);
+ DG_ScreenBuffer = s_window->pixels().data();
}
void DG_DrawFrame()
{
- for (size_t y = 0; y < DOOMGENERIC_RESY; y++)
- for (size_t x = 0; x < DOOMGENERIC_RESX; x++)
- s_window->set_pixel(x, y, 0xFF000000 | DG_ScreenBuffer[y * DOOMGENERIC_RESX + x]);
s_window->invalidate();
s_window->poll_events();
}
--
2.47.1

View File

@ -43,6 +43,8 @@ namespace LibGUI
return m_framebuffer[y * m_width + x]; return m_framebuffer[y * m_width + x];
} }
BAN::Span<uint32_t> pixels() { return m_framebuffer.span(); }
void fill_rect(int32_t x, int32_t y, uint32_t width, uint32_t height, uint32_t color); void fill_rect(int32_t x, int32_t y, uint32_t width, uint32_t height, uint32_t color);
void fill(uint32_t color) { return fill_rect(0, 0, width(), height(), color); } void fill(uint32_t color) { return fill_rect(0, 0, width(), height(), color); }