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