Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 283 lines (227 sloc) 6.667 kb
c23b974 add vnc driver
michux authored
1 /* $Id$
2 * $URL$
3 *
4 * Libvncserver driver
5 *
6 * Copyright (C) 2009 Michael Vogt <michu@neophob.com>
7 * Modified from sample code by:
8 * Copyright (C) 2005 Michael Reinelt <michael@reinelt.co.at>
9 * Copyright (C) 2005, 2006, 2007, 2008, 2009 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
10 *
11 * This file is part of LCD4Linux.
12 *
13 * LCD4Linux is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
16 * any later version.
17 *
18 * LCD4Linux is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 */
28
29 /*
30 *
31 * exported fuctions:
32 *
33 * struct DRIVER drv_vnc
34 *
35 */
36
37 #include "config.h"
38
39 #include <stdlib.h>
40 #include <stdio.h>
41 #include <unistd.h>
42 #include <string.h>
43 #include <errno.h>
44
ec8146e more vnc driver stuff...
michux authored
45 #include <rfb/rfb.h>
c23b974 add vnc driver
michux authored
46
47 #include "debug.h"
48 #include "cfg.h"
49 #include "qprintf.h"
50 #include "udelay.h"
51 #include "plugin.h"
52 #include "widget.h"
53 #include "widget_text.h"
54 #include "widget_icon.h"
55 #include "widget_bar.h"
56 #include "drv.h"
57
58 #include "drv_generic_graphic.h"
59
ec8146e more vnc driver stuff...
michux authored
60 //todo: fps limiter
61 // key widget
c23b974 add vnc driver
michux authored
62
63 /* 15 frames per second (if we can) */
ec8146e more vnc driver stuff...
michux authored
64 #define PICTURE_TIMEOUT (1.0/15.0)
c23b974 add vnc driver
michux authored
65
66 static char Name[] = "VNC";
67
68 static rfbScreenInfoPtr server;
69 static int xres = 320;
70 static int yres = 200;
71 static int BPP = 4;
72
ec8146e more vnc driver stuff...
michux authored
73 static int clientCount = 0;
74
75 static void clientgone(rfbClientPtr cl)
76 {
77 if (clientCount > 0)
78 clientCount--;
79 debug("%d clients connected\n", clientCount);
80 }
81
82 static enum rfbNewClientAction newclient(rfbClientPtr cl)
83 {
84 cl->clientGoneHook = clientgone;
85 clientCount++;
86 debug("%d clients connected\n", clientCount);
87 return RFB_CLIENT_ACCEPT;
88 }
89
e3d860b minor fixup
michux authored
90 /* handle mouse action */
ec8146e more vnc driver stuff...
michux authored
91 static void doptr(int buttonMask, int x, int y, rfbClientPtr cl)
92 {
93 if (x >= 0 && y >= 0 && x < xres && y < yres) {
94 if (buttonMask) {
95 printf("btn:%d, x:%d, y:%d\n", buttonMask, x, y);
96 }
97 }
98
99 rfbDefaultPtrAddEvent(buttonMask, x, y, cl);
100 }
101
c23b974 add vnc driver
michux authored
102
103 static int drv_vnc_open(const char *Section)
104 {
105 if (cfg_number(Section, "xres", 320, 32, 2048, &xres) < 1) {
ec8146e more vnc driver stuff...
michux authored
106 info("[DRV_VNC] no '%s.xres' entry from %s using default %d", Section, cfg_source(), xres);
107 }
c23b974 add vnc driver
michux authored
108 if (cfg_number(Section, "yres", 200, 32, 2048, &yres) < 1) {
ec8146e more vnc driver stuff...
michux authored
109 info("[DRV_VNC] no '%s.yres' entry from %s using default %d", Section, cfg_source(), yres);
c23b974 add vnc driver
michux authored
110 }
111 if (cfg_number(Section, "bpp", 4, 1, 4, &BPP) < 1) {
ec8146e more vnc driver stuff...
michux authored
112 info("[DRV_VNC] no '%s.bpp' entry from %s using default %d", Section, cfg_source(), BPP);
c23b974 add vnc driver
michux authored
113 }
114 return 0;
115 }
116
117
118 static int drv_vnc_close(void)
119 {
120 rfbShutdownServer(server, TRUE);
121 free(server->frameBuffer);
122 return 0;
123 }
124
ec8146e more vnc driver stuff...
michux authored
125 static void drv_vnc_blit_it(const int row, const int col, const int height, const int width, unsigned char *buffer)
c23b974 add vnc driver
michux authored
126 {
127 int r, c, ofs;
128 RGBA p;
ec8146e more vnc driver stuff...
michux authored
129
c23b974 add vnc driver
michux authored
130 for (r = row; r < row + height; r++) {
131 for (c = col; c < col + width; c++) {
132 p = drv_generic_graphic_rgb(r, c);
133 ofs = (r * xres + c) * BPP;
134 buffer[ofs++] = p.R;
135 buffer[ofs++] = p.G;
136 buffer[ofs++] = p.B;
ec8146e more vnc driver stuff...
michux authored
137 buffer[ofs] = 255;
c23b974 add vnc driver
michux authored
138 }
139 }
140 }
141
142 static void drv_vnc_blit(const int row, const int col, const int height, const int width)
143 {
144 if (rfbIsActive(server)) {
ec8146e more vnc driver stuff...
michux authored
145
146 drv_vnc_blit_it(row, col, height, width, (unsigned char *) server->frameBuffer);
9ad3a78 I just wanted to commit the 1000st change to lcd4linux ;)
michux authored
147 if (clientCount > 0) {
e3d860b minor fixup
michux authored
148 rfbMarkRectAsModified(server, 0, 0, xres, yres);
9ad3a78 I just wanted to commit the 1000st change to lcd4linux ;)
michux authored
149 }
ec8146e more vnc driver stuff...
michux authored
150 rfbProcessEvents(server, server->deferUpdateTime * 1000);
c23b974 add vnc driver
michux authored
151 }
152 }
153
154 /* start graphic display */
155 static int drv_vnc_start(const char *section)
156 {
157 char *s;
158
159 s = cfg_get(section, "Font", "6x8");
160 if (s == NULL || *s == '\0') {
161 error("%s: no '%s.Font' entry from %s", Name, section, cfg_source());
162 return -1;
163 }
164
165 XRES = -1;
166 YRES = -1;
167 if (sscanf(s, "%dx%d", &XRES, &YRES) != 2 || XRES < 1 || YRES < 1) {
168 error("%s: bad Font '%s' from %s", Name, s, cfg_source());
169 return -1;
170 }
171
172 /* Fixme: provider other fonts someday... */
173 if (XRES != 6 && YRES != 8) {
174 error("%s: bad Font '%s' from %s (only 6x8 at the moment)", Name, s, cfg_source());
175 return -1;
176 }
177
178 /* open communication with the display */
179 if (drv_vnc_open(section) < 0) {
180 return -1;
181 }
182
183 /* you surely want to allocate a framebuffer or something... */
ec8146e more vnc driver stuff...
michux authored
184 server = rfbGetScreen(0, NULL, xres, yres, 8, 3, BPP);
c23b974 add vnc driver
michux authored
185 server->desktopName = "LCD4Linux VNC Driver";
ec8146e more vnc driver stuff...
michux authored
186 server->frameBuffer = (char *) malloc(xres * yres * BPP);
187 server->alwaysShared = (1 == 1);
c23b974 add vnc driver
michux authored
188 server->ptrAddEvent = doptr;
189 // server->kbdAddEvent = dokey;
ec8146e more vnc driver stuff...
michux authored
190 server->newClientHook = newclient;
191
c23b974 add vnc driver
michux authored
192 /* Initialize the server */
193 rfbInitServer(server);
ec8146e more vnc driver stuff...
michux authored
194
c23b974 add vnc driver
michux authored
195 /* set width/height */
196 DROWS = yres;
197 DCOLS = xres;
198
199 return 0;
200 }
201
202 /****************************************/
203 /*** widget callbacks ***/
204 /****************************************/
205
206
207 /* using drv_generic_text_draw(W) */
208 /* using drv_generic_text_icon_draw(W) */
209 /* using drv_generic_text_bar_draw(W) */
210 /* using drv_generic_gpio_draw(W) */
211
212
213 /****************************************/
214 /*** exported functions ***/
215 /****************************************/
216
217
218 /* list models */
219 int drv_vnc_list(void)
220 {
221 printf("vnc server");
222 return 0;
223 }
224
225
226 /* initialize driver & display */
227 int drv_vnc_init(const char *section, const int quiet)
228 {
229 int ret;
230
231 /* real worker functions */
232 drv_generic_graphic_real_blit = drv_vnc_blit;
233
234 /* start display */
235 if ((ret = drv_vnc_start(section)) != 0)
236 return ret;
237
238 /* initialize generic graphic driver */
239 if ((ret = drv_generic_graphic_init(section, Name)) != 0)
240 return ret;
241
242 if (!quiet) {
243 char buffer[40];
244 qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS);
245 if (drv_generic_graphic_greet(buffer, NULL)) {
246 sleep(3);
247 drv_generic_graphic_clear();
248 }
249 }
250
251 return 0;
252 }
253
254
255 /* close driver & display */
256 int drv_vnc_quit(const int quiet)
257 {
258 info("%s: shutting down.", Name);
259
260 /* clear display */
261 drv_generic_graphic_clear();
262
263 /* say goodbye... */
264 if (!quiet) {
265 drv_generic_graphic_greet("goodbye!", NULL);
266 }
267
268 drv_generic_graphic_quit();
269
270 debug("closing connection");
271 drv_vnc_close();
272
273 return (0);
274 }
275
276
277 DRIVER drv_vnc = {
278 .name = Name,
279 .list = drv_vnc_list,
280 .init = drv_vnc_init,
281 .quit = drv_vnc_quit,
282 };
Something went wrong with that request. Please try again.