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