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