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