-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFramebuffer.cpp
More file actions
executable file
·114 lines (109 loc) · 2.61 KB
/
Copy pathFramebuffer.cpp
File metadata and controls
executable file
·114 lines (109 loc) · 2.61 KB
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
extern "C"
{
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
}
#include <stdexcept>
#include "Framebuffer.hpp"
#include "geometry.hpp"
/**
* @brief Construct a new Framebuffer object
*
Gets information about monitor from FSCREENINFO and VSCREENINFO, puts it to Framebuffer fields. Also creates array of pixel vectors
* @see pixel
*/
Framebuffer::Framebuffer()
{
int fd = open("/dev/fb0", O_WRONLY);
if(fd < 0)
throw std::runtime_error(std::string("open:")+strerror(errno));
struct fb_fix_screeninfo fsinfo;
ioctl(fd, FBIOGET_FSCREENINFO, &fsinfo);
struct fb_var_screeninfo vsinfo;
ioctl(fd, FBIOGET_VSCREENINFO, &vsinfo);
width = (fsinfo.line_length * 8) / vsinfo.bits_per_pixel;
height = fsinfo.smem_len / fsinfo.line_length;
xres = vsinfo.xres;
yres = vsinfo.yres;
w = fsinfo.line_length * 8 / vsinfo.bits_per_pixel;
h = fsinfo.smem_len / fsinfo.line_length;
close(fd);
data = new pixel[w * h];
}
/**
* @brief Get actual width of monitor
*
* @return int Width of the monitor
*/
int Framebuffer::get_width() const noexcept
{
return width;
}
/**
* @brief Get actual height of monitor
*
* @return int Height of monitor
*/
int Framebuffer::get_height() const noexcept
{
return height;
}
/**
* @brief Easy access to data in form of 2D array
*
* @param i Number of line of pixels
* @return pixel* Array of pixel
*/
pixel *Framebuffer::operator[](int i) noexcept
{
return data + width * (yres - i - 1);
}
/**
* @brief Easy access to data in form of 2D array
* Used in case pixel is a constans
* @param i Number of line of pixels
* @return pixel* Array of pixel
*/
pixel const *Framebuffer::operator[](int i) const noexcept
{
return data + width * (yres - i - 1);
}
/**
* @brief Update screen
* Opens fb0 for writing. Writes data to it and closes it. As the result, new data array is displayed
* @exception std::runtime_error {Is thrown when fails to open fb0 for writing}
*/
void Framebuffer::update()
{
int fd = open("/dev/fb0", O_WRONLY);
if(fd == -1)
throw std::runtime_error(std::string("open:")+strerror(errno));
int res = write(fd, data, width * height * sizeof(pixel));
//write(fd, data, width * height * sizeof(pixel));
close(fd);
}
/**
* @brief Clear it with fork
* @author Polkovnik
*
Clears up your shit on the screen
*/
void Framebuffer::clear()
{
for(int i = 0 ; i < w * h; i++)
{
data[i] = {0,0,0,255};
}
}
/**
* @brief Destroy the Framebuffer object
* Clears the data array.
*/
Framebuffer::~Framebuffer()
{
delete[] data;
}