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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
/*
* GraphLCD driver library
*
* vncserver.h - vncserver device
* Output goes to a vncserver device
*
* This file is released under the GNU General Public License. Refer
* to the COPYING file distributed with this package.
*
* (c) 2013 Michael Heyer
*/
#include <fcntl.h>
#include <stdio.h>
#include <syslog.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include "common.h"
#include "config.h"
#include "vncserver.h"
namespace GLCD
{
cDriverVncServer::cDriverVncServer(cDriverConfig * config)
: cDriver(config),
offbuff(0)
{
}
int cDriverVncServer::Init()
{
printf(" init.\n");
width = config->width;
height = config->height;
// Figure out the size of the screen in bytes
screensize = width * height * 4;
depth = 24;
server = rfbGetScreen(NULL,NULL,width,height,8,3,4);
if (!server)
{
syslog(LOG_ERR, "failed to creat vncserver device.\n");
return -1;
}
for (unsigned int i = 0; i < config->options.size(); i++)
{
if (config->options[i].name == "HttpDir")
{
server->httpDir = (char *)config->options[i].value.c_str();
}
}
// init bounding box
bbox[0] = width - 1; // x top
bbox[1] = height - 1; // y top
bbox[2] = 0; // x bottom
bbox[3] = 0; // y bottom
// reserve another memory to draw into
offbuff = new char[screensize];
if (!offbuff)
{
syslog(LOG_ERR, "%s: failed to alloc memory for vncserver device.\n", config->name.c_str());
return -1;
}
server->frameBuffer=offbuff;
rfbInitServer(server);
*oldConfig = *config;
// clear display
Refresh(true);
rfbRunEventLoop(server, 5000, true);
syslog(LOG_INFO, "%s: VncServer initialized.\n", config->name.c_str());
return 0;
}
int cDriverVncServer::DeInit()
{
if (offbuff)
delete[] offbuff;
return 0;
}
int cDriverVncServer::CheckSetup()
{
if (config->device != oldConfig->device ||
config->port != oldConfig->port ||
32 != oldConfig->width ||
config->height != oldConfig->height)
{
DeInit();
Init();
return 0;
}
if (config->upsideDown != oldConfig->upsideDown ||
config->invert != oldConfig->invert)
{
oldConfig->upsideDown = config->upsideDown;
oldConfig->invert = config->invert;
return 1;
}
return 0;
}
void cDriverVncServer::SetPixel(int x, int y, uint32_t data)
{
int location;
if (x >= width || y >= height)
return;
if (config->upsideDown)
{
x = width - 1 - x;
y = height - 1 - y;
}
location = (x + y * width) * 4;
unsigned char r,g,b;
r = (data & 0x00FF0000) >> 16;
g = (data & 0x0000FF00) >> 8;
b = (data & 0x000000FF) >> 0;
if (config->invert) {
r = 255 - r;
g = 255 - g;
b = 255 - b;
}
*(offbuff + location + 0) = r;
*(offbuff + location + 1) = g;
*(offbuff + location + 2) = b;
if (x < bbox[0]) bbox[0] = x;
if (y < bbox[1]) bbox[1] = y;
if (x > bbox[2]) bbox[2] = x;
if (y > bbox[3]) bbox[3] = y;
}
void cDriverVncServer::Clear()
{
memset(offbuff, 0, screensize);
processDamage();
}
void cDriverVncServer::Refresh(bool refreshAll)
{
if (refreshAll) {
bbox[0] = 0;
bbox[1] = 0;
bbox[2] = width - 1;
bbox[3] = height - 1;
}
processDamage();
}
bool cDriverVncServer::GetDriverFeature (const std::string & Feature, int & value) {
if (offbuff) {
if (strcasecmp(Feature.c_str(), "depth") == 0) {
value = depth;
return true;
} else if (strcasecmp(Feature.c_str(), "ismonochrome") == 0) {
value = 0;
return true;
} else if (strcasecmp(Feature.c_str(), "isgreyscale") == 0 || strcasecmp(Feature.c_str(), "isgrayscale") == 0) {
value = 0;
return true;
} else if (strcasecmp(Feature.c_str(), "iscolour") == 0 || strcasecmp(Feature.c_str(), "iscolor") == 0) {
value = 1;
return true;
#if 0
} else if (strcasecmp(Feature.c_str(), "touch") == 0 || strcasecmp(Feature.c_str(), "touchscreen") == 0) {
if (...) {
value = (...) ? 1 : 0;
}
return true;
#endif
}
}
value = 0;
return false;
}
/* defines for different damage processing calls needed by _update() */
void cDriverVncServer::processDamage (void) {
if (!((bbox[0] == (width - 1)) && (bbox[1] == (height - 1)) && (bbox[2] == 0) && (bbox[3] == 0))) {
rfbMarkRectAsModified(server,bbox[0],bbox[1],bbox[2],bbox[3]);
}
/* reset bounding box */
bbox[0] = width - 1;
bbox[1] = height - 1;
bbox[2] = 0;
bbox[3] = 0;
}
} // end of namespace
|