blob: 440bd3a46c77ee2415d40c89a8df9e01cde1bd89 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/* -------------------------------------------
Copyright Zeta Electronics Corporation
File: Framebuffer.cxx
Purpose: Framebuffer object
Revision History:
01/02/24: Added file (amlel)
02/02/24: Add documentation (amlel)
07/07/07: Moved Framebuffer methods into Kernel::
------------------------------------------- */
#include <KernelKit/Framebuffer.hpp>
#include <HintKit/CompilerHint.hxx>
/**
* @brief Framebuffer object implementation.
*
*/
namespace Kernel
{
Framebuffer::Framebuffer(_Input Ref<FramebufferContext*>& addr)
: fFrameBufferAddr(addr)
{
}
/**
* @brief Get Pixel at **pos**
*
* @param pos position of pixel.
* @return volatile*
*/
_Output volatile UIntPtr* Framebuffer::operator[](_Input const UIntPtr& pos)
{
return (UIntPtr*)(fFrameBufferAddr->fBase * pos);
}
/// @brief Boolean operator.
Framebuffer::operator bool()
{
return fFrameBufferAddr.Leak()->fBase != 0 &&
fColour != FramebufferColorKind::INVALID &&
fFrameBufferAddr.Leak()->fBase != kBadPtr;
}
/// @brief Set color kind of framebuffer.
/// @param colour
/// @return
_Output const FramebufferColorKind& Framebuffer::Color(
const FramebufferColorKind& colour)
{
if (fColour != FramebufferColorKind::INVALID &&
colour != FramebufferColorKind::INVALID)
{
fColour = colour;
}
return fColour;
}
/// @brief Leak framebuffer context.
/// @return The reference of the framebuffer context.
_Output Ref<FramebufferContext*>& Framebuffer::Leak()
{
return this->fFrameBufferAddr;
}
/// @brief Draws a rectangle.
/// @param width
/// @param height
/// @param x
/// @param y
/// @param color
/// @return
_Output Framebuffer& Framebuffer::DrawRect(SizeT width, SizeT height,
SizeT x, SizeT y, UInt32 color)
{
for (Kernel::SizeT i = x; i < width + x; ++i)
{
for (Kernel::SizeT u = y; u < height + y; ++u)
{
*(((volatile Kernel::UInt32*)(fFrameBufferAddr.Leak()->fBase +
4 * fFrameBufferAddr.Leak()->fBpp * i +
4 * u))) = color;
}
}
return *this;
}
/// @brief Put a pixel on the screen.
/// @param x
/// @param y
/// @param color
/// @return
_Output Framebuffer& Framebuffer::PutPixel(SizeT x, SizeT y, UInt32 color)
{
*(((volatile Kernel::UInt32*)(fFrameBufferAddr.Leak()->fBase +
4 * fFrameBufferAddr.Leak()->fBpp * x +
4 * y))) = color;
return *this;
}
const UInt32 kRgbRed = 0x000000FF;
const UInt32 kRgbGreen = 0x0000FF00;
const UInt32 kRgbBlue = 0x00FF0000;
const UInt32 kRgbBlack = 0x00000000;
const UInt32 kRgbWhite = 0xFFFFFFFF;
} // namespace Kernel
|