Skip to content

Commit

Permalink
Kernel: Separate GenericFramebufferConsole implementation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tomuta authored and awesomekling committed Feb 4, 2022
1 parent 99e3e42 commit eb44672
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 20 deletions.
60 changes: 43 additions & 17 deletions Kernel/Graphics/Console/GenericFramebufferConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand All @@ -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));
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

}
25 changes: 22 additions & 3 deletions Kernel/Graphics/Console/GenericFramebufferConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,14 +39,33 @@ class GenericFramebufferConsole : public Console {
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;
};

}

0 comments on commit eb44672

Please sign in to comment.