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