Rev 1711 | Rev 1720 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1363 | vana | 1 | /* |
2 | * Copyright (C) 2006 Jakub Vana |
||
1404 | palkovsky | 3 | * Copyright (C) 2006 Ondrej Palkovsky |
1363 | vana | 4 | * All rights reserved. |
5 | * |
||
6 | * Redistribution and use in source and binary forms, with or without |
||
7 | * modification, are permitted provided that the following conditions |
||
8 | * are met: |
||
9 | * |
||
10 | * - Redistributions of source code must retain the above copyright |
||
11 | * notice, this list of conditions and the following disclaimer. |
||
12 | * - Redistributions in binary form must reproduce the above copyright |
||
13 | * notice, this list of conditions and the following disclaimer in the |
||
14 | * documentation and/or other materials provided with the distribution. |
||
15 | * - The name of the author may not be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | */ |
||
29 | |||
1649 | cejka | 30 | /** @defgroup fbs Framebuffers |
31 | * @brief HelenOS framebuffers. |
||
32 | * @{ |
||
33 | * @} |
||
34 | */ |
||
35 | /** @defgroup fb Framebuffer |
||
36 | * @brief HelenOS framebuffer. |
||
37 | * @ingroup fbs |
||
38 | * @{ |
||
39 | */ |
||
40 | /** @file |
||
41 | */ |
||
42 | |||
43 | |||
1430 | jermar | 44 | #include <stdlib.h> |
45 | #include <unistd.h> |
||
46 | #include <string.h> |
||
1363 | vana | 47 | #include <ddi.h> |
48 | #include <sysinfo.h> |
||
49 | #include <align.h> |
||
50 | #include <as.h> |
||
51 | #include <ipc/fb.h> |
||
52 | #include <ipc/ipc.h> |
||
1430 | jermar | 53 | #include <ipc/ns.h> |
1363 | vana | 54 | #include <ipc/services.h> |
55 | #include <kernel/errno.h> |
||
1392 | palkovsky | 56 | #include <async.h> |
1505 | palkovsky | 57 | |
1404 | palkovsky | 58 | #include "font-8x16.h" |
1363 | vana | 59 | #include "fb.h" |
1505 | palkovsky | 60 | #include "main.h" |
61 | #include "../console/screenbuffer.h" |
||
1547 | palkovsky | 62 | #include "ppm.h" |
1363 | vana | 63 | |
1711 | palkovsky | 64 | #include "pointer.xbm" |
65 | #include "pointer_mask.xbm" |
||
66 | |||
1630 | palkovsky | 67 | #define DEFAULT_BGCOLOR 0xf0f0f0 |
68 | #define DEFAULT_FGCOLOR 0x0 |
||
1363 | vana | 69 | |
70 | /***************************************************************/ |
||
71 | /* Pixel specific fuctions */ |
||
72 | |||
1555 | palkovsky | 73 | typedef void (*conv2scr_fn_t)(void *, int); |
74 | typedef int (*conv2rgb_fn_t)(void *); |
||
1363 | vana | 75 | |
1485 | palkovsky | 76 | struct { |
1363 | vana | 77 | __u8 *fbaddress ; |
78 | |||
79 | unsigned int xres ; |
||
80 | unsigned int yres ; |
||
81 | unsigned int scanline ; |
||
82 | unsigned int pixelbytes ; |
||
83 | |||
1555 | palkovsky | 84 | conv2scr_fn_t rgb2scr; |
85 | conv2rgb_fn_t scr2rgb; |
||
1485 | palkovsky | 86 | } screen; |
1363 | vana | 87 | |
1485 | palkovsky | 88 | typedef struct { |
89 | int initialized; |
||
90 | unsigned int x, y; |
||
91 | unsigned int width, height; |
||
1363 | vana | 92 | |
1485 | palkovsky | 93 | /* Text support in window */ |
94 | unsigned int rows, cols; |
||
95 | /* Style for text printing */ |
||
1509 | palkovsky | 96 | style_t style; |
1485 | palkovsky | 97 | /* Auto-cursor position */ |
1486 | palkovsky | 98 | int cursor_active, cur_col, cur_row; |
1500 | palkovsky | 99 | int cursor_shown; |
1672 | palkovsky | 100 | /* Double buffering */ |
101 | __u8 *dbdata; |
||
102 | unsigned int dboffset; |
||
103 | unsigned int paused; |
||
1485 | palkovsky | 104 | } viewport_t; |
1363 | vana | 105 | |
1646 | palkovsky | 106 | #define MAX_ANIM_LEN 8 |
107 | #define MAX_ANIMATIONS 4 |
||
108 | typedef struct { |
||
109 | int initialized; |
||
110 | int enabled; |
||
111 | unsigned int vp; |
||
112 | |||
113 | unsigned int pos; |
||
114 | unsigned int animlen; |
||
115 | unsigned int pixmaps[MAX_ANIM_LEN]; |
||
116 | } animation_t; |
||
117 | static animation_t animations[MAX_ANIMATIONS]; |
||
118 | static int anims_enabled; |
||
119 | |||
1552 | palkovsky | 120 | /** Maximum number of saved pixmaps |
121 | * Pixmap is a saved rectangle |
||
122 | */ |
||
123 | #define MAX_PIXMAPS 256 |
||
124 | typedef struct { |
||
125 | unsigned int width; |
||
126 | unsigned int height; |
||
1555 | palkovsky | 127 | __u8 *data; |
1552 | palkovsky | 128 | } pixmap_t; |
129 | static pixmap_t pixmaps[MAX_PIXMAPS]; |
||
130 | |||
131 | /* Viewport is a rectangular area on the screen */ |
||
1485 | palkovsky | 132 | #define MAX_VIEWPORTS 128 |
133 | static viewport_t viewports[128]; |
||
134 | |||
135 | /* Allow only 1 connection */ |
||
136 | static int client_connected = 0; |
||
137 | |||
1363 | vana | 138 | #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1)) |
139 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
||
140 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
||
141 | |||
1485 | palkovsky | 142 | #define COL_WIDTH 8 |
143 | #define ROW_BYTES (screen.scanline * FONT_SCANLINES) |
||
1363 | vana | 144 | |
1485 | palkovsky | 145 | #define POINTPOS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
1363 | vana | 146 | |
1555 | palkovsky | 147 | /* Conversion routines between different color representations */ |
148 | static void rgb_4byte(void *dst, int rgb) |
||
1363 | vana | 149 | { |
1555 | palkovsky | 150 | *(int *)dst = rgb; |
1363 | vana | 151 | } |
152 | |||
1555 | palkovsky | 153 | static int byte4_rgb(void *src) |
1363 | vana | 154 | { |
1555 | palkovsky | 155 | return (*(int *)src) & 0xffffff; |
1363 | vana | 156 | } |
157 | |||
1555 | palkovsky | 158 | static void rgb_3byte(void *dst, int rgb) |
1363 | vana | 159 | { |
1555 | palkovsky | 160 | __u8 *scr = dst; |
1363 | vana | 161 | #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN)) |
1555 | palkovsky | 162 | scr[0] = RED(rgb, 8); |
163 | scr[1] = GREEN(rgb, 8); |
||
164 | scr[2] = BLUE(rgb, 8); |
||
1363 | vana | 165 | #else |
1555 | palkovsky | 166 | scr[2] = RED(rgb, 8); |
167 | scr[1] = GREEN(rgb, 8); |
||
168 | scr[0] = BLUE(rgb, 8); |
||
1363 | vana | 169 | #endif |
170 | |||
1555 | palkovsky | 171 | |
1363 | vana | 172 | } |
173 | |||
1555 | palkovsky | 174 | static int byte3_rgb(void *src) |
1363 | vana | 175 | { |
1555 | palkovsky | 176 | __u8 *scr = src; |
1363 | vana | 177 | #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN)) |
1555 | palkovsky | 178 | return scr[0] << 16 | scr[1] << 8 | scr[2]; |
1363 | vana | 179 | #else |
1555 | palkovsky | 180 | return scr[2] << 16 | scr[1] << 8 | scr[0]; |
181 | #endif |
||
1363 | vana | 182 | } |
183 | |||
1555 | palkovsky | 184 | /** 16-bit depth (5:6:5) */ |
185 | static void rgb_2byte(void *dst, int rgb) |
||
1363 | vana | 186 | { |
187 | /* 5-bit, 6-bits, 5-bits */ |
||
1555 | palkovsky | 188 | *((__u16 *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5); |
1363 | vana | 189 | } |
190 | |||
1555 | palkovsky | 191 | /** 16-bit depth (5:6:5) */ |
192 | static int byte2_rgb(void *src) |
||
1363 | vana | 193 | { |
1555 | palkovsky | 194 | int color = *(__u16 *)(src); |
1363 | vana | 195 | return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
196 | } |
||
197 | |||
198 | /** Put pixel - 8-bit depth (3:2:3) */ |
||
1555 | palkovsky | 199 | static void rgb_1byte(void *dst, int rgb) |
1363 | vana | 200 | { |
1555 | palkovsky | 201 | *(__u8 *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3); |
1363 | vana | 202 | } |
203 | |||
204 | /** Return pixel color - 8-bit depth (3:2:3) */ |
||
1555 | palkovsky | 205 | static int byte1_rgb(void *src) |
1363 | vana | 206 | { |
1555 | palkovsky | 207 | int color = *(__u8 *)src; |
1363 | vana | 208 | return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
209 | } |
||
210 | |||
1498 | palkovsky | 211 | /** Put pixel into viewport |
212 | * |
||
1709 | jermar | 213 | * @param vport Viewport identification |
1498 | palkovsky | 214 | * @param x X coord relative to viewport |
215 | * @param y Y coord relative to viewport |
||
216 | * @param color RGB color |
||
217 | */ |
||
1673 | palkovsky | 218 | static void putpixel(viewport_t *vport, unsigned int x, unsigned int y, int color) |
1485 | palkovsky | 219 | { |
1673 | palkovsky | 220 | int dx = vport->x + x; |
221 | int dy = vport->y + y; |
||
1672 | palkovsky | 222 | |
1673 | palkovsky | 223 | if (! (vport->paused && vport->dbdata)) |
1672 | palkovsky | 224 | (*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)],color); |
225 | |||
1673 | palkovsky | 226 | if (vport->dbdata) { |
227 | int dline = (y + vport->dboffset) % vport->height; |
||
228 | int doffset = screen.pixelbytes * (dline * vport->width + x); |
||
229 | (*screen.rgb2scr)(&vport->dbdata[doffset],color); |
||
1672 | palkovsky | 230 | } |
1485 | palkovsky | 231 | } |
1672 | palkovsky | 232 | |
1498 | palkovsky | 233 | /** Get pixel from viewport */ |
1673 | palkovsky | 234 | static int getpixel(viewport_t *vport, unsigned int x, unsigned int y) |
1485 | palkovsky | 235 | { |
1673 | palkovsky | 236 | int dx = vport->x + x; |
237 | int dy = vport->y + y; |
||
1555 | palkovsky | 238 | |
239 | return (*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx,dy)]); |
||
1485 | palkovsky | 240 | } |
241 | |||
1668 | palkovsky | 242 | static inline void putpixel_mem(char *mem, unsigned int x, unsigned int y, |
243 | int color) |
||
1363 | vana | 244 | { |
1668 | palkovsky | 245 | (*screen.rgb2scr)(&mem[POINTPOS(x,y)],color); |
1363 | vana | 246 | } |
247 | |||
1673 | palkovsky | 248 | static void draw_rectangle(viewport_t *vport, unsigned int sx, unsigned int sy, |
1559 | palkovsky | 249 | unsigned int width, unsigned int height, |
250 | int color) |
||
251 | { |
||
252 | unsigned int x, y; |
||
1668 | palkovsky | 253 | static void *tmpline; |
1559 | palkovsky | 254 | |
1668 | palkovsky | 255 | if (!tmpline) |
256 | tmpline = malloc(screen.scanline*screen.pixelbytes); |
||
257 | |||
1559 | palkovsky | 258 | /* Clear first line */ |
259 | for (x = 0; x < width; x++) |
||
1668 | palkovsky | 260 | putpixel_mem(tmpline, x, 0, color); |
1559 | palkovsky | 261 | |
1673 | palkovsky | 262 | if (!vport->paused) { |
1672 | palkovsky | 263 | /* Recompute to screen coords */ |
1673 | palkovsky | 264 | sx += vport->x; |
265 | sy += vport->y; |
||
1672 | palkovsky | 266 | /* Copy the rest */ |
267 | for (y = sy;y < sy+height; y++) |
||
268 | memcpy(&screen.fbaddress[POINTPOS(sx,y)], tmpline, |
||
269 | screen.pixelbytes * width); |
||
270 | } |
||
1673 | palkovsky | 271 | if (vport->dbdata) { |
1672 | palkovsky | 272 | for (y=sy;y < sy+height; y++) { |
1673 | palkovsky | 273 | int rline = (y + vport->dboffset) % vport->height; |
274 | int rpos = (rline * vport->width + sx) * screen.pixelbytes; |
||
275 | memcpy(&vport->dbdata[rpos], tmpline, screen.pixelbytes * width); |
||
1672 | palkovsky | 276 | } |
277 | } |
||
1559 | palkovsky | 278 | |
279 | } |
||
280 | |||
1485 | palkovsky | 281 | /** Fill viewport with background color */ |
1673 | palkovsky | 282 | static void clear_port(viewport_t *vport) |
1363 | vana | 283 | { |
1673 | palkovsky | 284 | draw_rectangle(vport, 0, 0, vport->width, vport->height, vport->style.bg_color); |
1363 | vana | 285 | } |
286 | |||
1672 | palkovsky | 287 | /** Scroll unbuffered viewport up/down |
1485 | palkovsky | 288 | * |
1709 | jermar | 289 | * @param vport Viewport to scroll |
290 | * @param lines Positive number - scroll up, negative - scroll down |
||
1485 | palkovsky | 291 | */ |
1673 | palkovsky | 292 | static void scroll_port_nodb(viewport_t *vport, int lines) |
1363 | vana | 293 | { |
1485 | palkovsky | 294 | int y; |
295 | int startline; |
||
296 | int endline; |
||
1672 | palkovsky | 297 | |
298 | if (lines > 0) { |
||
299 | for (y=vport->y; y < vport->y+vport->height - lines; y++) |
||
1559 | palkovsky | 300 | memcpy(&screen.fbaddress[POINTPOS(vport->x,y)], |
1672 | palkovsky | 301 | &screen.fbaddress[POINTPOS(vport->x,y + lines)], |
1559 | palkovsky | 302 | screen.pixelbytes * vport->width); |
1673 | palkovsky | 303 | draw_rectangle(vport, 0, vport->height - lines, |
1672 | palkovsky | 304 | vport->width, lines, vport->style.bg_color); |
305 | } else if (lines < 0) { |
||
306 | lines = -lines; |
||
307 | for (y=vport->y + vport->height-1; y >= vport->y + lines; y--) |
||
1559 | palkovsky | 308 | memcpy(&screen.fbaddress[POINTPOS(vport->x,y)], |
1672 | palkovsky | 309 | &screen.fbaddress[POINTPOS(vport->x,y - lines)], |
310 | screen.pixelbytes * vport->width); |
||
1673 | palkovsky | 311 | draw_rectangle(vport, 0, 0, vport->width, lines, vport->style.bg_color); |
1485 | palkovsky | 312 | } |
1363 | vana | 313 | } |
314 | |||
1672 | palkovsky | 315 | /** Refresh given viewport from double buffer */ |
1673 | palkovsky | 316 | static void refresh_viewport_db(viewport_t *vport) |
1672 | palkovsky | 317 | { |
318 | unsigned int y, srcy, srcoff, dsty, dstx; |
||
319 | |||
1673 | palkovsky | 320 | for (y = 0; y < vport->height; y++) { |
321 | srcy = (y + vport->dboffset) % vport->height; |
||
322 | srcoff = (vport->width * srcy) * screen.pixelbytes; |
||
1672 | palkovsky | 323 | |
1673 | palkovsky | 324 | dstx = vport->x; |
325 | dsty = vport->y + y; |
||
1672 | palkovsky | 326 | |
327 | memcpy(&screen.fbaddress[POINTPOS(dstx,dsty)], |
||
1673 | palkovsky | 328 | &vport->dbdata[srcoff], |
329 | vport->width*screen.pixelbytes); |
||
1672 | palkovsky | 330 | } |
331 | } |
||
332 | |||
333 | /** Scroll viewport that has double buffering enabled */ |
||
1673 | palkovsky | 334 | static void scroll_port_db(viewport_t *vport, int lines) |
1672 | palkovsky | 335 | { |
1673 | palkovsky | 336 | ++vport->paused; |
1672 | palkovsky | 337 | if (lines > 0) { |
1673 | palkovsky | 338 | draw_rectangle(vport, 0, 0, vport->width, lines, |
339 | vport->style.bg_color); |
||
340 | vport->dboffset += lines; |
||
341 | vport->dboffset %= vport->height; |
||
1672 | palkovsky | 342 | } else if (lines < 0) { |
343 | lines = -lines; |
||
1673 | palkovsky | 344 | draw_rectangle(vport, 0, vport->height-lines, |
345 | vport->width, lines, |
||
346 | vport->style.bg_color); |
||
1672 | palkovsky | 347 | |
1673 | palkovsky | 348 | if (vport->dboffset < lines) |
349 | vport->dboffset += vport->height; |
||
350 | vport->dboffset -= lines; |
||
1672 | palkovsky | 351 | } |
352 | |||
1673 | palkovsky | 353 | --vport->paused; |
1672 | palkovsky | 354 | |
1673 | palkovsky | 355 | refresh_viewport_db(vport); |
1672 | palkovsky | 356 | } |
357 | |||
358 | /** Scrolls viewport given number of lines */ |
||
1673 | palkovsky | 359 | static void scroll_port(viewport_t *vport, int lines) |
1672 | palkovsky | 360 | { |
1673 | palkovsky | 361 | if (vport->dbdata) |
362 | scroll_port_db(vport, lines); |
||
1672 | palkovsky | 363 | else |
1673 | palkovsky | 364 | scroll_port_nodb(vport, lines); |
1672 | palkovsky | 365 | |
366 | } |
||
367 | |||
1673 | palkovsky | 368 | static void invert_pixel(viewport_t *vport, unsigned int x, unsigned int y) |
1363 | vana | 369 | { |
1673 | palkovsky | 370 | putpixel(vport, x, y, ~getpixel(vport, x, y)); |
1363 | vana | 371 | } |
372 | |||
373 | |||
374 | /***************************************************************/ |
||
375 | /* Character-console functions */ |
||
376 | |||
1558 | palkovsky | 377 | /** Draw character at given position |
378 | * |
||
1709 | jermar | 379 | * @param vport Viewport where the character is printed |
1558 | palkovsky | 380 | * @param sx Coordinates of top-left of the character |
381 | * @param sy Coordinates of top-left of the character |
||
382 | * @param style Color of the character |
||
383 | * @param transparent If false, print background color |
||
384 | */ |
||
1673 | palkovsky | 385 | static void draw_glyph(viewport_t *vport,__u8 glyph, unsigned int sx, unsigned int sy, |
1558 | palkovsky | 386 | style_t style, int transparent) |
1363 | vana | 387 | { |
1509 | palkovsky | 388 | int i; |
1363 | vana | 389 | unsigned int y; |
1509 | palkovsky | 390 | unsigned int glline; |
1363 | vana | 391 | |
1509 | palkovsky | 392 | for (y = 0; y < FONT_SCANLINES; y++) { |
393 | glline = fb_font[glyph * FONT_SCANLINES + y]; |
||
394 | for (i = 0; i < 8; i++) { |
||
395 | if (glline & (1 << (7 - i))) |
||
1673 | palkovsky | 396 | putpixel(vport, sx + i, sy + y, style.fg_color); |
1558 | palkovsky | 397 | else if (!transparent) |
1673 | palkovsky | 398 | putpixel(vport, sx + i, sy + y, style.bg_color); |
1509 | palkovsky | 399 | } |
400 | } |
||
1363 | vana | 401 | } |
402 | |||
403 | /** Invert character at given position */ |
||
1673 | palkovsky | 404 | static void invert_char(viewport_t *vport,unsigned int row, unsigned int col) |
1363 | vana | 405 | { |
406 | unsigned int x; |
||
407 | unsigned int y; |
||
408 | |||
409 | for (x = 0; x < COL_WIDTH; x++) |
||
410 | for (y = 0; y < FONT_SCANLINES; y++) |
||
1673 | palkovsky | 411 | invert_pixel(vport, col * COL_WIDTH + x, row * FONT_SCANLINES + y); |
1363 | vana | 412 | } |
413 | |||
414 | /***************************************************************/ |
||
415 | /* Stdout specific functions */ |
||
416 | |||
417 | |||
1485 | palkovsky | 418 | /** Create new viewport |
1363 | vana | 419 | * |
1485 | palkovsky | 420 | * @return New viewport number |
1363 | vana | 421 | */ |
1485 | palkovsky | 422 | static int viewport_create(unsigned int x, unsigned int y,unsigned int width, |
423 | unsigned int height) |
||
1363 | vana | 424 | { |
1485 | palkovsky | 425 | int i; |
426 | |||
1646 | palkovsky | 427 | for (i=0; i < MAX_VIEWPORTS; i++) { |
1485 | palkovsky | 428 | if (!viewports[i].initialized) |
1363 | vana | 429 | break; |
430 | } |
||
1485 | palkovsky | 431 | if (i == MAX_VIEWPORTS) |
432 | return ELIMIT; |
||
433 | |||
434 | viewports[i].x = x; |
||
435 | viewports[i].y = y; |
||
436 | viewports[i].width = width; |
||
437 | viewports[i].height = height; |
||
1363 | vana | 438 | |
1485 | palkovsky | 439 | viewports[i].rows = height / FONT_SCANLINES; |
440 | viewports[i].cols = width / COL_WIDTH; |
||
441 | |||
1509 | palkovsky | 442 | viewports[i].style.bg_color = DEFAULT_BGCOLOR; |
443 | viewports[i].style.fg_color = DEFAULT_FGCOLOR; |
||
1363 | vana | 444 | |
1489 | palkovsky | 445 | viewports[i].cur_col = 0; |
446 | viewports[i].cur_row = 0; |
||
447 | viewports[i].cursor_active = 0; |
||
448 | |||
1486 | palkovsky | 449 | viewports[i].initialized = 1; |
450 | |||
1485 | palkovsky | 451 | return i; |
1363 | vana | 452 | } |
453 | |||
454 | |||
455 | /** Initialize framebuffer as a chardev output device |
||
456 | * |
||
457 | * @param addr Address of theframebuffer |
||
1709 | jermar | 458 | * @param xres Screen width in pixels |
459 | * @param yres Screen height in pixels |
||
1363 | vana | 460 | * @param bpp Bits per pixel (8, 16, 24, 32) |
461 | * @param scan Bytes per one scanline |
||
462 | * |
||
463 | */ |
||
1501 | palkovsky | 464 | static void screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan) |
1363 | vana | 465 | { |
466 | switch (bpp) { |
||
467 | case 8: |
||
1555 | palkovsky | 468 | screen.rgb2scr = rgb_1byte; |
469 | screen.scr2rgb = byte1_rgb; |
||
1485 | palkovsky | 470 | screen.pixelbytes = 1; |
1363 | vana | 471 | break; |
472 | case 16: |
||
1555 | palkovsky | 473 | screen.rgb2scr = rgb_2byte; |
474 | screen.scr2rgb = byte2_rgb; |
||
1485 | palkovsky | 475 | screen.pixelbytes = 2; |
1363 | vana | 476 | break; |
477 | case 24: |
||
1555 | palkovsky | 478 | screen.rgb2scr = rgb_3byte; |
479 | screen.scr2rgb = byte3_rgb; |
||
1485 | palkovsky | 480 | screen.pixelbytes = 3; |
1363 | vana | 481 | break; |
482 | case 32: |
||
1555 | palkovsky | 483 | screen.rgb2scr = rgb_4byte; |
484 | screen.scr2rgb = byte4_rgb; |
||
1485 | palkovsky | 485 | screen.pixelbytes = 4; |
1363 | vana | 486 | break; |
487 | } |
||
488 | |||
489 | |||
1485 | palkovsky | 490 | screen.fbaddress = (unsigned char *) addr; |
491 | screen.xres = xres; |
||
492 | screen.yres = yres; |
||
493 | screen.scanline = scan; |
||
1363 | vana | 494 | |
1485 | palkovsky | 495 | /* Create first viewport */ |
496 | viewport_create(0,0,xres,yres); |
||
497 | } |
||
1363 | vana | 498 | |
1552 | palkovsky | 499 | /** Hide cursor if it is shown */ |
1673 | palkovsky | 500 | static void cursor_hide(viewport_t *vport) |
1500 | palkovsky | 501 | { |
502 | if (vport->cursor_active && vport->cursor_shown) { |
||
1673 | palkovsky | 503 | invert_char(vport, vport->cur_row, vport->cur_col); |
1500 | palkovsky | 504 | vport->cursor_shown = 0; |
505 | } |
||
506 | } |
||
507 | |||
1552 | palkovsky | 508 | /** Show cursor if cursor showing is enabled */ |
1673 | palkovsky | 509 | static void cursor_print(viewport_t *vport) |
1500 | palkovsky | 510 | { |
511 | /* Do not check for cursor_shown */ |
||
512 | if (vport->cursor_active) { |
||
1673 | palkovsky | 513 | invert_char(vport, vport->cur_row, vport->cur_col); |
1500 | palkovsky | 514 | vport->cursor_shown = 1; |
515 | } |
||
516 | } |
||
517 | |||
1552 | palkovsky | 518 | /** Invert cursor, if it is enabled */ |
1673 | palkovsky | 519 | static void cursor_blink(viewport_t *vport) |
1500 | palkovsky | 520 | { |
521 | if (vport->cursor_shown) |
||
1673 | palkovsky | 522 | cursor_hide(vport); |
1500 | palkovsky | 523 | else |
1673 | palkovsky | 524 | cursor_print(vport); |
1500 | palkovsky | 525 | } |
526 | |||
1498 | palkovsky | 527 | /** Draw character at given position relative to viewport |
528 | * |
||
1709 | jermar | 529 | * @param vport Viewport identification |
1498 | palkovsky | 530 | * @param c Character to print |
531 | * @param row Screen position relative to viewport |
||
532 | * @param col Screen position relative to viewport |
||
1558 | palkovsky | 533 | * @param transparent If false, print background color with character |
1498 | palkovsky | 534 | */ |
1673 | palkovsky | 535 | static void draw_char(viewport_t *vport, char c, unsigned int row, unsigned int col, |
536 | style_t style, int transparent) |
||
1486 | palkovsky | 537 | { |
1500 | palkovsky | 538 | /* Optimize - do not hide cursor if we are going to overwrite it */ |
539 | if (vport->cursor_active && vport->cursor_shown && |
||
540 | (vport->cur_col != col || vport->cur_row != row)) |
||
1673 | palkovsky | 541 | invert_char(vport, vport->cur_row, vport->cur_col); |
1486 | palkovsky | 542 | |
1673 | palkovsky | 543 | draw_glyph(vport, c, col * COL_WIDTH, row * FONT_SCANLINES, style, transparent); |
1489 | palkovsky | 544 | |
545 | vport->cur_col = col; |
||
546 | vport->cur_row = row; |
||
547 | |||
548 | vport->cur_col++; |
||
549 | if (vport->cur_col>= vport->cols) { |
||
550 | vport->cur_col = 0; |
||
551 | vport->cur_row++; |
||
552 | if (vport->cur_row >= vport->rows) |
||
553 | vport->cur_row--; |
||
1486 | palkovsky | 554 | } |
1673 | palkovsky | 555 | cursor_print(vport); |
1486 | palkovsky | 556 | } |
557 | |||
1552 | palkovsky | 558 | /** Draw text data to viewport |
559 | * |
||
1709 | jermar | 560 | * @param vport Viewport id |
1552 | palkovsky | 561 | * @param data Text data fitting exactly into viewport |
562 | */ |
||
1673 | palkovsky | 563 | static void draw_text_data(viewport_t *vport, keyfield_t *data) |
1505 | palkovsky | 564 | { |
565 | int i; |
||
566 | char c; |
||
1515 | palkovsky | 567 | int col,row; |
1505 | palkovsky | 568 | |
1673 | palkovsky | 569 | clear_port(vport); |
1505 | palkovsky | 570 | for (i=0; i < vport->cols * vport->rows; i++) { |
1509 | palkovsky | 571 | if (data[i].character == ' ' && style_same(data[i].style,vport->style)) |
1505 | palkovsky | 572 | continue; |
1515 | palkovsky | 573 | col = i % vport->cols; |
574 | row = i / vport->cols; |
||
1673 | palkovsky | 575 | draw_glyph(vport, data[i].character, col * COL_WIDTH, row * FONT_SCANLINES, |
1558 | palkovsky | 576 | data[i].style, style_same(data[i].style,vport->style)); |
1505 | palkovsky | 577 | } |
1673 | palkovsky | 578 | cursor_print(vport); |
1505 | palkovsky | 579 | } |
580 | |||
1555 | palkovsky | 581 | |
582 | /** Return first free pixmap */ |
||
583 | static int find_free_pixmap(void) |
||
584 | { |
||
585 | int i; |
||
586 | |||
587 | for (i=0;i < MAX_PIXMAPS;i++) |
||
588 | if (!pixmaps[i].data) |
||
589 | return i; |
||
590 | return -1; |
||
591 | } |
||
592 | |||
593 | static void putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color) |
||
594 | { |
||
595 | pixmap_t *pmap = &pixmaps[pm]; |
||
596 | int pos = (y * pmap->width + x) * screen.pixelbytes; |
||
597 | |||
598 | (*screen.rgb2scr)(&pmap->data[pos],color); |
||
599 | } |
||
600 | |||
601 | /** Create a new pixmap and return appropriate ID */ |
||
602 | static int shm2pixmap(char *shm, size_t size) |
||
603 | { |
||
604 | int pm; |
||
605 | pixmap_t *pmap; |
||
606 | |||
607 | pm = find_free_pixmap(); |
||
608 | if (pm == -1) |
||
609 | return ELIMIT; |
||
610 | pmap = &pixmaps[pm]; |
||
611 | |||
612 | if (ppm_get_data(shm, size, &pmap->width, &pmap->height)) |
||
613 | return EINVAL; |
||
614 | |||
615 | pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes); |
||
616 | if (!pmap->data) |
||
617 | return ENOMEM; |
||
618 | |||
619 | ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, |
||
1673 | palkovsky | 620 | (putpixel_cb_t)putpixel_pixmap, (void *)pm); |
1555 | palkovsky | 621 | |
622 | return pm; |
||
623 | } |
||
624 | |||
1552 | palkovsky | 625 | /** Handle shared memory communication calls |
626 | * |
||
627 | * Protocol for drawing pixmaps: |
||
628 | * - FB_PREPARE_SHM(client shm identification) |
||
629 | * - IPC_M_SEND_AS_AREA |
||
630 | * - FB_DRAW_PPM(startx,starty) |
||
631 | * - FB_DROP_SHM |
||
632 | * |
||
633 | * Protocol for text drawing |
||
634 | * - IPC_M_SEND_AS_AREA |
||
635 | * - FB_DRAW_TEXT_DATA |
||
636 | * |
||
637 | * @param callid Callid of the current call |
||
638 | * @param call Current call data |
||
639 | * @param vp Active viewport |
||
640 | * @return 0 if the call was not handled byt this function, 1 otherwise |
||
641 | * |
||
642 | * note: this function is not threads safe, you would have |
||
643 | * to redefine static variables with __thread |
||
644 | */ |
||
1547 | palkovsky | 645 | static int shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
646 | { |
||
647 | static keyfield_t *interbuffer = NULL; |
||
648 | static size_t intersize = 0; |
||
1505 | palkovsky | 649 | |
1555 | palkovsky | 650 | static char *shm = NULL; |
651 | static ipcarg_t shm_id = 0; |
||
652 | static size_t shm_size; |
||
1547 | palkovsky | 653 | |
654 | int handled = 1; |
||
655 | int retval = 0; |
||
656 | viewport_t *vport = &viewports[vp]; |
||
657 | unsigned int x,y; |
||
658 | |||
659 | switch (IPC_GET_METHOD(*call)) { |
||
660 | case IPC_M_AS_AREA_SEND: |
||
661 | /* We accept one area for data interchange */ |
||
1555 | palkovsky | 662 | if (IPC_GET_ARG1(*call) == shm_id) { |
1547 | palkovsky | 663 | void *dest = as_get_mappable_page(IPC_GET_ARG2(*call)); |
1555 | palkovsky | 664 | shm_size = IPC_GET_ARG2(*call); |
1547 | palkovsky | 665 | if (!ipc_answer_fast(callid, 0, (sysarg_t)dest, 0)) |
1555 | palkovsky | 666 | shm = dest; |
1547 | palkovsky | 667 | else |
1555 | palkovsky | 668 | shm_id = 0; |
669 | if (shm[0] != 'P') |
||
1547 | palkovsky | 670 | while (1) |
671 | ; |
||
672 | return 1; |
||
673 | } else { |
||
674 | intersize = IPC_GET_ARG2(*call); |
||
675 | receive_comm_area(callid,call,(void **)&interbuffer); |
||
676 | } |
||
677 | return 1; |
||
678 | case FB_PREPARE_SHM: |
||
1555 | palkovsky | 679 | if (shm_id) |
1547 | palkovsky | 680 | retval = EBUSY; |
681 | else |
||
1555 | palkovsky | 682 | shm_id = IPC_GET_ARG1(*call); |
1547 | palkovsky | 683 | break; |
684 | |||
685 | case FB_DROP_SHM: |
||
1555 | palkovsky | 686 | if (shm) { |
687 | as_area_destroy(shm); |
||
688 | shm = NULL; |
||
1547 | palkovsky | 689 | } |
1555 | palkovsky | 690 | shm_id = 0; |
1547 | palkovsky | 691 | break; |
1555 | palkovsky | 692 | |
693 | case FB_SHM2PIXMAP: |
||
694 | if (!shm) { |
||
695 | retval = EINVAL; |
||
696 | break; |
||
697 | } |
||
698 | retval = shm2pixmap(shm, shm_size); |
||
699 | break; |
||
1547 | palkovsky | 700 | case FB_DRAW_PPM: |
1555 | palkovsky | 701 | if (!shm) { |
1547 | palkovsky | 702 | retval = EINVAL; |
703 | break; |
||
704 | } |
||
705 | x = IPC_GET_ARG1(*call); |
||
706 | y = IPC_GET_ARG2(*call); |
||
707 | if (x > vport->width || y > vport->height) { |
||
708 | retval = EINVAL; |
||
709 | break; |
||
710 | } |
||
711 | |||
1555 | palkovsky | 712 | ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), IPC_GET_ARG2(*call), |
1673 | palkovsky | 713 | vport->width - x, vport->height - y, (putpixel_cb_t)putpixel, vport); |
1547 | palkovsky | 714 | break; |
715 | case FB_DRAW_TEXT_DATA: |
||
716 | if (!interbuffer) { |
||
717 | retval = EINVAL; |
||
718 | break; |
||
719 | } |
||
720 | if (intersize < vport->cols*vport->rows*sizeof(*interbuffer)) { |
||
721 | retval = EINVAL; |
||
722 | break; |
||
723 | } |
||
1673 | palkovsky | 724 | draw_text_data(vport, interbuffer); |
1547 | palkovsky | 725 | break; |
726 | default: |
||
727 | handled = 0; |
||
728 | } |
||
729 | |||
730 | if (handled) |
||
731 | ipc_answer_fast(callid, retval, 0, 0); |
||
732 | return handled; |
||
733 | } |
||
734 | |||
1711 | palkovsky | 735 | static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap) |
1552 | palkovsky | 736 | { |
737 | int x,y; |
||
738 | int rowsize; |
||
739 | int tmp; |
||
1711 | palkovsky | 740 | int width = vport->width; |
741 | int height = vport->height; |
||
1552 | palkovsky | 742 | |
1711 | palkovsky | 743 | if (width + vport->x > screen.xres) |
744 | width = screen.xres - vport->x; |
||
745 | if (height + vport->y > screen.yres) |
||
746 | height = screen.yres - vport->y; |
||
747 | |||
748 | rowsize = width * screen.pixelbytes; |
||
749 | |||
750 | for (y=0;y < height; y++) { |
||
751 | tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; |
||
752 | memcpy(pmap->data + rowsize*y, screen.fbaddress + tmp, rowsize); |
||
753 | } |
||
754 | } |
||
755 | |||
756 | /** Save viewport to pixmap */ |
||
757 | static int save_vp_to_pixmap(viewport_t *vport) |
||
758 | { |
||
759 | int pm; |
||
760 | pixmap_t *pmap; |
||
761 | |||
1552 | palkovsky | 762 | pm = find_free_pixmap(); |
763 | if (pm == -1) |
||
764 | return ELIMIT; |
||
765 | |||
766 | pmap = &pixmaps[pm]; |
||
767 | pmap->data = malloc(screen.pixelbytes * vport->width * vport->height); |
||
768 | if (!pmap->data) |
||
769 | return ENOMEM; |
||
770 | |||
771 | pmap->width = vport->width; |
||
772 | pmap->height = vport->height; |
||
1711 | palkovsky | 773 | |
774 | copy_vp_to_pixmap(vport, pmap); |
||
1552 | palkovsky | 775 | |
776 | return pm; |
||
777 | } |
||
778 | |||
779 | /** Draw pixmap on screen |
||
780 | * |
||
781 | * @param vp Viewport to draw on |
||
782 | * @param pm Pixmap identifier |
||
783 | */ |
||
784 | static int draw_pixmap(int vp, int pm) |
||
785 | { |
||
786 | pixmap_t *pmap = &pixmaps[pm]; |
||
787 | viewport_t *vport = &viewports[vp]; |
||
788 | int x,y; |
||
789 | int tmp, srcrowsize; |
||
790 | int realwidth, realheight, realrowsize; |
||
1711 | palkovsky | 791 | int width = vport->width; |
792 | int height = vport->height; |
||
1552 | palkovsky | 793 | |
1711 | palkovsky | 794 | if (width + vport->x > screen.xres) |
795 | width = screen.xres - vport->x; |
||
796 | if (height + vport->y > screen.yres) |
||
797 | height = screen.yres - vport->y; |
||
798 | |||
1552 | palkovsky | 799 | if (!pmap->data) |
800 | return EINVAL; |
||
801 | |||
1711 | palkovsky | 802 | realwidth = pmap->width <= width ? pmap->width : width; |
803 | realheight = pmap->height <= height ? pmap->height : height; |
||
1552 | palkovsky | 804 | |
805 | srcrowsize = vport->width * screen.pixelbytes; |
||
806 | realrowsize = realwidth * screen.pixelbytes; |
||
807 | |||
808 | for (y=0; y < realheight; y++) { |
||
809 | tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; |
||
810 | memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize, realrowsize); |
||
811 | } |
||
1567 | palkovsky | 812 | return 0; |
1552 | palkovsky | 813 | } |
814 | |||
1646 | palkovsky | 815 | /** Tick animation one step forward */ |
816 | static void anims_tick(void) |
||
817 | { |
||
818 | int i; |
||
819 | static int counts = 0; |
||
820 | |||
821 | /* Limit redrawing */ |
||
822 | counts = (counts+1) % 8; |
||
823 | if (counts) |
||
824 | return; |
||
825 | |||
826 | for (i=0; i < MAX_ANIMATIONS; i++) { |
||
827 | if (!animations[i].animlen || !animations[i].initialized || !animations[i].enabled) |
||
828 | continue; |
||
829 | draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]); |
||
830 | animations[i].pos = (animations[i].pos+1) % animations[i].animlen; |
||
831 | } |
||
832 | } |
||
833 | |||
1711 | palkovsky | 834 | |
835 | static int pointer_x, pointer_y; |
||
836 | static int pointer_shown; |
||
837 | static int pointer_vport = -1; |
||
838 | static int pointer_pixmap = -1; |
||
839 | |||
840 | static void mouse_show(void) |
||
841 | { |
||
842 | int i,j; |
||
843 | int visibility; |
||
844 | int color; |
||
845 | int bytepos; |
||
846 | |||
847 | /* Save image under the cursor */ |
||
848 | if (pointer_vport == -1) { |
||
849 | pointer_vport = viewport_create(pointer_x, pointer_y, pointer_width, pointer_height); |
||
850 | if (pointer_vport < 0) |
||
851 | return; |
||
852 | } else { |
||
853 | viewports[pointer_vport].x = pointer_x; |
||
854 | viewports[pointer_vport].y = pointer_y; |
||
855 | } |
||
856 | |||
857 | if (pointer_pixmap == -1) |
||
858 | pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]); |
||
859 | else |
||
860 | copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]); |
||
861 | |||
862 | /* Draw cursor */ |
||
863 | for (i=0; i < pointer_height; i++) |
||
864 | for (j=0;j < pointer_width; j++) { |
||
865 | bytepos = i*((pointer_width-1)/8+1) + j/8; |
||
866 | visibility = pointer_mask_bits[bytepos] & (1 << (j % 8)); |
||
867 | if (visibility) { |
||
868 | color = pointer_bits[bytepos] & (1 << (j % 8)) ? 0 : 0xffffff; |
||
869 | if (pointer_x+j < screen.xres && pointer_y+i < screen.yres) |
||
870 | putpixel(&viewports[0], pointer_x+j, pointer_y+i, color); |
||
871 | } |
||
872 | } |
||
873 | pointer_shown = 1; |
||
874 | } |
||
875 | |||
876 | static void mouse_hide(void) |
||
877 | { |
||
878 | /* Restore image under the cursor */ |
||
879 | if (pointer_shown) { |
||
880 | draw_pixmap(pointer_vport, pointer_pixmap); |
||
881 | pointer_shown = 0; |
||
882 | } |
||
883 | } |
||
884 | |||
885 | static void mouse_move(unsigned int x, unsigned int y) |
||
886 | { |
||
887 | mouse_hide(); |
||
888 | pointer_x = x; |
||
889 | pointer_y = y; |
||
890 | mouse_show(); |
||
891 | } |
||
892 | |||
1646 | palkovsky | 893 | static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
894 | { |
||
895 | int handled = 1; |
||
896 | int retval = 0; |
||
897 | int i,nvp; |
||
898 | int newval; |
||
899 | |||
900 | switch (IPC_GET_METHOD(*call)) { |
||
901 | case FB_ANIM_CREATE: |
||
902 | nvp = IPC_GET_ARG1(*call); |
||
903 | if (nvp == -1) |
||
904 | nvp = vp; |
||
905 | if (nvp >= MAX_VIEWPORTS || nvp < 0 || !viewports[nvp].initialized) { |
||
906 | retval = EINVAL; |
||
907 | break; |
||
908 | } |
||
909 | for (i=0; i < MAX_ANIMATIONS; i++) { |
||
910 | if (! animations[i].initialized) |
||
911 | break; |
||
912 | } |
||
913 | if (i == MAX_ANIMATIONS) { |
||
914 | retval = ELIMIT; |
||
915 | break; |
||
916 | } |
||
917 | animations[i].initialized = 1; |
||
918 | animations[i].animlen = 0; |
||
919 | animations[i].pos = 0; |
||
920 | animations[i].enabled = 0; |
||
921 | animations[i].vp = nvp; |
||
922 | retval = i; |
||
923 | break; |
||
924 | case FB_ANIM_DROP: |
||
925 | i = IPC_GET_ARG1(*call); |
||
926 | if (nvp >= MAX_ANIMATIONS || i < 0) { |
||
927 | retval = EINVAL; |
||
928 | break; |
||
929 | } |
||
930 | animations[i].initialized = 0; |
||
931 | break; |
||
932 | case FB_ANIM_ADDPIXMAP: |
||
933 | i = IPC_GET_ARG1(*call); |
||
934 | if (i >= MAX_ANIMATIONS || i < 0 || !animations[i].initialized) { |
||
935 | retval = EINVAL; |
||
936 | break; |
||
937 | } |
||
938 | if (animations[i].animlen == MAX_ANIM_LEN) { |
||
939 | retval = ELIMIT; |
||
940 | break; |
||
941 | } |
||
942 | newval = IPC_GET_ARG2(*call); |
||
943 | if (newval < 0 || newval > MAX_PIXMAPS || !pixmaps[newval].data) { |
||
944 | retval = EINVAL; |
||
945 | break; |
||
946 | } |
||
947 | animations[i].pixmaps[animations[i].animlen++] = newval; |
||
948 | break; |
||
949 | case FB_ANIM_CHGVP: |
||
950 | i = IPC_GET_ARG1(*call); |
||
951 | if (i >= MAX_ANIMATIONS || i < 0) { |
||
952 | retval = EINVAL; |
||
953 | break; |
||
954 | } |
||
955 | nvp = IPC_GET_ARG2(*call); |
||
956 | if (nvp == -1) |
||
957 | nvp = vp; |
||
958 | if (nvp >= MAX_VIEWPORTS || nvp < 0 || !viewports[nvp].initialized) { |
||
959 | retval = EINVAL; |
||
960 | break; |
||
961 | } |
||
962 | animations[i].vp = nvp; |
||
963 | break; |
||
964 | case FB_ANIM_START: |
||
965 | case FB_ANIM_STOP: |
||
966 | i = IPC_GET_ARG1(*call); |
||
967 | if (i >= MAX_ANIMATIONS || i < 0) { |
||
968 | retval = EINVAL; |
||
969 | break; |
||
970 | } |
||
971 | newval = (IPC_GET_METHOD(*call) == FB_ANIM_START); |
||
972 | if (newval ^ animations[i].enabled) { |
||
973 | animations[i].enabled = newval; |
||
974 | anims_enabled += newval ? 1 : -1; |
||
975 | } |
||
976 | break; |
||
977 | default: |
||
978 | handled = 0; |
||
979 | } |
||
980 | if (handled) |
||
981 | ipc_answer_fast(callid, retval, 0, 0); |
||
982 | return handled; |
||
983 | } |
||
984 | |||
1552 | palkovsky | 985 | /** Handler for messages concerning pixmap handling */ |
986 | static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
||
987 | { |
||
988 | int handled = 1; |
||
989 | int retval = 0; |
||
990 | int i,nvp; |
||
991 | |||
992 | switch (IPC_GET_METHOD(*call)) { |
||
993 | case FB_VP_DRAW_PIXMAP: |
||
994 | nvp = IPC_GET_ARG1(*call); |
||
995 | if (nvp == -1) |
||
996 | nvp = vp; |
||
997 | if (nvp < 0 || nvp >= MAX_VIEWPORTS || !viewports[nvp].initialized) { |
||
998 | retval = EINVAL; |
||
999 | break; |
||
1000 | } |
||
1001 | i = IPC_GET_ARG2(*call); |
||
1002 | retval = draw_pixmap(nvp, i); |
||
1003 | break; |
||
1004 | case FB_VP2PIXMAP: |
||
1005 | nvp = IPC_GET_ARG1(*call); |
||
1006 | if (nvp == -1) |
||
1007 | nvp = vp; |
||
1008 | if (nvp < 0 || nvp >= MAX_VIEWPORTS || !viewports[nvp].initialized) |
||
1009 | retval = EINVAL; |
||
1010 | else |
||
1711 | palkovsky | 1011 | retval = save_vp_to_pixmap(&viewports[nvp]); |
1552 | palkovsky | 1012 | break; |
1013 | case FB_DROP_PIXMAP: |
||
1014 | i = IPC_GET_ARG1(*call); |
||
1015 | if (i >= MAX_PIXMAPS) { |
||
1016 | retval = EINVAL; |
||
1017 | break; |
||
1018 | } |
||
1019 | if (pixmaps[i].data) { |
||
1020 | free(pixmaps[i].data); |
||
1021 | pixmaps[i].data = NULL; |
||
1022 | } |
||
1023 | break; |
||
1024 | default: |
||
1025 | handled = 0; |
||
1026 | } |
||
1027 | |||
1028 | if (handled) |
||
1029 | ipc_answer_fast(callid, retval, 0, 0); |
||
1030 | return handled; |
||
1031 | |||
1032 | } |
||
1033 | |||
1498 | palkovsky | 1034 | /** Function for handling connections to FB |
1035 | * |
||
1036 | */ |
||
1490 | palkovsky | 1037 | static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
1363 | vana | 1038 | { |
1485 | palkovsky | 1039 | ipc_callid_t callid; |
1040 | ipc_call_t call; |
||
1041 | int retval; |
||
1042 | int i; |
||
1043 | unsigned int row,col; |
||
1044 | char c; |
||
1486 | palkovsky | 1045 | |
1485 | palkovsky | 1046 | int vp = 0; |
1486 | palkovsky | 1047 | viewport_t *vport = &viewports[0]; |
1363 | vana | 1048 | |
1485 | palkovsky | 1049 | if (client_connected) { |
1050 | ipc_answer_fast(iid, ELIMIT, 0,0); |
||
1051 | return; |
||
1052 | } |
||
1486 | palkovsky | 1053 | client_connected = 1; |
1485 | palkovsky | 1054 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
1363 | vana | 1055 | |
1485 | palkovsky | 1056 | while (1) { |
1646 | palkovsky | 1057 | if (vport->cursor_active || anims_enabled) |
1640 | palkovsky | 1058 | callid = async_get_call_timeout(&call,250000); |
1059 | else |
||
1060 | callid = async_get_call(&call); |
||
1061 | |||
1713 | palkovsky | 1062 | mouse_hide(); |
1500 | palkovsky | 1063 | if (!callid) { |
1673 | palkovsky | 1064 | cursor_blink(vport); |
1646 | palkovsky | 1065 | anims_tick(); |
1500 | palkovsky | 1066 | continue; |
1067 | } |
||
1547 | palkovsky | 1068 | if (shm_handle(callid, &call, vp)) |
1069 | continue; |
||
1552 | palkovsky | 1070 | if (pixmap_handle(callid, &call, vp)) |
1071 | continue; |
||
1646 | palkovsky | 1072 | if (anim_handle(callid, &call, vp)) |
1073 | continue; |
||
1547 | palkovsky | 1074 | |
1485 | palkovsky | 1075 | switch (IPC_GET_METHOD(call)) { |
1076 | case IPC_M_PHONE_HUNGUP: |
||
1077 | client_connected = 0; |
||
1078 | /* cleanup other viewports */ |
||
1079 | for (i=1; i < MAX_VIEWPORTS; i++) |
||
1486 | palkovsky | 1080 | vport->initialized = 0; |
1485 | palkovsky | 1081 | return; /* Exit thread */ |
1505 | palkovsky | 1082 | |
1485 | palkovsky | 1083 | case FB_PUTCHAR: |
1558 | palkovsky | 1084 | case FB_TRANS_PUTCHAR: |
1485 | palkovsky | 1085 | c = IPC_GET_ARG1(call); |
1086 | row = IPC_GET_ARG2(call); |
||
1087 | col = IPC_GET_ARG3(call); |
||
1486 | palkovsky | 1088 | if (row >= vport->rows || col >= vport->cols) { |
1485 | palkovsky | 1089 | retval = EINVAL; |
1090 | break; |
||
1091 | } |
||
1092 | ipc_answer_fast(callid,0,0,0); |
||
1486 | palkovsky | 1093 | |
1673 | palkovsky | 1094 | draw_char(vport, c, row, col, vport->style, IPC_GET_METHOD(call) == FB_TRANS_PUTCHAR); |
1485 | palkovsky | 1095 | continue; /* msg already answered */ |
1096 | case FB_CLEAR: |
||
1673 | palkovsky | 1097 | clear_port(vport); |
1098 | cursor_print(vport); |
||
1485 | palkovsky | 1099 | retval = 0; |
1100 | break; |
||
1486 | palkovsky | 1101 | case FB_CURSOR_GOTO: |
1102 | row = IPC_GET_ARG1(call); |
||
1103 | col = IPC_GET_ARG2(call); |
||
1104 | if (row >= vport->rows || col >= vport->cols) { |
||
1105 | retval = EINVAL; |
||
1106 | break; |
||
1107 | } |
||
1108 | retval = 0; |
||
1673 | palkovsky | 1109 | cursor_hide(vport); |
1486 | palkovsky | 1110 | vport->cur_col = col; |
1111 | vport->cur_row = row; |
||
1673 | palkovsky | 1112 | cursor_print(vport); |
1486 | palkovsky | 1113 | break; |
1114 | case FB_CURSOR_VISIBILITY: |
||
1673 | palkovsky | 1115 | cursor_hide(vport); |
1500 | palkovsky | 1116 | vport->cursor_active = IPC_GET_ARG1(call); |
1673 | palkovsky | 1117 | cursor_print(vport); |
1486 | palkovsky | 1118 | retval = 0; |
1119 | break; |
||
1485 | palkovsky | 1120 | case FB_GET_CSIZE: |
1486 | palkovsky | 1121 | ipc_answer_fast(callid, 0, vport->rows, vport->cols); |
1485 | palkovsky | 1122 | continue; |
1486 | palkovsky | 1123 | case FB_SCROLL: |
1124 | i = IPC_GET_ARG1(call); |
||
1125 | if (i > vport->rows || i < (- (int)vport->rows)) { |
||
1126 | retval = EINVAL; |
||
1127 | break; |
||
1128 | } |
||
1673 | palkovsky | 1129 | cursor_hide(vport); |
1130 | scroll_port(vport, i*FONT_SCANLINES); |
||
1131 | cursor_print(vport); |
||
1486 | palkovsky | 1132 | retval = 0; |
1133 | break; |
||
1672 | palkovsky | 1134 | case FB_VIEWPORT_DB: |
1135 | /* Enable double buffering */ |
||
1136 | i = IPC_GET_ARG1(call); |
||
1137 | if (i == -1) |
||
1138 | i = vp; |
||
1139 | if (i < 0 || i >= MAX_VIEWPORTS) { |
||
1140 | retval = EINVAL; |
||
1141 | break; |
||
1142 | } |
||
1143 | if (! viewports[i].initialized ) { |
||
1144 | while (1) |
||
1145 | ; |
||
1146 | retval = EADDRNOTAVAIL; |
||
1147 | break; |
||
1148 | } |
||
1149 | viewports[i].dboffset = 0; |
||
1150 | if (IPC_GET_ARG2(call) == 1 && !viewports[i].dbdata) |
||
1151 | viewports[i].dbdata = malloc(screen.pixelbytes*viewports[i].width * viewports[i].height); |
||
1152 | else if (IPC_GET_ARG2(call) == 0 && viewports[i].dbdata) { |
||
1153 | free(viewports[i].dbdata); |
||
1154 | viewports[i].dbdata = NULL; |
||
1155 | } |
||
1156 | retval = 0; |
||
1157 | break; |
||
1486 | palkovsky | 1158 | case FB_VIEWPORT_SWITCH: |
1159 | i = IPC_GET_ARG1(call); |
||
1160 | if (i < 0 || i >= MAX_VIEWPORTS) { |
||
1161 | retval = EINVAL; |
||
1162 | break; |
||
1163 | } |
||
1164 | if (! viewports[i].initialized ) { |
||
1165 | retval = EADDRNOTAVAIL; |
||
1166 | break; |
||
1167 | } |
||
1673 | palkovsky | 1168 | cursor_hide(vport); |
1486 | palkovsky | 1169 | vp = i; |
1170 | vport = &viewports[vp]; |
||
1673 | palkovsky | 1171 | cursor_print(vport); |
1486 | palkovsky | 1172 | retval = 0; |
1173 | break; |
||
1174 | case FB_VIEWPORT_CREATE: |
||
1175 | retval = viewport_create(IPC_GET_ARG1(call) >> 16, |
||
1176 | IPC_GET_ARG1(call) & 0xffff, |
||
1177 | IPC_GET_ARG2(call) >> 16, |
||
1178 | IPC_GET_ARG2(call) & 0xffff); |
||
1179 | break; |
||
1180 | case FB_VIEWPORT_DELETE: |
||
1181 | i = IPC_GET_ARG1(call); |
||
1182 | if (i < 0 || i >= MAX_VIEWPORTS) { |
||
1183 | retval = EINVAL; |
||
1184 | break; |
||
1185 | } |
||
1186 | if (! viewports[i].initialized ) { |
||
1187 | retval = EADDRNOTAVAIL; |
||
1188 | break; |
||
1189 | } |
||
1190 | viewports[i].initialized = 0; |
||
1672 | palkovsky | 1191 | if (viewports[i].dbdata) { |
1192 | free(viewports[i].dbdata); |
||
1193 | viewports[i].dbdata = NULL; |
||
1194 | } |
||
1486 | palkovsky | 1195 | retval = 0; |
1196 | break; |
||
1197 | case FB_SET_STYLE: |
||
1509 | palkovsky | 1198 | vport->style.fg_color = IPC_GET_ARG1(call); |
1199 | vport->style.bg_color = IPC_GET_ARG2(call); |
||
1486 | palkovsky | 1200 | retval = 0; |
1201 | break; |
||
1202 | case FB_GET_RESOLUTION: |
||
1203 | ipc_answer_fast(callid, 0, screen.xres,screen.yres); |
||
1204 | continue; |
||
1707 | palkovsky | 1205 | case FB_POINTER_MOVE: |
1711 | palkovsky | 1206 | mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
1707 | palkovsky | 1207 | break; |
1485 | palkovsky | 1208 | default: |
1209 | retval = ENOENT; |
||
1210 | } |
||
1211 | ipc_answer_fast(callid,retval,0,0); |
||
1363 | vana | 1212 | } |
1485 | palkovsky | 1213 | } |
1363 | vana | 1214 | |
1498 | palkovsky | 1215 | /** Initialization of framebuffer */ |
1490 | palkovsky | 1216 | int fb_init(void) |
1485 | palkovsky | 1217 | { |
1501 | palkovsky | 1218 | void *fb_ph_addr; |
1490 | palkovsky | 1219 | unsigned int fb_width; |
1220 | unsigned int fb_height; |
||
1221 | unsigned int fb_bpp; |
||
1222 | unsigned int fb_scanline; |
||
1501 | palkovsky | 1223 | void *fb_addr; |
1224 | size_t asz; |
||
1363 | vana | 1225 | |
1490 | palkovsky | 1226 | async_set_client_connection(fb_client_connection); |
1363 | vana | 1227 | |
1501 | palkovsky | 1228 | fb_ph_addr=(void *)sysinfo_value("fb.address.physical"); |
1490 | palkovsky | 1229 | fb_width=sysinfo_value("fb.width"); |
1230 | fb_height=sysinfo_value("fb.height"); |
||
1231 | fb_bpp=sysinfo_value("fb.bpp"); |
||
1232 | fb_scanline=sysinfo_value("fb.scanline"); |
||
1233 | |||
1501 | palkovsky | 1234 | asz = fb_scanline*fb_height; |
1235 | fb_addr = as_get_mappable_page(asz); |
||
1485 | palkovsky | 1236 | |
1501 | palkovsky | 1237 | map_physmem(fb_ph_addr, fb_addr, ALIGN_UP(asz,PAGE_SIZE) >>PAGE_WIDTH, |
1490 | palkovsky | 1238 | AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); |
1239 | |||
1240 | screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline); |
||
1363 | vana | 1241 | |
1485 | palkovsky | 1242 | return 0; |
1363 | vana | 1243 | } |
1490 | palkovsky | 1244 | |
1649 | cejka | 1245 | |
1246 | /** |
||
1247 | * @} |
||
1248 | */ |