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