1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// scr_vnc_ecos.c
|
4 |
|
|
//
|
5 |
|
|
//
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): Chris Garry <cgarry@sweeneydesign.co.uk>
|
43 |
|
|
// Contributors:
|
44 |
|
|
// Date: 2003-08-22
|
45 |
|
|
// Purpose:
|
46 |
|
|
// Description: Microwindows screen driver for VNC server on eCos
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
//
|
50 |
|
|
//========================================================================*/
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
#define _GNU_SOURCE 1
|
55 |
|
|
|
56 |
|
|
#include <pkgconf/system.h>
|
57 |
|
|
|
58 |
|
|
#include <assert.h>
|
59 |
|
|
#include <fcntl.h>
|
60 |
|
|
#include <limits.h>
|
61 |
|
|
#include <cyg/hal/drv_api.h>
|
62 |
|
|
#include <cyg/infra/diag.h>
|
63 |
|
|
#include <cyg/io/io.h>
|
64 |
|
|
#include <stdarg.h>
|
65 |
|
|
#include <stdio.h>
|
66 |
|
|
#include <stdlib.h>
|
67 |
|
|
#include <sys/stat.h>
|
68 |
|
|
#include <sys/time.h>
|
69 |
|
|
#include <sys/types.h>
|
70 |
|
|
#include <unistd.h>
|
71 |
|
|
#include "device.h"
|
72 |
|
|
#include "genfont.h"
|
73 |
|
|
#include "genmem.h"
|
74 |
|
|
#include <vnc-server.h>
|
75 |
|
|
|
76 |
|
|
/* In genmem.c*/
|
77 |
|
|
MWBOOL set_subdriver(PSD psd, PSUBDRIVER subdriver, MWBOOL init);
|
78 |
|
|
|
79 |
|
|
/* Prototypes for driver functions */
|
80 |
|
|
static int vnc_init(PSD psd);
|
81 |
|
|
static PSD vnc_open(PSD psd);
|
82 |
|
|
static void vnc_close(PSD psd);
|
83 |
|
|
static void vnc_getscreeninfo(PSD psd,PMWSCREENINFO psi);
|
84 |
|
|
static void vnc_drawpixel(PSD psd,MWCOORD x, MWCOORD y, MWPIXELVAL c);
|
85 |
|
|
static MWPIXELVAL vnc_readpixel(PSD psd,MWCOORD x, MWCOORD y);
|
86 |
|
|
static void vnc_drawhorizline(PSD psd,MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c);
|
87 |
|
|
static void vnc_drawvertline(PSD psd,MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c);
|
88 |
|
|
static void vnc_fillrect(PSD psd,MWCOORD x1, MWCOORD y1, MWCOORD x2, MWCOORD y2, MWPIXELVAL c);
|
89 |
|
|
static void vnc_blit(PSD , MWCOORD, MWCOORD, MWCOORD, MWCOORD, PSD, MWCOORD, MWCOORD, long);
|
90 |
|
|
static void vnc_stretchblit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD dstw,
|
91 |
|
|
MWCOORD dsth, PSD srcpsd, MWCOORD srcx, MWCOORD srcy,
|
92 |
|
|
MWCOORD srcw, MWCOORD srch, long op);
|
93 |
|
|
static void vnc_drawarea(PSD psd, driver_gc_t *gc, int op);
|
94 |
|
|
MWBOOL vnc_mapmemgc(PSD, MWCOORD, MWCOORD, int, int, int, int, void *);
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
SCREENDEVICE scrdev = {
|
99 |
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL,
|
100 |
|
|
vnc_open,
|
101 |
|
|
vnc_close,
|
102 |
|
|
vnc_getscreeninfo,
|
103 |
|
|
NULL,
|
104 |
|
|
vnc_drawpixel, /* DrawPixel subdriver*/
|
105 |
|
|
vnc_readpixel, /* ReadPixel subdriver*/
|
106 |
|
|
vnc_drawhorizline, /* DrawHorzLine subdriver*/
|
107 |
|
|
vnc_drawvertline, /* DrawVertLine subdriver*/
|
108 |
|
|
vnc_fillrect, /* FillRect subdriver*/
|
109 |
|
|
gen_fonts,
|
110 |
|
|
vnc_blit, /* Blit subdriver*/
|
111 |
|
|
NULL, /* PreSelect*/
|
112 |
|
|
NULL, /* DrawArea subdriver*/
|
113 |
|
|
NULL, /* SetIOPermissions*/
|
114 |
|
|
gen_allocatememgc,
|
115 |
|
|
vnc_mapmemgc,
|
116 |
|
|
gen_freememgc,
|
117 |
|
|
vnc_stretchblit, /* StretchBlit subdriver*/
|
118 |
|
|
NULL /* SetPortrait*/
|
119 |
|
|
};
|
120 |
|
|
|
121 |
|
|
SUBDRIVER vnc_subdriver = {
|
122 |
|
|
vnc_init,
|
123 |
|
|
vnc_drawpixel,
|
124 |
|
|
vnc_readpixel,
|
125 |
|
|
vnc_drawhorizline,
|
126 |
|
|
vnc_drawvertline,
|
127 |
|
|
vnc_fillrect,
|
128 |
|
|
vnc_blit,
|
129 |
|
|
vnc_drawarea,
|
130 |
|
|
vnc_stretchblit
|
131 |
|
|
};
|
132 |
|
|
|
133 |
|
|
/* Static variables*/
|
134 |
|
|
static int status; /* 0=never inited, 1=once inited, 2=inited. */
|
135 |
|
|
static vnc_frame_format_t *frame_format;
|
136 |
|
|
|
137 |
|
|
/* Calc linelen and mmap size, return 0 on fail*/
|
138 |
|
|
static int vnc_init(PSD psd)
|
139 |
|
|
{
|
140 |
|
|
if (!psd->size)
|
141 |
|
|
{
|
142 |
|
|
psd->size = psd->yres * psd->xres * psd->bpp / 8;
|
143 |
|
|
/* convert linelen from byte to pixel len for bpp 16, 24, 32*/
|
144 |
|
|
psd->linelen = psd->xres;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
return 1;
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
/* Initialise the VNC framebuffer */
|
151 |
|
|
static PSD vnc_open(PSD psd)
|
152 |
|
|
{
|
153 |
|
|
/* Get frame format details */
|
154 |
|
|
frame_format = VncGetInfo();
|
155 |
|
|
|
156 |
|
|
psd->xres = psd->xvirtres = frame_format->frame_width;
|
157 |
|
|
psd->yres = psd->yvirtres = frame_format->frame_height;
|
158 |
|
|
psd->portrait = MWPORTRAIT_NONE;
|
159 |
|
|
psd->planes = 1; /* Should probably find out what this means */
|
160 |
|
|
|
161 |
|
|
if (frame_format->rgb332)
|
162 |
|
|
{
|
163 |
|
|
psd->bpp = 8;
|
164 |
|
|
psd->ncolors = 0xFF + 1;
|
165 |
|
|
psd->pixtype = MWPF_TRUECOLOR332;
|
166 |
|
|
}
|
167 |
|
|
else if (frame_format->rgb555)
|
168 |
|
|
{
|
169 |
|
|
psd->bpp = 16;
|
170 |
|
|
psd->ncolors = 0x7FFF + 1;
|
171 |
|
|
psd->pixtype = MWPF_TRUECOLOR555;
|
172 |
|
|
}
|
173 |
|
|
else if (frame_format->rgb565)
|
174 |
|
|
{
|
175 |
|
|
psd->bpp = 16;
|
176 |
|
|
psd->ncolors = 0xFFFF + 1;
|
177 |
|
|
psd->pixtype = MWPF_TRUECOLOR565;
|
178 |
|
|
}
|
179 |
|
|
else if (frame_format->bgr233)
|
180 |
|
|
{
|
181 |
|
|
psd->bpp = 8;
|
182 |
|
|
psd->ncolors = 0xFF + 1;
|
183 |
|
|
psd->pixtype = MWPF_TRUECOLOR233;
|
184 |
|
|
}
|
185 |
|
|
else if (frame_format->truecolor0888)
|
186 |
|
|
{
|
187 |
|
|
psd->bpp = 32;
|
188 |
|
|
psd->ncolors = 0xFFFFFF + 1;
|
189 |
|
|
psd->pixtype = MWPF_TRUECOLOR0888;
|
190 |
|
|
}
|
191 |
|
|
else
|
192 |
|
|
{
|
193 |
|
|
EPRINTF("Unsupported display type\n");
|
194 |
|
|
goto fail;
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
psd->linelen = frame_format->frame_width * psd->bpp / 8;; /* What is linelen? - linelen in bytes for now...*/
|
198 |
|
|
psd->size = psd->xres * psd->yres * psd->bpp / 8;
|
199 |
|
|
psd->flags = PSF_SCREEN | PSF_HAVEBLIT;
|
200 |
|
|
psd->addr = frame_format->frame_buffer; /* Test */
|
201 |
|
|
// psd->addr = NULL; /* We do not want MW to access the frame buffer directly */
|
202 |
|
|
|
203 |
|
|
/* Initialise the frame buffer (white) */
|
204 |
|
|
VncInit(VNC_WHITE);
|
205 |
|
|
|
206 |
|
|
/* We always use our own subdriver */
|
207 |
|
|
psd->orgsubdriver = &vnc_subdriver;
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
status = 2;
|
211 |
|
|
return psd; /* success*/
|
212 |
|
|
|
213 |
|
|
fail:
|
214 |
|
|
return NULL;
|
215 |
|
|
}
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
/* Close framebuffer*/
|
219 |
|
|
static void vnc_close(PSD psd)
|
220 |
|
|
{
|
221 |
|
|
printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);
|
222 |
|
|
}
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
static void vnc_getscreeninfo(PSD psd,PMWSCREENINFO psi)
|
226 |
|
|
{
|
227 |
|
|
psi->rows = psd->yvirtres;
|
228 |
|
|
psi->cols = psd->xvirtres;
|
229 |
|
|
psi->planes = psd->planes;
|
230 |
|
|
psi->bpp = psd->bpp;
|
231 |
|
|
psi->ncolors = psd->ncolors;
|
232 |
|
|
psi->pixtype = psd->pixtype;
|
233 |
|
|
psi->fonts = NUMBER_FONTS;
|
234 |
|
|
psi->portrait = psd->portrait;
|
235 |
|
|
psi->fbdriver = true;
|
236 |
|
|
|
237 |
|
|
switch (psd->pixtype) {
|
238 |
|
|
case MWPF_TRUECOLOR332:
|
239 |
|
|
psi->rmask = 0xE0;
|
240 |
|
|
psi->gmask = 0x1C;
|
241 |
|
|
psi->bmask = 0x03;
|
242 |
|
|
break;
|
243 |
|
|
case MWPF_TRUECOLOR233:
|
244 |
|
|
psi->rmask = 0x07;
|
245 |
|
|
psi->gmask = 0x38;
|
246 |
|
|
psi->bmask = 0xC0;
|
247 |
|
|
break;
|
248 |
|
|
case MWPF_TRUECOLOR555:
|
249 |
|
|
psi->rmask = 0x7c00;
|
250 |
|
|
psi->gmask = 0x03e0;
|
251 |
|
|
psi->bmask = 0x001f;
|
252 |
|
|
break;
|
253 |
|
|
case MWPF_TRUECOLOR565:
|
254 |
|
|
psi->rmask = 0xf800;
|
255 |
|
|
psi->gmask = 0x07e0;
|
256 |
|
|
psi->bmask = 0x001f;
|
257 |
|
|
break;
|
258 |
|
|
case MWPF_TRUECOLOR0888:
|
259 |
|
|
psi->rmask = 0xFF0000;
|
260 |
|
|
psi->gmask = 0x00FF00;
|
261 |
|
|
psi->bmask = 0x0000FF;
|
262 |
|
|
break;
|
263 |
|
|
default:
|
264 |
|
|
printf("%s - unsupported pixtype\n", __FUNCTION__);
|
265 |
|
|
psi->rmask = 0xff;
|
266 |
|
|
psi->gmask = 0xff;
|
267 |
|
|
psi->bmask = 0xff;
|
268 |
|
|
break;
|
269 |
|
|
}
|
270 |
|
|
|
271 |
|
|
/* Need to figure out better values possibly */
|
272 |
|
|
psi->xdpcm = 27; /* assumes screen width of 24 cm */
|
273 |
|
|
psi->ydpcm = 27; /* assumes screen height of 18 cm */
|
274 |
|
|
}
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
static void vnc_drawpixel(PSD psd, MWCOORD x, MWCOORD y, MWPIXELVAL c)
|
278 |
|
|
{
|
279 |
|
|
VncDrawPixel(x, y, (vnc_colour_t)c);
|
280 |
|
|
}
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
static MWPIXELVAL vnc_readpixel(PSD psd, MWCOORD x, MWCOORD y)
|
284 |
|
|
{
|
285 |
|
|
return VncReadPixel(x, y);
|
286 |
|
|
}
|
287 |
|
|
|
288 |
|
|
|
289 |
|
|
static void vnc_drawhorizline(PSD psd, MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
|
290 |
|
|
{
|
291 |
|
|
VncDrawHorzLine(x1, x2, y, (vnc_colour_t)c);
|
292 |
|
|
}
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
static void vnc_drawvertline(PSD psd, MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
|
296 |
|
|
{
|
297 |
|
|
VncDrawVertLine(x, y1, y2, (vnc_colour_t)c);
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
static void vnc_fillrect(PSD psd,MWCOORD x1, MWCOORD y1, MWCOORD x2, MWCOORD y2, MWPIXELVAL c)
|
302 |
|
|
{
|
303 |
|
|
VncFillRect(x1, y1, x2, y2, (vnc_colour_t)c);
|
304 |
|
|
}
|
305 |
|
|
|
306 |
|
|
|
307 |
|
|
static void vnc_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
|
308 |
|
|
PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
|
309 |
|
|
{
|
310 |
|
|
if (op != 0)
|
311 |
|
|
{
|
312 |
|
|
diag_printf("vnc_blit(): op = 0x%x not supported\n", op);
|
313 |
|
|
}
|
314 |
|
|
|
315 |
|
|
if (srcpsd->addr == frame_format->frame_buffer && dstpsd->addr != frame_format->frame_buffer)
|
316 |
|
|
{
|
317 |
|
|
/* Copying rectangle from VNC frame buffer to supplied buffer */
|
318 |
|
|
VncCopyRect2Buffer(srcx, srcy, w, h, dstpsd->addr, dstpsd->xres, dstpsd->yres, dstx, dsty);
|
319 |
|
|
}
|
320 |
|
|
else if (srcpsd->addr != frame_format->frame_buffer && dstpsd->addr == frame_format->frame_buffer)
|
321 |
|
|
{
|
322 |
|
|
/* Copying rectangle from a supplied buffer to the VNC frame buffer */
|
323 |
|
|
VncCopyBuffer2Rect(srcpsd->addr, srcpsd->xres, srcpsd->yres, srcx, srcy, dstx, dsty, w, h);
|
324 |
|
|
}
|
325 |
|
|
else if (srcpsd->addr == frame_format->frame_buffer && dstpsd->addr == frame_format->frame_buffer)
|
326 |
|
|
{
|
327 |
|
|
/* Copying rectangle from VNC frame buffer to VNC frame buffer */
|
328 |
|
|
VncCopyRect(srcx, srcy, w, h, dstx, dsty);
|
329 |
|
|
}
|
330 |
|
|
else
|
331 |
|
|
{
|
332 |
|
|
diag_printf("vnc_blit(): Error unsupported operation\n");
|
333 |
|
|
}
|
334 |
|
|
}
|
335 |
|
|
|
336 |
|
|
static void vnc_stretchblit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD dstw,
|
337 |
|
|
MWCOORD dsth, PSD srcpsd, MWCOORD srcx, MWCOORD srcy,
|
338 |
|
|
MWCOORD srcw, MWCOORD srch, long op)
|
339 |
|
|
{
|
340 |
|
|
diag_printf("vnc_stretch_blit() not implemented\n");
|
341 |
|
|
}
|
342 |
|
|
|
343 |
|
|
static void vnc_drawarea(PSD psd, driver_gc_t *gc, int op)
|
344 |
|
|
{
|
345 |
|
|
diag_printf("vnc_drawarea() not implemented\n");
|
346 |
|
|
}
|
347 |
|
|
|
348 |
|
|
|
349 |
|
|
/*
|
350 |
|
|
* Initialize memory device with passed parms,
|
351 |
|
|
* select suitable framebuffer subdriver,
|
352 |
|
|
* and set subdriver in memory device.
|
353 |
|
|
*/
|
354 |
|
|
MWBOOL vnc_mapmemgc(PSD mempsd,MWCOORD w,MWCOORD h,int planes,int bpp,int linelen,
|
355 |
|
|
int size,void *addr)
|
356 |
|
|
{
|
357 |
|
|
PSUBDRIVER subdriver;
|
358 |
|
|
|
359 |
|
|
/* initialize mem screen driver*/
|
360 |
|
|
initmemgc(mempsd, w, h, planes, bpp, linelen, size, addr);
|
361 |
|
|
|
362 |
|
|
subdriver = &vnc_subdriver;
|
363 |
|
|
|
364 |
|
|
/* set and initialize subdriver into mem screen driver*/
|
365 |
|
|
if(!set_subdriver(mempsd, subdriver, TRUE))
|
366 |
|
|
{
|
367 |
|
|
diag_printf("set_subdriver() failed\n");
|
368 |
|
|
return 0;
|
369 |
|
|
}
|
370 |
|
|
|
371 |
|
|
return 1;
|
372 |
|
|
}
|