ladybird/Kernel/Graphics/Console/VGATextModeConsole.h
kleines Filmröllchen a6a439243f Kernel: Turn lock ranks into template parameters
This step would ideally not have been necessary (increases amount of
refactoring and templates necessary, which in turn increases build
times), but it gives us a couple of nice properties:
- SpinlockProtected inside Singleton (a very common combination) can now
  obtain any lock rank just via the template parameter. It was not
  previously possible to do this with SingletonInstanceCreator magic.
- SpinlockProtected's lock rank is now mandatory; this is the majority
  of cases and allows us to see where we're still missing proper ranks.
- The type already informs us what lock rank a lock has, which aids code
  readability and (possibly, if gdb cooperates) lock mismatch debugging.
- The rank of a lock can no longer be dynamic, which is not something we
  wanted in the first place (or made use of). Locks randomly changing
  their rank sounds like a disaster waiting to happen.
- In some places, we might be able to statically check that locks are
  taken in the right order (with the right lock rank checking
  implementation) as rank information is fully statically known.

This refactoring even more exposes the fact that Mutex has no lock rank
capabilites, which is not fixed here.
2023-01-02 18:15:27 -05:00

47 lines
1.5 KiB
C++

/*
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
#include <Kernel/Graphics/Console/Console.h>
#include <Kernel/Locking/Spinlock.h>
namespace Kernel::Graphics {
class VGATextModeConsole final : public Console {
public:
static NonnullLockRefPtr<VGATextModeConsole> initialize();
virtual size_t chars_per_line() const override { return width(); };
virtual bool has_hardware_cursor() const override { return true; }
virtual bool is_hardware_paged_capable() const override { return true; }
virtual size_t bytes_per_base_glyph() const override { return 2; }
virtual void set_cursor(size_t x, size_t y) override;
virtual void clear(size_t x, size_t y, size_t length) override;
virtual void write(size_t x, size_t y, char ch, bool critical = false) override;
virtual void write(size_t x, size_t y, char ch, Color background, Color foreground, bool critical = false) override;
virtual void write(char ch, bool critical = false) override;
virtual void flush(size_t, size_t, size_t, size_t) override { }
virtual void enable() override { }
virtual void disable() override { }
private:
virtual void hide_cursor() override;
virtual void show_cursor() override;
void clear_vga_row(u16 row);
explicit VGATextModeConsole(NonnullOwnPtr<Memory::Region>);
mutable Spinlock<LockRank::None> m_vga_lock {};
NonnullOwnPtr<Memory::Region> m_vga_window_region;
VirtualAddress m_current_vga_window;
};
}