Rev 4263 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4263 | Rev 4327 | ||
---|---|---|---|
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 <console/color.h> |
54 | #include <console/color.h> |
55 | #include <console/style.h> |
55 | #include <console/style.h> |
56 | #include <async.h> |
56 | #include <async.h> |
57 | #include <bool.h> |
57 | #include <bool.h> |
58 | 58 | ||
59 | #include "font-8x16.h" |
59 | #include "font-8x16.h" |
60 | #include "fb.h" |
60 | #include "fb.h" |
61 | #include "main.h" |
61 | #include "main.h" |
62 | #include "../console/screenbuffer.h" |
62 | #include "../console/screenbuffer.h" |
63 | #include "ppm.h" |
63 | #include "ppm.h" |
64 | 64 | ||
65 | #include "pointer.xbm" |
65 | #include "pointer.xbm" |
66 | #include "pointer_mask.xbm" |
66 | #include "pointer_mask.xbm" |
67 | 67 | ||
68 | #define DEFAULT_BGCOLOR 0xf0f0f0 |
68 | #define DEFAULT_BGCOLOR 0xf0f0f0 |
69 | #define DEFAULT_FGCOLOR 0x000000 |
69 | #define DEFAULT_FGCOLOR 0x000000 |
70 | 70 | ||
71 | #define GLYPH_UNAVAIL '?' |
71 | #define GLYPH_UNAVAIL '?' |
72 | 72 | ||
73 | #define MAX_ANIM_LEN 8 |
73 | #define MAX_ANIM_LEN 8 |
74 | #define MAX_ANIMATIONS 4 |
74 | #define MAX_ANIMATIONS 4 |
75 | #define MAX_PIXMAPS 256 /**< Maximum number of saved pixmaps */ |
75 | #define MAX_PIXMAPS 256 /**< Maximum number of saved pixmaps */ |
76 | #define MAX_VIEWPORTS 128 /**< Viewport is a rectangular area on the screen */ |
76 | #define MAX_VIEWPORTS 128 /**< Viewport is a rectangular area on the screen */ |
77 | 77 | ||
78 | /** Function to render a pixel from a RGB value. */ |
78 | /** Function to render a pixel from a RGB value. */ |
79 | typedef void (*rgb_conv_t)(void *, uint32_t); |
79 | typedef void (*rgb_conv_t)(void *, uint32_t); |
80 | 80 | ||
- | 81 | /** Function to render a bit mask. */ |
|
- | 82 | typedef void (*mask_conv_t)(void *, bool); |
|
- | 83 | ||
81 | /** Function to draw a glyph. */ |
84 | /** Function to draw a glyph. */ |
82 | typedef void (*dg_t)(unsigned int x, unsigned int y, bool cursor, |
85 | typedef void (*dg_t)(unsigned int x, unsigned int y, bool cursor, |
83 | uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color); |
86 | uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color); |
84 | 87 | ||
85 | struct { |
88 | struct { |
86 | uint8_t *fb_addr; |
89 | uint8_t *fb_addr; |
87 | 90 | ||
88 | unsigned int xres; |
91 | unsigned int xres; |
89 | unsigned int yres; |
92 | unsigned int yres; |
90 | 93 | ||
91 | unsigned int scanline; |
94 | unsigned int scanline; |
92 | unsigned int glyphscanline; |
95 | unsigned int glyphscanline; |
93 | 96 | ||
94 | unsigned int pixelbytes; |
97 | unsigned int pixelbytes; |
95 | unsigned int glyphbytes; |
98 | unsigned int glyphbytes; |
96 | 99 | ||
97 | /** Pre-rendered mask for rendering glyphs. Specific for the visual. */ |
100 | /** Pre-rendered mask for rendering glyphs. Specific for the visual. */ |
98 | uint8_t *glyphs; |
101 | uint8_t *glyphs; |
99 | 102 | ||
100 | rgb_conv_t rgb_conv; |
103 | rgb_conv_t rgb_conv; |
- | 104 | mask_conv_t mask_conv; |
|
101 | } screen; |
105 | } screen; |
102 | 106 | ||
103 | /** Backbuffer character cell. */ |
107 | /** Backbuffer character cell. */ |
104 | typedef struct { |
108 | typedef struct { |
105 | uint32_t glyph; |
109 | uint32_t glyph; |
106 | uint32_t fg_color; |
110 | uint32_t fg_color; |
107 | uint32_t bg_color; |
111 | uint32_t bg_color; |
108 | } bb_cell_t; |
112 | } bb_cell_t; |
109 | 113 | ||
110 | typedef struct { |
114 | typedef struct { |
111 | bool initialized; |
115 | bool initialized; |
112 | unsigned int x; |
116 | unsigned int x; |
113 | unsigned int y; |
117 | unsigned int y; |
114 | unsigned int width; |
118 | unsigned int width; |
115 | unsigned int height; |
119 | unsigned int height; |
116 | 120 | ||
117 | /* Text support in window */ |
121 | /* Text support in window */ |
118 | unsigned int cols; |
122 | unsigned int cols; |
119 | unsigned int rows; |
123 | unsigned int rows; |
120 | 124 | ||
121 | /* |
125 | /* |
122 | * Style and glyphs for text printing |
126 | * Style and glyphs for text printing |
123 | */ |
127 | */ |
124 | 128 | ||
125 | /** Current attributes. */ |
129 | /** Current attributes. */ |
126 | attr_rgb_t attr; |
130 | attr_rgb_t attr; |
127 | 131 | ||
128 | uint8_t *bgpixel; |
132 | uint8_t *bgpixel; |
129 | 133 | ||
130 | /** |
134 | /** |
131 | * Glyph drawing function for this viewport. Different viewports |
135 | * Glyph drawing function for this viewport. Different viewports |
132 | * might use different drawing functions depending on whether their |
136 | * might use different drawing functions depending on whether their |
133 | * scanlines are aligned on a word boundary. |
137 | * scanlines are aligned on a word boundary. |
134 | */ |
138 | */ |
135 | dg_t dglyph; |
139 | dg_t dglyph; |
136 | 140 | ||
137 | /* Auto-cursor position */ |
141 | /* Auto-cursor position */ |
138 | bool cursor_active; |
142 | bool cursor_active; |
139 | unsigned int cur_col; |
143 | unsigned int cur_col; |
140 | unsigned int cur_row; |
144 | unsigned int cur_row; |
141 | bool cursor_shown; |
145 | bool cursor_shown; |
142 | 146 | ||
143 | /* Back buffer */ |
147 | /* Back buffer */ |
144 | bb_cell_t *backbuf; |
148 | bb_cell_t *backbuf; |
145 | unsigned int bbsize; |
149 | unsigned int bbsize; |
146 | } viewport_t; |
150 | } viewport_t; |
147 | 151 | ||
148 | typedef struct { |
152 | typedef struct { |
149 | bool initialized; |
153 | bool initialized; |
150 | bool enabled; |
154 | bool enabled; |
151 | unsigned int vp; |
155 | unsigned int vp; |
152 | 156 | ||
153 | unsigned int pos; |
157 | unsigned int pos; |
154 | unsigned int animlen; |
158 | unsigned int animlen; |
155 | unsigned int pixmaps[MAX_ANIM_LEN]; |
159 | unsigned int pixmaps[MAX_ANIM_LEN]; |
156 | } animation_t; |
160 | } animation_t; |
157 | 161 | ||
158 | static animation_t animations[MAX_ANIMATIONS]; |
162 | static animation_t animations[MAX_ANIMATIONS]; |
159 | static bool anims_enabled; |
163 | static bool anims_enabled; |
160 | 164 | ||
161 | typedef struct { |
165 | typedef struct { |
162 | unsigned int width; |
166 | unsigned int width; |
163 | unsigned int height; |
167 | unsigned int height; |
164 | uint8_t *data; |
168 | uint8_t *data; |
165 | } pixmap_t; |
169 | } pixmap_t; |
166 | 170 | ||
167 | static pixmap_t pixmaps[MAX_PIXMAPS]; |
171 | static pixmap_t pixmaps[MAX_PIXMAPS]; |
168 | static viewport_t viewports[128]; |
172 | static viewport_t viewports[128]; |
169 | 173 | ||
170 | static bool client_connected = false; /**< Allow only 1 connection */ |
174 | static bool client_connected = false; /**< Allow only 1 connection */ |
171 | 175 | ||
172 | static uint32_t color_table[16] = { |
176 | static uint32_t color_table[16] = { |
173 | [COLOR_BLACK] = 0x000000, |
177 | [COLOR_BLACK] = 0x000000, |
174 | [COLOR_BLUE] = 0x0000f0, |
178 | [COLOR_BLUE] = 0x0000f0, |
175 | [COLOR_GREEN] = 0x00f000, |
179 | [COLOR_GREEN] = 0x00f000, |
176 | [COLOR_CYAN] = 0x00f0f0, |
180 | [COLOR_CYAN] = 0x00f0f0, |
177 | [COLOR_RED] = 0xf00000, |
181 | [COLOR_RED] = 0xf00000, |
178 | [COLOR_MAGENTA] = 0xf000f0, |
182 | [COLOR_MAGENTA] = 0xf000f0, |
179 | [COLOR_YELLOW] = 0xf0f000, |
183 | [COLOR_YELLOW] = 0xf0f000, |
180 | [COLOR_WHITE] = 0xf0f0f0, |
184 | [COLOR_WHITE] = 0xf0f0f0, |
181 | 185 | ||
182 | [8 + COLOR_BLACK] = 0x000000, |
186 | [8 + COLOR_BLACK] = 0x000000, |
183 | [8 + COLOR_BLUE] = 0x0000ff, |
187 | [8 + COLOR_BLUE] = 0x0000ff, |
184 | [8 + COLOR_GREEN] = 0x00ff00, |
188 | [8 + COLOR_GREEN] = 0x00ff00, |
185 | [8 + COLOR_CYAN] = 0x00ffff, |
189 | [8 + COLOR_CYAN] = 0x00ffff, |
186 | [8 + COLOR_RED] = 0xff0000, |
190 | [8 + COLOR_RED] = 0xff0000, |
187 | [8 + COLOR_MAGENTA] = 0xff00ff, |
191 | [8 + COLOR_MAGENTA] = 0xff00ff, |
188 | [8 + COLOR_YELLOW] = 0xffff00, |
192 | [8 + COLOR_YELLOW] = 0xffff00, |
189 | [8 + COLOR_WHITE] = 0xffffff, |
193 | [8 + COLOR_WHITE] = 0xffffff, |
190 | }; |
194 | }; |
191 | 195 | ||
192 | static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a); |
196 | static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a); |
193 | static int rgb_from_style(attr_rgb_t *rgb, int style); |
197 | static int rgb_from_style(attr_rgb_t *rgb, int style); |
194 | static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color, |
198 | static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color, |
195 | ipcarg_t bg_color, ipcarg_t flags); |
199 | ipcarg_t bg_color, ipcarg_t flags); |
196 | 200 | ||
197 | static int fb_set_color(viewport_t *vport, ipcarg_t fg_color, |
201 | static int fb_set_color(viewport_t *vport, ipcarg_t fg_color, |
198 | ipcarg_t bg_color, ipcarg_t attr); |
202 | ipcarg_t bg_color, ipcarg_t attr); |
199 | 203 | ||
200 | static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor, |
204 | static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor, |
201 | uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color); |
205 | uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color); |
202 | static void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor, |
206 | static void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor, |
203 | uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color); |
207 | uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color); |
204 | 208 | ||
205 | static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col, |
209 | static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col, |
206 | unsigned int row); |
210 | unsigned int row); |
207 | 211 | ||
208 | 212 | ||
209 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
213 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
210 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
214 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
211 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
215 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
212 | 216 | ||
213 | #define COL2X(col) ((col) * FONT_WIDTH) |
217 | #define COL2X(col) ((col) * FONT_WIDTH) |
214 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
218 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
215 | 219 | ||
216 | #define X2COL(x) ((x) / FONT_WIDTH) |
220 | #define X2COL(x) ((x) / FONT_WIDTH) |
217 | #define Y2ROW(y) ((y) / FONT_SCANLINES) |
221 | #define Y2ROW(y) ((y) / FONT_SCANLINES) |
218 | 222 | ||
219 | #define FB_POS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
223 | #define FB_POS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
220 | #define BB_POS(vport, col, row) ((row) * vport->cols + (col)) |
224 | #define BB_POS(vport, col, row) ((row) * vport->cols + (col)) |
221 | #define GLYPH_POS(glyph, y, cursor) (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline) |
225 | #define GLYPH_POS(glyph, y, cursor) (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline) |
222 | 226 | ||
223 | 227 | ||
224 | /** ARGB 8:8:8:8 conversion |
228 | /** ARGB 8:8:8:8 conversion |
225 | * |
229 | * |
226 | */ |
230 | */ |
227 | static void rgb_0888(void *dst, uint32_t rgb) |
231 | static void rgb_0888(void *dst, uint32_t rgb) |
228 | { |
232 | { |
229 | *((uint32_t *) dst) = rgb & 0xffffff; |
233 | *((uint32_t *) dst) = rgb & 0x00ffffff; |
- | 234 | } |
|
- | 235 | ||
- | 236 | static void mask_0888(void *dst, bool mask) |
|
- | 237 | { |
|
- | 238 | *((uint32_t *) dst) = (mask ? 0x00ffffff : 0); |
|
230 | } |
239 | } |
231 | 240 | ||
232 | 241 | ||
233 | /** ABGR 8:8:8:8 conversion |
242 | /** ABGR 8:8:8:8 conversion |
234 | * |
243 | * |
235 | */ |
244 | */ |
236 | static void bgr_0888(void *dst, uint32_t rgb) |
245 | static void bgr_0888(void *dst, uint32_t rgb) |
237 | { |
246 | { |
238 | *((uint32_t *) dst) |
247 | *((uint32_t *) dst) |
239 | = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8); |
248 | = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8); |
240 | } |
249 | } |
241 | 250 | ||
242 | 251 | ||
243 | /** RGB 8:8:8 conversion |
252 | /** RGB 8:8:8 conversion |
244 | * |
253 | * |
245 | */ |
254 | */ |
246 | static void rgb_888(void *dst, uint32_t rgb) |
255 | static void rgb_888(void *dst, uint32_t rgb) |
247 | { |
256 | { |
248 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
257 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
249 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
258 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
250 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
259 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
251 | } |
260 | } |
252 | 261 | ||
- | 262 | static void mask_888(void *dst, bool mask) |
|
- | 263 | { |
|
- | 264 | if (mask) { |
|
- | 265 | ((uint8_t *) dst)[0] = 0xff; |
|
- | 266 | ((uint8_t *) dst)[1] = 0xff; |
|
- | 267 | ((uint8_t *) dst)[2] = 0xff; |
|
- | 268 | } else { |
|
- | 269 | ((uint8_t *) dst)[0] = 0; |
|
- | 270 | ((uint8_t *) dst)[1] = 0; |
|
- | 271 | ((uint8_t *) dst)[2] = 0; |
|
- | 272 | } |
|
- | 273 | } |
|
- | 274 | ||
253 | 275 | ||
254 | /** BGR 8:8:8 conversion |
276 | /** BGR 8:8:8 conversion |
255 | * |
277 | * |
256 | */ |
278 | */ |
257 | static void bgr_888(void *dst, uint32_t rgb) |
279 | static void bgr_888(void *dst, uint32_t rgb) |
258 | { |
280 | { |
259 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
281 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
260 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
282 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
261 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
283 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
262 | } |
284 | } |
263 | 285 | ||
264 | 286 | ||
265 | /** RGB 5:5:5 conversion |
287 | /** RGB 5:5:5 conversion |
266 | * |
288 | * |
267 | */ |
289 | */ |
268 | static void rgb_555(void *dst, uint32_t rgb) |
290 | static void rgb_555(void *dst, uint32_t rgb) |
269 | { |
291 | { |
270 | *((uint16_t *) dst) |
292 | *((uint16_t *) dst) |
271 | = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5); |
293 | = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5); |
272 | } |
294 | } |
273 | 295 | ||
- | 296 | static void mask_555(void *dst, bool mask) |
|
- | 297 | { |
|
- | 298 | *((uint16_t *) dst) = (mask ? 0x7fff : 0); |
|
- | 299 | } |
|
- | 300 | ||
274 | 301 | ||
275 | /** RGB 5:6:5 conversion |
302 | /** RGB 5:6:5 conversion |
276 | * |
303 | * |
277 | */ |
304 | */ |
278 | static void rgb_565(void *dst, uint32_t rgb) |
305 | static void rgb_565(void *dst, uint32_t rgb) |
279 | { |
306 | { |
280 | *((uint16_t *) dst) |
307 | *((uint16_t *) dst) |
281 | = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5); |
308 | = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5); |
282 | } |
309 | } |
283 | 310 | ||
- | 311 | static void mask_565(void *dst, bool mask) |
|
- | 312 | { |
|
- | 313 | *((uint16_t *) dst) = (mask ? 0xffff : 0); |
|
- | 314 | } |
|
- | 315 | ||
284 | 316 | ||
285 | /** RGB 3:2:3 |
317 | /** RGB 3:2:3 |
286 | * |
318 | * |
287 | */ |
319 | */ |
288 | static void rgb_323(void *dst, uint32_t rgb) |
320 | static void rgb_323(void *dst, uint32_t rgb) |
289 | { |
321 | { |
290 | *((uint8_t *) dst) |
322 | *((uint8_t *) dst) |
291 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
323 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
292 | } |
324 | } |
293 | 325 | ||
- | 326 | static void mask_323(void *dst, bool mask) |
|
- | 327 | { |
|
- | 328 | *((uint8_t *) dst) = (mask ? 0xff : 0); |
|
- | 329 | } |
|
- | 330 | ||
294 | /** Draw a filled rectangle. |
331 | /** Draw a filled rectangle. |
295 | * |
332 | * |
296 | * @note Need real implementation that does not access VRAM twice. |
333 | * @note Need real implementation that does not access VRAM twice. |
- | 334 | * |
|
297 | */ |
335 | */ |
298 | static void draw_filled_rect(unsigned int x0, unsigned int y0, unsigned int x1, |
336 | static void draw_filled_rect(unsigned int x0, unsigned int y0, unsigned int x1, |
299 | unsigned int y1, uint32_t color) |
337 | unsigned int y1, uint32_t color) |
300 | { |
338 | { |
- | 339 | unsigned int x; |
|
301 | unsigned int x, y; |
340 | unsigned int y; |
302 | unsigned int copy_bytes; |
341 | unsigned int copy_bytes; |
303 | 342 | ||
304 | uint8_t *sp, *dp; |
343 | uint8_t *sp; |
- | 344 | uint8_t *dp; |
|
305 | uint8_t cbuf[4]; |
345 | uint8_t cbuf[4]; |
306 | 346 | ||
307 | if (y0 >= y1 || x0 >= x1) return; |
347 | if ((y0 >= y1) || (x0 >= x1)) |
- | 348 | return; |
|
- | 349 | ||
308 | screen.rgb_conv(cbuf, color); |
350 | screen.rgb_conv(cbuf, color); |
309 | 351 | ||
310 | sp = &screen.fb_addr[FB_POS(x0, y0)]; |
352 | sp = &screen.fb_addr[FB_POS(x0, y0)]; |
311 | dp = sp; |
353 | dp = sp; |
312 | 354 | ||
313 | /* Draw the first line. */ |
355 | /* Draw the first line. */ |
314 | for (x = x0; x < x1; x++) { |
356 | for (x = x0; x < x1; x++) { |
315 | memcpy(dp, cbuf, screen.pixelbytes); |
357 | memcpy(dp, cbuf, screen.pixelbytes); |
316 | dp += screen.pixelbytes; |
358 | dp += screen.pixelbytes; |
317 | } |
359 | } |
318 | 360 | ||
319 | dp = sp + screen.scanline; |
361 | dp = sp + screen.scanline; |
320 | copy_bytes = (x1 - x0) * screen.pixelbytes; |
362 | copy_bytes = (x1 - x0) * screen.pixelbytes; |
321 | 363 | ||
322 | /* Draw the remaining lines by copying. */ |
364 | /* Draw the remaining lines by copying. */ |
323 | for (y = y0 + 1; y < y1; y++) { |
365 | for (y = y0 + 1; y < y1; y++) { |
324 | memcpy(dp, sp, copy_bytes); |
366 | memcpy(dp, sp, copy_bytes); |
325 | dp += screen.scanline; |
367 | dp += screen.scanline; |
326 | } |
368 | } |
327 | } |
369 | } |
328 | 370 | ||
329 | /** Redraw viewport. |
371 | /** Redraw viewport. |
330 | * |
372 | * |
331 | * @param vport Viewport to redraw |
373 | * @param vport Viewport to redraw |
332 | * |
374 | * |
333 | */ |
375 | */ |
334 | static void vport_redraw(viewport_t *vport) |
376 | static void vport_redraw(viewport_t *vport) |
335 | { |
377 | { |
- | 378 | unsigned int row; |
|
336 | unsigned int row, col; |
379 | unsigned int col; |
337 | 380 | ||
338 | for (row = 0; row < vport->rows; row++) { |
381 | for (row = 0; row < vport->rows; row++) { |
339 | for (col = 0; col < vport->cols; col++) { |
382 | for (col = 0; col < vport->cols; col++) { |
340 | draw_vp_glyph(vport, false, col, row); |
383 | draw_vp_glyph(vport, false, col, row); |
341 | } |
384 | } |
342 | } |
385 | } |
343 | 386 | ||
344 | if (COL2X(vport->cols) < vport->width) { |
387 | if (COL2X(vport->cols) < vport->width) { |
345 | draw_filled_rect( |
388 | draw_filled_rect( |
346 | vport->x + COL2X(vport->cols), vport->y, |
389 | vport->x + COL2X(vport->cols), vport->y, |
347 | vport->x + vport->width, vport->y + vport->height, |
390 | vport->x + vport->width, vport->y + vport->height, |
348 | vport->attr.bg_color); |
391 | vport->attr.bg_color); |
349 | } |
392 | } |
350 | 393 | ||
351 | if (ROW2Y(vport->rows) < vport->height) { |
394 | if (ROW2Y(vport->rows) < vport->height) { |
352 | draw_filled_rect( |
395 | draw_filled_rect( |
353 | vport->x, vport->y + ROW2Y(vport->rows), |
396 | vport->x, vport->y + ROW2Y(vport->rows), |
354 | vport->x + vport->width, vport->y + vport->height, |
397 | vport->x + vport->width, vport->y + vport->height, |
355 | vport->attr.bg_color); |
398 | vport->attr.bg_color); |
356 | } |
399 | } |
357 | } |
400 | } |
358 | 401 | ||
359 | static void backbuf_clear(bb_cell_t *backbuf, size_t len, uint32_t fg_color, |
402 | static void backbuf_clear(bb_cell_t *backbuf, size_t len, uint32_t fg_color, |
360 | uint32_t bg_color) |
403 | uint32_t bg_color) |
361 | { |
404 | { |
362 | unsigned i; |
405 | size_t i; |
363 | 406 | ||
364 | for (i = 0; i < len; i++) { |
407 | for (i = 0; i < len; i++) { |
365 | backbuf[i].glyph = 0; |
408 | backbuf[i].glyph = 0; |
366 | backbuf[i].fg_color = fg_color; |
409 | backbuf[i].fg_color = fg_color; |
367 | backbuf[i].bg_color = bg_color; |
410 | backbuf[i].bg_color = bg_color; |
368 | } |
411 | } |
369 | } |
412 | } |
370 | 413 | ||
371 | /** Clear viewport. |
414 | /** Clear viewport. |
372 | * |
415 | * |
373 | * @param vport Viewport to clear |
416 | * @param vport Viewport to clear |
374 | * |
417 | * |
375 | */ |
418 | */ |
376 | static void vport_clear(viewport_t *vport) |
419 | static void vport_clear(viewport_t *vport) |
377 | { |
420 | { |
378 | backbuf_clear(vport->backbuf, vport->cols * vport->rows, |
421 | backbuf_clear(vport->backbuf, vport->cols * vport->rows, |
379 | vport->attr.fg_color, vport->attr.bg_color); |
422 | vport->attr.fg_color, vport->attr.bg_color); |
380 | vport_redraw(vport); |
423 | vport_redraw(vport); |
381 | } |
424 | } |
382 | 425 | ||
383 | /** Scroll viewport by the specified number of lines. |
426 | /** Scroll viewport by the specified number of lines. |
384 | * |
427 | * |
385 | * @param vport Viewport to scroll |
428 | * @param vport Viewport to scroll |
386 | * @param lines Number of lines to scroll |
429 | * @param lines Number of lines to scroll |
387 | * |
430 | * |
388 | */ |
431 | */ |
389 | static void vport_scroll(viewport_t *vport, int lines) |
432 | static void vport_scroll(viewport_t *vport, int lines) |
390 | { |
433 | { |
- | 434 | unsigned int row; |
|
391 | unsigned int row, col; |
435 | unsigned int col; |
- | 436 | unsigned int x; |
|
392 | unsigned int x, y; |
437 | unsigned int y; |
393 | uint32_t glyph; |
438 | uint32_t glyph; |
394 | uint32_t fg_color; |
439 | uint32_t fg_color; |
395 | uint32_t bg_color; |
440 | uint32_t bg_color; |
- | 441 | bb_cell_t *bbp; |
|
396 | bb_cell_t *bbp, *xbp; |
442 | bb_cell_t *xbp; |
397 | 443 | ||
398 | /* |
444 | /* |
399 | * Redraw. |
445 | * Redraw. |
400 | */ |
446 | */ |
401 | 447 | ||
402 | y = vport->y; |
448 | y = vport->y; |
403 | for (row = 0; row < vport->rows; row++) { |
449 | for (row = 0; row < vport->rows; row++) { |
404 | x = vport->x; |
450 | x = vport->x; |
405 | for (col = 0; col < vport->cols; col++) { |
451 | for (col = 0; col < vport->cols; col++) { |
406 | if ((row + lines >= 0) && (row + lines < vport->rows)) { |
452 | if ((row + lines >= 0) && (row + lines < vport->rows)) { |
407 | xbp = &vport->backbuf[BB_POS(vport, col, row + lines)]; |
453 | xbp = &vport->backbuf[BB_POS(vport, col, row + lines)]; |
408 | bbp = &vport->backbuf[BB_POS(vport, col, row)]; |
454 | bbp = &vport->backbuf[BB_POS(vport, col, row)]; |
409 | 455 | ||
410 | glyph = xbp->glyph; |
456 | glyph = xbp->glyph; |
411 | fg_color = xbp->fg_color; |
457 | fg_color = xbp->fg_color; |
412 | bg_color = xbp->bg_color; |
458 | bg_color = xbp->bg_color; |
413 | 459 | ||
414 | if (bbp->glyph == glyph && |
460 | if ((bbp->glyph == glyph) |
415 | bbp->fg_color == xbp->fg_color && |
461 | && (bbp->fg_color == xbp->fg_color) |
416 | bbp->bg_color == xbp->bg_color) { |
462 | && (bbp->bg_color == xbp->bg_color)) { |
417 | x += FONT_WIDTH; |
463 | x += FONT_WIDTH; |
418 | continue; |
464 | continue; |
419 | } |
465 | } |
420 | } else { |
466 | } else { |
421 | glyph = 0; |
467 | glyph = 0; |
422 | fg_color = vport->attr.fg_color; |
468 | fg_color = vport->attr.fg_color; |
423 | bg_color = vport->attr.bg_color; |
469 | bg_color = vport->attr.bg_color; |
424 | } |
470 | } |
425 | 471 | ||
426 | (*vport->dglyph)(x, y, false, screen.glyphs, glyph, |
472 | (*vport->dglyph)(x, y, false, screen.glyphs, glyph, |
427 | fg_color, bg_color); |
473 | fg_color, bg_color); |
428 | x += FONT_WIDTH; |
474 | x += FONT_WIDTH; |
429 | } |
475 | } |
430 | y += FONT_SCANLINES; |
476 | y += FONT_SCANLINES; |
431 | } |
477 | } |
432 | 478 | ||
433 | /* |
479 | /* |
434 | * Scroll backbuffer. |
480 | * Scroll backbuffer. |
435 | */ |
481 | */ |
436 | 482 | ||
437 | if (lines > 0) { |
483 | if (lines > 0) { |
438 | memmove(vport->backbuf, vport->backbuf + vport->cols * lines, |
484 | memmove(vport->backbuf, vport->backbuf + vport->cols * lines, |
439 | vport->cols * (vport->rows - lines) * sizeof(bb_cell_t)); |
485 | vport->cols * (vport->rows - lines) * sizeof(bb_cell_t)); |
440 | backbuf_clear(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)], |
486 | backbuf_clear(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)], |
441 | vport->cols * lines, vport->attr.fg_color, vport->attr.bg_color); |
487 | vport->cols * lines, vport->attr.fg_color, vport->attr.bg_color); |
442 | } else { |
488 | } else { |
443 | memmove(vport->backbuf - vport->cols * lines, vport->backbuf, |
489 | memmove(vport->backbuf - vport->cols * lines, vport->backbuf, |
444 | vport->cols * (vport->rows + lines) * sizeof(bb_cell_t)); |
490 | vport->cols * (vport->rows + lines) * sizeof(bb_cell_t)); |
445 | backbuf_clear(vport->backbuf, - vport->cols * lines, |
491 | backbuf_clear(vport->backbuf, - vport->cols * lines, |
446 | vport->attr.fg_color, vport->attr.bg_color); |
492 | vport->attr.fg_color, vport->attr.bg_color); |
447 | } |
493 | } |
448 | } |
494 | } |
449 | 495 | ||
450 | /** Render glyphs |
496 | /** Render glyphs |
451 | * |
497 | * |
452 | * Convert glyphs from device independent font |
498 | * Convert glyphs from device independent font |
453 | * description to current visual representation. |
499 | * description to current visual representation. |
- | 500 | * |
|
454 | */ |
501 | */ |
455 | static void render_glyphs(void) |
502 | static void render_glyphs(void) |
456 | { |
503 | { |
457 | unsigned int glyph; |
504 | unsigned int glyph; |
458 | 505 | ||
459 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
506 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
460 | unsigned int y; |
507 | unsigned int y; |
461 | 508 | ||
462 | for (y = 0; y < FONT_SCANLINES; y++) { |
509 | for (y = 0; y < FONT_SCANLINES; y++) { |
463 | unsigned int x; |
510 | unsigned int x; |
464 | 511 | ||
465 | for (x = 0; x < FONT_WIDTH; x++) { |
512 | for (x = 0; x < FONT_WIDTH; x++) { |
466 | screen.rgb_conv(&screen.glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes], |
513 | screen.mask_conv(&screen.glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes], |
467 | (fb_font[glyph][y] & (1 << (7 - x))) |
514 | (fb_font[glyph][y] & (1 << (7 - x))) ? true : false); |
468 | ? 0xffffff : 0x000000); |
- | |
469 | 515 | ||
470 | screen.rgb_conv(&screen.glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes], |
516 | screen.mask_conv(&screen.glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes], |
471 | (fb_font[glyph][y] & (1 << (7 - x))) |
517 | (fb_font[glyph][y] & (1 << (7 - x))) ? false : true); |
472 | ? 0x000000 : 0xffffff); |
- | |
473 | } |
518 | } |
474 | } |
519 | } |
475 | } |
520 | } |
476 | } |
521 | } |
477 | 522 | ||
478 | - | ||
479 | /** Create new viewport |
523 | /** Create new viewport |
480 | * |
524 | * |
481 | * @param x Origin of the viewport (x). |
525 | * @param x Origin of the viewport (x). |
482 | * @param y Origin of the viewport (y). |
526 | * @param y Origin of the viewport (y). |
483 | * @param width Width of the viewport. |
527 | * @param width Width of the viewport. |
484 | * @param height Height of the viewport. |
528 | * @param height Height of the viewport. |
485 | * |
529 | * |
486 | * @return New viewport number. |
530 | * @return New viewport number. |
487 | * |
531 | * |
488 | */ |
532 | */ |
489 | static int vport_create(unsigned int x, unsigned int y, |
533 | static int vport_create(unsigned int x, unsigned int y, |
490 | unsigned int width, unsigned int height) |
534 | unsigned int width, unsigned int height) |
491 | { |
535 | { |
492 | unsigned int i; |
536 | unsigned int i; |
493 | 537 | ||
494 | for (i = 0; i < MAX_VIEWPORTS; i++) { |
538 | for (i = 0; i < MAX_VIEWPORTS; i++) { |
495 | if (!viewports[i].initialized) |
539 | if (!viewports[i].initialized) |
496 | break; |
540 | break; |
497 | } |
541 | } |
- | 542 | ||
498 | if (i == MAX_VIEWPORTS) |
543 | if (i == MAX_VIEWPORTS) |
499 | return ELIMIT; |
544 | return ELIMIT; |
500 | 545 | ||
501 | unsigned int cols = width / FONT_WIDTH; |
546 | unsigned int cols = width / FONT_WIDTH; |
502 | unsigned int rows = height / FONT_SCANLINES; |
547 | unsigned int rows = height / FONT_SCANLINES; |
503 | unsigned int bbsize = cols * rows * sizeof(bb_cell_t); |
548 | unsigned int bbsize = cols * rows * sizeof(bb_cell_t); |
504 | unsigned int word_size = sizeof(unsigned long); |
549 | unsigned int word_size = sizeof(unsigned long); |
505 | 550 | ||
506 | bb_cell_t *backbuf = (bb_cell_t *) malloc(bbsize); |
551 | bb_cell_t *backbuf = (bb_cell_t *) malloc(bbsize); |
507 | if (!backbuf) |
552 | if (!backbuf) |
508 | return ENOMEM; |
553 | return ENOMEM; |
509 | 554 | ||
510 | uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes); |
555 | uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes); |
511 | if (!bgpixel) { |
556 | if (!bgpixel) { |
512 | free(backbuf); |
557 | free(backbuf); |
513 | return ENOMEM; |
558 | return ENOMEM; |
514 | } |
559 | } |
515 | 560 | ||
516 | backbuf_clear(backbuf, cols * rows, DEFAULT_FGCOLOR, DEFAULT_BGCOLOR); |
561 | backbuf_clear(backbuf, cols * rows, DEFAULT_FGCOLOR, DEFAULT_BGCOLOR); |
517 | memset(bgpixel, 0, screen.pixelbytes); |
562 | memset(bgpixel, 0, screen.pixelbytes); |
518 | 563 | ||
519 | viewports[i].x = x; |
564 | viewports[i].x = x; |
520 | viewports[i].y = y; |
565 | viewports[i].y = y; |
521 | viewports[i].width = width; |
566 | viewports[i].width = width; |
522 | viewports[i].height = height; |
567 | viewports[i].height = height; |
523 | 568 | ||
524 | viewports[i].cols = cols; |
569 | viewports[i].cols = cols; |
525 | viewports[i].rows = rows; |
570 | viewports[i].rows = rows; |
526 | 571 | ||
527 | viewports[i].attr.bg_color = DEFAULT_BGCOLOR; |
572 | viewports[i].attr.bg_color = DEFAULT_BGCOLOR; |
528 | viewports[i].attr.fg_color = DEFAULT_FGCOLOR; |
573 | viewports[i].attr.fg_color = DEFAULT_FGCOLOR; |
529 | 574 | ||
530 | viewports[i].bgpixel = bgpixel; |
575 | viewports[i].bgpixel = bgpixel; |
531 | 576 | ||
532 | /* |
577 | /* |
533 | * Conditions necessary to select aligned version: |
578 | * Conditions necessary to select aligned version: |
- | 579 | * - word size is divisible by pixelbytes |
|
- | 580 | * - cell scanline size is divisible by word size |
|
- | 581 | * - cell scanlines are word-aligned |
|
534 | * |
582 | * |
535 | * - word size is divisible by pixelbytes |
- | |
536 | * - cell scanline size is divisible by word size |
- | |
537 | * - cell scanlines are word-aligned |
- | |
538 | */ |
583 | */ |
539 | if ((word_size % screen.pixelbytes) == 0 && |
584 | if (((word_size % screen.pixelbytes) == 0) |
540 | (FONT_WIDTH * screen.pixelbytes) % word_size == 0 && |
585 | && ((FONT_WIDTH * screen.pixelbytes) % word_size == 0) |
541 | (x * screen.pixelbytes) % word_size == 0 && |
586 | && ((x * screen.pixelbytes) % word_size == 0) |
542 | screen.scanline % word_size == 0) { |
587 | && (screen.scanline % word_size == 0)) { |
543 | - | ||
544 | viewports[i].dglyph = draw_glyph_aligned; |
588 | viewports[i].dglyph = draw_glyph_aligned; |
545 | } else { |
589 | } else { |
546 | viewports[i].dglyph = draw_glyph_fallback; |
590 | viewports[i].dglyph = draw_glyph_fallback; |
547 | } |
591 | } |
548 | 592 | ||
549 | viewports[i].cur_col = 0; |
593 | viewports[i].cur_col = 0; |
550 | viewports[i].cur_row = 0; |
594 | viewports[i].cur_row = 0; |
551 | viewports[i].cursor_active = false; |
595 | viewports[i].cursor_active = false; |
552 | viewports[i].cursor_shown = false; |
596 | viewports[i].cursor_shown = false; |
553 | 597 | ||
554 | viewports[i].bbsize = bbsize; |
598 | viewports[i].bbsize = bbsize; |
555 | viewports[i].backbuf = backbuf; |
599 | viewports[i].backbuf = backbuf; |
556 | 600 | ||
557 | viewports[i].initialized = true; |
601 | viewports[i].initialized = true; |
558 | 602 | ||
559 | screen.rgb_conv(viewports[i].bgpixel, viewports[i].attr.bg_color); |
603 | screen.rgb_conv(viewports[i].bgpixel, viewports[i].attr.bg_color); |
560 | 604 | ||
561 | return i; |
605 | return i; |
562 | } |
606 | } |
563 | 607 | ||
564 | 608 | ||
565 | /** Initialize framebuffer as a chardev output device |
609 | /** Initialize framebuffer as a chardev output device |
566 | * |
610 | * |
567 | * @param addr Address of the framebuffer |
611 | * @param addr Address of the framebuffer |
568 | * @param xres Screen width in pixels |
612 | * @param xres Screen width in pixels |
569 | * @param yres Screen height in pixels |
613 | * @param yres Screen height in pixels |
570 | * @param visual Bits per pixel (8, 16, 24, 32) |
614 | * @param visual Bits per pixel (8, 16, 24, 32) |
571 | * @param scan Bytes per one scanline |
615 | * @param scan Bytes per one scanline |
572 | * |
616 | * |
573 | */ |
617 | */ |
574 | static bool screen_init(void *addr, unsigned int xres, unsigned int yres, |
618 | static bool screen_init(void *addr, unsigned int xres, unsigned int yres, |
575 | unsigned int scan, unsigned int visual) |
619 | unsigned int scan, unsigned int visual) |
576 | { |
620 | { |
577 | unsigned int glyphsize; |
621 | |
578 | uint8_t *glyphs; |
622 | |
579 | switch (visual) { |
623 | switch (visual) { |
580 | case VISUAL_INDIRECT_8: |
624 | case VISUAL_INDIRECT_8: |
581 | screen.rgb_conv = rgb_323; |
625 | screen.rgb_conv = rgb_323; |
- | 626 | screen.mask_conv = mask_323; |
|
582 | screen.pixelbytes = 1; |
627 | screen.pixelbytes = 1; |
583 | break; |
628 | break; |
584 | case VISUAL_RGB_5_5_5: |
629 | case VISUAL_RGB_5_5_5: |
585 | screen.rgb_conv = rgb_555; |
630 | screen.rgb_conv = rgb_555; |
- | 631 | screen.mask_conv = mask_555; |
|
586 | screen.pixelbytes = 2; |
632 | screen.pixelbytes = 2; |
587 | break; |
633 | break; |
588 | case VISUAL_RGB_5_6_5: |
634 | case VISUAL_RGB_5_6_5: |
589 | screen.rgb_conv = rgb_565; |
635 | screen.rgb_conv = rgb_565; |
- | 636 | screen.mask_conv = mask_565; |
|
590 | screen.pixelbytes = 2; |
637 | screen.pixelbytes = 2; |
591 | break; |
638 | break; |
592 | case VISUAL_RGB_8_8_8: |
639 | case VISUAL_RGB_8_8_8: |
593 | screen.rgb_conv = rgb_888; |
640 | screen.rgb_conv = rgb_888; |
- | 641 | screen.mask_conv = mask_888; |
|
594 | screen.pixelbytes = 3; |
642 | screen.pixelbytes = 3; |
595 | break; |
643 | break; |
596 | case VISUAL_BGR_8_8_8: |
644 | case VISUAL_BGR_8_8_8: |
597 | screen.rgb_conv = bgr_888; |
645 | screen.rgb_conv = bgr_888; |
- | 646 | screen.mask_conv = mask_888; |
|
598 | screen.pixelbytes = 3; |
647 | screen.pixelbytes = 3; |
599 | break; |
648 | break; |
600 | case VISUAL_RGB_8_8_8_0: |
649 | case VISUAL_RGB_8_8_8_0: |
601 | screen.rgb_conv = rgb_888; |
650 | screen.rgb_conv = rgb_888; |
- | 651 | screen.mask_conv = mask_888; |
|
602 | screen.pixelbytes = 4; |
652 | screen.pixelbytes = 4; |
603 | break; |
653 | break; |
604 | case VISUAL_RGB_0_8_8_8: |
654 | case VISUAL_RGB_0_8_8_8: |
605 | screen.rgb_conv = rgb_0888; |
655 | screen.rgb_conv = rgb_0888; |
- | 656 | screen.mask_conv = mask_0888; |
|
606 | screen.pixelbytes = 4; |
657 | screen.pixelbytes = 4; |
607 | break; |
658 | break; |
608 | case VISUAL_BGR_0_8_8_8: |
659 | case VISUAL_BGR_0_8_8_8: |
609 | screen.rgb_conv = bgr_0888; |
660 | screen.rgb_conv = bgr_0888; |
- | 661 | screen.mask_conv = mask_0888; |
|
610 | screen.pixelbytes = 4; |
662 | screen.pixelbytes = 4; |
611 | break; |
663 | break; |
612 | default: |
664 | default: |
613 | return false; |
665 | return false; |
614 | } |
666 | } |
615 | 667 | ||
616 | screen.fb_addr = (unsigned char *) addr; |
668 | screen.fb_addr = (unsigned char *) addr; |
617 | screen.xres = xres; |
669 | screen.xres = xres; |
618 | screen.yres = yres; |
670 | screen.yres = yres; |
619 | screen.scanline = scan; |
671 | screen.scanline = scan; |
620 | 672 | ||
621 | screen.glyphscanline = FONT_WIDTH * screen.pixelbytes; |
673 | screen.glyphscanline = FONT_WIDTH * screen.pixelbytes; |
622 | screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES; |
674 | screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES; |
623 | 675 | ||
624 | glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes; |
676 | size_t glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes; |
625 | glyphs = (uint8_t *) malloc(glyphsize); |
677 | uint8_t *glyphs = (uint8_t *) malloc(glyphsize); |
626 | if (!glyphs) |
678 | if (!glyphs) |
627 | return false; |
679 | return false; |
628 | 680 | ||
629 | memset(glyphs, 0, glyphsize); |
681 | memset(glyphs, 0, glyphsize); |
630 | screen.glyphs = glyphs; |
682 | screen.glyphs = glyphs; |
631 | 683 | ||
632 | render_glyphs(); |
684 | render_glyphs(); |
633 | 685 | ||
634 | /* Create first viewport */ |
686 | /* Create first viewport */ |
635 | vport_create(0, 0, xres, yres); |
687 | vport_create(0, 0, xres, yres); |
636 | 688 | ||
637 | return true; |
689 | return true; |
638 | } |
690 | } |
639 | 691 | ||
640 | 692 | ||
641 | /** Draw a glyph, takes advantage of alignment. |
693 | /** Draw a glyph, takes advantage of alignment. |
642 | * |
694 | * |
643 | * This version can only be used if the following conditions are met: |
695 | * This version can only be used if the following conditions are met: |
644 | * |
696 | * |
645 | * - word size is divisible by pixelbytes |
697 | * - word size is divisible by pixelbytes |
646 | * - cell scanline size is divisible by word size |
698 | * - cell scanline size is divisible by word size |
647 | * - cell scanlines are word-aligned |
699 | * - cell scanlines are word-aligned |
648 | * |
700 | * |
649 | * It makes use of the pre-rendered mask to process (possibly) several |
701 | * It makes use of the pre-rendered mask to process (possibly) several |
650 | * pixels at once (word size / pixelbytes pixels at a time are processed) |
702 | * pixels at once (word size / pixelbytes pixels at a time are processed) |
651 | * making it very fast. Most notably this version is not applicable at 24 bits |
703 | * making it very fast. Most notably this version is not applicable at 24 bits |
652 | * per pixel. |
704 | * per pixel. |
653 | * |
705 | * |
654 | * @param x x coordinate of top-left corner on screen. |
706 | * @param x x coordinate of top-left corner on screen. |
655 | * @param y y coordinate of top-left corner on screen. |
707 | * @param y y coordinate of top-left corner on screen. |
656 | * @param cursor Draw glyph with cursor |
708 | * @param cursor Draw glyph with cursor |
657 | * @param glyphs Pointer to font bitmap. |
709 | * @param glyphs Pointer to font bitmap. |
658 | * @param glyph Code of the glyph to draw. |
710 | * @param glyph Code of the glyph to draw. |
659 | * @param fg_color Foreground color. |
711 | * @param fg_color Foreground color. |
660 | * @param bg_color Backgroudn color. |
712 | * @param bg_color Backgroudn color. |
- | 713 | * |
|
661 | */ |
714 | */ |
662 | static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor, |
715 | static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor, |
663 | uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color) |
716 | uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color) |
664 | { |
717 | { |
- | 718 | unsigned int i; |
|
665 | unsigned int i, yd; |
719 | unsigned int yd; |
666 | unsigned long fg_buf, bg_buf; |
720 | unsigned long fg_buf; |
667 | unsigned long *maskp, *dp; |
721 | unsigned long bg_buf; |
668 | unsigned long mask; |
722 | unsigned long mask; |
669 | unsigned int ww, d_add; |
- | |
670 | 723 | ||
671 | /* |
724 | /* |
672 | * Prepare a pair of words, one filled with foreground-color |
725 | * Prepare a pair of words, one filled with foreground-color |
673 | * pattern and the other filled with background-color pattern. |
726 | * pattern and the other filled with background-color pattern. |
674 | */ |
727 | */ |
675 | for (i = 0; i < sizeof(unsigned long) / screen.pixelbytes; i++) { |
728 | for (i = 0; i < sizeof(unsigned long) / screen.pixelbytes; i++) { |
676 | screen.rgb_conv(&((uint8_t *)&fg_buf)[i * screen.pixelbytes], |
729 | screen.rgb_conv(&((uint8_t *) &fg_buf)[i * screen.pixelbytes], |
677 | fg_color); |
730 | fg_color); |
678 | screen.rgb_conv(&((uint8_t *)&bg_buf)[i * screen.pixelbytes], |
731 | screen.rgb_conv(&((uint8_t *) &bg_buf)[i * screen.pixelbytes], |
679 | bg_color); |
732 | bg_color); |
680 | } |
733 | } |
681 | 734 | ||
682 | /* Pointer to the current position in the mask. */ |
735 | /* Pointer to the current position in the mask. */ |
683 | maskp = (unsigned long *) &glyphs[GLYPH_POS(glyph, 0, cursor)]; |
736 | unsigned long *maskp = (unsigned long *) &glyphs[GLYPH_POS(glyph, 0, cursor)]; |
684 | 737 | ||
685 | /* Pointer to the current position on the screen. */ |
738 | /* Pointer to the current position on the screen. */ |
686 | dp = (unsigned long *) &screen.fb_addr[FB_POS(x, y)]; |
739 | unsigned long *dp = (unsigned long *) &screen.fb_addr[FB_POS(x, y)]; |
687 | 740 | ||
688 | /* Width of the character cell in words. */ |
741 | /* Width of the character cell in words. */ |
689 | ww = FONT_WIDTH * screen.pixelbytes / sizeof(unsigned long); |
742 | unsigned int ww = FONT_WIDTH * screen.pixelbytes / sizeof(unsigned long); |
690 | 743 | ||
691 | /* Offset to add when moving to another screen scanline. */ |
744 | /* Offset to add when moving to another screen scanline. */ |
692 | d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes; |
745 | unsigned int d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes; |
693 | 746 | ||
694 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
747 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
695 | /* |
748 | /* |
696 | * Now process the cell scanline, combining foreground |
749 | * Now process the cell scanline, combining foreground |
697 | * and background color patters using the pre-rendered mask. |
750 | * and background color patters using the pre-rendered mask. |
698 | */ |
751 | */ |
699 | for (i = 0; i < ww; i++) { |
752 | for (i = 0; i < ww; i++) { |
700 | mask = *maskp++; |
753 | mask = *maskp++; |
701 | *dp++ = (fg_buf & mask) | (bg_buf & ~mask); |
754 | *dp++ = (fg_buf & mask) | (bg_buf & ~mask); |
702 | } |
755 | } |
703 | 756 | ||
704 | /* Move to the beginning of the next scanline of the cell. */ |
757 | /* Move to the beginning of the next scanline of the cell. */ |
705 | dp = (unsigned long *) ((uint8_t *) dp + d_add); |
758 | dp = (unsigned long *) ((uint8_t *) dp + d_add); |
706 | } |
759 | } |
707 | } |
760 | } |
708 | 761 | ||
709 | /** Draw a glyph, fallback version. |
762 | /** Draw a glyph, fallback version. |
710 | * |
763 | * |
711 | * This version does not make use of the pre-rendered mask, it uses |
764 | * This version does not make use of the pre-rendered mask, it uses |
712 | * the font bitmap directly. It works always, but it is slower. |
765 | * the font bitmap directly. It works always, but it is slower. |
713 | * |
766 | * |
714 | * @param x x coordinate of top-left corner on screen. |
767 | * @param x x coordinate of top-left corner on screen. |
715 | * @param y y coordinate of top-left corner on screen. |
768 | * @param y y coordinate of top-left corner on screen. |
716 | * @param cursor Draw glyph with cursor |
769 | * @param cursor Draw glyph with cursor |
717 | * @param glyphs Pointer to font bitmap. |
770 | * @param glyphs Pointer to font bitmap. |
718 | * @param glyph Code of the glyph to draw. |
771 | * @param glyph Code of the glyph to draw. |
719 | * @param fg_color Foreground color. |
772 | * @param fg_color Foreground color. |
720 | * @param bg_color Backgroudn color. |
773 | * @param bg_color Backgroudn color. |
- | 774 | * |
|
721 | */ |
775 | */ |
722 | void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor, |
776 | void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor, |
723 | uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color) |
777 | uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color) |
724 | { |
778 | { |
- | 779 | unsigned int i; |
|
- | 780 | unsigned int j; |
|
725 | unsigned int i, j, yd; |
781 | unsigned int yd; |
726 | uint8_t fg_buf[4], bg_buf[4]; |
782 | uint8_t fg_buf[4]; |
727 | uint8_t *dp, *sp; |
783 | uint8_t bg_buf[4]; |
728 | unsigned int d_add; |
784 | uint8_t *sp; |
729 | uint8_t b; |
785 | uint8_t b; |
730 | 786 | ||
731 | /* Pre-render 1x the foreground and background color pixels. */ |
787 | /* Pre-render 1x the foreground and background color pixels. */ |
732 | if (cursor) { |
788 | if (cursor) { |
733 | screen.rgb_conv(fg_buf, bg_color); |
789 | screen.rgb_conv(fg_buf, bg_color); |
734 | screen.rgb_conv(bg_buf, fg_color); |
790 | screen.rgb_conv(bg_buf, fg_color); |
735 | } else { |
791 | } else { |
736 | screen.rgb_conv(fg_buf, fg_color); |
792 | screen.rgb_conv(fg_buf, fg_color); |
737 | screen.rgb_conv(bg_buf, bg_color); |
793 | screen.rgb_conv(bg_buf, bg_color); |
738 | } |
794 | } |
739 | 795 | ||
740 | /* Pointer to the current position on the screen. */ |
796 | /* Pointer to the current position on the screen. */ |
741 | dp = (uint8_t *) &screen.fb_addr[FB_POS(x, y)]; |
797 | uint8_t *dp = (uint8_t *) &screen.fb_addr[FB_POS(x, y)]; |
742 | 798 | ||
743 | /* Offset to add when moving to another screen scanline. */ |
799 | /* Offset to add when moving to another screen scanline. */ |
744 | d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes; |
800 | unsigned int d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes; |
745 | 801 | ||
746 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
802 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
747 | /* Byte containing bits of the glyph scanline. */ |
803 | /* Byte containing bits of the glyph scanline. */ |
748 | b = fb_font[glyph][yd]; |
804 | b = fb_font[glyph][yd]; |
749 | 805 | ||
750 | for (i = 0; i < FONT_WIDTH; i++) { |
806 | for (i = 0; i < FONT_WIDTH; i++) { |
751 | /* Choose color based on the current bit. */ |
807 | /* Choose color based on the current bit. */ |
752 | sp = (b & 0x80) ? fg_buf : bg_buf; |
808 | sp = (b & 0x80) ? fg_buf : bg_buf; |
753 | 809 | ||
754 | /* Copy the pixel. */ |
810 | /* Copy the pixel. */ |
755 | for (j = 0; j < screen.pixelbytes; j++) { |
811 | for (j = 0; j < screen.pixelbytes; j++) { |
756 | *dp++ = *sp++; |
812 | *dp++ = *sp++; |
757 | } |
813 | } |
758 | 814 | ||
759 | /* Move to the next bit. */ |
815 | /* Move to the next bit. */ |
760 | b = b << 1; |
816 | b = b << 1; |
761 | } |
817 | } |
762 | 818 | ||
763 | /* Move to the beginning of the next scanline of the cell. */ |
819 | /* Move to the beginning of the next scanline of the cell. */ |
764 | dp += d_add; |
820 | dp += d_add; |
765 | } |
821 | } |
766 | } |
822 | } |
767 | 823 | ||
768 | /** Draw glyph at specified position in viewport. |
824 | /** Draw glyph at specified position in viewport. |
769 | * |
825 | * |
770 | * @param vport Viewport identification |
826 | * @param vport Viewport identification |
771 | * @param cursor Draw glyph with cursor |
827 | * @param cursor Draw glyph with cursor |
772 | * @param col Screen position relative to viewport |
828 | * @param col Screen position relative to viewport |
773 | * @param row Screen position relative to viewport |
829 | * @param row Screen position relative to viewport |
774 | * |
830 | * |
775 | */ |
831 | */ |
776 | static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col, |
832 | static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col, |
777 | unsigned int row) |
833 | unsigned int row) |
778 | { |
834 | { |
779 | unsigned int x = vport->x + COL2X(col); |
835 | unsigned int x = vport->x + COL2X(col); |
780 | unsigned int y = vport->y + ROW2Y(row); |
836 | unsigned int y = vport->y + ROW2Y(row); |
781 | - | ||
782 | uint32_t glyph; |
- | |
783 | uint32_t fg_color; |
- | |
784 | uint32_t bg_color; |
- | |
785 | 837 | ||
786 | glyph = vport->backbuf[BB_POS(vport, col, row)].glyph; |
838 | uint32_t glyph = vport->backbuf[BB_POS(vport, col, row)].glyph; |
787 | fg_color = vport->backbuf[BB_POS(vport, col, row)].fg_color; |
839 | uint32_t fg_color = vport->backbuf[BB_POS(vport, col, row)].fg_color; |
788 | bg_color = vport->backbuf[BB_POS(vport, col, row)].bg_color; |
840 | uint32_t bg_color = vport->backbuf[BB_POS(vport, col, row)].bg_color; |
789 | 841 | ||
790 | (*vport->dglyph)(x, y, cursor, screen.glyphs, glyph, |
842 | (*vport->dglyph)(x, y, cursor, screen.glyphs, glyph, |
791 | fg_color, bg_color); |
843 | fg_color, bg_color); |
792 | } |
844 | } |
793 | 845 | ||
794 | /** Hide cursor if it is shown |
846 | /** Hide cursor if it is shown |
795 | * |
847 | * |
796 | */ |
848 | */ |
797 | static void cursor_hide(viewport_t *vport) |
849 | static void cursor_hide(viewport_t *vport) |
798 | { |
850 | { |
799 | if ((vport->cursor_active) && (vport->cursor_shown)) { |
851 | if ((vport->cursor_active) && (vport->cursor_shown)) { |
800 | draw_vp_glyph(vport, false, vport->cur_col, vport->cur_row); |
852 | draw_vp_glyph(vport, false, vport->cur_col, vport->cur_row); |
801 | vport->cursor_shown = false; |
853 | vport->cursor_shown = false; |
802 | } |
854 | } |
803 | } |
855 | } |
804 | 856 | ||
805 | 857 | ||
806 | /** Show cursor if cursor showing is enabled |
858 | /** Show cursor if cursor showing is enabled |
807 | * |
859 | * |
808 | */ |
860 | */ |
809 | static void cursor_show(viewport_t *vport) |
861 | static void cursor_show(viewport_t *vport) |
810 | { |
862 | { |
811 | /* Do not check for cursor_shown */ |
863 | /* Do not check for cursor_shown */ |
812 | if (vport->cursor_active) { |
864 | if (vport->cursor_active) { |
813 | draw_vp_glyph(vport, true, vport->cur_col, vport->cur_row); |
865 | draw_vp_glyph(vport, true, vport->cur_col, vport->cur_row); |
814 | vport->cursor_shown = true; |
866 | vport->cursor_shown = true; |
815 | } |
867 | } |
816 | } |
868 | } |
817 | 869 | ||
818 | 870 | ||
819 | /** Invert cursor, if it is enabled |
871 | /** Invert cursor, if it is enabled |
820 | * |
872 | * |
821 | */ |
873 | */ |
822 | static void cursor_blink(viewport_t *vport) |
874 | static void cursor_blink(viewport_t *vport) |
823 | { |
875 | { |
824 | if (vport->cursor_shown) |
876 | if (vport->cursor_shown) |
825 | cursor_hide(vport); |
877 | cursor_hide(vport); |
826 | else |
878 | else |
827 | cursor_show(vport); |
879 | cursor_show(vport); |
828 | } |
880 | } |
829 | 881 | ||
830 | 882 | ||
831 | /** Draw character at given position relative to viewport |
883 | /** Draw character at given position relative to viewport |
832 | * |
884 | * |
833 | * @param vport Viewport identification |
885 | * @param vport Viewport identification |
834 | * @param c Character to draw |
886 | * @param c Character to draw |
835 | * @param col Screen position relative to viewport |
887 | * @param col Screen position relative to viewport |
836 | * @param row Screen position relative to viewport |
888 | * @param row Screen position relative to viewport |
837 | * |
889 | * |
838 | */ |
890 | */ |
839 | static void draw_char(viewport_t *vport, wchar_t c, unsigned int col, unsigned int row) |
891 | static void draw_char(viewport_t *vport, wchar_t c, unsigned int col, unsigned int row) |
840 | { |
892 | { |
841 | bb_cell_t *bbp; |
893 | bb_cell_t *bbp; |
842 | 894 | ||
843 | /* Do not hide cursor if we are going to overwrite it */ |
895 | /* Do not hide cursor if we are going to overwrite it */ |
844 | if ((vport->cursor_active) && (vport->cursor_shown) && |
896 | if ((vport->cursor_active) && (vport->cursor_shown) && |
845 | ((vport->cur_col != col) || (vport->cur_row != row))) |
897 | ((vport->cur_col != col) || (vport->cur_row != row))) |
846 | cursor_hide(vport); |
898 | cursor_hide(vport); |
847 | 899 | ||
848 | bbp = &vport->backbuf[BB_POS(vport, col, row)]; |
900 | bbp = &vport->backbuf[BB_POS(vport, col, row)]; |
849 | bbp->glyph = fb_font_glyph(c); |
901 | bbp->glyph = fb_font_glyph(c); |
850 | bbp->fg_color = vport->attr.fg_color; |
902 | bbp->fg_color = vport->attr.fg_color; |
851 | bbp->bg_color = vport->attr.bg_color; |
903 | bbp->bg_color = vport->attr.bg_color; |
852 | 904 | ||
853 | draw_vp_glyph(vport, false, col, row); |
905 | draw_vp_glyph(vport, false, col, row); |
854 | 906 | ||
855 | vport->cur_col = col; |
907 | vport->cur_col = col; |
856 | vport->cur_row = row; |
908 | vport->cur_row = row; |
857 | 909 | ||
858 | vport->cur_col++; |
910 | vport->cur_col++; |
859 | if (vport->cur_col >= vport->cols) { |
911 | if (vport->cur_col >= vport->cols) { |
860 | vport->cur_col = 0; |
912 | vport->cur_col = 0; |
861 | vport->cur_row++; |
913 | vport->cur_row++; |
862 | if (vport->cur_row >= vport->rows) |
914 | if (vport->cur_row >= vport->rows) |
863 | vport->cur_row--; |
915 | vport->cur_row--; |
864 | } |
916 | } |
865 | 917 | ||
866 | cursor_show(vport); |
918 | cursor_show(vport); |
867 | } |
919 | } |
868 | 920 | ||
869 | /** Draw text data to viewport. |
921 | /** Draw text data to viewport. |
870 | * |
922 | * |
871 | * @param vport Viewport id |
923 | * @param vport Viewport id |
872 | * @param data Text data. |
924 | * @param data Text data. |
873 | * @param x Leftmost column of the area. |
925 | * @param x Leftmost column of the area. |
874 | * @param y Topmost row of the area. |
926 | * @param y Topmost row of the area. |
875 | * @param w Number of rows. |
927 | * @param w Number of rows. |
876 | * @param h Number of columns. |
928 | * @param h Number of columns. |
- | 929 | * |
|
877 | */ |
930 | */ |
878 | static void draw_text_data(viewport_t *vport, keyfield_t *data, unsigned int x, |
931 | static void draw_text_data(viewport_t *vport, keyfield_t *data, unsigned int x, |
879 | unsigned int y, unsigned int w, unsigned int h) |
932 | unsigned int y, unsigned int w, unsigned int h) |
880 | { |
933 | { |
- | 934 | unsigned int i; |
|
881 | unsigned int i, j; |
935 | unsigned int j; |
882 | bb_cell_t *bbp; |
936 | bb_cell_t *bbp; |
883 | attrs_t *a; |
937 | attrs_t *a; |
884 | attr_rgb_t rgb; |
938 | attr_rgb_t rgb; |
885 | 939 | ||
886 | for (j = 0; j < h; j++) { |
940 | for (j = 0; j < h; j++) { |
887 | for (i = 0; i < w; i++) { |
941 | for (i = 0; i < w; i++) { |
888 | unsigned int col = x + i; |
942 | unsigned int col = x + i; |
889 | unsigned int row = y + j; |
943 | unsigned int row = y + j; |
890 | 944 | ||
891 | bbp = &vport->backbuf[BB_POS(vport, col, row)]; |
945 | bbp = &vport->backbuf[BB_POS(vport, col, row)]; |
892 | 946 | ||
893 | a = &data[j * w + i].attrs; |
947 | a = &data[j * w + i].attrs; |
894 | rgb_from_attr(&rgb, a); |
948 | rgb_from_attr(&rgb, a); |
895 | 949 | ||
896 | bbp->glyph = fb_font_glyph(data[j * w + i].character); |
950 | bbp->glyph = fb_font_glyph(data[j * w + i].character); |
897 | bbp->fg_color = rgb.fg_color; |
951 | bbp->fg_color = rgb.fg_color; |
898 | bbp->bg_color = rgb.bg_color; |
952 | bbp->bg_color = rgb.bg_color; |
899 | 953 | ||
900 | draw_vp_glyph(vport, false, col, row); |
954 | draw_vp_glyph(vport, false, col, row); |
901 | } |
955 | } |
902 | } |
956 | } |
903 | cursor_show(vport); |
957 | cursor_show(vport); |
904 | } |
958 | } |
905 | 959 | ||
906 | 960 | ||
907 | static void putpixel_pixmap(void *data, unsigned int x, unsigned int y, uint32_t color) |
961 | static void putpixel_pixmap(void *data, unsigned int x, unsigned int y, uint32_t color) |
908 | { |
962 | { |
909 | int pm = *((int *) data); |
963 | int pm = *((int *) data); |
910 | pixmap_t *pmap = &pixmaps[pm]; |
964 | pixmap_t *pmap = &pixmaps[pm]; |
911 | unsigned int pos = (y * pmap->width + x) * screen.pixelbytes; |
965 | unsigned int pos = (y * pmap->width + x) * screen.pixelbytes; |
912 | 966 | ||
913 | screen.rgb_conv(&pmap->data[pos], color); |
967 | screen.rgb_conv(&pmap->data[pos], color); |
914 | } |
968 | } |
915 | 969 | ||
916 | 970 | ||
917 | static void putpixel(void *data, unsigned int x, unsigned int y, uint32_t color) |
971 | static void putpixel(void *data, unsigned int x, unsigned int y, uint32_t color) |
918 | { |
972 | { |
919 | viewport_t *vport = (viewport_t *) data; |
973 | viewport_t *vport = (viewport_t *) data; |
920 | unsigned int dx = vport->x + x; |
974 | unsigned int dx = vport->x + x; |
921 | unsigned int dy = vport->y + y; |
975 | unsigned int dy = vport->y + y; |
922 | 976 | ||
923 | screen.rgb_conv(&screen.fb_addr[FB_POS(dx, dy)], color); |
977 | screen.rgb_conv(&screen.fb_addr[FB_POS(dx, dy)], color); |
924 | } |
978 | } |
925 | 979 | ||
926 | 980 | ||
927 | /** Return first free pixmap |
981 | /** Return first free pixmap |
928 | * |
982 | * |
929 | */ |
983 | */ |
930 | static int find_free_pixmap(void) |
984 | static int find_free_pixmap(void) |
931 | { |
985 | { |
932 | unsigned int i; |
986 | unsigned int i; |
933 | 987 | ||
934 | for (i = 0; i < MAX_PIXMAPS; i++) |
988 | for (i = 0; i < MAX_PIXMAPS; i++) |
935 | if (!pixmaps[i].data) |
989 | if (!pixmaps[i].data) |
936 | return i; |
990 | return i; |
937 | 991 | ||
938 | return -1; |
992 | return -1; |
939 | } |
993 | } |
940 | 994 | ||
941 | 995 | ||
942 | /** Create a new pixmap and return appropriate ID |
996 | /** Create a new pixmap and return appropriate ID |
943 | * |
997 | * |
944 | */ |
998 | */ |
945 | static int shm2pixmap(unsigned char *shm, size_t size) |
999 | static int shm2pixmap(unsigned char *shm, size_t size) |
946 | { |
1000 | { |
947 | int pm; |
1001 | int pm; |
948 | pixmap_t *pmap; |
1002 | pixmap_t *pmap; |
949 | 1003 | ||
950 | pm = find_free_pixmap(); |
1004 | pm = find_free_pixmap(); |
951 | if (pm == -1) |
1005 | if (pm == -1) |
952 | return ELIMIT; |
1006 | return ELIMIT; |
953 | 1007 | ||
954 | pmap = &pixmaps[pm]; |
1008 | pmap = &pixmaps[pm]; |
955 | 1009 | ||
956 | if (ppm_get_data(shm, size, &pmap->width, &pmap->height)) |
1010 | if (ppm_get_data(shm, size, &pmap->width, &pmap->height)) |
957 | return EINVAL; |
1011 | return EINVAL; |
958 | 1012 | ||
959 | pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes); |
1013 | pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes); |
960 | if (!pmap->data) |
1014 | if (!pmap->data) |
961 | return ENOMEM; |
1015 | return ENOMEM; |
962 | 1016 | ||
963 | ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, putpixel_pixmap, (void *) &pm); |
1017 | ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, putpixel_pixmap, (void *) &pm); |
964 | 1018 | ||
965 | return pm; |
1019 | return pm; |
966 | } |
1020 | } |
967 | 1021 | ||
968 | 1022 | ||
969 | /** Handle shared memory communication calls |
1023 | /** Handle shared memory communication calls |
970 | * |
1024 | * |
971 | * Protocol for drawing pixmaps: |
1025 | * Protocol for drawing pixmaps: |
972 | * - FB_PREPARE_SHM(client shm identification) |
1026 | * - FB_PREPARE_SHM(client shm identification) |
973 | * - IPC_M_AS_AREA_SEND |
1027 | * - IPC_M_AS_AREA_SEND |
974 | * - FB_DRAW_PPM(startx, starty) |
1028 | * - FB_DRAW_PPM(startx, starty) |
975 | * - FB_DROP_SHM |
1029 | * - FB_DROP_SHM |
976 | * |
1030 | * |
977 | * Protocol for text drawing |
1031 | * Protocol for text drawing |
978 | * - IPC_M_AS_AREA_SEND |
1032 | * - IPC_M_AS_AREA_SEND |
979 | * - FB_DRAW_TEXT_DATA |
1033 | * - FB_DRAW_TEXT_DATA |
980 | * |
1034 | * |
981 | * @param callid Callid of the current call |
1035 | * @param callid Callid of the current call |
982 | * @param call Current call data |
1036 | * @param call Current call data |
983 | * @param vp Active viewport |
1037 | * @param vp Active viewport |
984 | * |
1038 | * |
985 | * @return false if the call was not handled byt this function, true otherwise |
1039 | * @return false if the call was not handled byt this function, true otherwise |
986 | * |
1040 | * |
987 | * Note: this function is not threads safe, you would have |
1041 | * Note: this function is not threads safe, you would have |
988 | * to redefine static variables with __thread |
1042 | * to redefine static variables with __thread |
989 | * |
1043 | * |
990 | */ |
1044 | */ |
991 | static bool shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
1045 | static bool shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
992 | { |
1046 | { |
993 | static keyfield_t *interbuffer = NULL; |
1047 | static keyfield_t *interbuffer = NULL; |
994 | static size_t intersize = 0; |
1048 | static size_t intersize = 0; |
995 | 1049 | ||
996 | static unsigned char *shm = NULL; |
1050 | static unsigned char *shm = NULL; |
997 | static ipcarg_t shm_id = 0; |
1051 | static ipcarg_t shm_id = 0; |
998 | static size_t shm_size; |
1052 | static size_t shm_size; |
999 | 1053 | ||
1000 | bool handled = true; |
1054 | bool handled = true; |
1001 | int retval = EOK; |
1055 | int retval = EOK; |
1002 | viewport_t *vport = &viewports[vp]; |
1056 | viewport_t *vport = &viewports[vp]; |
1003 | unsigned int x; |
1057 | unsigned int x; |
1004 | unsigned int y; |
1058 | unsigned int y; |
1005 | unsigned int w; |
1059 | unsigned int w; |
1006 | unsigned int h; |
1060 | unsigned int h; |
1007 | 1061 | ||
1008 | switch (IPC_GET_METHOD(*call)) { |
1062 | switch (IPC_GET_METHOD(*call)) { |
1009 | case IPC_M_SHARE_OUT: |
1063 | case IPC_M_SHARE_OUT: |
1010 | /* We accept one area for data interchange */ |
1064 | /* We accept one area for data interchange */ |
1011 | if (IPC_GET_ARG1(*call) == shm_id) { |
1065 | if (IPC_GET_ARG1(*call) == shm_id) { |
1012 | void *dest = as_get_mappable_page(IPC_GET_ARG2(*call)); |
1066 | void *dest = as_get_mappable_page(IPC_GET_ARG2(*call)); |
1013 | shm_size = IPC_GET_ARG2(*call); |
1067 | shm_size = IPC_GET_ARG2(*call); |
1014 | if (!ipc_answer_1(callid, EOK, (sysarg_t) dest)) |
1068 | if (!ipc_answer_1(callid, EOK, (sysarg_t) dest)) |
1015 | shm = dest; |
1069 | shm = dest; |
1016 | else |
1070 | else |
1017 | shm_id = 0; |
1071 | shm_id = 0; |
1018 | 1072 | ||
1019 | if (shm[0] != 'P') |
1073 | if (shm[0] != 'P') |
1020 | return false; |
1074 | return false; |
1021 | 1075 | ||
1022 | return true; |
1076 | return true; |
1023 | } else { |
1077 | } else { |
1024 | intersize = IPC_GET_ARG2(*call); |
1078 | intersize = IPC_GET_ARG2(*call); |
1025 | receive_comm_area(callid, call, (void *) &interbuffer); |
1079 | receive_comm_area(callid, call, (void *) &interbuffer); |
1026 | } |
1080 | } |
1027 | return true; |
1081 | return true; |
1028 | case FB_PREPARE_SHM: |
1082 | case FB_PREPARE_SHM: |
1029 | if (shm_id) |
1083 | if (shm_id) |
1030 | retval = EBUSY; |
1084 | retval = EBUSY; |
1031 | else |
1085 | else |
1032 | shm_id = IPC_GET_ARG1(*call); |
1086 | shm_id = IPC_GET_ARG1(*call); |
1033 | break; |
1087 | break; |
1034 | 1088 | ||
1035 | case FB_DROP_SHM: |
1089 | case FB_DROP_SHM: |
1036 | if (shm) { |
1090 | if (shm) { |
1037 | as_area_destroy(shm); |
1091 | as_area_destroy(shm); |
1038 | shm = NULL; |
1092 | shm = NULL; |
1039 | } |
1093 | } |
1040 | shm_id = 0; |
1094 | shm_id = 0; |
1041 | break; |
1095 | break; |
1042 | 1096 | ||
1043 | case FB_SHM2PIXMAP: |
1097 | case FB_SHM2PIXMAP: |
1044 | if (!shm) { |
1098 | if (!shm) { |
1045 | retval = EINVAL; |
1099 | retval = EINVAL; |
1046 | break; |
1100 | break; |
1047 | } |
1101 | } |
1048 | retval = shm2pixmap(shm, shm_size); |
1102 | retval = shm2pixmap(shm, shm_size); |
1049 | break; |
1103 | break; |
1050 | case FB_DRAW_PPM: |
1104 | case FB_DRAW_PPM: |
1051 | if (!shm) { |
1105 | if (!shm) { |
1052 | retval = EINVAL; |
1106 | retval = EINVAL; |
1053 | break; |
1107 | break; |
1054 | } |
1108 | } |
1055 | x = IPC_GET_ARG1(*call); |
1109 | x = IPC_GET_ARG1(*call); |
1056 | y = IPC_GET_ARG2(*call); |
1110 | y = IPC_GET_ARG2(*call); |
1057 | 1111 | ||
1058 | if ((x > vport->width) || (y > vport->height)) { |
1112 | if ((x > vport->width) || (y > vport->height)) { |
1059 | retval = EINVAL; |
1113 | retval = EINVAL; |
1060 | break; |
1114 | break; |
1061 | } |
1115 | } |
1062 | 1116 | ||
1063 | ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), |
1117 | ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), |
1064 | IPC_GET_ARG2(*call), vport->width - x, vport->height - y, putpixel, (void *) vport); |
1118 | IPC_GET_ARG2(*call), vport->width - x, vport->height - y, putpixel, (void *) vport); |
1065 | break; |
1119 | break; |
1066 | case FB_DRAW_TEXT_DATA: |
1120 | case FB_DRAW_TEXT_DATA: |
1067 | x = IPC_GET_ARG1(*call); |
1121 | x = IPC_GET_ARG1(*call); |
1068 | y = IPC_GET_ARG2(*call); |
1122 | y = IPC_GET_ARG2(*call); |
1069 | w = IPC_GET_ARG3(*call); |
1123 | w = IPC_GET_ARG3(*call); |
1070 | h = IPC_GET_ARG4(*call); |
1124 | h = IPC_GET_ARG4(*call); |
1071 | if (!interbuffer) { |
1125 | if (!interbuffer) { |
1072 | retval = EINVAL; |
1126 | retval = EINVAL; |
1073 | break; |
1127 | break; |
1074 | } |
1128 | } |
1075 | if (x + w > vport->cols || y + h > vport->rows) { |
1129 | if (x + w > vport->cols || y + h > vport->rows) { |
1076 | retval = EINVAL; |
1130 | retval = EINVAL; |
1077 | break; |
1131 | break; |
1078 | } |
1132 | } |
1079 | if (intersize < w * h * sizeof(*interbuffer)) { |
1133 | if (intersize < w * h * sizeof(*interbuffer)) { |
1080 | retval = EINVAL; |
1134 | retval = EINVAL; |
1081 | break; |
1135 | break; |
1082 | } |
1136 | } |
1083 | draw_text_data(vport, interbuffer, x, y, w, h); |
1137 | draw_text_data(vport, interbuffer, x, y, w, h); |
1084 | break; |
1138 | break; |
1085 | default: |
1139 | default: |
1086 | handled = false; |
1140 | handled = false; |
1087 | } |
1141 | } |
1088 | 1142 | ||
1089 | if (handled) |
1143 | if (handled) |
1090 | ipc_answer_0(callid, retval); |
1144 | ipc_answer_0(callid, retval); |
1091 | return handled; |
1145 | return handled; |
1092 | } |
1146 | } |
1093 | 1147 | ||
1094 | 1148 | ||
1095 | static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap) |
1149 | static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap) |
1096 | { |
1150 | { |
1097 | unsigned int width = vport->width; |
1151 | unsigned int width = vport->width; |
1098 | unsigned int height = vport->height; |
1152 | unsigned int height = vport->height; |
1099 | 1153 | ||
1100 | if (width + vport->x > screen.xres) |
1154 | if (width + vport->x > screen.xres) |
1101 | width = screen.xres - vport->x; |
1155 | width = screen.xres - vport->x; |
1102 | if (height + vport->y > screen.yres) |
1156 | if (height + vport->y > screen.yres) |
1103 | height = screen.yres - vport->y; |
1157 | height = screen.yres - vport->y; |
1104 | 1158 | ||
1105 | unsigned int realwidth = pmap->width <= width ? pmap->width : width; |
1159 | unsigned int realwidth = pmap->width <= width ? pmap->width : width; |
1106 | unsigned int realheight = pmap->height <= height ? pmap->height : height; |
1160 | unsigned int realheight = pmap->height <= height ? pmap->height : height; |
1107 | 1161 | ||
1108 | unsigned int srcrowsize = vport->width * screen.pixelbytes; |
1162 | unsigned int srcrowsize = vport->width * screen.pixelbytes; |
1109 | unsigned int realrowsize = realwidth * screen.pixelbytes; |
1163 | unsigned int realrowsize = realwidth * screen.pixelbytes; |
1110 | 1164 | ||
1111 | unsigned int y; |
1165 | unsigned int y; |
1112 | for (y = 0; y < realheight; y++) { |
1166 | for (y = 0; y < realheight; y++) { |
1113 | unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; |
1167 | unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; |
1114 | memcpy(pmap->data + srcrowsize * y, screen.fb_addr + tmp, realrowsize); |
1168 | memcpy(pmap->data + srcrowsize * y, screen.fb_addr + tmp, realrowsize); |
1115 | } |
1169 | } |
1116 | } |
1170 | } |
1117 | 1171 | ||
1118 | 1172 | ||
1119 | /** Save viewport to pixmap |
1173 | /** Save viewport to pixmap |
1120 | * |
1174 | * |
1121 | */ |
1175 | */ |
1122 | static int save_vp_to_pixmap(viewport_t *vport) |
1176 | static int save_vp_to_pixmap(viewport_t *vport) |
1123 | { |
1177 | { |
1124 | int pm; |
1178 | int pm; |
1125 | pixmap_t *pmap; |
1179 | pixmap_t *pmap; |
1126 | 1180 | ||
1127 | pm = find_free_pixmap(); |
1181 | pm = find_free_pixmap(); |
1128 | if (pm == -1) |
1182 | if (pm == -1) |
1129 | return ELIMIT; |
1183 | return ELIMIT; |
1130 | 1184 | ||
1131 | pmap = &pixmaps[pm]; |
1185 | pmap = &pixmaps[pm]; |
1132 | pmap->data = malloc(screen.pixelbytes * vport->width * vport->height); |
1186 | pmap->data = malloc(screen.pixelbytes * vport->width * vport->height); |
1133 | if (!pmap->data) |
1187 | if (!pmap->data) |
1134 | return ENOMEM; |
1188 | return ENOMEM; |
1135 | 1189 | ||
1136 | pmap->width = vport->width; |
1190 | pmap->width = vport->width; |
1137 | pmap->height = vport->height; |
1191 | pmap->height = vport->height; |
1138 | 1192 | ||
1139 | copy_vp_to_pixmap(vport, pmap); |
1193 | copy_vp_to_pixmap(vport, pmap); |
1140 | 1194 | ||
1141 | return pm; |
1195 | return pm; |
1142 | } |
1196 | } |
1143 | 1197 | ||
1144 | 1198 | ||
1145 | /** Draw pixmap on screen |
1199 | /** Draw pixmap on screen |
1146 | * |
1200 | * |
1147 | * @param vp Viewport to draw on |
1201 | * @param vp Viewport to draw on |
1148 | * @param pm Pixmap identifier |
1202 | * @param pm Pixmap identifier |
1149 | * |
1203 | * |
1150 | */ |
1204 | */ |
1151 | static int draw_pixmap(int vp, int pm) |
1205 | static int draw_pixmap(int vp, int pm) |
1152 | { |
1206 | { |
1153 | pixmap_t *pmap = &pixmaps[pm]; |
1207 | pixmap_t *pmap = &pixmaps[pm]; |
1154 | viewport_t *vport = &viewports[vp]; |
1208 | viewport_t *vport = &viewports[vp]; |
1155 | 1209 | ||
1156 | unsigned int width = vport->width; |
1210 | unsigned int width = vport->width; |
1157 | unsigned int height = vport->height; |
1211 | unsigned int height = vport->height; |
1158 | 1212 | ||
1159 | if (width + vport->x > screen.xres) |
1213 | if (width + vport->x > screen.xres) |
1160 | width = screen.xres - vport->x; |
1214 | width = screen.xres - vport->x; |
1161 | if (height + vport->y > screen.yres) |
1215 | if (height + vport->y > screen.yres) |
1162 | height = screen.yres - vport->y; |
1216 | height = screen.yres - vport->y; |
1163 | 1217 | ||
1164 | if (!pmap->data) |
1218 | if (!pmap->data) |
1165 | return EINVAL; |
1219 | return EINVAL; |
1166 | 1220 | ||
1167 | unsigned int realwidth = pmap->width <= width ? pmap->width : width; |
1221 | unsigned int realwidth = pmap->width <= width ? pmap->width : width; |
1168 | unsigned int realheight = pmap->height <= height ? pmap->height : height; |
1222 | unsigned int realheight = pmap->height <= height ? pmap->height : height; |
1169 | 1223 | ||
1170 | unsigned int srcrowsize = vport->width * screen.pixelbytes; |
1224 | unsigned int srcrowsize = vport->width * screen.pixelbytes; |
1171 | unsigned int realrowsize = realwidth * screen.pixelbytes; |
1225 | unsigned int realrowsize = realwidth * screen.pixelbytes; |
1172 | 1226 | ||
1173 | unsigned int y; |
1227 | unsigned int y; |
1174 | for (y = 0; y < realheight; y++) { |
1228 | for (y = 0; y < realheight; y++) { |
1175 | unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; |
1229 | unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; |
1176 | memcpy(screen.fb_addr + tmp, pmap->data + y * srcrowsize, realrowsize); |
1230 | memcpy(screen.fb_addr + tmp, pmap->data + y * srcrowsize, realrowsize); |
1177 | } |
1231 | } |
1178 | 1232 | ||
1179 | return EOK; |
1233 | return EOK; |
1180 | } |
1234 | } |
1181 | 1235 | ||
1182 | 1236 | ||
1183 | /** Tick animation one step forward |
1237 | /** Tick animation one step forward |
1184 | * |
1238 | * |
1185 | */ |
1239 | */ |
1186 | static void anims_tick(void) |
1240 | static void anims_tick(void) |
1187 | { |
1241 | { |
1188 | unsigned int i; |
1242 | unsigned int i; |
1189 | static int counts = 0; |
1243 | static int counts = 0; |
1190 | 1244 | ||
1191 | /* Limit redrawing */ |
1245 | /* Limit redrawing */ |
1192 | counts = (counts + 1) % 8; |
1246 | counts = (counts + 1) % 8; |
1193 | if (counts) |
1247 | if (counts) |
1194 | return; |
1248 | return; |
1195 | 1249 | ||
1196 | for (i = 0; i < MAX_ANIMATIONS; i++) { |
1250 | for (i = 0; i < MAX_ANIMATIONS; i++) { |
1197 | if ((!animations[i].animlen) || (!animations[i].initialized) || |
1251 | if ((!animations[i].animlen) || (!animations[i].initialized) || |
1198 | (!animations[i].enabled)) |
1252 | (!animations[i].enabled)) |
1199 | continue; |
1253 | continue; |
1200 | 1254 | ||
1201 | draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]); |
1255 | draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]); |
1202 | animations[i].pos = (animations[i].pos + 1) % animations[i].animlen; |
1256 | animations[i].pos = (animations[i].pos + 1) % animations[i].animlen; |
1203 | } |
1257 | } |
1204 | } |
1258 | } |
1205 | 1259 | ||
1206 | 1260 | ||
1207 | static unsigned int pointer_x; |
1261 | static unsigned int pointer_x; |
1208 | static unsigned int pointer_y; |
1262 | static unsigned int pointer_y; |
1209 | static bool pointer_shown, pointer_enabled; |
1263 | static bool pointer_shown, pointer_enabled; |
1210 | static int pointer_vport = -1; |
1264 | static int pointer_vport = -1; |
1211 | static int pointer_pixmap = -1; |
1265 | static int pointer_pixmap = -1; |
1212 | 1266 | ||
1213 | 1267 | ||
1214 | static void mouse_show(void) |
1268 | static void mouse_show(void) |
1215 | { |
1269 | { |
1216 | int i, j; |
1270 | int i, j; |
1217 | int visibility; |
1271 | int visibility; |
1218 | int color; |
1272 | int color; |
1219 | int bytepos; |
1273 | int bytepos; |
1220 | 1274 | ||
1221 | if ((pointer_shown) || (!pointer_enabled)) |
1275 | if ((pointer_shown) || (!pointer_enabled)) |
1222 | return; |
1276 | return; |
1223 | 1277 | ||
1224 | /* Save image under the pointer. */ |
1278 | /* Save image under the pointer. */ |
1225 | if (pointer_vport == -1) { |
1279 | if (pointer_vport == -1) { |
1226 | pointer_vport = vport_create(pointer_x, pointer_y, pointer_width, pointer_height); |
1280 | pointer_vport = vport_create(pointer_x, pointer_y, pointer_width, pointer_height); |
1227 | if (pointer_vport < 0) |
1281 | if (pointer_vport < 0) |
1228 | return; |
1282 | return; |
1229 | } else { |
1283 | } else { |
1230 | viewports[pointer_vport].x = pointer_x; |
1284 | viewports[pointer_vport].x = pointer_x; |
1231 | viewports[pointer_vport].y = pointer_y; |
1285 | viewports[pointer_vport].y = pointer_y; |
1232 | } |
1286 | } |
1233 | 1287 | ||
1234 | if (pointer_pixmap == -1) |
1288 | if (pointer_pixmap == -1) |
1235 | pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]); |
1289 | pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]); |
1236 | else |
1290 | else |
1237 | copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]); |
1291 | copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]); |
1238 | 1292 | ||
1239 | /* Draw mouse pointer. */ |
1293 | /* Draw mouse pointer. */ |
1240 | for (i = 0; i < pointer_height; i++) |
1294 | for (i = 0; i < pointer_height; i++) |
1241 | for (j = 0; j < pointer_width; j++) { |
1295 | for (j = 0; j < pointer_width; j++) { |
1242 | bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8; |
1296 | bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8; |
1243 | visibility = pointer_mask_bits[bytepos] & |
1297 | visibility = pointer_mask_bits[bytepos] & |
1244 | (1 << (j % 8)); |
1298 | (1 << (j % 8)); |
1245 | if (visibility) { |
1299 | if (visibility) { |
1246 | color = pointer_bits[bytepos] & |
1300 | color = pointer_bits[bytepos] & |
1247 | (1 << (j % 8)) ? 0 : 0xffffff; |
1301 | (1 << (j % 8)) ? 0 : 0xffffff; |
1248 | if (pointer_x + j < screen.xres && pointer_y + |
1302 | if (pointer_x + j < screen.xres && pointer_y + |
1249 | i < screen.yres) |
1303 | i < screen.yres) |
1250 | putpixel(&viewports[0], pointer_x + j, |
1304 | putpixel(&viewports[0], pointer_x + j, |
1251 | pointer_y + i, color); |
1305 | pointer_y + i, color); |
1252 | } |
1306 | } |
1253 | } |
1307 | } |
1254 | pointer_shown = 1; |
1308 | pointer_shown = 1; |
1255 | } |
1309 | } |
1256 | 1310 | ||
1257 | 1311 | ||
1258 | static void mouse_hide(void) |
1312 | static void mouse_hide(void) |
1259 | { |
1313 | { |
1260 | /* Restore image under the pointer. */ |
1314 | /* Restore image under the pointer. */ |
1261 | if (pointer_shown) { |
1315 | if (pointer_shown) { |
1262 | draw_pixmap(pointer_vport, pointer_pixmap); |
1316 | draw_pixmap(pointer_vport, pointer_pixmap); |
1263 | pointer_shown = 0; |
1317 | pointer_shown = 0; |
1264 | } |
1318 | } |
1265 | } |
1319 | } |
1266 | 1320 | ||
1267 | 1321 | ||
1268 | static void mouse_move(unsigned int x, unsigned int y) |
1322 | static void mouse_move(unsigned int x, unsigned int y) |
1269 | { |
1323 | { |
1270 | mouse_hide(); |
1324 | mouse_hide(); |
1271 | pointer_x = x; |
1325 | pointer_x = x; |
1272 | pointer_y = y; |
1326 | pointer_y = y; |
1273 | mouse_show(); |
1327 | mouse_show(); |
1274 | } |
1328 | } |
1275 | 1329 | ||
1276 | 1330 | ||
1277 | static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
1331 | static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
1278 | { |
1332 | { |
1279 | bool handled = true; |
1333 | bool handled = true; |
1280 | int retval = EOK; |
1334 | int retval = EOK; |
1281 | int i, nvp; |
1335 | int i, nvp; |
1282 | int newval; |
1336 | int newval; |
1283 | 1337 | ||
1284 | switch (IPC_GET_METHOD(*call)) { |
1338 | switch (IPC_GET_METHOD(*call)) { |
1285 | case FB_ANIM_CREATE: |
1339 | case FB_ANIM_CREATE: |
1286 | nvp = IPC_GET_ARG1(*call); |
1340 | nvp = IPC_GET_ARG1(*call); |
1287 | if (nvp == -1) |
1341 | if (nvp == -1) |
1288 | nvp = vp; |
1342 | nvp = vp; |
1289 | if (nvp >= MAX_VIEWPORTS || nvp < 0 || |
1343 | if (nvp >= MAX_VIEWPORTS || nvp < 0 || |
1290 | !viewports[nvp].initialized) { |
1344 | !viewports[nvp].initialized) { |
1291 | retval = EINVAL; |
1345 | retval = EINVAL; |
1292 | break; |
1346 | break; |
1293 | } |
1347 | } |
1294 | for (i = 0; i < MAX_ANIMATIONS; i++) { |
1348 | for (i = 0; i < MAX_ANIMATIONS; i++) { |
1295 | if (!animations[i].initialized) |
1349 | if (!animations[i].initialized) |
1296 | break; |
1350 | break; |
1297 | } |
1351 | } |
1298 | if (i == MAX_ANIMATIONS) { |
1352 | if (i == MAX_ANIMATIONS) { |
1299 | retval = ELIMIT; |
1353 | retval = ELIMIT; |
1300 | break; |
1354 | break; |
1301 | } |
1355 | } |
1302 | animations[i].initialized = 1; |
1356 | animations[i].initialized = 1; |
1303 | animations[i].animlen = 0; |
1357 | animations[i].animlen = 0; |
1304 | animations[i].pos = 0; |
1358 | animations[i].pos = 0; |
1305 | animations[i].enabled = 0; |
1359 | animations[i].enabled = 0; |
1306 | animations[i].vp = nvp; |
1360 | animations[i].vp = nvp; |
1307 | retval = i; |
1361 | retval = i; |
1308 | break; |
1362 | break; |
1309 | case FB_ANIM_DROP: |
1363 | case FB_ANIM_DROP: |
1310 | i = IPC_GET_ARG1(*call); |
1364 | i = IPC_GET_ARG1(*call); |
1311 | if (i >= MAX_ANIMATIONS || i < 0) { |
1365 | if (i >= MAX_ANIMATIONS || i < 0) { |
1312 | retval = EINVAL; |
1366 | retval = EINVAL; |
1313 | break; |
1367 | break; |
1314 | } |
1368 | } |
1315 | animations[i].initialized = 0; |
1369 | animations[i].initialized = 0; |
1316 | break; |
1370 | break; |
1317 | case FB_ANIM_ADDPIXMAP: |
1371 | case FB_ANIM_ADDPIXMAP: |
1318 | i = IPC_GET_ARG1(*call); |
1372 | i = IPC_GET_ARG1(*call); |
1319 | if (i >= MAX_ANIMATIONS || i < 0 || |
1373 | if (i >= MAX_ANIMATIONS || i < 0 || |
1320 | !animations[i].initialized) { |
1374 | !animations[i].initialized) { |
1321 | retval = EINVAL; |
1375 | retval = EINVAL; |
1322 | break; |
1376 | break; |
1323 | } |
1377 | } |
1324 | if (animations[i].animlen == MAX_ANIM_LEN) { |
1378 | if (animations[i].animlen == MAX_ANIM_LEN) { |
1325 | retval = ELIMIT; |
1379 | retval = ELIMIT; |
1326 | break; |
1380 | break; |
1327 | } |
1381 | } |
1328 | newval = IPC_GET_ARG2(*call); |
1382 | newval = IPC_GET_ARG2(*call); |
1329 | if (newval < 0 || newval > MAX_PIXMAPS || |
1383 | if (newval < 0 || newval > MAX_PIXMAPS || |
1330 | !pixmaps[newval].data) { |
1384 | !pixmaps[newval].data) { |
1331 | retval = EINVAL; |
1385 | retval = EINVAL; |
1332 | break; |
1386 | break; |
1333 | } |
1387 | } |
1334 | animations[i].pixmaps[animations[i].animlen++] = newval; |
1388 | animations[i].pixmaps[animations[i].animlen++] = newval; |
1335 | break; |
1389 | break; |
1336 | case FB_ANIM_CHGVP: |
1390 | case FB_ANIM_CHGVP: |
1337 | i = IPC_GET_ARG1(*call); |
1391 | i = IPC_GET_ARG1(*call); |
1338 | if (i >= MAX_ANIMATIONS || i < 0) { |
1392 | if (i >= MAX_ANIMATIONS || i < 0) { |
1339 | retval = EINVAL; |
1393 | retval = EINVAL; |
1340 | break; |
1394 | break; |
1341 | } |
1395 | } |
1342 | nvp = IPC_GET_ARG2(*call); |
1396 | nvp = IPC_GET_ARG2(*call); |
1343 | if (nvp == -1) |
1397 | if (nvp == -1) |
1344 | nvp = vp; |
1398 | nvp = vp; |
1345 | if (nvp >= MAX_VIEWPORTS || nvp < 0 || |
1399 | if (nvp >= MAX_VIEWPORTS || nvp < 0 || |
1346 | !viewports[nvp].initialized) { |
1400 | !viewports[nvp].initialized) { |
1347 | retval = EINVAL; |
1401 | retval = EINVAL; |
1348 | break; |
1402 | break; |
1349 | } |
1403 | } |
1350 | animations[i].vp = nvp; |
1404 | animations[i].vp = nvp; |
1351 | break; |
1405 | break; |
1352 | case FB_ANIM_START: |
1406 | case FB_ANIM_START: |
1353 | case FB_ANIM_STOP: |
1407 | case FB_ANIM_STOP: |
1354 | i = IPC_GET_ARG1(*call); |
1408 | i = IPC_GET_ARG1(*call); |
1355 | if (i >= MAX_ANIMATIONS || i < 0) { |
1409 | if (i >= MAX_ANIMATIONS || i < 0) { |
1356 | retval = EINVAL; |
1410 | retval = EINVAL; |
1357 | break; |
1411 | break; |
1358 | } |
1412 | } |
1359 | newval = (IPC_GET_METHOD(*call) == FB_ANIM_START); |
1413 | newval = (IPC_GET_METHOD(*call) == FB_ANIM_START); |
1360 | if (newval ^ animations[i].enabled) { |
1414 | if (newval ^ animations[i].enabled) { |
1361 | animations[i].enabled = newval; |
1415 | animations[i].enabled = newval; |
1362 | anims_enabled += newval ? 1 : -1; |
1416 | anims_enabled += newval ? 1 : -1; |
1363 | } |
1417 | } |
1364 | break; |
1418 | break; |
1365 | default: |
1419 | default: |
1366 | handled = 0; |
1420 | handled = 0; |
1367 | } |
1421 | } |
1368 | if (handled) |
1422 | if (handled) |
1369 | ipc_answer_0(callid, retval); |
1423 | ipc_answer_0(callid, retval); |
1370 | return handled; |
1424 | return handled; |
1371 | } |
1425 | } |
1372 | 1426 | ||
1373 | 1427 | ||
1374 | /** Handler for messages concerning pixmap handling |
1428 | /** Handler for messages concerning pixmap handling |
1375 | * |
1429 | * |
1376 | */ |
1430 | */ |
1377 | static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
1431 | static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
1378 | { |
1432 | { |
1379 | bool handled = true; |
1433 | bool handled = true; |
1380 | int retval = EOK; |
1434 | int retval = EOK; |
1381 | int i, nvp; |
1435 | int i, nvp; |
1382 | 1436 | ||
1383 | switch (IPC_GET_METHOD(*call)) { |
1437 | switch (IPC_GET_METHOD(*call)) { |
1384 | case FB_VP_DRAW_PIXMAP: |
1438 | case FB_VP_DRAW_PIXMAP: |
1385 | nvp = IPC_GET_ARG1(*call); |
1439 | nvp = IPC_GET_ARG1(*call); |
1386 | if (nvp == -1) |
1440 | if (nvp == -1) |
1387 | nvp = vp; |
1441 | nvp = vp; |
1388 | if (nvp < 0 || nvp >= MAX_VIEWPORTS || |
1442 | if (nvp < 0 || nvp >= MAX_VIEWPORTS || |
1389 | !viewports[nvp].initialized) { |
1443 | !viewports[nvp].initialized) { |
1390 | retval = EINVAL; |
1444 | retval = EINVAL; |
1391 | break; |
1445 | break; |
1392 | } |
1446 | } |
1393 | i = IPC_GET_ARG2(*call); |
1447 | i = IPC_GET_ARG2(*call); |
1394 | retval = draw_pixmap(nvp, i); |
1448 | retval = draw_pixmap(nvp, i); |
1395 | break; |
1449 | break; |
1396 | case FB_VP2PIXMAP: |
1450 | case FB_VP2PIXMAP: |
1397 | nvp = IPC_GET_ARG1(*call); |
1451 | nvp = IPC_GET_ARG1(*call); |
1398 | if (nvp == -1) |
1452 | if (nvp == -1) |
1399 | nvp = vp; |
1453 | nvp = vp; |
1400 | if (nvp < 0 || nvp >= MAX_VIEWPORTS || |
1454 | if (nvp < 0 || nvp >= MAX_VIEWPORTS || |
1401 | !viewports[nvp].initialized) |
1455 | !viewports[nvp].initialized) |
1402 | retval = EINVAL; |
1456 | retval = EINVAL; |
1403 | else |
1457 | else |
1404 | retval = save_vp_to_pixmap(&viewports[nvp]); |
1458 | retval = save_vp_to_pixmap(&viewports[nvp]); |
1405 | break; |
1459 | break; |
1406 | case FB_DROP_PIXMAP: |
1460 | case FB_DROP_PIXMAP: |
1407 | i = IPC_GET_ARG1(*call); |
1461 | i = IPC_GET_ARG1(*call); |
1408 | if (i >= MAX_PIXMAPS) { |
1462 | if (i >= MAX_PIXMAPS) { |
1409 | retval = EINVAL; |
1463 | retval = EINVAL; |
1410 | break; |
1464 | break; |
1411 | } |
1465 | } |
1412 | if (pixmaps[i].data) { |
1466 | if (pixmaps[i].data) { |
1413 | free(pixmaps[i].data); |
1467 | free(pixmaps[i].data); |
1414 | pixmaps[i].data = NULL; |
1468 | pixmaps[i].data = NULL; |
1415 | } |
1469 | } |
1416 | break; |
1470 | break; |
1417 | default: |
1471 | default: |
1418 | handled = 0; |
1472 | handled = 0; |
1419 | } |
1473 | } |
1420 | 1474 | ||
1421 | if (handled) |
1475 | if (handled) |
1422 | ipc_answer_0(callid, retval); |
1476 | ipc_answer_0(callid, retval); |
1423 | return handled; |
1477 | return handled; |
1424 | 1478 | ||
1425 | } |
1479 | } |
1426 | 1480 | ||
1427 | static int rgb_from_style(attr_rgb_t *rgb, int style) |
1481 | static int rgb_from_style(attr_rgb_t *rgb, int style) |
1428 | { |
1482 | { |
1429 | switch (style) { |
1483 | switch (style) { |
1430 | case STYLE_NORMAL: |
1484 | case STYLE_NORMAL: |
1431 | rgb->fg_color = color_table[COLOR_BLACK]; |
1485 | rgb->fg_color = color_table[COLOR_BLACK]; |
1432 | rgb->bg_color = color_table[COLOR_WHITE]; |
1486 | rgb->bg_color = color_table[COLOR_WHITE]; |
1433 | break; |
1487 | break; |
1434 | case STYLE_EMPHASIS: |
1488 | case STYLE_EMPHASIS: |
1435 | rgb->fg_color = color_table[COLOR_RED]; |
1489 | rgb->fg_color = color_table[COLOR_RED]; |
1436 | rgb->bg_color = color_table[COLOR_WHITE]; |
1490 | rgb->bg_color = color_table[COLOR_WHITE]; |
1437 | break; |
1491 | break; |
1438 | default: |
1492 | default: |
1439 | return EINVAL; |
1493 | return EINVAL; |
1440 | } |
1494 | } |
1441 | 1495 | ||
1442 | return EOK; |
1496 | return EOK; |
1443 | } |
1497 | } |
1444 | 1498 | ||
1445 | static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color, |
1499 | static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color, |
1446 | ipcarg_t bg_color, ipcarg_t flags) |
1500 | ipcarg_t bg_color, ipcarg_t flags) |
1447 | { |
1501 | { |
1448 | fg_color = (fg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0); |
1502 | fg_color = (fg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0); |
1449 | bg_color = (bg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0); |
1503 | bg_color = (bg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0); |
1450 | 1504 | ||
1451 | rgb->fg_color = color_table[fg_color]; |
1505 | rgb->fg_color = color_table[fg_color]; |
1452 | rgb->bg_color = color_table[bg_color]; |
1506 | rgb->bg_color = color_table[bg_color]; |
1453 | 1507 | ||
1454 | return EOK; |
1508 | return EOK; |
1455 | } |
1509 | } |
1456 | 1510 | ||
1457 | static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a) |
1511 | static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a) |
1458 | { |
1512 | { |
1459 | int rc; |
1513 | int rc; |
1460 | 1514 | ||
1461 | switch (a->t) { |
1515 | switch (a->t) { |
1462 | case at_style: |
1516 | case at_style: |
1463 | rc = rgb_from_style(rgb, a->a.s.style); |
1517 | rc = rgb_from_style(rgb, a->a.s.style); |
1464 | break; |
1518 | break; |
1465 | case at_idx: |
1519 | case at_idx: |
1466 | rc = rgb_from_idx(rgb, a->a.i.fg_color, |
1520 | rc = rgb_from_idx(rgb, a->a.i.fg_color, |
1467 | a->a.i.bg_color, a->a.i.flags); |
1521 | a->a.i.bg_color, a->a.i.flags); |
1468 | break; |
1522 | break; |
1469 | case at_rgb: |
1523 | case at_rgb: |
1470 | *rgb = a->a.r; |
1524 | *rgb = a->a.r; |
1471 | rc = EOK; |
1525 | rc = EOK; |
1472 | break; |
1526 | break; |
1473 | } |
1527 | } |
1474 | 1528 | ||
1475 | return rc; |
1529 | return rc; |
1476 | } |
1530 | } |
1477 | 1531 | ||
1478 | static int fb_set_style(viewport_t *vport, ipcarg_t style) |
1532 | static int fb_set_style(viewport_t *vport, ipcarg_t style) |
1479 | { |
1533 | { |
1480 | return rgb_from_style(&vport->attr, (int) style); |
1534 | return rgb_from_style(&vport->attr, (int) style); |
1481 | } |
1535 | } |
1482 | 1536 | ||
1483 | static int fb_set_color(viewport_t *vport, ipcarg_t fg_color, |
1537 | static int fb_set_color(viewport_t *vport, ipcarg_t fg_color, |
1484 | ipcarg_t bg_color, ipcarg_t flags) |
1538 | ipcarg_t bg_color, ipcarg_t flags) |
1485 | { |
1539 | { |
1486 | return rgb_from_idx(&vport->attr, fg_color, bg_color, flags); |
1540 | return rgb_from_idx(&vport->attr, fg_color, bg_color, flags); |
1487 | } |
1541 | } |
1488 | 1542 | ||
1489 | /** Function for handling connections to FB |
1543 | /** Function for handling connections to FB |
1490 | * |
1544 | * |
1491 | */ |
1545 | */ |
1492 | static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
1546 | static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
1493 | { |
1547 | { |
1494 | unsigned int vp = 0; |
1548 | unsigned int vp = 0; |
1495 | viewport_t *vport = &viewports[vp]; |
1549 | viewport_t *vport = &viewports[vp]; |
1496 | 1550 | ||
1497 | if (client_connected) { |
1551 | if (client_connected) { |
1498 | ipc_answer_0(iid, ELIMIT); |
1552 | ipc_answer_0(iid, ELIMIT); |
1499 | return; |
1553 | return; |
1500 | } |
1554 | } |
1501 | 1555 | ||
1502 | /* Accept connection */ |
1556 | /* Accept connection */ |
1503 | client_connected = true; |
1557 | client_connected = true; |
1504 | ipc_answer_0(iid, EOK); |
1558 | ipc_answer_0(iid, EOK); |
1505 | 1559 | ||
1506 | while (true) { |
1560 | while (true) { |
1507 | ipc_callid_t callid; |
1561 | ipc_callid_t callid; |
1508 | ipc_call_t call; |
1562 | ipc_call_t call; |
1509 | int retval; |
1563 | int retval; |
1510 | unsigned int i; |
1564 | unsigned int i; |
1511 | int scroll; |
1565 | int scroll; |
1512 | wchar_t ch; |
1566 | wchar_t ch; |
1513 | unsigned int row, col; |
1567 | unsigned int row, col; |
1514 | 1568 | ||
1515 | if ((vport->cursor_active) || (anims_enabled)) |
1569 | if ((vport->cursor_active) || (anims_enabled)) |
1516 | callid = async_get_call_timeout(&call, 250000); |
1570 | callid = async_get_call_timeout(&call, 250000); |
1517 | else |
1571 | else |
1518 | callid = async_get_call(&call); |
1572 | callid = async_get_call(&call); |
1519 | 1573 | ||
1520 | mouse_hide(); |
1574 | mouse_hide(); |
1521 | if (!callid) { |
1575 | if (!callid) { |
1522 | cursor_blink(vport); |
1576 | cursor_blink(vport); |
1523 | anims_tick(); |
1577 | anims_tick(); |
1524 | mouse_show(); |
1578 | mouse_show(); |
1525 | continue; |
1579 | continue; |
1526 | } |
1580 | } |
1527 | 1581 | ||
1528 | if (shm_handle(callid, &call, vp)) |
1582 | if (shm_handle(callid, &call, vp)) |
1529 | continue; |
1583 | continue; |
1530 | 1584 | ||
1531 | if (pixmap_handle(callid, &call, vp)) |
1585 | if (pixmap_handle(callid, &call, vp)) |
1532 | continue; |
1586 | continue; |
1533 | 1587 | ||
1534 | if (anim_handle(callid, &call, vp)) |
1588 | if (anim_handle(callid, &call, vp)) |
1535 | continue; |
1589 | continue; |
1536 | 1590 | ||
1537 | switch (IPC_GET_METHOD(call)) { |
1591 | switch (IPC_GET_METHOD(call)) { |
1538 | case IPC_M_PHONE_HUNGUP: |
1592 | case IPC_M_PHONE_HUNGUP: |
1539 | client_connected = false; |
1593 | client_connected = false; |
1540 | 1594 | ||
1541 | /* Cleanup other viewports */ |
1595 | /* Cleanup other viewports */ |
1542 | for (i = 1; i < MAX_VIEWPORTS; i++) |
1596 | for (i = 1; i < MAX_VIEWPORTS; i++) |
1543 | vport->initialized = false; |
1597 | vport->initialized = false; |
1544 | 1598 | ||
1545 | /* Exit thread */ |
1599 | /* Exit thread */ |
1546 | return; |
1600 | return; |
1547 | 1601 | ||
1548 | case FB_PUTCHAR: |
1602 | case FB_PUTCHAR: |
1549 | ch = IPC_GET_ARG1(call); |
1603 | ch = IPC_GET_ARG1(call); |
1550 | row = IPC_GET_ARG2(call); |
1604 | row = IPC_GET_ARG2(call); |
1551 | col = IPC_GET_ARG3(call); |
1605 | col = IPC_GET_ARG3(call); |
1552 | 1606 | ||
1553 | if ((col >= vport->cols) || (row >= vport->rows)) { |
1607 | if ((col >= vport->cols) || (row >= vport->rows)) { |
1554 | retval = EINVAL; |
1608 | retval = EINVAL; |
1555 | break; |
1609 | break; |
1556 | } |
1610 | } |
1557 | ipc_answer_0(callid, EOK); |
1611 | ipc_answer_0(callid, EOK); |
1558 | 1612 | ||
1559 | draw_char(vport, ch, col, row); |
1613 | draw_char(vport, ch, col, row); |
1560 | 1614 | ||
1561 | /* Message already answered */ |
1615 | /* Message already answered */ |
1562 | continue; |
1616 | continue; |
1563 | case FB_CLEAR: |
1617 | case FB_CLEAR: |
1564 | vport_clear(vport); |
1618 | vport_clear(vport); |
1565 | cursor_show(vport); |
1619 | cursor_show(vport); |
1566 | retval = EOK; |
1620 | retval = EOK; |
1567 | break; |
1621 | break; |
1568 | case FB_CURSOR_GOTO: |
1622 | case FB_CURSOR_GOTO: |
1569 | row = IPC_GET_ARG1(call); |
1623 | row = IPC_GET_ARG1(call); |
1570 | col = IPC_GET_ARG2(call); |
1624 | col = IPC_GET_ARG2(call); |
1571 | 1625 | ||
1572 | if ((col >= vport->cols) || (row >= vport->rows)) { |
1626 | if ((col >= vport->cols) || (row >= vport->rows)) { |
1573 | retval = EINVAL; |
1627 | retval = EINVAL; |
1574 | break; |
1628 | break; |
1575 | } |
1629 | } |
1576 | retval = EOK; |
1630 | retval = EOK; |
1577 | 1631 | ||
1578 | cursor_hide(vport); |
1632 | cursor_hide(vport); |
1579 | vport->cur_col = col; |
1633 | vport->cur_col = col; |
1580 | vport->cur_row = row; |
1634 | vport->cur_row = row; |
1581 | cursor_show(vport); |
1635 | cursor_show(vport); |
1582 | break; |
1636 | break; |
1583 | case FB_CURSOR_VISIBILITY: |
1637 | case FB_CURSOR_VISIBILITY: |
1584 | cursor_hide(vport); |
1638 | cursor_hide(vport); |
1585 | vport->cursor_active = IPC_GET_ARG1(call); |
1639 | vport->cursor_active = IPC_GET_ARG1(call); |
1586 | cursor_show(vport); |
1640 | cursor_show(vport); |
1587 | retval = EOK; |
1641 | retval = EOK; |
1588 | break; |
1642 | break; |
1589 | case FB_GET_CSIZE: |
1643 | case FB_GET_CSIZE: |
1590 | ipc_answer_2(callid, EOK, vport->rows, vport->cols); |
1644 | ipc_answer_2(callid, EOK, vport->rows, vport->cols); |
1591 | continue; |
1645 | continue; |
1592 | case FB_SCROLL: |
1646 | case FB_SCROLL: |
1593 | scroll = IPC_GET_ARG1(call); |
1647 | scroll = IPC_GET_ARG1(call); |
1594 | if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) { |
1648 | if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) { |
1595 | retval = EINVAL; |
1649 | retval = EINVAL; |
1596 | break; |
1650 | break; |
1597 | } |
1651 | } |
1598 | cursor_hide(vport); |
1652 | cursor_hide(vport); |
1599 | vport_scroll(vport, scroll); |
1653 | vport_scroll(vport, scroll); |
1600 | cursor_show(vport); |
1654 | cursor_show(vport); |
1601 | retval = EOK; |
1655 | retval = EOK; |
1602 | break; |
1656 | break; |
1603 | case FB_VIEWPORT_SWITCH: |
1657 | case FB_VIEWPORT_SWITCH: |
1604 | i = IPC_GET_ARG1(call); |
1658 | i = IPC_GET_ARG1(call); |
1605 | if (i >= MAX_VIEWPORTS) { |
1659 | if (i >= MAX_VIEWPORTS) { |
1606 | retval = EINVAL; |
1660 | retval = EINVAL; |
1607 | break; |
1661 | break; |
1608 | } |
1662 | } |
1609 | if (!viewports[i].initialized) { |
1663 | if (!viewports[i].initialized) { |
1610 | retval = EADDRNOTAVAIL; |
1664 | retval = EADDRNOTAVAIL; |
1611 | break; |
1665 | break; |
1612 | } |
1666 | } |
1613 | cursor_hide(vport); |
1667 | cursor_hide(vport); |
1614 | vp = i; |
1668 | vp = i; |
1615 | vport = &viewports[vp]; |
1669 | vport = &viewports[vp]; |
1616 | cursor_show(vport); |
1670 | cursor_show(vport); |
1617 | retval = EOK; |
1671 | retval = EOK; |
1618 | break; |
1672 | break; |
1619 | case FB_VIEWPORT_CREATE: |
1673 | case FB_VIEWPORT_CREATE: |
1620 | retval = vport_create(IPC_GET_ARG1(call) >> 16, |
1674 | retval = vport_create(IPC_GET_ARG1(call) >> 16, |
1621 | IPC_GET_ARG1(call) & 0xffff, |
1675 | IPC_GET_ARG1(call) & 0xffff, |
1622 | IPC_GET_ARG2(call) >> 16, |
1676 | IPC_GET_ARG2(call) >> 16, |
1623 | IPC_GET_ARG2(call) & 0xffff); |
1677 | IPC_GET_ARG2(call) & 0xffff); |
1624 | break; |
1678 | break; |
1625 | case FB_VIEWPORT_DELETE: |
1679 | case FB_VIEWPORT_DELETE: |
1626 | i = IPC_GET_ARG1(call); |
1680 | i = IPC_GET_ARG1(call); |
1627 | if (i >= MAX_VIEWPORTS) { |
1681 | if (i >= MAX_VIEWPORTS) { |
1628 | retval = EINVAL; |
1682 | retval = EINVAL; |
1629 | break; |
1683 | break; |
1630 | } |
1684 | } |
1631 | if (!viewports[i].initialized) { |
1685 | if (!viewports[i].initialized) { |
1632 | retval = EADDRNOTAVAIL; |
1686 | retval = EADDRNOTAVAIL; |
1633 | break; |
1687 | break; |
1634 | } |
1688 | } |
1635 | viewports[i].initialized = false; |
1689 | viewports[i].initialized = false; |
1636 | if (viewports[i].bgpixel) |
1690 | if (viewports[i].bgpixel) |
1637 | free(viewports[i].bgpixel); |
1691 | free(viewports[i].bgpixel); |
1638 | if (viewports[i].backbuf) |
1692 | if (viewports[i].backbuf) |
1639 | free(viewports[i].backbuf); |
1693 | free(viewports[i].backbuf); |
1640 | retval = EOK; |
1694 | retval = EOK; |
1641 | break; |
1695 | break; |
1642 | case FB_SET_STYLE: |
1696 | case FB_SET_STYLE: |
1643 | retval = fb_set_style(vport, IPC_GET_ARG1(call)); |
1697 | retval = fb_set_style(vport, IPC_GET_ARG1(call)); |
1644 | break; |
1698 | break; |
1645 | case FB_SET_COLOR: |
1699 | case FB_SET_COLOR: |
1646 | retval = fb_set_color(vport, IPC_GET_ARG1(call), |
1700 | retval = fb_set_color(vport, IPC_GET_ARG1(call), |
1647 | IPC_GET_ARG2(call), IPC_GET_ARG3(call)); |
1701 | IPC_GET_ARG2(call), IPC_GET_ARG3(call)); |
1648 | break; |
1702 | break; |
1649 | case FB_SET_RGB_COLOR: |
1703 | case FB_SET_RGB_COLOR: |
1650 | vport->attr.fg_color = IPC_GET_ARG1(call); |
1704 | vport->attr.fg_color = IPC_GET_ARG1(call); |
1651 | vport->attr.bg_color = IPC_GET_ARG2(call); |
1705 | vport->attr.bg_color = IPC_GET_ARG2(call); |
1652 | retval = EOK; |
1706 | retval = EOK; |
1653 | break; |
1707 | break; |
1654 | case FB_GET_RESOLUTION: |
1708 | case FB_GET_RESOLUTION: |
1655 | ipc_answer_2(callid, EOK, screen.xres, screen.yres); |
1709 | ipc_answer_2(callid, EOK, screen.xres, screen.yres); |
1656 | continue; |
1710 | continue; |
1657 | case FB_POINTER_MOVE: |
1711 | case FB_POINTER_MOVE: |
1658 | pointer_enabled = true; |
1712 | pointer_enabled = true; |
1659 | mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
1713 | mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
1660 | retval = EOK; |
1714 | retval = EOK; |
- | 1715 | break; |
|
- | 1716 | case FB_SCREEN_YIELD: |
|
- | 1717 | case FB_SCREEN_RECLAIM: |
|
- | 1718 | retval = EOK; |
|
1661 | break; |
1719 | break; |
1662 | default: |
1720 | default: |
1663 | retval = ENOENT; |
1721 | retval = ENOENT; |
1664 | } |
1722 | } |
1665 | ipc_answer_0(callid, retval); |
1723 | ipc_answer_0(callid, retval); |
1666 | } |
1724 | } |
1667 | } |
1725 | } |
1668 | 1726 | ||
1669 | /** Initialization of framebuffer |
1727 | /** Initialization of framebuffer |
1670 | * |
1728 | * |
1671 | */ |
1729 | */ |
1672 | int fb_init(void) |
1730 | int fb_init(void) |
1673 | { |
1731 | { |
1674 | async_set_client_connection(fb_client_connection); |
1732 | async_set_client_connection(fb_client_connection); |
1675 | 1733 | ||
1676 | void *fb_ph_addr = (void *) sysinfo_value("fb.address.physical"); |
1734 | void *fb_ph_addr = (void *) sysinfo_value("fb.address.physical"); |
1677 | unsigned int fb_offset = sysinfo_value("fb.offset"); |
1735 | unsigned int fb_offset = sysinfo_value("fb.offset"); |
1678 | unsigned int fb_width = sysinfo_value("fb.width"); |
1736 | unsigned int fb_width = sysinfo_value("fb.width"); |
1679 | unsigned int fb_height = sysinfo_value("fb.height"); |
1737 | unsigned int fb_height = sysinfo_value("fb.height"); |
1680 | unsigned int fb_scanline = sysinfo_value("fb.scanline"); |
1738 | unsigned int fb_scanline = sysinfo_value("fb.scanline"); |
1681 | unsigned int fb_visual = sysinfo_value("fb.visual"); |
1739 | unsigned int fb_visual = sysinfo_value("fb.visual"); |
1682 | 1740 | ||
1683 | unsigned int fbsize = fb_scanline * fb_height; |
1741 | unsigned int fbsize = fb_scanline * fb_height; |
1684 | void *fb_addr = as_get_mappable_page(fbsize); |
1742 | void *fb_addr = as_get_mappable_page(fbsize); |
1685 | 1743 | ||
1686 | if (physmem_map(fb_ph_addr + fb_offset, fb_addr, |
1744 | if (physmem_map(fb_ph_addr + fb_offset, fb_addr, |
1687 | ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0) |
1745 | ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0) |
1688 | return -1; |
1746 | return -1; |
1689 | 1747 | ||
1690 | if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual)) |
1748 | if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual)) |
1691 | return 0; |
1749 | return 0; |
1692 | 1750 | ||
1693 | return -1; |
1751 | return -1; |
1694 | } |
1752 | } |
1695 | 1753 | ||
1696 | /** |
1754 | /** |
1697 | * @} |
1755 | * @} |
1698 | */ |
1756 | */ |
1699 | 1757 |