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