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