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