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