mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-30 00:08:03 +00:00
Display functions are now in a file
This commit is contained in:
parent
742082f755
commit
7d37988e3c
@ -11,6 +11,132 @@ NewLock(PrintLock);
|
|||||||
|
|
||||||
namespace Video
|
namespace Video
|
||||||
{
|
{
|
||||||
|
Font *Display::GetCurrentFont()
|
||||||
|
{
|
||||||
|
return CurrentFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::SetCurrentFont(Font *Font)
|
||||||
|
{
|
||||||
|
CurrentFont = Font;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::CreateBuffer(uint32_t Width, uint32_t Height, int Index)
|
||||||
|
{
|
||||||
|
if (Width == 0 && Height == 0)
|
||||||
|
{
|
||||||
|
Width = this->framebuffer.Width;
|
||||||
|
Height = this->framebuffer.Height;
|
||||||
|
debug("No width and height specified, using %ldx%lld", Width, Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Size = this->framebuffer.Pitch * Height;
|
||||||
|
if (this->Buffers[Index])
|
||||||
|
{
|
||||||
|
if (this->Buffers[Index]->Checksum == 0xDEAD)
|
||||||
|
{
|
||||||
|
warn("Buffer %d already exists, skipping creation", Index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ScreenBuffer *buffer = new ScreenBuffer;
|
||||||
|
buffer->Buffer = KernelAllocator.RequestPages(TO_PAGES(Size));
|
||||||
|
buffer->Width = Width;
|
||||||
|
buffer->Height = Height;
|
||||||
|
buffer->Size = Size;
|
||||||
|
buffer->Color = 0xFFFFFF;
|
||||||
|
buffer->CursorX = 0;
|
||||||
|
buffer->CursorY = 0;
|
||||||
|
this->Buffers[Index] = buffer;
|
||||||
|
memset(this->Buffers[Index]->Buffer, 0, Size);
|
||||||
|
this->Buffers[Index]->Checksum = 0xDEAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::SetBuffer(int Index)
|
||||||
|
{
|
||||||
|
memcpy(this->framebuffer.BaseAddress, this->Buffers[Index]->Buffer, this->Buffers[Index]->Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScreenBuffer *Display::GetBuffer(int Index)
|
||||||
|
{
|
||||||
|
return this->Buffers[Index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::ClearBuffer(int Index)
|
||||||
|
{
|
||||||
|
memset(this->Buffers[Index]->Buffer, 0, this->Buffers[Index]->Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::DeleteBuffer(int Index)
|
||||||
|
{
|
||||||
|
if (this->Buffers[Index] == nullptr)
|
||||||
|
return;
|
||||||
|
KernelAllocator.FreePages(this->Buffers[Index]->Buffer, TO_PAGES(this->Buffers[Index]->Size));
|
||||||
|
this->Buffers[Index]->Checksum = 0; // Making sure that the buffer is not used anymore
|
||||||
|
delete this->Buffers[Index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::SetBufferCursor(int Index, uint32_t X, uint32_t Y)
|
||||||
|
{
|
||||||
|
this->Buffers[Index]->CursorX = X;
|
||||||
|
this->Buffers[Index]->CursorY = Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::GetBufferCursor(int Index, uint32_t *X, uint32_t *Y)
|
||||||
|
{
|
||||||
|
*X = this->Buffers[Index]->CursorX;
|
||||||
|
*Y = this->Buffers[Index]->CursorY;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::SetPixel(uint32_t X, uint32_t Y, uint32_t Color, int Index)
|
||||||
|
{
|
||||||
|
if (unlikely(X >= this->Buffers[Index]->Width))
|
||||||
|
X = this->Buffers[Index]->Width - 1;
|
||||||
|
if (unlikely(Y >= this->Buffers[Index]->Height))
|
||||||
|
Y = this->Buffers[Index]->Height - 1;
|
||||||
|
uint32_t *Pixel = (uint32_t *)((uintptr_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8));
|
||||||
|
*Pixel = Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Display::GetPixel(uint32_t X, uint32_t Y, int Index)
|
||||||
|
{
|
||||||
|
if (unlikely(X >= this->Buffers[Index]->Width || Y >= this->Buffers[Index]->Height))
|
||||||
|
return 0;
|
||||||
|
uint32_t *Pixel = (uint32_t *)((uintptr_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8));
|
||||||
|
return *Pixel;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t Display::GetBitsPerPixel()
|
||||||
|
{
|
||||||
|
return this->framebuffer.BitsPerPixel;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t Display::GetPitch()
|
||||||
|
{
|
||||||
|
return this->framebuffer.Pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::Scroll(int Index, int Lines)
|
||||||
|
{
|
||||||
|
if (Lines == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Lines > 0)
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < this->CurrentFont->GetInfo().Height; i++) // TODO: Make this more efficient.
|
||||||
|
{
|
||||||
|
memmove(this->Buffers[Index]->Buffer,
|
||||||
|
(uint8_t *)this->Buffers[Index]->Buffer + (this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines),
|
||||||
|
this->Buffers[Index]->Size - (this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines));
|
||||||
|
|
||||||
|
memset((uint8_t *)this->Buffers[Index]->Buffer + (this->Buffers[Index]->Size - (this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines)),
|
||||||
|
0,
|
||||||
|
this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char Display::Print(char Char, int Index, bool WriteToUART)
|
char Display::Print(char Char, int Index, bool WriteToUART)
|
||||||
{
|
{
|
||||||
// SmartLock(PrintLock);
|
// SmartLock(PrintLock);
|
||||||
|
@ -96,104 +96,20 @@ namespace Video
|
|||||||
int ColorPickerIteration = 0;
|
int ColorPickerIteration = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Font *GetCurrentFont() { return CurrentFont; }
|
Font *GetCurrentFont();
|
||||||
void SetCurrentFont(Font *Font) { CurrentFont = Font; }
|
void SetCurrentFont(Font *Font);
|
||||||
void CreateBuffer(uint32_t Width, uint32_t Height, int Index)
|
void CreateBuffer(uint32_t Width, uint32_t Height, int Index);
|
||||||
{
|
void SetBuffer(int Index);
|
||||||
if (Width == 0 && Height == 0)
|
ScreenBuffer *GetBuffer(int Index);
|
||||||
{
|
void ClearBuffer(int Index);
|
||||||
Width = this->framebuffer.Width;
|
void DeleteBuffer(int Index);
|
||||||
Height = this->framebuffer.Height;
|
void SetBufferCursor(int Index, uint32_t X, uint32_t Y);
|
||||||
debug("No width and height specified, using %ldx%lld", Width, Height);
|
void GetBufferCursor(int Index, uint32_t *X, uint32_t *Y);
|
||||||
}
|
void SetPixel(uint32_t X, uint32_t Y, uint32_t Color, int Index);
|
||||||
|
uint32_t GetPixel(uint32_t X, uint32_t Y, int Index);
|
||||||
size_t Size = this->framebuffer.Pitch * Height;
|
uint16_t GetBitsPerPixel();
|
||||||
if (!this->Buffers[Index])
|
uint64_t GetPitch();
|
||||||
{
|
void Scroll(int Index, int Lines);
|
||||||
if (this->Buffers[Index]->Checksum != 0xDEAD)
|
|
||||||
{
|
|
||||||
ScreenBuffer *buffer = new ScreenBuffer;
|
|
||||||
buffer->Buffer = KernelAllocator.RequestPages(TO_PAGES(Size));
|
|
||||||
buffer->Width = Width;
|
|
||||||
buffer->Height = Height;
|
|
||||||
buffer->Size = Size;
|
|
||||||
buffer->Color = 0xFFFFFF;
|
|
||||||
buffer->CursorX = 0;
|
|
||||||
buffer->CursorY = 0;
|
|
||||||
this->Buffers[Index] = buffer;
|
|
||||||
memset(this->Buffers[Index]->Buffer, 0, Size);
|
|
||||||
this->Buffers[Index]->Checksum = 0xDEAD;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
warn("Buffer %d already exists, skipping creation", Index);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
warn("Buffer %d already exists, skipping creation", Index);
|
|
||||||
}
|
|
||||||
void SetBuffer(int Index) { memcpy(this->framebuffer.BaseAddress, this->Buffers[Index]->Buffer, this->Buffers[Index]->Size); }
|
|
||||||
ScreenBuffer *GetBuffer(int Index) { return this->Buffers[Index]; }
|
|
||||||
void ClearBuffer(int Index) { memset(this->Buffers[Index]->Buffer, 0, this->Buffers[Index]->Size); }
|
|
||||||
void DeleteBuffer(int Index)
|
|
||||||
{
|
|
||||||
if (this->Buffers[Index] == nullptr)
|
|
||||||
return;
|
|
||||||
KernelAllocator.FreePages(this->Buffers[Index]->Buffer, TO_PAGES(this->Buffers[Index]->Size));
|
|
||||||
this->Buffers[Index]->Checksum = 0; // Making sure that the buffer is not used anymore
|
|
||||||
delete this->Buffers[Index];
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetBufferCursor(int Index, uint32_t X, uint32_t Y)
|
|
||||||
{
|
|
||||||
this->Buffers[Index]->CursorX = X;
|
|
||||||
this->Buffers[Index]->CursorY = Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetBufferCursor(int Index, uint32_t *X, uint32_t *Y)
|
|
||||||
{
|
|
||||||
*X = this->Buffers[Index]->CursorX;
|
|
||||||
*Y = this->Buffers[Index]->CursorY;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void SetPixel(uint32_t X, uint32_t Y, uint32_t Color, int Index)
|
|
||||||
{
|
|
||||||
if (unlikely(X >= this->Buffers[Index]->Width))
|
|
||||||
X = this->Buffers[Index]->Width - 1;
|
|
||||||
if (unlikely(Y >= this->Buffers[Index]->Height))
|
|
||||||
Y = this->Buffers[Index]->Height - 1;
|
|
||||||
uint32_t *Pixel = (uint32_t *)((uintptr_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8));
|
|
||||||
*Pixel = Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline uint32_t GetPixel(uint32_t X, uint32_t Y, int Index)
|
|
||||||
{
|
|
||||||
if (unlikely(X >= this->Buffers[Index]->Width || Y >= this->Buffers[Index]->Height))
|
|
||||||
return 0;
|
|
||||||
uint32_t *Pixel = (uint32_t *)((uintptr_t)this->Buffers[Index]->Buffer + (Y * this->Buffers[Index]->Width + X) * (this->framebuffer.BitsPerPixel / 8));
|
|
||||||
return *Pixel;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline uint16_t GetBitsPerPixel() { return this->framebuffer.BitsPerPixel; }
|
|
||||||
inline uint64_t GetPitch() { return this->framebuffer.Pitch; }
|
|
||||||
|
|
||||||
void Scroll(int Index, int Lines)
|
|
||||||
{
|
|
||||||
if (Lines == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (Lines > 0)
|
|
||||||
{
|
|
||||||
for (uint32_t i = 0; i < this->CurrentFont->GetInfo().Height; i++) // TODO: Make this more efficient.
|
|
||||||
{
|
|
||||||
memmove(this->Buffers[Index]->Buffer,
|
|
||||||
(uint8_t *)this->Buffers[Index]->Buffer + (this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines),
|
|
||||||
this->Buffers[Index]->Size - (this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines));
|
|
||||||
|
|
||||||
memset((uint8_t *)this->Buffers[Index]->Buffer + (this->Buffers[Index]->Size - (this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines)),
|
|
||||||
0,
|
|
||||||
this->Buffers[Index]->Width * (this->framebuffer.BitsPerPixel / 8) * Lines);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char Print(char Char, int Index, bool WriteToUART = false);
|
char Print(char Char, int Index, bool WriteToUART = false);
|
||||||
void DrawString(const char *String, uint32_t X, uint32_t Y, int Index, bool WriteToUART = false);
|
void DrawString(const char *String, uint32_t X, uint32_t Y, int Index, bool WriteToUART = false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user