summaryrefslogtreecommitdiff
path: root/Kernel/Graphics
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2022-01-28 18:48:07 -0700
committerAndreas Kling <kling@serenityos.org>2022-02-04 21:34:12 +0100
commiteb446725d5cda24a0aa9cedd1e861b2543c785b9 (patch)
tree0c52049305ad866bdb09035309d8cab0d98cb619 /Kernel/Graphics
parent99e3e42fa552ab34538fa180054f91cbcac2798a (diff)
downloadserenity-eb446725d5cda24a0aa9cedd1e861b2543c785b9.zip
Kernel: Separate GenericFramebufferConsole implementation
The GenericFramebufferConsoleImpl class implements the logic without taking into account any other details such as synchronization. The GenericFramebufferConsole class then is a simple wrapper around GenericFramebufferConsoleImpl that takes care of synchronization. This allows us to re-use this implementation with e.g. different synchronization schemes.
Diffstat (limited to 'Kernel/Graphics')
-rw-r--r--Kernel/Graphics/Console/GenericFramebufferConsole.cpp60
-rw-r--r--Kernel/Graphics/Console/GenericFramebufferConsole.h25
2 files changed, 65 insertions, 20 deletions
diff --git a/Kernel/Graphics/Console/GenericFramebufferConsole.cpp b/Kernel/Graphics/Console/GenericFramebufferConsole.cpp
index f8d7b01a46..a9d7e8aff9 100644
--- a/Kernel/Graphics/Console/GenericFramebufferConsole.cpp
+++ b/Kernel/Graphics/Console/GenericFramebufferConsole.cpp
@@ -200,31 +200,30 @@ static inline BGRColor convert_standard_color_to_bgr_color(Console::Color color)
}
}
-size_t GenericFramebufferConsole::bytes_per_base_glyph() const
+size_t GenericFramebufferConsoleImpl::bytes_per_base_glyph() const
{
// FIXME: We assume we have 32 bit bpp framebuffer.
return 8 * 32;
}
-size_t GenericFramebufferConsole::chars_per_line() const
+size_t GenericFramebufferConsoleImpl::chars_per_line() const
{
return width() / bytes_per_base_glyph();
}
-void GenericFramebufferConsole::set_cursor(size_t, size_t)
+void GenericFramebufferConsoleImpl::set_cursor(size_t, size_t)
{
}
-void GenericFramebufferConsole::hide_cursor()
+void GenericFramebufferConsoleImpl::hide_cursor()
{
}
-void GenericFramebufferConsole::show_cursor()
+void GenericFramebufferConsoleImpl::show_cursor()
{
}
-void GenericFramebufferConsole::clear(size_t x, size_t y, size_t length)
+void GenericFramebufferConsoleImpl::clear(size_t x, size_t y, size_t length)
{
- SpinlockLocker lock(m_lock);
if (x == 0 && length == max_column()) {
// if we need to clear the entire row, just clean it with quick memset :)
auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * 8 + y * 8 * sizeof(u32) * width()];
@@ -251,9 +250,8 @@ void GenericFramebufferConsole::clear(size_t x, size_t y, size_t length)
}
}
-void GenericFramebufferConsole::clear_glyph(size_t x, size_t y)
+void GenericFramebufferConsoleImpl::clear_glyph(size_t x, size_t y)
{
- VERIFY(m_lock.is_locked());
auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * 8 + y * 8 * sizeof(u32) * width()];
for (size_t current_x = 0; current_x < 8; current_x++) {
memset(offset_in_framebuffer, 0, 8 * sizeof(u32));
@@ -262,21 +260,19 @@ void GenericFramebufferConsole::clear_glyph(size_t x, size_t y)
flush(8 * x, 8 * y, 8, 8);
}
-void GenericFramebufferConsole::enable()
+void GenericFramebufferConsoleImpl::enable()
{
- SpinlockLocker lock(m_lock);
memset(framebuffer_data(), 0, height() * width() * sizeof(u32));
m_enabled.store(true);
}
-void GenericFramebufferConsole::disable()
+
+void GenericFramebufferConsoleImpl::disable()
{
- SpinlockLocker lock(m_lock);
m_enabled.store(false);
}
-void GenericFramebufferConsole::write(size_t x, size_t y, char ch, Color background, Color foreground, bool critical)
+void GenericFramebufferConsoleImpl::write(size_t x, size_t y, char ch, Color background, Color foreground, bool critical)
{
- SpinlockLocker lock(m_lock);
if (!m_enabled.load())
return;
@@ -323,14 +319,44 @@ void GenericFramebufferConsole::write(size_t x, size_t y, char ch, Color backgro
}
}
-void GenericFramebufferConsole::write(size_t x, size_t y, char ch, bool critical)
+void GenericFramebufferConsoleImpl::write(size_t x, size_t y, char ch, bool critical)
{
write(x, y, ch, m_default_background_color, m_default_foreground_color, critical);
}
-void GenericFramebufferConsole::write(char ch, bool critical)
+void GenericFramebufferConsoleImpl::write(char ch, bool critical)
{
write(m_x, m_y, ch, m_default_background_color, m_default_foreground_color, critical);
}
+void GenericFramebufferConsole::clear(size_t x, size_t y, size_t length)
+{
+ SpinlockLocker lock(m_lock);
+ GenericFramebufferConsoleImpl::clear(x, y, length);
+}
+
+void GenericFramebufferConsole::clear_glyph(size_t x, size_t y)
+{
+ VERIFY(m_lock.is_locked());
+ GenericFramebufferConsoleImpl::clear_glyph(x, y);
+}
+
+void GenericFramebufferConsole::enable()
+{
+ SpinlockLocker lock(m_lock);
+ GenericFramebufferConsoleImpl::enable();
+}
+
+void GenericFramebufferConsole::disable()
+{
+ SpinlockLocker lock(m_lock);
+ GenericFramebufferConsoleImpl::disable();
+}
+
+void GenericFramebufferConsole::write(size_t x, size_t y, char ch, Color background, Color foreground, bool critical)
+{
+ SpinlockLocker lock(m_lock);
+ GenericFramebufferConsoleImpl::write(x, y, ch, background, foreground, critical);
+}
+
}
diff --git a/Kernel/Graphics/Console/GenericFramebufferConsole.h b/Kernel/Graphics/Console/GenericFramebufferConsole.h
index d9b048c196..bce81a90b7 100644
--- a/Kernel/Graphics/Console/GenericFramebufferConsole.h
+++ b/Kernel/Graphics/Console/GenericFramebufferConsole.h
@@ -13,7 +13,7 @@
namespace Kernel::Graphics {
-class GenericFramebufferConsole : public Console {
+class GenericFramebufferConsoleImpl : public Console {
public:
virtual size_t bytes_per_base_glyph() const override;
virtual size_t chars_per_line() const override;
@@ -39,14 +39,33 @@ public:
virtual void set_resolution(size_t width, size_t height, size_t pitch) = 0;
protected:
- GenericFramebufferConsole(size_t width, size_t height, size_t pitch)
+ GenericFramebufferConsoleImpl(size_t width, size_t height, size_t pitch)
: Console(width, height)
, m_pitch(pitch)
{
}
virtual u8* framebuffer_data() = 0;
- void clear_glyph(size_t x, size_t y);
+ virtual void clear_glyph(size_t x, size_t y);
size_t m_pitch;
+};
+
+class GenericFramebufferConsole : public GenericFramebufferConsoleImpl {
+public:
+ virtual void clear(size_t x, size_t y, size_t length) override;
+ virtual void write(size_t x, size_t y, char ch, Color background, Color foreground, bool critical = false) override;
+
+ virtual void enable() override;
+ virtual void disable() override;
+
+protected:
+ GenericFramebufferConsole(size_t width, size_t height, size_t pitch)
+ : GenericFramebufferConsoleImpl(width, height, pitch)
+ {
+ }
+
+ virtual void clear_glyph(size_t x, size_t y) override;
+
mutable Spinlock m_lock;
};
+
}